def error(self, obj, error): request = getattr(self.context, 'REQUEST', None) if request is not None: title = utils.pretty_title_or_id(obj, obj) message = _(u"Unable to apply local roles on ${name}: ${error}", mapping={'name': title, 'error': error}) IStatusMessage(request).addStatusMessage(message, type="error")
def __call__(self): obj = self.event.object mt = getToolByName(self.context, 'portal_membership', None) gt = getToolByName(self.context, 'portal_groups', None) interpolator = IStringInterpolator(obj) if mt is None: return False roles = list(self.element.roles) principal_id = self.element.principal #User interpolator to process principal information # This way it's possible to set Group_${title} # and receive a Group_ContentTitle principal_id = interpolator(principal_id).strip() principal = mt.getMemberById(principal_id) if not principal: # Must be a group principal = gt.getGroupById(principal_id) if not principal: self.error(obj, _(u'No user or group found with the provided id.')) return False actual_roles = list(obj.get_local_roles_for_userid(principal_id)) wanted_roles = list(set(roles + actual_roles)) try: obj.manage_setLocalRoles(principal_id, list(wanted_roles)) except ConflictError, e: raise e
def summary(self): roles = ', '.join(self.roles) return _(u"Apply local roles ${roles} to ${principal}", mapping=dict(roles=roles, principal=self.principal))