def specialGroups(event): """Set groups for IGroupAwarePrincipal.""" principal = event.principal # only apply to non groups because it will end in cycle dependencies # since the principal will have tis role anyway if (IGroup.providedBy(principal) or not (IGroupAwarePrincipal.providedBy(principal) or IUnauthenticatedPrincipal.providedBy(principal))): return # global utility registered by everybodyGroup directive everyone = zope.component.queryUtility(IEveryoneGroup) if everyone is not None and everyone.id != principal.id and \ everyone.id not in principal.groups: principal.groups.append(everyone.id) if IUnauthenticatedPrincipal.providedBy(principal): # global utility registered by unauthenticatedGroup directive unAuthGroup = zope.component.queryUtility(IUnauthenticatedGroup) if unAuthGroup is not None and unAuthGroup.id != principal.id and \ unAuthGroup.id not in principal.groups: principal.groups.append(unAuthGroup.id) else: # global utility registered by authenticatedGroup directive authGroup = zope.component.queryUtility(IAuthenticatedGroup) if authGroup is not None and authGroup.id != principal.id and \ authGroup.id not in principal.groups: principal.groups.append(authGroup.id)
def getGroups(self, type=None): if type is None: type = IPrincipal principal = self.principal if IGroupAwarePrincipal.providedBy(principal): if principal.groups: seen = set() principals = getUtility(IAuthentication) stack = [iter(principal.groups)] if IGroup.providedBy(principal): stack.append(iter([principal.id])) while stack: try: group_id = stack[-1].next() except StopIteration: stack.pop() else: if group_id not in seen: group = principals.getPrincipal(group_id) seen.add(group_id) stack.append(iter(group.groups)) if type.providedBy(group): yield group
def canAssignPrincipal(self, principal): if (not IUnauthenticatedPrincipal.providedBy(principal) and IPrincipal.providedBy(principal) and not IGroup.providedBy(principal) and checkPermissionForPrincipal(principal,'zojax.PersonalSpace',self)): return True return False
def _validate(self, value): super(PrincipalField, self)._validate(value) try: principal = getUtility(IAuthentication).getPrincipal(value) except PrincipalLookupError: raise InvalidPrincipal(value) if not IGroup.providedBy(principal): raise InvalidPrincipal(value)
def specialGroups(event): principal = event.principal if (IGroup.providedBy(principal) or not IGroupAwarePrincipal.providedBy(principal)): return everyone = component.queryUtility(IEveryoneGroup) if everyone is not None: principal.groups.append(everyone.id) auth = component.queryUtility(IAuthenticatedGroup) if auth is not None: principal.groups.append(auth.id)
def owner(self, owner): if IPrincipal.providedBy(owner): oldOwner = self.owner self._ownerId = owner.id self.isGroup = IGroup.providedBy(owner) self.annotations[ANNOTATION_KEY] = {'ownerId': self._ownerId, 'isGroup': self.isGroup} event.notify(OwnerChangedEvent(self.context, owner, oldOwner)) else: raise ValueError('IPrincipal object is required.')
def isAvailable(group): principal = group.__principal__ if IPrincipal.providedBy(principal) and not IGroup.providedBy(principal): return getUtility(IProduct, 'zojax-forum').isInstalled() return False
def isGroup(group): return IGroup.providedBy(group.__principal__)
def isUser(group): principal = group.__principal__ return IPrincipal.providedBy(principal) and not IGroup.providedBy(principal)