Пример #1
0
    def reopen(self):
        """
        This only applies to Todo items in Case Workspaces.

        Set the workflow state to "open" if the milestone of the Todo item is
        the same as the current, or earlier workflow state of the Case
        Workspace, otherwise set to "planned".

        Only Open items will appear in the dashboard.
        """
        wft = api.portal.get_tool("portal_workflow")
        todo_state = wft.getInfoFor(self, "review_state")
        workspace = parent_workspace(self)
        if not ICase.providedBy(workspace):
            if todo_state != 'open':
                api.content.transition(self, 'set_to_open')
        else:
            milestone = self.milestone
            if milestone:
                case_state = wft.getInfoFor(workspace, 'review_state')
                mm = IMetroMap(workspace).metromap_sequence.keys()
                future = mm.index(milestone) > mm.index(case_state)
                current_or_past = not future
                if current_or_past and todo_state != 'open':
                    api.content.transition(self, 'set_to_open')
                if future and todo_state != 'planned':
                    api.content.transition(self, 'set_to_planned')
            elif todo_state != 'planned':
                api.content.transition(self, 'set_to_planned')
Пример #2
0
    def reopen(self):
        """
        This only applies to Todo items in Case Workspaces.

        Set the workflow state to "open" if the milestone of the Todo item is
        the same as the current, or earlier workflow state of the Case
        Workspace, otherwise set to "planned".

        Only Open items will appear in the dashboard.
        """
        todo_state = api.content.get_state(self)
        workspace = parent_workspace(self)
        if not ICase.providedBy(workspace):
            if todo_state != 'open':
                api.content.transition(self, 'set_to_open')
        else:
            milestone = self.milestone
            if milestone:
                case_state = api.content.get_state(workspace)
                mm = IMetroMap(workspace).metromap_sequence.keys()
                # A case could be set to a state which isn't included in the
                # metromap e.g. on-hold, rejected. If that happens we can treat
                # it as a future state and set all open tasks to planned
                mm_states = case_state in mm and milestone in mm
                future = (not mm_states
                          or mm.index(milestone) > mm.index(case_state))
                current_or_past = not future
                if current_or_past and todo_state != 'open':
                    api.content.transition(self, 'set_to_open')
                if future and todo_state != 'planned':
                    api.content.transition(self, 'set_to_planned')
            elif todo_state != 'planned':
                api.content.transition(self, 'set_to_planned')
Пример #3
0
    def reopen(self):
        """
        This only applies to Todo items in Case Workspaces.

        Set the workflow state to "open" if the milestone of the Todo item is
        the same as the current, or earlier workflow state of the Case
        Workspace, otherwise set to "planned".

        Only Open items will appear in the dashboard.
        """
        wft = api.portal.get_tool("portal_workflow")
        state = wft.getInfoFor(self, "review_state")
        workspace = parent_workspace(self)
        if not ICase.providedBy(workspace):
            if state != "open":
                api.content.transition(self, "set_to_open")
        else:
            milestone = self.milestone
            if milestone:
                workspace_state = wft.getInfoFor(workspace, "review_state")
                mm_seq = IMetroMap(workspace).metromap_sequence.keys()
                if mm_seq.index(milestone) > mm_seq.index(workspace_state):
                    if state != "planned":
                        api.content.transition(self, "set_to_planned")
                elif state != "open":
                    api.content.transition(self, "set_to_open")
            elif state != "planned":
                api.content.transition(self, "set_to_planned")
Пример #4
0
def workspace_added(ob, event):
    """
    when a workspace is created, we add the creator to
    the admin group. We then setup our placeful workflow

    """
    is_case = ICase.providedBy(ob)
    preserve_template_ownership = api.portal.get_registry_record(
        'ploneintranet.workspace.preserve_template_ownership',
        default=False,
    )
    userid = api.user.get_current().id

    # If not stated otherwise through the registry record:
    # ploneintranet.workspace.preserve_template_ownership
    # whoever creates the workspace should be added as an Admin
    # When copying a template, that is the current user
    # (not the one who created the original template)
    if (not is_case) or (not preserve_template_ownership):
        ob.setCreators([userid])
        IWorkspace(ob).add_to_team(
            user=userid,
            groups=set(['Admins']),
        )
    # During workspace creation, various functions
    # are called (renaming / workflow transitions) which do
    # low-level AccessControl checks.
    # Unfortunately these checks never re-ask PAS for a user's roles
    # or groups during a request, so we have to manually re-initialise
    # the security context for the current user.
    # ref: https://github.com/ploneintranet/ploneintranet/pull/438
    _reset_security_context(userid, ob.REQUEST)

    if is_case:
        """Case Workspaces have their own custom workflows
        """
        return

    # Configure our placeful workflow
    cmfpw = 'CMFPlacefulWorkflow'

    try:
        ob.manage_addProduct[cmfpw].manage_addWorkflowPolicyConfig()
    except BadRequest:
        # 'The id ".wf_policy_config" is invalid - it is already in use.'
        # copying a template workspace which already has a policy defined
        return

    # Set the policy for the config
    pc = getattr(ob, WorkflowPolicyConfig_id)
    pc.setPolicyIn('')
    pc.setPolicyBelow('ploneintranet_policy')
Пример #5
0
 def maybe_preserve_ownership(self, new, template):
     ''' In some cases we want to preserve the template ownership
     on the new object
     '''
     if not ICase.providedBy(new):
         # We do not want this to happen for workspaces...
         return
     if not api.portal.get_registry_record(
         'ploneintranet.workspace.preserve_template_ownership',
         default=False,
     ):
         # ...or if it is not specified through a registry record
         return
     pu = api.portal.get_tool('plone_utils')
     pu.changeOwnershipOf(
         new,
         template.getOwner().getId(),
         recursive=True,
     )
Пример #6
0
def workspace_added(ob, event):
    """
    when a workspace is created, we add the creator to
    the admin group. We then setup our placeful workflow

    """
    # Whoever creates the workspace should be added as an Admin
    # When copying a case template, that is the current user
    # (not the one who created the original case template)
    userid = api.user.get_current().id
    ob.setCreators([userid])
    IWorkspace(ob).add_to_team(
        user=userid,
        groups=set(['Admins']),
    )
    # During workspace creation, various functions
    # are called (renaming / workflow transitions) which do
    # low-level AccessControl checks.
    # Unfortunately these checks never re-ask PAS for a user's roles
    # or groups during a request, so we have to manually re-initialise
    # the security context for the current user.
    # ref: https://github.com/ploneintranet/ploneintranet/pull/438
    IAnnotations(ob.REQUEST)[('workspaces', userid)] = None
    acl_users = api.portal.get_tool('acl_users')
    user = acl_users.getUserById(userid)
    if user is not None:
        # NB when copying a case template with execute_as_manager
        # this is 'finally' replaced again
        newSecurityManager(None, user)

    if not ICase.providedBy(ob):
        """Case Workspaces have their own custom workflows
        """
        # Configure our placeful workflow
        cmfpw = 'CMFPlacefulWorkflow'
        ob.manage_addProduct[cmfpw].manage_addWorkflowPolicyConfig()

        # Set the policy for the config
        pc = getattr(ob, WorkflowPolicyConfig_id)
        pc.setPolicyIn('')
        pc.setPolicyBelow('ploneintranet_policy')
Пример #7
0
def workspace_added(ob, event):
    """
    when a workspace is created, we add the creator to
    the admin group. We then setup our placeful workflow

    """
    # Whoever creates the workspace should be added as an Admin
    # When copying a case template, that is the current user
    # (not the one who created the original case template)
    userid = api.user.get_current().id
    ob.setCreators([userid])
    IWorkspace(ob).add_to_team(
        user=userid,
        groups=set(['Admins']),
    )
    # During workspace creation, various functions
    # are called (renaming / workflow transitions) which do
    # low-level AccessControl checks.
    # Unfortunately these checks never re-ask PAS for a user's roles
    # or groups during a request, so we have to manually re-initialise
    # the security context for the current user.
    # ref: https://github.com/ploneintranet/ploneintranet/pull/438
    IAnnotations(ob.REQUEST)[('workspaces', userid)] = None
    acl_users = api.portal.get_tool('acl_users')
    user = acl_users.getUserById(userid)
    if user is not None:
        # NB when copying a case template with execute_as_manager
        # this is 'finally' replaced again
        newSecurityManager(None, user)

    if not ICase.providedBy(ob):
        """Case Workspaces have their own custom workflows
        """
        # Configure our placeful workflow
        cmfpw = 'CMFPlacefulWorkflow'
        ob.manage_addProduct[cmfpw].manage_addWorkflowPolicyConfig()

        # Set the policy for the config
        pc = getattr(ob, WorkflowPolicyConfig_id)
        pc.setPolicyIn('')
        pc.setPolicyBelow('ploneintranet_policy')
Пример #8
0
def workspace_added(ob, event):
    """
    when a workspace is created, we add the creator to
    the admin group. We then setup our placeful workflow

    """
    # Whoever creates the workspace should be added as an Admin
    creator = ob.Creator()
    IWorkspace(ob).add_to_team(user=creator, groups=set(["Admins"]))

    if not ICase.providedBy(ob):
        """Case Workspaces have their own custom workflows
        """
        # Configure our placeful workflow
        cmfpw = "CMFPlacefulWorkflow"
        ob.manage_addProduct[cmfpw].manage_addWorkflowPolicyConfig()

        # Set the policy for the config
        pc = getattr(ob, WorkflowPolicyConfig_id)
        pc.setPolicyIn("")
        pc.setPolicyBelow("ploneintranet_policy")
Пример #9
0
def update_todo_state(obj, event):
    """
    After editing a Todo item, set the workflow state to either Open or Planned
    depending on the state of the Case.
    Also update access permissions on the Case, which might have changed due to
    a change in assignment.

    """
    # Do nothing on copy
    if IObjectCopiedEvent.providedBy(event):
        return

    if IObjectAddedEvent.providedBy(event):
        # This attribute is set when copying from a template
        # handle_case_workflow_state_changed will take care of everything
        if getattr(event.newParent, '_v_skip_update_todo_state', None):
            return
    obj.set_appropriate_state()
    obj.reindexObject()
    parent = parent_workspace(obj)
    if ICase.providedBy(parent):
        parent.update_case_access()