Back to index

plone3  3.1.7
autogroup.py
Go to the documentation of this file.
00001 from Globals import InitializeClass
00002 import Acquisition
00003 from Products.PluggableAuthService.plugins.BasePlugin import BasePlugin
00004 from Products.PluggableAuthService.interfaces.plugins import IGroupEnumerationPlugin
00005 from Products.PluggableAuthService.interfaces.plugins import IGroupsPlugin
00006 from Products.PluggableAuthService.utils import classImplements
00007 from Products.PlonePAS.interfaces.group import IGroupIntrospection
00008 
00009 
00010 from Products.PageTemplates.PageTemplateFile import PageTemplateFile
00011 
00012 manage_addAutoGroupForm = PageTemplateFile("../zmi/AutoGroupForm", globals())
00013 
00014 def manage_addAutoGroup(self, id, title='', group='', description='', RESPONSE=None):
00015     """Add an Auto Group plugin."""
00016 
00017     plugin = AutoGroup(id, title, group, description)
00018     self._setObject(id, plugin)
00019 
00020     if RESPONSE is not None:
00021         return RESPONSE.redirect("%s/manage_workspace?manage_tabs_message=AutoGroup+plugin+added" %
00022                 self.absolute_url())
00023 
00024 
00025 class VirtualGroup(Acquisition.Implicit):
00026     def __init__(self, id, description):
00027         self.id = id
00028         self.title = description
00029 
00030     def getId(self):
00031         return self.id
00032 
00033     def getUserName(self):
00034         return self.id
00035 
00036     def getName(self):
00037         return self.id
00038 
00039     def getMemberIds(self, transitive=1):
00040         return []
00041 
00042     def getRolesInContext(self, context):
00043         return []
00044 
00045     def getRoles(self):
00046         return []
00047 
00048     def allowed(self, object, obect_roles=None):
00049         return 0
00050 
00051     def getDomains(self):
00052         return []
00053 
00054     def isGroup(self):
00055         return True
00056 
00057 
00058 
00059 
00060 class AutoGroup(BasePlugin):
00061     meta_type = "Automatic Group Plugin"
00062 
00063     _properties = (
00064             { 'id'      : 'title',
00065               'label'   : 'Title',
00066               'type'    : 'string',
00067               'mode'    : 'w',
00068             },
00069             { 'id'      : 'group',
00070               'label'   : 'Group',
00071               'type'    : 'string',
00072               'mode'    : 'w',
00073             },
00074             { 'id'      : 'description',
00075               'label'   : 'Description',
00076               'type'    : 'string',
00077               'mode'    : 'w',
00078             },
00079             )
00080                 
00081 
00082     def __init__(self, id, title='', group=None, description=''):
00083         self._setId(id)
00084         self.title = title
00085         self.group = group
00086         self.description = description
00087 
00088     # IGroupEnumerationPlugin implementation
00089     def enumerateGroups(self, id=None, exact_match=False, sort_by=None, max_results=None, **kw):
00090         if kw:
00091             return []
00092 
00093         if id:
00094             id = id.lower()
00095             mygroup = self.group.lower()
00096 
00097             if exact_match and id!=mygroup:
00098                 return []
00099 
00100             if not exact_match and id not in mygroup:
00101                 return []
00102 
00103         return [ { 'id' : self.group,
00104                    'groupid' : self.group,
00105                    'title' : self.description,
00106                    'pluginid' : self.getId(),
00107                } ]
00108 
00109 
00110     # IGroupsPlugin implementation
00111     def getGroupsForPrincipal(self, principal, request=None):
00112         return (self.group,)
00113 
00114 
00115     # IGroupIntrospection implementation
00116     def getGroupById(self, group_id):
00117         if group_id != self.group:
00118             return None
00119 
00120         return VirtualGroup(self.group, self.description)
00121 
00122 
00123     def getGroups(self):
00124         return [self.getGroupById(id) for id in self.getGroupIds()]
00125 
00126 
00127     def getGroupIds(self):
00128         return [ self.group ]
00129 
00130 
00131     def getGroupMembers(self, group_id):
00132         return ()
00133 
00134 classImplements(AutoGroup, IGroupEnumerationPlugin, IGroupsPlugin, IGroupIntrospection)
00135 InitializeClass(AutoGroup)
00136