0001-formdata-hold-get_role_translation-function-38254.patch
wcs/backoffice/management.py | ||
---|---|---|
70 | 70 |
from wcs.forms.backoffice import FormDefUI |
71 | 71 |
from wcs.forms.common import FormStatusPage |
72 | 72 |
from wcs.admin.settings import UserFieldsFormDef |
73 | 73 |
from wcs.categories import Category |
74 | 74 |
from wcs.formdata import FormData |
75 | 75 |
from wcs.formdef import FormDef |
76 | 76 |
from wcs.roles import logged_users_role, Role |
77 | 77 |
from wcs.variables import LazyFieldVar |
78 |
from wcs.workflows import get_role_translation, template_on_formdata, WorkflowStatusItem
|
|
78 |
from wcs.workflows import template_on_formdata, WorkflowStatusItem |
|
79 | 79 | |
80 | 80 |
from .submission import FormFillPage |
81 | 81 | |
82 | 82 | |
83 | 83 |
def geojson_formdatas(formdatas, geoloc_key='base', fields=None): |
84 | 84 |
geojson = {'type': 'FeatureCollection', 'features': []} |
85 | 85 | |
86 | 86 |
for formdata in formdatas: |
... | ... | |
3287 | 3287 |
# assigned functions |
3288 | 3288 |
if self.formdef.workflow.roles: |
3289 | 3289 |
workflow = self.formdef.workflow |
3290 | 3290 |
r += htmltext('<div id="inspect-functions" class="section">') |
3291 | 3291 |
r += htmltext('<h2>%s</h2></li>\n') % _('Functions') |
3292 | 3292 |
r += htmltext('<ul class="form-inspector biglist">') |
3293 | 3293 |
for key, label in (workflow.roles or {}).items(): |
3294 | 3294 |
r += htmltext('<li><span class="label">%s</span>') % label |
3295 |
acting_role_id = get_role_translation(self.filled, key)
|
|
3295 |
acting_role_id = self.filled.get_role_translation(key)
|
|
3296 | 3296 |
if acting_role_id: |
3297 | 3297 |
try: |
3298 | 3298 |
acting_role = Role.get(acting_role_id) |
3299 | 3299 |
r += htmltext('<div class="value"><span>%s</span></div>') % acting_role.name |
3300 | 3300 |
except KeyError: |
3301 | 3301 |
r += htmltext('<div class="value"><span>%s %s</span></div>') % ( |
3302 | 3302 |
acting_role_id, |
3303 | 3303 |
_('(deleted)'), |
wcs/formdata.py | ||
---|---|---|
671 | 671 |
return self.get_url(backoffice=True) |
672 | 672 | |
673 | 673 |
def get_api_url(self): |
674 | 674 |
return '%s%s/' % (self.formdef.get_api_url(), self.id) |
675 | 675 | |
676 | 676 |
def get_display_id(self): |
677 | 677 |
return str(self.id_display or self.id) |
678 | 678 | |
679 |
def get_role_translation(self, role_name): |
|
680 |
if role_name == '_submitter': |
|
681 |
raise Exception('_submitter is not a valid role') |
|
682 |
elif str(role_name).startswith('_'): |
|
683 |
role_id = None |
|
684 |
if self.workflow_roles: |
|
685 |
role_id = self.workflow_roles.get(role_name) |
|
686 |
if not role_id and self.formdef.workflow_roles: |
|
687 |
role_id = self.formdef.workflow_roles.get(role_name) |
|
688 |
if role_id is None: |
|
689 |
return role_id |
|
690 |
return str(role_id) |
|
691 |
else: |
|
692 |
return str(role_name) |
|
693 | ||
679 | 694 |
def get_handling_role_id(self): |
680 | 695 |
# TODO: look at current status and return the role(s) actually |
681 | 696 |
# concerned by the handling of the formdata |
682 |
from wcs.workflows import get_role_translation |
|
683 | ||
684 |
return get_role_translation(self, '_receiver') |
|
697 |
return self.get_role_translation('_receiver') |
|
685 | 698 | |
686 | 699 |
def get_handling_role(self): |
687 | 700 |
try: |
688 | 701 |
return Role.get(self.get_handling_role_id()) |
689 | 702 |
except KeyError: |
690 | 703 |
return None |
691 | 704 | |
692 | 705 |
def get_field_view_value(self, field, max_length=None): |
... | ... | |
981 | 994 |
# drafts are only visible to submitter |
982 | 995 |
return ['_submitter'] |
983 | 996 | |
984 | 997 |
status_action_roles = set() |
985 | 998 | |
986 | 999 |
# make sure the handling roles always gets access to the formdata, till |
987 | 1000 |
# the very end (where it may be that there is no workflow status item |
988 | 1001 |
# at all). |
989 |
from wcs.workflows import get_role_translation |
|
990 | ||
991 | 1002 |
for function_key in self.formdef.workflow.roles.keys(): |
992 |
handling_role = get_role_translation(self, function_key)
|
|
1003 |
handling_role = self.get_role_translation(function_key)
|
|
993 | 1004 |
if handling_role: |
994 | 1005 |
status_action_roles.add(handling_role) |
995 | 1006 | |
996 | 1007 |
wf_status = self.get_status() |
997 | 1008 |
if not wf_status: |
998 | 1009 |
status_action_roles.add('_submitter') |
999 | 1010 |
else: |
1000 | 1011 |
status_action_roles |= set(self.get_actions_roles()) |
... | ... | |
1005 | 1016 |
def get_actions_roles(self): |
1006 | 1017 |
if self.is_draft(): |
1007 | 1018 |
return [] |
1008 | 1019 | |
1009 | 1020 |
wf_status = self.get_status() |
1010 | 1021 |
if not wf_status: |
1011 | 1022 |
return [] |
1012 | 1023 | |
1013 |
from wcs.workflows import get_role_translation |
|
1014 | ||
1015 | 1024 |
status_action_roles = set() |
1016 | 1025 |
for item in wf_status.items or []: |
1017 | 1026 |
if not hasattr(item, 'by') or not item.by: |
1018 | 1027 |
continue |
1019 | 1028 |
with get_publisher().substitutions.temporary_feed(self): |
1020 | 1029 |
if not item.check_condition(self): |
1021 | 1030 |
continue |
1022 | 1031 |
for role in item.by: |
1023 | 1032 |
if role == '_submitter': |
1024 | 1033 |
status_action_roles.add(role) |
1025 | 1034 |
else: |
1026 |
real_role = get_role_translation(self, role)
|
|
1035 |
real_role = self.get_role_translation(role)
|
|
1027 | 1036 |
if real_role: |
1028 | 1037 |
status_action_roles.add(real_role) |
1029 | 1038 | |
1030 | 1039 |
return status_action_roles |
1031 | 1040 | |
1032 | 1041 |
actions_roles = property(get_actions_roles) |
1033 | 1042 | |
1034 | 1043 |
def get_last_update_time(self): |
wcs/forms/workflows.py | ||
---|---|---|
18 | 18 | |
19 | 19 |
from quixote import get_request, get_response |
20 | 20 |
from quixote.directory import Directory |
21 | 21 | |
22 | 22 |
from ..qommon import errors |
23 | 23 | |
24 | 24 |
from wcs.api import get_user_from_api_query_string, is_url_signed |
25 | 25 |
from wcs.roles import logged_users_role |
26 |
from wcs.workflows import WorkflowGlobalActionWebserviceTrigger, get_role_translation, perform_items
|
|
26 |
from wcs.workflows import WorkflowGlobalActionWebserviceTrigger, perform_items |
|
27 | 27 | |
28 | 28 | |
29 | 29 |
class HookDirectory(Directory): |
30 | 30 |
_q_exports = [''] |
31 | 31 | |
32 | 32 |
def __init__(self, formdata, action, trigger): |
33 | 33 |
self.formdata = formdata |
34 | 34 |
self.action = action |
... | ... | |
44 | 44 |
if self.trigger.roles: |
45 | 45 |
for role in self.trigger.roles: |
46 | 46 |
if role == logged_users_role().id and (user or is_url_signed()): |
47 | 47 |
break |
48 | 48 |
if role == '_submitter' and self.formdata.is_submitter(user): |
49 | 49 |
break |
50 | 50 |
if not user: |
51 | 51 |
continue |
52 |
if get_role_translation(self.formdata, role) in user.get_roles():
|
|
52 |
if self.formdata.get_role_translation(role) in user.get_roles():
|
|
53 | 53 |
break |
54 | 54 |
else: |
55 | 55 |
raise errors.AccessForbiddenError('insufficient roles') |
56 | 56 | |
57 | 57 |
if hasattr(get_request(), '_json'): |
58 | 58 |
workflow_data = {self.trigger.identifier: get_request().json} |
59 | 59 |
self.formdata.update_workflow_data(workflow_data) |
60 | 60 |
self.formdata.store() |
wcs/wf/aggregation_email.py | ||
---|---|---|
16 | 16 | |
17 | 17 |
from ..qommon import _, N_ |
18 | 18 |
from ..qommon.publisher import get_publisher_class |
19 | 19 |
from ..qommon.storage import StorableObject |
20 | 20 |
from ..qommon.form import * |
21 | 21 |
from ..qommon.cron import CronJob |
22 | 22 |
from ..qommon import emails |
23 | 23 | |
24 |
from wcs.workflows import WorkflowStatusItem, register_item_class, get_role_translation |
|
25 | ||
24 |
from wcs.workflows import WorkflowStatusItem, register_item_class |
|
26 | 25 |
from wcs.roles import Role |
27 | 26 | |
28 | 27 | |
29 | 28 |
class AggregationEmailWorkflowStatusItem(WorkflowStatusItem): |
30 | 29 |
description = N_('Daily Summary Email') |
31 | 30 |
key = 'aggregationemail' |
32 | 31 |
category = 'interaction' |
33 | 32 |
ok_in_global_action = False |
... | ... | |
61 | 60 |
def get_parameters(self): |
62 | 61 |
return ('to', 'condition') |
63 | 62 | |
64 | 63 |
def perform(self, formdata): |
65 | 64 |
if not self.to: |
66 | 65 |
return |
67 | 66 | |
68 | 67 |
for dest in self.to: |
69 |
dest = get_role_translation(formdata, dest)
|
|
68 |
dest = formdata.get_role_translation(dest)
|
|
70 | 69 |
try: |
71 | 70 |
aggregate = AggregationEmail.get(dest) |
72 | 71 |
except KeyError: |
73 | 72 |
aggregate = AggregationEmail(id=dest) |
74 | 73 | |
75 | 74 |
aggregate.append( |
76 | 75 |
{'formdef': formdata.formdef.id, 'formdata': formdata.id, 'formurl': formdata.get_url()} |
77 | 76 |
) |
wcs/wf/notification.py | ||
---|---|---|
19 | 19 |
from quixote import get_publisher |
20 | 20 | |
21 | 21 |
from ..qommon import _, N_, ezt |
22 | 22 |
from ..qommon.form import * |
23 | 23 |
from ..qommon.template import TemplateError |
24 | 24 |
from ..qommon import get_logger |
25 | 25 | |
26 | 26 |
from wcs.roles import Role |
27 |
from wcs.workflows import WorkflowStatusItem, register_item_class, template_on_formdata, get_role_translation
|
|
27 |
from wcs.workflows import WorkflowStatusItem, register_item_class, template_on_formdata |
|
28 | 28 |
from .wscall import WebserviceCallStatusItem |
29 | 29 | |
30 | 30 | |
31 | 31 |
class SendNotificationWorkflowStatusItem(WebserviceCallStatusItem): |
32 | 32 |
description = N_('User Notification') |
33 | 33 |
key = 'notification' |
34 | 34 |
category = 'interaction' |
35 | 35 |
support_substitution_variables = True |
... | ... | |
147 | 147 |
self.url = self.get_api_url() |
148 | 148 | |
149 | 149 |
users = [] |
150 | 150 |
for dest in self.to: |
151 | 151 |
if dest == '_submitter': |
152 | 152 |
users.append(formdata.get_user()) |
153 | 153 |
continue |
154 | 154 | |
155 |
dest = get_role_translation(formdata, dest)
|
|
155 |
dest = formdata.get_role_translation(dest)
|
|
156 | 156 |
try: |
157 | 157 |
role = Role.get(dest) |
158 | 158 |
except KeyError: |
159 | 159 |
continue |
160 | 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 | ||
---|---|---|
517 | 517 |
actions = [] |
518 | 518 |
for action in self.global_actions or []: |
519 | 519 |
for trigger in action.triggers or []: |
520 | 520 |
if isinstance(trigger, WorkflowGlobalActionManualTrigger): |
521 | 521 |
if '_submitter' in (trigger.roles or []) and formdata.is_submitter(user): |
522 | 522 |
actions.append(action) |
523 | 523 |
break |
524 | 524 |
roles = [ |
525 |
get_role_translation(formdata, x) for x in (trigger.roles or []) if x != '_submitter'
|
|
525 |
formdata.get_role_translation(x) for x in (trigger.roles or []) if x != '_submitter'
|
|
526 | 526 |
] |
527 | 527 |
if set(roles).intersection(user.get_roles()): |
528 | 528 |
actions.append(action) |
529 | 529 |
break |
530 | 530 |
return actions |
531 | 531 | |
532 | 532 |
def get_subdirectories(self, formdata): |
533 | 533 |
wf_status = formdata.get_status() |
... | ... | |
1628 | 1628 |
break |
1629 | 1629 |
if role == '_submitter': |
1630 | 1630 |
if filled.is_submitter(user): |
1631 | 1631 |
break |
1632 | 1632 |
else: |
1633 | 1633 |
continue |
1634 | 1634 |
if user is None: |
1635 | 1635 |
continue |
1636 |
role = get_role_translation(filled, role)
|
|
1636 |
role = filled.get_role_translation(role)
|
|
1637 | 1637 |
if role in user.get_roles(): |
1638 | 1638 |
break |
1639 | 1639 |
else: |
1640 | 1640 |
continue |
1641 | 1641 |
if not item.check_condition(filled): |
1642 | 1642 |
continue |
1643 | 1643 |
yield item |
1644 | 1644 | |
... | ... | |
1719 | 1719 |
visibility_roles = self.visibility[:] |
1720 | 1720 |
for item in self.items or []: |
1721 | 1721 |
if not hasattr(item, 'by') or not item.by: |
1722 | 1722 |
continue |
1723 | 1723 |
visibility_roles.extend(item.by) |
1724 | 1724 | |
1725 | 1725 |
for role in visibility_roles: |
1726 | 1726 |
if role != '_submitter': |
1727 |
role = get_role_translation(formdata, role)
|
|
1727 |
role = formdata.get_role_translation(role)
|
|
1728 | 1728 |
if role in user_roles: |
1729 | 1729 |
return True |
1730 | 1730 |
return False |
1731 | 1731 | |
1732 | 1732 |
def is_endpoint(self): |
1733 | 1733 |
# an endpoint status is a status that marks the end of the workflow; it |
1734 | 1734 |
# can either be computed automatically (if there's no way out of the |
1735 | 1735 |
# status) or be set manually (to mark the expected end while still |
... | ... | |
1921 | 1921 |
return True |
1922 | 1922 |
if role == '_submitter': |
1923 | 1923 |
t = formdata.is_submitter(user) |
1924 | 1924 |
if t is True: |
1925 | 1925 |
return True |
1926 | 1926 |
continue |
1927 | 1927 |
if not user: |
1928 | 1928 |
continue |
1929 |
role = get_role_translation(formdata, role)
|
|
1929 |
role = formdata.get_role_translation(role)
|
|
1930 | 1930 |
if role in user.get_roles(): |
1931 | 1931 |
return True |
1932 | 1932 | |
1933 | 1933 |
return False |
1934 | 1934 | |
1935 | 1935 |
def check_condition(self, formdata): |
1936 | 1936 |
context = {'formdata': formdata, 'status_item': self} |
1937 | 1937 |
try: |
... | ... | |
2387 | 2387 |
markers_stack = [] |
2388 | 2388 |
markers_stack.append({'status_id': formdata.status[3:]}) |
2389 | 2389 |
formdata.update_workflow_data({'_markers_stack': markers_stack}) |
2390 | 2390 | |
2391 | 2391 |
def get_parameters(self): |
2392 | 2392 |
return ('status', 'set_marker_on_status', 'condition') |
2393 | 2393 | |
2394 | 2394 | |
2395 |
def get_role_translation(formdata, role_name): |
|
2396 |
if role_name == '_submitter': |
|
2397 |
raise Exception('_submitter is not a valid role') |
|
2398 |
elif str(role_name).startswith('_'): |
|
2399 |
role_id = None |
|
2400 |
if formdata.workflow_roles: |
|
2401 |
role_id = formdata.workflow_roles.get(role_name) |
|
2402 |
if not role_id and formdata.formdef.workflow_roles: |
|
2403 |
role_id = formdata.formdef.workflow_roles.get(role_name) |
|
2404 |
if role_id is None: |
|
2405 |
return role_id |
|
2406 |
return str(role_id) |
|
2407 |
else: |
|
2408 |
return str(role_name) |
|
2409 | ||
2410 | ||
2411 | 2395 |
def get_role_translation_label(workflow, role_id): |
2412 | 2396 |
if role_id == logged_users_role().id: |
2413 | 2397 |
return logged_users_role().name |
2414 | 2398 |
if role_id == '_submitter': |
2415 | 2399 |
return C_('role|User') |
2416 | 2400 |
if str(role_id).startswith('_'): |
2417 | 2401 |
return workflow.roles.get(role_id) |
2418 | 2402 |
else: |
... | ... | |
2962 | 2946 |
continue |
2963 | 2947 | |
2964 | 2948 |
if dest == '_submitter': |
2965 | 2949 |
submitter_email = formdata.formdef.get_submitter_email(formdata) |
2966 | 2950 |
if submitter_email: |
2967 | 2951 |
addresses.append(submitter_email) |
2968 | 2952 |
continue |
2969 | 2953 | |
2970 |
dest = get_role_translation(formdata, dest)
|
|
2954 |
dest = formdata.get_role_translation(dest)
|
|
2971 | 2955 | |
2972 | 2956 |
try: |
2973 | 2957 |
role = Role.get(dest) |
2974 | 2958 |
except KeyError: |
2975 | 2959 |
continue |
2976 | 2960 |
addresses.extend(role.get_emails()) |
2977 | 2961 | |
2978 | 2962 |
if not addresses: |
... | ... | |
3155 | 3139 |
if not get_request(): |
3156 | 3140 |
return False |
3157 | 3141 |
user = get_request().user |
3158 | 3142 |
for role in self.to or []: |
3159 | 3143 |
if role == '_submitter': |
3160 | 3144 |
if filled.is_submitter(user): |
3161 | 3145 |
return True |
3162 | 3146 |
elif user: |
3163 |
role = get_role_translation(filled, role)
|
|
3147 |
role = filled.get_role_translation(role)
|
|
3164 | 3148 |
if role in user.get_roles(): |
3165 | 3149 |
return True |
3166 | 3150 |
return False |
3167 | 3151 | |
3168 | 3152 |
def get_message(self, filled, position='top'): |
3169 | 3153 |
if not (self.message and self.position == position and self.is_for_current_user(filled)): |
3170 | 3154 |
return '' |
3171 | 3155 | |
3172 |
- |