collective / collective.workspace

Restricted workspaces for Plone
7 stars 11 forks source link

Can this be made to work with ATFolder? #7

Closed sureshvv closed 9 years ago

sureshvv commented 9 years ago

For Plone 4.3

davisagli commented 9 years ago

You obviously can't use the behavior with an Archetypes-based content type, but you can write your own workspace adapter and it will work. I've done so with the ATContentTypes event content type to handle event registration.

sureshvv commented 9 years ago

Great. There is some sample code to write an adapter on the README file.

from collective.workspace.workspace import Workspace
class MyWorkspace(Workspace):
    """
    A custom workspace behaviour, based on collective.workspace
    """
    # A list of groups to which team members can be assigned.
    # Maps group name -> roles
    available_groups = {
        u'Supervillians': ('Reader', ),
        u'Superheroes': ('Reader', 'Contributor', 'Reviewer', 'Editor',),
    }

Can the configure.zcml just say:

<adapter
     for="Products.ATContentTypes.content.folder.ATFolder"
     provides="collective.workspace.interfaces.IWorkspace"
     factory=".adapters.MyWorkspace"
/>

Is this enough? Or does anything special need to be done inside the adapter. Any pointers/sample code appreciated.

davisagli commented 9 years ago

Yeah, I think that's all you need to do. If you don't specify available_groups in your workspace adapter you'll inherit the default ones from the Workspace base class (Members and Admins).

If you want to add custom fields for each member of the roster, you can do that like this:

from collective.workspace.membership import ITeamMembership
from collective.workspace.membership import TeamMembership
from collective.workspace.workspace import Workspace
from zope import schema

class IFolderMembership(ITeamMembership):
    notes = schema.Text(title=u'Notes', required=False)

class FolderMembership(TeamMembership):
    _schema = IFolderMembership

class FolderWorkspace(Workspace):  # this is the same as MyWorkspace in the example above
    membership_schema = IFolderMembership
    membership_factory = FolderMembership

You can also implement handle_added, handle_modified and handle_removed callbacks on the Membership class if you need to perform custom logic when members are added, updated, or removed.

sureshvv commented 9 years ago

Thanks David, for your response and all your contributions to Open source and Plone.