0001-misc-replace-get_role_translation-with-a-get_functio.patch
wcs/backoffice/management.py | ||
---|---|---|
3378 | 3378 |
r += htmltext('<ul class="form-inspector biglist">') |
3379 | 3379 |
for key, label in (workflow.roles or {}).items(): |
3380 | 3380 |
r += htmltext('<li><span class="label">%s</span>') % label |
3381 |
acting_role_id = self.filled.get_role_translation(key) |
|
3382 |
if acting_role_id: |
|
3381 |
r += htmltext('<div class="value">') |
|
3382 |
acting_role_ids = self.filled.get_function_roles(key) |
|
3383 |
for acting_role_id in acting_role_ids: |
|
3383 | 3384 |
try: |
3384 | 3385 |
acting_role = get_publisher().role_class.get(acting_role_id) |
3385 |
r += htmltext('<div class="value"><span>%s</span></div>') % acting_role.name
|
|
3386 |
r += htmltext('<span>%s</span> ') % acting_role.name
|
|
3386 | 3387 |
except KeyError: |
3387 |
r += htmltext('<div class="value"><span>%s %s</span></div>') % (
|
|
3388 |
r += htmltext('<span>%s %s</span> ') % (
|
|
3388 | 3389 |
acting_role_id, |
3389 | 3390 |
_('(deleted)'), |
3390 | 3391 |
) |
3391 |
else: |
|
3392 |
r += htmltext('<div class="value"><span class="unset">%s</span></div>') % _('unset') |
|
3392 |
if not acting_role_ids: |
|
3393 |
r += htmltext('<span class="unset">%s</span>') % _('unset') |
|
3394 |
r += htmltext('</div>') |
|
3393 | 3395 |
r += htmltext('</li>\n') |
3394 | 3396 |
r += htmltext('</ul>') |
3395 | 3397 |
r += htmltext('</div>') |
wcs/formdata.py | ||
---|---|---|
672 | 672 |
def get_display_id(self): |
673 | 673 |
return str(self.id_display or self.id) |
674 | 674 | |
675 |
def get_role_translation(self, role_name): |
|
675 |
def get_function_roles(self, role_name): |
|
676 |
# receive a function name or role identifier and return a set of role identifiers |
|
676 | 677 |
if role_name == '_submitter': |
677 | 678 |
raise Exception('_submitter is not a valid role') |
678 | 679 |
if str(role_name).startswith('_'): |
... | ... | |
682 | 683 |
if not role_id and self.formdef.workflow_roles: |
683 | 684 |
role_id = self.formdef.workflow_roles.get(role_name) |
684 | 685 |
if role_id is None: |
685 |
return role_id
|
|
686 |
return str(role_id)
|
|
687 |
return str(role_name)
|
|
686 |
return set()
|
|
687 |
return set([str(role_id)])
|
|
688 |
return set([str(role_name)])
|
|
688 | 689 | |
689 | 690 |
def get_handling_role_id(self): |
690 | 691 |
# TODO: look at current status and return the role(s) actually |
691 | 692 |
# concerned by the handling of the formdata |
692 |
return self.get_role_translation('_receiver') |
|
693 |
for role_id in self.get_function_roles('_receiver'): |
|
694 |
return role_id |
|
693 | 695 | |
694 | 696 |
def get_handling_role(self): |
695 | 697 |
try: |
... | ... | |
989 | 991 |
if self.is_submitter(user): |
990 | 992 |
return True |
991 | 993 |
elif user: |
992 |
role = self.get_role_translation(role) |
|
993 |
if role in user.get_roles(): |
|
994 |
if self.get_function_roles(role).intersection(user.get_roles()): |
|
994 | 995 |
return True |
995 | 996 |
return False |
996 | 997 | |
... | ... | |
1010 | 1011 |
# the very end (where it may be that there is no workflow status item |
1011 | 1012 |
# at all). |
1012 | 1013 |
for function_key in self.formdef.workflow.roles.keys(): |
1013 |
handling_role = self.get_role_translation(function_key) |
|
1014 |
if handling_role: |
|
1014 |
for handling_role in self.get_function_roles(function_key): |
|
1015 | 1015 |
status_action_roles.add(handling_role) |
1016 | 1016 | |
1017 | 1017 |
wf_status = self.get_status() |
... | ... | |
1042 | 1042 |
if role == '_submitter': |
1043 | 1043 |
status_action_roles.add(role) |
1044 | 1044 |
else: |
1045 |
real_role = self.get_role_translation(role) |
|
1046 |
if real_role: |
|
1045 |
for real_role in self.get_function_roles(role): |
|
1047 | 1046 |
status_action_roles.add(real_role) |
1048 | 1047 | |
1049 | 1048 |
return status_action_roles |
wcs/forms/workflows.py | ||
---|---|---|
49 | 49 |
break |
50 | 50 |
if not user: |
51 | 51 |
continue |
52 |
if self.formdata.get_role_translation(role) in user.get_roles():
|
|
52 |
if self.formdata.get_function_roles(role).intersection(user.get_roles()):
|
|
53 | 53 |
break |
54 | 54 |
else: |
55 | 55 |
raise errors.AccessForbiddenError('insufficient roles') |
wcs/wf/aggregation_email.py | ||
---|---|---|
63 | 63 |
return |
64 | 64 | |
65 | 65 |
for dest in self.to: |
66 |
dest = formdata.get_role_translation(dest)
|
|
67 |
try: |
|
68 |
aggregate = AggregationEmail.get(dest)
|
|
69 |
except KeyError: |
|
70 |
aggregate = AggregationEmail(id=dest)
|
|
66 |
for dest_id in formdata.get_function_roles(dest):
|
|
67 |
try:
|
|
68 |
aggregate = AggregationEmail.get(dest_id)
|
|
69 |
except KeyError:
|
|
70 |
aggregate = AggregationEmail(id=dest_id)
|
|
71 | 71 | |
72 |
aggregate.append( |
|
73 |
{'formdef': formdata.formdef.id, 'formdata': formdata.id, 'formurl': formdata.get_url()} |
|
74 |
) |
|
75 |
aggregate.store() |
|
72 |
aggregate.append(
|
|
73 |
{'formdef': formdata.formdef.id, 'formdata': formdata.id, 'formurl': formdata.get_url()}
|
|
74 |
)
|
|
75 |
aggregate.store()
|
|
76 | 76 | |
77 | 77 | |
78 | 78 |
register_item_class(AggregationEmailWorkflowStatusItem) |
wcs/wf/notification.py | ||
---|---|---|
152 | 152 |
users.append(formdata.get_user()) |
153 | 153 |
continue |
154 | 154 | |
155 |
dest = formdata.get_role_translation(dest)
|
|
156 |
try: |
|
157 |
role = get_publisher().role_class.get(dest)
|
|
158 |
except KeyError: |
|
159 |
continue |
|
160 |
users.extend(get_publisher().user_class.get_users_with_role(role.id)) |
|
155 |
for dest_id in formdata.get_function_roles(dest):
|
|
156 |
try:
|
|
157 |
role = get_publisher().role_class.get(dest_id)
|
|
158 |
except KeyError:
|
|
159 |
continue
|
|
160 |
users.extend(get_publisher().user_class.get_users_with_role(role.id))
|
|
161 | 161 | |
162 | 162 |
for user in users: |
163 | 163 |
if not user or not user.is_active: |
wcs/workflows.py | ||
---|---|---|
539 | 539 |
if '_submitter' in (trigger.roles or []) and formdata.is_submitter(user): |
540 | 540 |
actions.append(action) |
541 | 541 |
break |
542 |
roles = [ |
|
543 |
formdata.get_role_translation(x) for x in (trigger.roles or []) if x != '_submitter' |
|
544 |
] |
|
545 |
if set(roles).intersection(user.get_roles()): |
|
542 |
roles = set() |
|
543 |
for role_id in trigger.roles or []: |
|
544 |
if role_id == '_submitter': |
|
545 |
continue |
|
546 |
roles |= formdata.get_function_roles(role_id) |
|
547 |
if roles.intersection(user.get_roles()): |
|
546 | 548 |
actions.append(action) |
547 | 549 |
break |
548 | 550 |
return actions |
... | ... | |
1650 | 1652 |
continue |
1651 | 1653 |
if user is None: |
1652 | 1654 |
continue |
1653 |
role = filled.get_role_translation(role) |
|
1654 |
if role in user.get_roles(): |
|
1655 |
if filled.get_function_roles(role).intersection(user.get_roles()): |
|
1655 | 1656 |
break |
1656 | 1657 |
else: |
1657 | 1658 |
continue |
... | ... | |
1746 | 1747 | |
1747 | 1748 |
for role in visibility_roles: |
1748 | 1749 |
if role != '_submitter': |
1749 |
role = formdata.get_role_translation(role) |
|
1750 |
if role in user_roles: |
|
1751 |
return True |
|
1750 |
if formdata.get_function_roles(role).intersection(user_roles): |
|
1751 |
return True |
|
1752 | 1752 |
return False |
1753 | 1753 | |
1754 | 1754 |
def is_endpoint(self): |
... | ... | |
1948 | 1948 |
continue |
1949 | 1949 |
if not user: |
1950 | 1950 |
continue |
1951 |
role = formdata.get_role_translation(role) |
|
1952 |
if role in user.get_roles(): |
|
1951 |
if formdata.get_function_roles(role).intersection(user.get_roles()): |
|
1953 | 1952 |
return True |
1954 | 1953 | |
1955 | 1954 |
return False |
... | ... | |
2963 | 2962 |
addresses.append(submitter_email) |
2964 | 2963 |
continue |
2965 | 2964 | |
2966 |
dest = formdata.get_role_translation(dest) |
|
2967 | ||
2968 |
try: |
|
2969 |
role = get_publisher().role_class.get(dest) |
|
2970 |
except KeyError: |
|
2971 |
continue |
|
2972 |
addresses.extend(role.get_emails()) |
|
2965 |
for real_dest in formdata.get_function_roles(dest): |
|
2966 |
try: |
|
2967 |
role = get_publisher().role_class.get(real_dest) |
|
2968 |
except KeyError: |
|
2969 |
continue |
|
2970 |
addresses.extend(role.get_emails()) |
|
2973 | 2971 | |
2974 | 2972 |
if not addresses: |
2975 | 2973 |
return |
2976 |
- |