Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions
PlonePAS.tools.groups.GroupsTool Class Reference
Collaboration diagram for PlonePAS.tools.groups.GroupsTool:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def invalidateGroup
 basic group mgmt
def addGroup
def editGroup
def removeGroup
def removeGroups
def setRolesForGroup
def addPrincipalToGroup
 basic principal mgmt
def removePrincipalFromGroup
def getGroupById
 group getters
def searchGroups
def searchForGroups
def listGroups
def getGroupIds
def getGroupMembers
def getGroupsForPrincipal

Static Public Attributes

string id = 'portal_groups'
string meta_type = 'PlonePAS Groups Tool'
tuple security = ClassSecurityInfo()
string toolicon = 'tool.gif'
 listGroupIds = getGroupIds

Private Member Functions

def _getPlugins
 plugin getters
def _getGroupManagers
def _getGroupIntrospectors
def _getGroupSpaceManagers

Detailed Description

Replace the GRUF groups tool with PAS-specific methods.

Definition at line 42 of file groups.py.


Member Function Documentation

Definition at line 368 of file groups.py.

00368 
00369     def _getGroupIntrospectors(self):
00370         return self._getPlugins().listPlugins(
00371             igroup.IGroupIntrospection
00372             )

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 362 of file groups.py.

00362 
00363     def _getGroupManagers(self):
00364         return self._getPlugins().listPlugins(
00365             igroup.IGroupManagement
00366             )

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 374 of file groups.py.

00374 
00375     def _getGroupSpaceManagers(self):
00376         return self._getPlugins().listPlugins(
00377             igroup.IGroupSpaceManagers
00378             )
00379 
00380 classImplements(GroupsTool,
00381                 *tuple(implementedBy(PloneGroupsTool)) +
00382                 (igroup.IGroupTool,))
00383 
00384 InitializeClass(GroupsTool)
00385 registerToolInterface('portal_groups', igroup.IGroupTool)

Here is the call graph for this function:

plugin getters

Definition at line 358 of file groups.py.

00358 
00359     def _getPlugins(self):
00360         return self.acl_users.plugins

Here is the caller graph for this function:

def PlonePAS.tools.groups.GroupsTool.addGroup (   self,
  id,
  roles = [],
  groups = [],
  properties = None,
  REQUEST = None,
  args,
  kw 
)

Definition at line 63 of file groups.py.

00063 
00064                  REQUEST=None, *args, **kw):
00065         group = None
00066         success = 0
00067         managers = self._getGroupManagers()
00068         if roles is None:
00069             roles = []
00070         if groups is None:
00071             groups = []
00072 
00073         # Check to see if a user with the id already exists fail if it does
00074         results = self.acl_users.searchPrincipals(id=id, exact_match=True)
00075         if results:
00076             return 0
00077 
00078         if not managers:
00079             raise NotSupported, 'No plugins allow for group management'
00080         for mid, manager in managers:
00081             success = manager.addGroup(id, title=kw.get('title', id),
00082                                        description=kw.get('title', None))
00083             if success:
00084                 self.setRolesForGroup(id, roles)
00085                 for g in groups:
00086                     manager.addPrincipalToGroup(g, id)
00087                 break
00088 
00089         if success:
00090             group = self.getGroupById(id)
00091             group.setGroupProperties(properties or kw)
00092             self.createGrouparea(id)
00093 
00094         return success

Here is the call graph for this function:

Here is the caller graph for this function:

def PlonePAS.tools.groups.GroupsTool.addPrincipalToGroup (   self,
  principal_id,
  group_id,
  REQUEST = None 
)

basic principal mgmt

Definition at line 188 of file groups.py.

00188 
00189     def addPrincipalToGroup(self, principal_id, group_id, REQUEST=None):
00190         managers = self._getGroupManagers()
00191         if not managers:
00192             raise NotSupported, 'No plugins allow for group management'
00193         for mid, manager in managers:
00194             if manager.addPrincipalToGroup(principal_id, group_id):
00195                 return True
00196         return False

Here is the call graph for this function:

Here is the caller graph for this function:

def PlonePAS.tools.groups.GroupsTool.editGroup (   self,
  id,
  roles = None,
  groups = None,
  REQUEST = None,
  args,
  kw 
)
Edit the given group with the supplied roles.

Passwords for groups seem to be irrelevant.
PlonePAS doesn't deal with domains either.

If user is not present, returns without exception.

Definition at line 96 of file groups.py.

00096 
00097     def editGroup(self, id, roles=None, groups=None, REQUEST=None, *args, **kw):
00098         """Edit the given group with the supplied roles.
00099 
00100         Passwords for groups seem to be irrelevant.
00101         PlonePAS doesn't deal with domains either.
00102 
00103         If user is not present, returns without exception.
00104         """
00105         g = self.getGroupById(id)
00106         if not g:
00107             raise KeyError, 'Trying to edit a non-existing group: %s' % id
00108 
00109         if roles is not None:
00110             self.setRolesForGroup(id, roles)
00111         g.setGroupProperties(kw)
00112         if groups:
00113             # remove absent groups
00114             groupset = Set(groups)
00115             p_groups = Set(self.getGroupsForPrincipal(g))
00116             rmgroups = p_groups - groupset
00117             for gid in rmgroups:
00118                 self.removePrincipalFromGroup(g, gid)
00119 
00120             # add groups
00121             try:
00122                 groupmanagers = self._getGroupManagers()
00123             except _SWALLOWABLE_PLUGIN_EXCEPTIONS:
00124                 log('Plugin listing error')
00125                 groupmanagers = ()
00126 
00127             for group in groups:
00128                 for gm_id, gm in groupmanagers:
00129                     try:
00130                         if gm.addPrincipalToGroup(id, group):
00131                             break
00132                     except _SWALLOWABLE_PLUGIN_EXCEPTIONS:
00133                         log('AuthenticationPlugin %s error' % gm_id)

Here is the call graph for this function:

def PlonePAS.tools.groups.GroupsTool.getGroupById (   self,
  group_id 
)

group getters

Definition at line 213 of file groups.py.

00213 
00214     def getGroupById(self, group_id):
00215         group = self.acl_users.getGroup(group_id)
00216         if group is not None:
00217             group = self.wrapGroup(group)
00218         return group

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 318 of file groups.py.

00318 
00319     def getGroupIds(self):
00320         groups = []
00321         introspectors = self._getGroupIntrospectors()
00322         for iid, introspector in introspectors:
00323             groups.extend(introspector.getGroupIds())
00324         return groups

Here is the call graph for this function:

def PlonePAS.tools.groups.GroupsTool.getGroupMembers (   self,
  group_id 
)

Definition at line 331 of file groups.py.

00331 
00332     def getGroupMembers(self, group_id):
00333         members = []
00334         introspectors = self._getGroupIntrospectors()
00335         for iid, introspector in introspectors:
00336             members = introspector.getGroupMembers(group_id)
00337             if members:
00338                 break
00339         return members
00340 

Here is the call graph for this function:

Definition at line 345 of file groups.py.

00345 
00346     def getGroupsForPrincipal(self, principal):
00347         introspectors = self._getGroupIntrospectors()
00348         for iid, introspector in introspectors:
00349             groups = introspector.getGroupsForPrincipal(principal)
00350             if groups:
00351                 break
00352         return groups

Here is the call graph for this function:

Here is the caller graph for this function:

basic group mgmt

Definition at line 57 of file groups.py.

00057 
00058     def invalidateGroup(self, id):
00059         view_name = '_findGroup-%s' % id
00060         self.acl_users.ZCacheable_invalidate(view_name=view_name)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 306 of file groups.py.

00306 
00307     def listGroups(self):
00308         # potentially not all groups may be found by this interface
00309         # if the underlying group source doesn't support introspection
00310         groups = []
00311         introspectors = self._getGroupIntrospectors()
00312         for iid, introspector in introspectors:
00313             groups.extend(introspector.getGroups())
00314         return [self.wrapGroup(elt) for elt in groups]

Here is the call graph for this function:

def PlonePAS.tools.groups.GroupsTool.removeGroup (   self,
  group_id,
  keep_workspaces = 0,
  REQUEST = None 
)
Remove a single group, including group workspace, unless
keep_workspaces==true.

Definition at line 136 of file groups.py.

00136 
00137     def removeGroup(self, group_id, keep_workspaces=0, REQUEST=None):
00138         """Remove a single group, including group workspace, unless
00139         keep_workspaces==true.
00140         """
00141         retval = False
00142         managers = self._getGroupManagers()
00143         if not managers:
00144             raise NotSupported, 'No plugins allow for group management'
00145 
00146         for mid, manager in managers:
00147             if manager.removeGroup(group_id):
00148                 retval = True
00149 
00150         gwf = self.getGroupWorkspacesFolder()
00151         if retval and gwf and not keep_workspaces:
00152             grouparea = self.getGroupareaFolder(group_id)
00153             if grouparea is not None:
00154                 workspace_id = grouparea.getId()
00155                 if hasattr(aq_base(gwf), workspace_id):
00156                     gwf._delObject(workspace_id)
00157 
00158         self.invalidateGroup(group_id)
00159         return retval

Here is the call graph for this function:

Here is the caller graph for this function:

def PlonePAS.tools.groups.GroupsTool.removeGroups (   self,
  ids,
  keep_workspaces = 0,
  REQUEST = None 
)
Remove the group in the provided list (if possible).

Will by default remove this group's GroupWorkspace if it exists. You may
turn this off by specifying keep_workspaces=true.

Definition at line 162 of file groups.py.

00162 
00163     def removeGroups(self, ids, keep_workspaces=0, REQUEST=None):
00164         """Remove the group in the provided list (if possible).
00165 
00166         Will by default remove this group's GroupWorkspace if it exists. You may
00167         turn this off by specifying keep_workspaces=true.
00168         """
00169         for id in ids:
00170             self.removeGroup(id, keep_workspaces)

Here is the call graph for this function:

def PlonePAS.tools.groups.GroupsTool.removePrincipalFromGroup (   self,
  principal_id,
  group_id,
  REQUEST = None 
)

Definition at line 199 of file groups.py.

00199 
00200     def removePrincipalFromGroup(self, principal_id, group_id, REQUEST=None):
00201         managers = self._getGroupManagers()
00202         if not managers:
00203             raise NotSupported, 'No plugins allow for group management'
00204         for mid, manager in managers:
00205             if manager.removePrincipalFromGroup(principal_id, group_id):
00206                 return True
00207         return False
00208 

Here is the call graph for this function:

Here is the caller graph for this function:

def PlonePAS.tools.groups.GroupsTool.searchForGroups (   self,
  REQUEST = {},
  kw 
)
Search for groups by keyword.
The following properties can be searched:
- name
#- email
#- title

Only id/title search is implemented for groups. Is the rest of
this junk used anywhere?

This is an 'AND' request.

When it takes 'name' as keyword (or in REQUEST) and searches on
Full name and id.

Simple name searches are "fast".

Definition at line 228 of file groups.py.

00228 
00229     def searchForGroups(self, REQUEST={}, **kw):
00230         """Search for groups by keyword.
00231         The following properties can be searched:
00232         - name
00233         #- email
00234         #- title
00235 
00236         Only id/title search is implemented for groups. Is the rest of
00237         this junk used anywhere?
00238 
00239         This is an 'AND' request.
00240 
00241         When it takes 'name' as keyword (or in REQUEST) and searches on
00242         Full name and id.
00243 
00244         Simple name searches are "fast".
00245         """
00246         acl_users = self.acl_users
00247         groups_tool = self.portal_groups
00248         if REQUEST:
00249             dict = REQUEST
00250         else:
00251             dict = kw
00252 
00253         name = dict.get('name', None)
00254         #email = dict.get('email', None)
00255         #roles = dict.get('roles', None)
00256         #title = dict.get('title', None)
00257         title_or_name = dict.get('title_or_name', None)
00258         if name:
00259             name = name.strip().lower()
00260         if not name:
00261             name = None
00262         if title_or_name: name = title_or_name
00263         #if email:
00264         #    email = email.strip().lower()
00265         #if not email:
00266         #    email = None
00267         #if title:
00268         #    title = title.strip().lower()
00269         #if not title:
00270         #    title = None
00271 
00272         md_groups = []
00273         uf_groups = []
00274 
00275         if name:
00276             # This will allow us to retrieve groups by their id only
00277             uf_groups = acl_users.searchGroups(id=name)
00278 
00279             # PAS allows search to return dupes. We must winnow...
00280             uf_groups_new = []
00281             for group in uf_groups:
00282                 if group not in uf_groups_new:
00283                     uf_groups_new.append(group)
00284             uf_groups = uf_groups_new
00285 
00286         groups = []
00287         if md_groups or uf_groups:
00288             getGroupById = self.getGroupById
00289 
00290             for groupid in md_groups:
00291                 groups.append(getGroupById(groupid))
00292             for group in uf_groups:
00293                 groupid = group['groupid']
00294                 if groupid in md_groups:
00295                     continue             # Kill dupes
00296                 groups.append(getGroupById(groupid))
00297 
00298             #if not email and \
00299             #       not roles and \
00300             #       not last_login_time:
00301             #    return groups
00302 
00303         return groups

Here is the call graph for this function:

def PlonePAS.tools.groups.GroupsTool.searchGroups (   self,
  args,
  kw 
)

Definition at line 222 of file groups.py.

00222 
00223     def searchGroups(self, *args, **kw):
00224         # XXX document interface.. returns a list of dictionaries
00225         return self.acl_users.searchGroups(*args, **kw)

Here is the caller graph for this function:

def PlonePAS.tools.groups.GroupsTool.setRolesForGroup (   self,
  group_id,
  roles = (),
  REQUEST = None 
)

Definition at line 173 of file groups.py.

00173 
00174     def setRolesForGroup(self, group_id, roles=(), REQUEST=None):
00175         rmanagers = self._getPlugins().listPlugins(IRoleAssignerPlugin)
00176         if not (rmanagers):
00177             raise NotImplementedError, ('There is no plugin that can '
00178                                         'assign roles to groups')
00179         for rid, rmanager in rmanagers:
00180             rmanager.assignRolesToPrincipal(roles, group_id)
00181 
        self.invalidateGroup(group_id)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

string PlonePAS.tools.groups.GroupsTool.id = 'portal_groups' [static]

Definition at line 47 of file groups.py.

Definition at line 325 of file groups.py.

string PlonePAS.tools.groups.GroupsTool.meta_type = 'PlonePAS Groups Tool' [static]

Definition at line 48 of file groups.py.

tuple PlonePAS.tools.groups.GroupsTool.security = ClassSecurityInfo() [static]

Definition at line 49 of file groups.py.

string PlonePAS.tools.groups.GroupsTool.toolicon = 'tool.gif' [static]

Definition at line 50 of file groups.py.


The documentation for this class was generated from the following file: