Example #1
0
 def __acl__(self):
     acl_reg = get_acl_registry()
     wf = get_context_wf(self)
     if wf:
         state = wf.state in wf.states and wf.state or wf.initial_state
         return acl_reg.get_acl("%s:%s" % (wf.name, state))
     return acl_reg.default()
Example #2
0
def root_populator(title="", userid="", email="", password="", populator_name=""):
    factories = get_content_factories()
    root = factories["Root"](title=title)
    # Add users
    root["users"] = users = factories["Users"]()
    # Add user
    assert userid
    users[userid] = factories["User"](email=email, password=password)
    # Add groups
    root["groups"] = groups = factories["Groups"]()
    # Add administrators group
    description = _("Group for all administrators. Add any administrators to this group.")
    groups["administrators"] = adm_group = factories["Group"](
        title=_("Administrators"), description=description, members=[userid]
    )
    # Add admin role
    local_roles = get_local_roles(root)
    local_roles[adm_group.principal_name] = (ROLE_ADMIN,)
    # Run extra populator
    if populator_name:
        reg = get_current_registry()
        populator = reg.getAdapter(root, IPopulator, name=populator_name)
        populator.populate()
    # Publish root
    try:
        wf = get_context_wf(root)
        wf.do_transition("private:public", force=True)
    except WorkflowException:
        pass
    return root
Example #3
0
 def __acl__(self):
     acl_reg = get_acl_registry()
     wf = get_context_wf(self)
     if wf:
         state = wf.state in wf.states and wf.state or wf.initial_state
         return acl_reg.get_acl("%s:%s" % (wf.name, state))
     return acl_reg.default()
Example #4
0
def root_populator(title="",
                   userid="",
                   email="",
                   password="",
                   populator_name=""):
    factories = get_content_factories()
    root = factories['Root'](title=title)
    #Add users
    root['users'] = users = factories['Users']()
    #Add user
    assert userid
    users[userid] = factories['User'](email=email, password=password)
    #Add groups
    root['groups'] = groups = factories['Groups']()
    #Add administrators group
    description = _(
        u"Group for all administrators. Add any administrators to this group.")
    groups['administrators'] = adm_group = factories['Group'](
        title=_(u"Administrators"), description=description, members=[userid])
    #Add admin role
    local_roles = get_local_roles(root)
    local_roles[adm_group.principal_name] = (ROLE_ADMIN, )
    #Run extra populator
    if populator_name:
        reg = get_current_registry()
        populator = reg.getAdapter(root, IPopulator, name=populator_name)
        populator.populate()
    #Publish root
    try:
        wf = get_context_wf(root)
        wf.do_transition('private:public', force=True)
    except WorkflowException:
        pass
    return root
Example #5
0
 def test_get_context_wf(self):
     from arche.workflow import get_context_wf
     dummy = _mk_dummy()
     #self.assertEqual(get_context_wf(dummy), None)
     self.config.set_content_workflow('Dummy', 'simple_workflow')
     wf_obj = get_context_wf(dummy)
     self.assertTrue(IWorkflow.providedBy(wf_obj))
Example #6
0
 def __call__(self):
     transition_id = self.request.GET.get('id')
     wf = get_context_wf(self.context, self.request.registry)
     transition = wf.do_transition(transition_id)
     if transition.message:
         self.flash_messages.add(transition.message)
     return_url = self.request.GET.get('return_url')
     return HTTPFound(location = return_url)
Example #7
0
def wf_menu(context, request, va, **kw):
    if not IContextACL.providedBy(context):
        return
    wf = get_context_wf(context)
    if wf:
        view = kw['view']
        transitions = tuple(wf.get_transitions(request))
        if transitions or request.has_permission(security.PERM_EDIT, context):
            return view.render_template('arche:templates/menus/workflow.pt', wf = wf, transitions = transitions)
Example #8
0
 def test_do_transiton_events(self):
     from arche.workflow import get_context_wf
     self.config.set_content_workflow('Dummy', 'simple_workflow')
     dummy = _mk_dummy()
     wf = get_context_wf(dummy)
     before_events = []
     after_events = []
     def before_s(obj, event):
         before_events.append(event.workflow.state)
     def after_s(obj, event):
         after_events.append(event.workflow.state)
     self.config.add_subscriber(before_s, [IContextACL, IWorkflowBeforeTransition])
     self.config.add_subscriber(after_s, [IContextACL, IWorkflowAfterTransition])
     wf.do_transition('private:public')
     self.assertEqual(before_events[0], 'private')
     self.assertEqual(after_events[0], 'public')
Example #9
0
    def test_workflow_subscriber(self):
        from arche.workflow import get_context_wf

        root = self._fixture()
        root['a'] = context = _wf_fixture(self.config)
        obj = self._cut(context)
        obj.index_object()
        res = obj.catalog.query("wf_state == 'private'")
        self.assertEqual(res[0], 1)

        request = testing.DummyRequest()
        wf = get_context_wf(context)
        wf.do_transition('private:public', request)
        res = obj.catalog.query("wf_state == 'private'")
        self.assertEqual(res[0], 0)
        res = obj.catalog.query("wf_state == 'public'")
        self.assertEqual(res[0], 1)
Example #10
0
    def test_workflow_subscriber(self):
        from arche.workflow import get_context_wf

        root = self._fixture()
        root['a'] = context = _wf_fixture(self.config)
        obj = self._cut(context)
        obj.index_object()
        res = obj.catalog.query("wf_state == 'private'")
        self.assertEqual(res[0], 1)

        request = testing.DummyRequest()
        wf = get_context_wf(context)
        wf.do_transition('private:public', request)
        res = obj.catalog.query("wf_state == 'private'")
        self.assertEqual(res[0], 0)
        res = obj.catalog.query("wf_state == 'public'")
        self.assertEqual(res[0], 1)
Example #11
0
def get_workflow(context, default):
    try:
        wf = get_context_wf(context)
    except WorkflowException:
        return default
    return wf and wf.name or default
Example #12
0
def get_wf_state(context, default):
    try:
        wf = get_context_wf(context)
    except WorkflowException:
        return default
    return wf and wf.state or default
Example #13
0
def get_workflow(context, default):
    try:
        wf = get_context_wf(context)
    except WorkflowException:
        return default
    return wf and wf.name or default
Example #14
0
def get_wf_state(context, default):
    try:
        wf = get_context_wf(context)
    except WorkflowException:
        return default
    return wf and wf.state or default
Example #15
0
 def test_do_transition(self):
     from arche.workflow import get_context_wf
     self.config.set_content_workflow('Dummy', 'simple_workflow')
     dummy = _mk_dummy()
     wf = get_context_wf(dummy)
     wf.do_transition('private:public')