1 | """ |
---|
2 | CMF Marshall namespace is overrided here in order to fix |
---|
3 | LocalRolesAttribute class. It's not working in Marshall Product. |
---|
4 | """ |
---|
5 | |
---|
6 | from Products.Marshall import utils |
---|
7 | from Products.Marshall.namespaces import cmfns as base |
---|
8 | |
---|
9 | |
---|
10 | class LocalRolesAttribute(base.LocalRolesAttribute): |
---|
11 | |
---|
12 | def getAttributeNames(self): |
---|
13 | return (self.name, 'security') |
---|
14 | |
---|
15 | def processXml(self, context, node): |
---|
16 | nsprefix = node.tag[:node.tag.find('}')+1] |
---|
17 | local_roles = node.findall(nsprefix+self.name) |
---|
18 | |
---|
19 | if len(local_roles) == 0: |
---|
20 | return |
---|
21 | |
---|
22 | data = context.getDataFor(self.namespace.xmlns) |
---|
23 | values = data.setdefault(self.name, []) |
---|
24 | |
---|
25 | for lrole in local_roles: |
---|
26 | values.append((lrole.get('user_id'), lrole.get('role'))) |
---|
27 | |
---|
28 | return True |
---|
29 | |
---|
30 | class WorkflowAttribute(base.WorkflowAttribute): |
---|
31 | |
---|
32 | def processXml(self, context, node): |
---|
33 | data = context.getDataFor(self.namespace.xmlns) |
---|
34 | wf_data = data.setdefault(self.name, {}) |
---|
35 | nsprefix = node.tag[:node.tag.find('}')+1] |
---|
36 | |
---|
37 | for wf_node in node.findall(nsprefix+'workflow'): |
---|
38 | # workflow |
---|
39 | wf_id = wf_node.attrib.get(nsprefix+'id') or \ |
---|
40 | wf_node.attrib.get('id') |
---|
41 | if wf_id is None: |
---|
42 | continue |
---|
43 | |
---|
44 | # history |
---|
45 | wf = wf_data.setdefault(wf_id, []) |
---|
46 | hist_nodes = wf_node.findall(nsprefix+'history') |
---|
47 | for hist_node in hist_nodes: |
---|
48 | record = {} |
---|
49 | wf.append(record) |
---|
50 | |
---|
51 | #var |
---|
52 | var_nodes = hist_node.findall(nsprefix+'var') |
---|
53 | vid = vtype = value = None |
---|
54 | |
---|
55 | for var_node in var_nodes: |
---|
56 | vid = var_node.attrib.get(nsprefix+'id') or \ |
---|
57 | var_node.attrib.get('id') |
---|
58 | vtype = var_node.attrib.get(nsprefix+'type',None) or \ |
---|
59 | var_node.attrib.get('type') |
---|
60 | value = var_node.attrib.get(nsprefix+'value',None) or \ |
---|
61 | var_node.attrib.get('value') or '' |
---|
62 | |
---|
63 | if not (vid and vtype and value is not None): |
---|
64 | continue |
---|
65 | |
---|
66 | value = base.demarshall_value(value, vtype) |
---|
67 | record[vid] = value |
---|
68 | |
---|
69 | return True |
---|
70 | |
---|
71 | class CMF(base.CMF): |
---|
72 | |
---|
73 | attributes = ( |
---|
74 | base.TypeAttribute('type'), |
---|
75 | WorkflowAttribute('workflow_history'), |
---|
76 | LocalRolesAttribute('local_role') |
---|
77 | ) |
---|