Using Workflow to implement a quota
Need guidance on best practice for implementing a simple quota system
I'd like to limit the number of times a Member can add a custom content type (called Token) to their Member Folder (I've also created a custom Member Folder).
Use Case (limit number of tokens addable by a Member):
Let's assume that our custom content type is called a 'Token'. It should be possible to set a limit on the number of tokens that can be added. E.g. the limit is set to 2. After adding two tokens to their Member Area they no longer have permission to add further tokens.
What I'm considering
I'm looking into DCWorkflow and wondering if some kind of guard condition may be an option. I also l开发者_StackOverflowooked at the source code for an addon called 'quota' which uses a class/require zcml directive (code is here: http://svn.plone.org/svn/collective/quota/trunk/configure.zcml).
It seems that I may need to customize the Member Folder and not the workflow on the 'Token' itself. I would appreciate any pointers/guidance on this.
I don't believe this can be achieved with workflow, as adding content is not a workflow action. I would use a custom add form for your token type, and disallow content creation when the user already has two or more tokens.
You could monitor count of added content type objects with events and revoke the add permission when object count exceeds your limit.
Event docs: http://plone.org/products/dexterity/documentation/manual/five.grok/core-components/events
Permission revoking could be done for example with groups. Just remove user from the group that is allowed to add content.
You can also override the allowedContentTypes method of your Member Folder.
You can filter from the returned list any AT type based on whatever you want.
The good thing is that you get also the classic "add new" drop down menu updated with the list of addable types.
I did this in a project where I needed to limit number of items by group/role.
精彩评论