예제 #1
0
    def test_ActionState(self):
        parent = BaseNode(name='root')
        model = parent['model'] = BaseNode()
        request = self.layer.new_request()

        action = ActionState()
        self.assertFalse(IWorkflowState.providedBy(model))
        self.assertEqual(action(model, request), u'')

        wfmodel = parent['wfmodel'] = WorkflowNode()
        self.assertTrue(IWorkflowState.providedBy(wfmodel))
        self.assertEqual(action(wfmodel, request), u'')

        with self.layer.authenticated('editor'):
            rule = request.has_permission('change_state', wfmodel)
            self.assertTrue(isinstance(rule, ACLDenied))
            self.assertEqual(action(wfmodel, request), u'')

        with self.layer.authenticated('manager'):
            rule = request.has_permission('change_state', wfmodel)
            self.assertTrue(isinstance(rule, ACLAllowed))

            rendered = action(wfmodel, request)
            self.checkOutput(
                """
            ...<li class="dropdown">...
            <a href="#"
            ajax:bind="click"
            ajax:target="http://example.com/root/wfmodel?do_transition=initial_2_final"
            ajax:action="wf_dropdown:NONE:NONE">initial_2_final</a>...
            """, rendered)
예제 #2
0
파일: layout.py 프로젝트: lenadax/cone.app
 def fillchildren(self, model, path, tree):
     """XXX: consider cone.app.interfaces.INavigationLeaf
     """
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
         if path:
             path = path[1:]
             if path:
                 curpath = path[0]
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     for key in model:
         node = model[key]
         if not self.request.has_permission('view', node):
             continue
         if not node.properties.get('in_navtree'):
             continue
         title = node.metadata.title
         if title:
             title = safe_decode(title)
         url = make_url(self.request, node=node)
         query = make_query(
             contenttile=node.properties.default_content_tile)
         target = make_url(self.request, node=node, query=query)
         curnode = curpath == safe_decode(key)
         icon = node_icon(node)
         css = ''
         if IWorkflowState.providedBy(node):
             css = 'state-%s' % node.state
         child = self.navtreeitem(title, url, target, node_path(node), icon,
                                  css)
         child['showchildren'] = curnode
         if curnode:
             child['selected'] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = node_path(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             # XXX: probably superfluous. keep as of cone.app 1.1
             # if selected_path == node_path(node):
             #     selected = True
             child['selected'] = selected
         tree['children'].append(child)
예제 #3
0
 def fillchildren(self, model, path, tree):
     """XXX: consider cone.app.interfaces.INavigationLeaf
     """
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
         if path:
             path = path[1:]
             if path:
                 curpath = path[0]
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     for key in model:
         node = model[key]
         if not self.request.has_permission('view', node):
             continue
         if not node.properties.get('in_navtree'):
             continue
         title = node.metadata.title
         if title:
             title = safe_decode(title)
         url = make_url(self.request, node=node)
         query = make_query(contenttile=node.properties.default_content_tile)
         target = make_url(self.request, node=node, query=query)
         curnode = curpath == safe_decode(key)
         icon = node_icon(node)
         css = ''
         if IWorkflowState.providedBy(node):
             css = 'state-%s' % node.state
         child = self.navtreeitem(
             title, url, target, node_path(node), icon, css)
         child['showchildren'] = curnode
         if curnode:
             child['selected'] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = node_path(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             # XXX: probably superfluous. keep as of cone.app 1.1
             # if selected_path == node_path(node):
             #     selected = True
             child['selected'] = selected
         tree['children'].append(child)
예제 #4
0
def create_default_metadata(node):
    metadata = dict()
    metadata['uid'] = node.uuid
    metadata['path'] = zodb_path(node)
    metadata['app_path'] = app_path(node)
    metadata['title'] = get_title(node, node.name)
    metadata['combined_title'] = combined_title(node)
    if IWorkflowState.providedBy(node):
        metadata['state'] = node.state
    return metadata
예제 #5
0
 def fillchildren(self, model, path, tree):
     """XXX: consider cone.app.interfaces.INavigationLeaf
     """
     curpath = None
     if path:
         curpath = path[0]
     default_child = None
     if model.properties.default_child:
         if not curpath or curpath == model.properties.default_child:
             default_child = model[model.properties.default_child]
     if default_child and default_child.properties.hide_if_default:
         model = default_child
         default_child = None
         if path:
             path = path[1:]
             if path:
                 curpath = path[0]
     if default_child:
         if not curpath:
             curpath = model.properties.default_child
     for key in model:
         node = model[key]
         if not has_permission("view", node, self.request):
             continue
         if not node.properties.get("in_navtree"):
             continue
         title = node.metadata.title
         if title:
             title = safe_decode(title)
         url = make_url(self.request, node=node)
         query = make_query(contenttile=node.properties.default_content_tile)
         target = make_url(self.request, node=node, query=query)
         curnode = curpath == key and True or False
         icon = node_icon(self.request, node)
         css = ""
         if IWorkflowState.providedBy(node):
             css = "state-%s" % node.state
         child = self.navtreeitem(title, url, target, nodepath(node), icon, css)
         child["showchildren"] = curnode
         if curnode:
             child["selected"] = True
             if default_child:
                 self.fillchildren(default_child, path[1:], child)
             else:
                 self.fillchildren(node, path[1:], child)
         else:
             selected_path = nodepath(self.model)
             if default_child:
                 selected_path.append(default_child.name)
             selected = False
             if selected_path == nodepath(node):
                 selected = True
             child["selected"] = selected
         tree["children"].append(child)
예제 #6
0
    def test_workflow(self):
        node = WorkflowNode()
        self.assertTrue(IWorkflowState.providedBy(node))

        # Workflow name is set on node properties for lookup
        self.assertEqual(node.workflow_name, u'dummy')

        # Initial workflow state gets set at node creation time if not set yet
        self.assertEqual(node.state, u'initial')

        node.state = u'final'
        self.assertEqual(node.attrs['state'], u'final')
        self.assertTrue(node.attrs['state'] is node.state)

        initialize_workflow(node)
        self.assertEqual(node.state, u'final')
예제 #7
0
 def sorted_rows(self, start, end, sort, order):
     children = self.sorted_children(sort, order)
     rows = list()
     cut_urls = extract_copysupport_cookie(self.request, 'cut')
     for child in children[start:end]:
         row_data = self.row_data(child)
         target = make_url(self.request, node=child)
         if ICopySupport.providedBy(child):
             row_data.selectable = True
             row_data.target = target
             row_data.css = 'copysupportitem'
             if target in cut_urls:
                 row_data.css += ' copysupport_cut'
         if IWorkflowState.providedBy(child):
             row_data.css += ' state-%s' % child.state
         if hasattr(child, 'node_info_name') and child.node_info_name:
             row_data.css += ' node-type-%s' % child.node_info_name
         rows.append(row_data)
     return rows
예제 #8
0
 def sorted_rows(self, start, end, sort, order):
     children = self.sorted_children(sort, order)
     rows = list()
     cut_urls = extract_copysupport_cookie(self.request, 'cut')
     for child in children[start:end]:
         row_data = self.row_data(child)
         target = make_url(self.request, node=child)
         if ICopySupport.providedBy(child):
             row_data.selectable = True
             row_data.target = target
             row_data.css = 'copysupportitem'
             if target in cut_urls:
                 row_data.css += ' copysupport_cut'
         if IWorkflowState.providedBy(child):
             row_data.css += ' state-%s' % child.state
         if hasattr(child, 'node_info_name') and child.node_info_name:
             row_data.css += ' node-type-%s' % child.node_info_name
         rows.append(row_data)
     return rows
예제 #9
0
    def test_workflow(self):
        # Dummy workflow is registered for ``WorkflowNode``
        wf = get_workflow(WorkflowNode, u'dummy')
        self.assertTrue(isinstance(wf, Workflow))

        node = WorkflowNode()
        self.assertTrue(IWorkflowState.providedBy(node))

        # Workflow name is set on node properties for lookup
        self.assertEqual(node.workflow_name, u'dummy')

        # Initial workflow state gets set at node creation time if not set yet
        self.assertEqual(node.state, u'initial')

        node.state = u'final'
        self.assertEqual(node.attrs['state'], u'final')
        self.assertTrue(node.attrs['state'] is node.state)

        initialize_workflow(node)
        self.assertEqual(node.state, u'final')
예제 #10
0
    def test_state_acl(self):
        node = StateACLWorkflowNode()
        self.assertEqual(node.workflow_name, u'dummy')
        self.assertTrue(IWorkflowState.providedBy(node))

        self.assertEqual(
            node.__acl__,
            [('Allow', 'role:manager', ['manage', 'edit', 'change_state']),
             ('Allow', 'system.Everyone', ['login']),
             ('Deny', 'system.Everyone', ALL_PERMISSIONS)])

        with self.layer.authenticated('manager'):
            request = self.layer.new_request()
            wf = lookup_workflow(node)
            wf.transition(node, request, u'initial_2_final')
            self.assertEqual(node.state, u'final')

        self.assertEqual(
            node.__acl__,
            [('Allow', 'role:manager', ['view', 'edit', 'change_state']),
             ('Deny', 'system.Everyone', ALL_PERMISSIONS)])
예제 #11
0
 def recursiv_initial_state(node):
     if IWorkflowState.providedBy(node):
         initialize_workflow(node, force=True)
         for child in node.values():
             recursiv_initial_state(child)
예제 #12
0
 def recursiv_initial_state(node):
     if IWorkflowState.providedBy(node):
         initialize_workflow(node, force=True)
         for child in node.values():
             recursiv_initial_state(child)
예제 #13
0
 def display(self):
     return IWorkflowState.providedBy(self.model) \
         and self.permitted('change_state')
예제 #14
0
 def display(self):
     return IWorkflowState.providedBy(self.model) \
         and self.permitted('change_state')