0002-formdata-hold-is_for_current_user-function-38254.patch
wcs/formdata.py | ||
---|---|---|
924 | 924 | |
925 | 925 |
def is_submitter(self, user): |
926 | 926 |
if self.user_id and user and str(self.user_id) == str(user.id): |
927 | 927 |
return True |
928 | 928 |
if get_session() and get_session().is_anonymous_submitter(self): |
929 | 929 |
return True |
930 | 930 |
return False |
931 | 931 | |
932 |
def is_for_current_user(self, to): |
|
933 |
if not to: |
|
934 |
return True |
|
935 |
if not get_request(): |
|
936 |
return False |
|
937 |
user = get_request().user |
|
938 |
for role in to or []: |
|
939 |
if role == '_submitter': |
|
940 |
if self.is_submitter(user): |
|
941 |
return True |
|
942 |
elif user: |
|
943 |
role = self.get_role_translation(role) |
|
944 |
if role in user.get_roles(): |
|
945 |
return True |
|
946 |
return False |
|
947 | ||
932 | 948 |
def is_draft(self, status=None): |
933 | 949 |
if status is None: |
934 | 950 |
status = self.status |
935 | 951 |
return status == 'draft' |
936 | 952 | |
937 | 953 |
def get_concerned_roles(self): |
938 | 954 |
if self.is_draft(): |
939 | 955 |
# drafts are only visible to submitter |
wcs/forms/common.py | ||
---|---|---|
347 | 347 |
if form.has_errors(): |
348 | 348 |
return |
349 | 349 |
url = self.submit(form) |
350 | 350 |
if url is None: |
351 | 351 |
url = get_request().get_frontoffice_url() |
352 | 352 |
status = self.filled.get_status() |
353 | 353 |
top_alert = False |
354 | 354 |
for item in status.items or []: |
355 |
if item.key == 'displaymsg' and item.position == 'top' and item.is_for_current_user(self.filled):
|
|
355 |
if item.key == 'displaymsg' and item.position == 'top' and self.filled.is_for_current_user(item.to):
|
|
356 | 356 |
top_alert = True |
357 | 357 |
break |
358 | 358 |
if top_alert: |
359 | 359 |
# prevent an existing anchor client side to take effect |
360 | 360 |
url += '#' |
361 | 361 |
else: |
362 | 362 |
url += '#action-zone' |
363 | 363 |
response = get_response() |
wcs/workflows.py | ||
---|---|---|
2880 | 2880 |
elif self.position == 'bottom': |
2881 | 2881 |
parts.append(_('bottom of page')) |
2882 | 2882 |
elif self.position == 'actions': |
2883 | 2883 |
parts.append(_('with actions')) |
2884 | 2884 |
if self.to: |
2885 | 2885 |
parts.append(_('for %s') % self.render_list_of_roles(self.to)) |
2886 | 2886 |
return ', '.join(parts) |
2887 | 2887 | |
2888 |
def is_for_current_user(self, filled): |
|
2889 |
if not self.to: |
|
2890 |
return True |
|
2891 |
if not get_request(): |
|
2892 |
return False |
|
2893 |
user = get_request().user |
|
2894 |
for role in self.to or []: |
|
2895 |
if role == '_submitter': |
|
2896 |
if filled.is_submitter(user): |
|
2897 |
return True |
|
2898 |
elif user: |
|
2899 |
role = filled.get_role_translation(role) |
|
2900 |
if role in user.get_roles(): |
|
2901 |
return True |
|
2902 |
return False |
|
2903 | ||
2904 | 2888 |
def get_message(self, filled, position='top'): |
2905 |
if not (self.message and self.position == position and self.is_for_current_user(filled)):
|
|
2889 |
if not (self.message and self.position == position and filled.is_for_current_user(self.to)):
|
|
2906 | 2890 |
return '' |
2907 | 2891 | |
2908 | 2892 |
dict = copy.copy(get_publisher().substitutions.get_context_variables('lazy')) |
2909 | 2893 |
dict['date'] = misc.localstrftime(filled.receipt_time) |
2910 | 2894 |
dict['number'] = filled.id |
2911 | 2895 |
handling_role = filled.get_handling_role() |
2912 | 2896 |
if handling_role and handling_role.details: |
2913 | 2897 |
dict['receiver'] = handling_role.details.replace('\n', '<br />') |
2914 |
- |