Example #1
0
 def doActionFor(self, ob, action, wf_id=None, *args, **kw):
     """ Perform the given workflow action on 'ob'.
     """
     wfs = self.getWorkflowsFor(ob)
     if wfs is None:
         wfs = ()
     if wf_id is None:
         if not wfs:
             raise WorkflowException(_(u'No workflows found.'))
         found = 0
         for wf in wfs:
             if wf.isActionSupported(ob, action, **kw):
                 found = 1
                 break
         if not found:
             msg = _(u"No workflow provides the '${action_id}' action.",
                     mapping={'action_id': action})
             raise WorkflowException(msg)
     else:
         wf = self.getWorkflowById(wf_id)
         if wf is None:
             raise WorkflowException(
                 _(u'Requested workflow definition not found.'))
     return self._invokeWithNotification(wfs, ob, action, wf.doActionFor,
                                         (ob, action) + args, kw)
Example #2
0
 def getInfoFor(self, ob, name, default=_marker, wf_id=None, *args, **kw):
     """ Get the given bit of workflow information for the object.
     """
     if wf_id is None:
         wfs = self.getWorkflowsFor(ob)
         if wfs is None:
             if default is _marker:
                 raise WorkflowException(_(u'No workflows found.'))
             else:
                 return default
         found = 0
         for wf in wfs:
             if wf.isInfoSupported(ob, name):
                 found = 1
                 break
         if not found:
             if default is _marker:
                 msg = _(u"No workflow provides '${name}' information.",
                         mapping={'name': name})
                 raise WorkflowException(msg)
             else:
                 return default
     else:
         wf = self.getWorkflowById(wf_id)
         if wf is None:
             if default is _marker:
                 raise WorkflowException(
                     _(u'Requested workflow definition not found.'))
             else:
                 return default
     res = wf.getInfoFor(ob, name, default, *args, **kw)
     if res is _marker:
         msg = _(u'Could not get info: ${name}', mapping={'name': name})
         raise WorkflowException(msg)
     return res
Example #3
0
 def getInfoFor(self, ob, name, default=_marker, wf_id=None, *args, **kw):
     """ Get the given bit of workflow information for the object.
     """
     if wf_id is None:
         wfs = self.getWorkflowsFor(ob)
         if wfs is None:
             if default is _marker:
                 raise WorkflowException(_(u'No workflows found.'))
             else:
                 return default
         found = 0
         for wf in wfs:
             if wf.isInfoSupported(ob, name):
                 found = 1
                 break
         if not found:
             if default is _marker:
                 msg = _(u"No workflow provides '${name}' information.",
                         mapping={'name': name})
                 raise WorkflowException(msg)
             else:
                 return default
     else:
         wf = self.getWorkflowById(wf_id)
         if wf is None:
             if default is _marker:
                 raise WorkflowException(
                     _(u'Requested workflow definition not found.'))
             else:
                 return default
     res = wf.getInfoFor(ob, name, default, *args, **kw)
     if res is _marker:
         msg = _(u'Could not get info: ${name}', mapping={'name': name})
         raise WorkflowException(msg)
     return res
Example #4
0
 def doActionFor(self, ob, action, wf_id=None, *args, **kw):
     """ Perform the given workflow action on 'ob'.
     """
     wfs = self.getWorkflowsFor(ob)
     if wfs is None:
         wfs = ()
     if wf_id is None:
         if not wfs:
             raise WorkflowException(_(u'No workflows found.'))
         found = 0
         for wf in wfs:
             if wf.isActionSupported(ob, action, **kw):
                 found = 1
                 break
         if not found:
             msg = _(u"No workflow provides the '${action_id}' action.",
                     mapping={'action_id': action})
             raise WorkflowException(msg)
     else:
         wf = self.getWorkflowById(wf_id)
         if wf is None:
             raise WorkflowException(
                 _(u'Requested workflow definition not found.'))
     return self._invokeWithNotification(
         wfs, ob, action, wf.doActionFor, (ob, action) + args, kw)
Example #5
0
    def addMember(self, id, password, roles=('Member',), domains='',
                  properties=None, REQUEST=None):
        '''Creates a PortalMember and returns it. The properties argument
        can be a mapping with additional member properties. Raises an
        exception if the given id already exists, the password does not
        comply with the policy in effect, or the authenticated user is not
        allowed to grant one of the roles listed (where Member is a special
        role that can always be granted); these conditions should be
        detected before the fact so that a cleaner message can be printed.
        '''
        # XXX: this method violates the rules for tools/utilities:
        # it depends on a non-utility tool
        if not self.isMemberIdAllowed(id):
            raise ValueError(_(u'The login name you selected is already in '
                               u'use or is not valid. Please choose another.'))

        failMessage = self.testPasswordValidity(password)
        if failMessage is not None:
            raise ValueError(failMessage)

        if properties is not None:
            failMessage = self.testPropertiesValidity(properties)
            if failMessage is not None:
                raise ValueError(failMessage)

        # Limit the granted roles.
        # Anyone is always allowed to grant the 'Member' role.
        _limitGrantedRoles(roles, self, ('Member',))

        membership = getToolByName(self, 'portal_membership')
        membership.addMember(id, password, roles, domains, properties)

        member = membership.getMemberById(id)
        self.afterAdd(member, id, password, properties)
        return member
Example #6
0
 def failIfLocked(self):
     """ Check if isLocked via webDav.
     """
     if self.wl_isLocked():
         raise ResourceLockedError(_(u'This resource is locked via '
                                     u'webDAV.'))
     return 0
Example #7
0
class HomeFolderFactoryBase(object):
    """Creates a home folder.
    """

    title = _(u'Home Folder')
    description = _(u'A home folder for portal members.')

    def __call__(self, id, title=None, *args, **kw):
        if title is None:
            title = "{0}'s Home".format(id)
        item = PortalFolder(id, title, *args, **kw)
        item.manage_setLocalRoles(id, ['Owner'])
        return item

    def getInterfaces(self):
        return implementedBy(PortalFolder)
Example #8
0
    def addMember(self, id, password, roles=('Member',), domains='',
                  properties=None, REQUEST=None):
        '''Creates a PortalMember and returns it. The properties argument
        can be a mapping with additional member properties. Raises an
        exception if the given id already exists, the password does not
        comply with the policy in effect, or the authenticated user is not
        allowed to grant one of the roles listed (where Member is a special
        role that can always be granted); these conditions should be
        detected before the fact so that a cleaner message can be printed.
        '''
        # XXX: this method violates the rules for tools/utilities:
        # it depends on a non-utility tool
        if not self.isMemberIdAllowed(id):
            raise ValueError(_(u'The login name you selected is already in '
                               u'use or is not valid. Please choose another.'))

        failMessage = self.testPasswordValidity(password)
        if failMessage is not None:
            raise ValueError(failMessage)

        if properties is not None:
            failMessage = self.testPropertiesValidity(properties)
            if failMessage is not None:
                raise ValueError(failMessage)

        # Limit the granted roles.
        # Anyone is always allowed to grant the 'Member' role.
        _limitGrantedRoles(roles, self, ('Member',))

        membership = getToolByName(self, 'portal_membership')
        membership.addMember(id, password, roles, domains, properties)

        member = membership.getMemberById(id)
        self.afterAdd(member, id, password, properties)
        return member
 def failIfLocked(self):
     """ Check if isLocked via webDav.
     """
     if self.wl_isLocked():
         raise ResourceLockedError(_(u'This resource is locked via '
                                     u'webDAV.'))
     return 0
Example #10
0
class _BBBHomeFolderFactory(HomeFolderFactoryBase):
    """Creates a home folder.
    """

    description = _(u'Classic CMFCore home folder for portal members.')

    def __call__(self, id, title=None, *args, **kw):
        item = super(_BBBHomeFolderFactory, self).__call__(id,
                                                           title=title,
                                                           *args,
                                                           **kw)

        item.manage_permission(View, ['Owner', 'Manager', 'Reviewer'], 0)
        item.manage_permission(AccessContentsInformation,
                               ['Owner', 'Manager', 'Reviewer'], 0)
        return item
    def addMember(self,
                  id,
                  password,
                  roles=('Member', ),
                  domains='',
                  properties=None,
                  REQUEST=None):
        # XXX Do not make this a normal method comment. Doing so makes
        # this method publishable

        # Creates a PortalMember and returns it. The properties argument
        # can be a mapping with additional member properties. Raises an
        # exception if the given id already exists, the password does not
        # comply with the policy in effect, or the authenticated user is not
        # allowed to grant one of the roles listed (where Member is a special
        # role that can always be granted); these conditions should be
        # detected before the fact so that a cleaner message can be printed.

        if not self.isMemberIdAllowed(id):
            raise ValueError(
                _(u'The login name you selected is already in '
                  u'use or is not valid. Please choose another.'))

        failMessage = self.testPasswordValidity(password)
        if failMessage is not None:
            raise ValueError(failMessage)

        if properties is not None:
            failMessage = self.testPropertiesValidity(properties)
            if failMessage is not None:
                raise ValueError(failMessage)

        # Limit the granted roles.
        # Anyone is always allowed to grant the 'Member' role.
        _limitGrantedRoles(roles, self, ('Member', ))

        mtool = getUtility(IMembershipTool)
        mtool.addMember(id, password, roles, domains, properties)

        member = mtool.getMemberById(id)
        self.afterAdd(member, id, password, properties)
        return member