Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 looked 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.

like image 668
David Bain Avatar asked Jul 04 '11 16:07

David Bain


3 Answers

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.

like image 171
Laurence Rowe Avatar answered Oct 29 '22 00:10

Laurence Rowe


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.

like image 42
Epeli Avatar answered Oct 29 '22 01:10

Epeli


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.

like image 40
simahawk Avatar answered Oct 29 '22 01:10

simahawk