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)
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)
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)
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
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)
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')
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
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')
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)])
def recursiv_initial_state(node): if IWorkflowState.providedBy(node): initialize_workflow(node, force=True) for child in node.values(): recursiv_initial_state(child)
def display(self): return IWorkflowState.providedBy(self.model) \ and self.permitted('change_state')