def fset(self, new_owner): if not (new_owner is None or IPrincipal.providedBy(new_owner)): raise ValueError('IPrincipal object or None required') if new_owner is None: new_owner_id = None else: new_owner_id = new_owner.id current_owner_id = self._getCurrentOwnerId() if new_owner_id == current_owner_id: return if current_owner_id is not None: self._rolemanager.unsetRoleForPrincipal( OWNER_ROLE, current_owner_id) current_owner = getUtility(IAuthentication).getPrincipal( current_owner_id) else: current_owner = None if new_owner_id: self._rolemanager.assignRoleToPrincipal( OWNER_ROLE, new_owner_id) notify(OwnerChangedEvent(self.context, new_owner, current_owner))
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 new_interaction(principal): if not IPrincipal.providedBy(principal): auth = getUtility(IAuthentication, context=None) principal = auth.getPrincipal(principal) interaction = OmsSecurityPolicy() interaction.add(SessionStub(principal)) return interaction
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 test_principal(self): pr = principal.Principal("0101010001") self.assertTrue(isinstance(pr, principal.Principal)) self.assertTrue(IPrincipal.providedBy(pr)) class F: def __init__(self, pr): self.object = pr with testing.AuthenticatedRequest("0101010001"): self.layer.create_application("app") applyPermissionsForExistentCoUsers(F(pr)) self.assertEqual(str(pr.homefolder), "<Homefolder for 0101010001>") self.assertEqual(pr.homefolder_url, "http://127.0.0.1/app/members/0101010001") self.assertEqual(pr.getRoles(), ['ENMS'])
def classifySubscriber(item, event): """ A subscriber for an object event that fires a quotationtool.classify workflow process for this item.""" pd = zope.component.getUtility(IProcessDefinition, name='quotationtool.classify') context = ClassificationContext(item) process = pd(context) contributor = u"unkown" for principal in getInteraction().participations: if IPrincipal.providedBy(principal): contributor = principal.id elif IRequest.providedBy(principal): contributor = principal.principal.id break history = IWorkflowHistory(item) process.start(contributor, datetime.datetime.now(), _(u"Newly created items need to be classified."), history, PersistentAttribution())
def authenticated(self): """Check whether context is an authenticated principal. Sample usage in a page template: <tal:span tal:define="user request/principal" tal:condition="user/schooltool:authenticated" tal:replace="user/title"> User title </tal:span> <tal:span tal:define="user request/principal" tal:condition="not:user/schooltool:authenticated"> Anonymous </tal:span> """ if self.context is None: # no one is logged in return False if not IPrincipal.providedBy(self.context): raise TypeError("schooltool:authenticated can only be applied" " to a principal but was applied on %r" % self.context) return not IUnauthenticatedPrincipal.providedBy(self.context)
def isAvailable(group): principal = group.__principal__ if IPrincipal.providedBy(principal) and not IGroup.providedBy(principal): return getUtility(IProduct, 'zojax-forum').isInstalled() return False
def isUser(group): principal = group.__principal__ return IPrincipal.providedBy(principal) and not IGroup.providedBy(principal)
def __init__(self, principal=unauthenticated_principal, replace=True): assert IPrincipal.providedBy(principal) self.participation = Participation(principal) self.replace = replace self.previous = None self.current = None