0002-formdata-hold-is_for_current_user-function-38254.patch
wcs/formdata.py | ||
---|---|---|
909 | 909 | |
910 | 910 |
def is_submitter(self, user): |
911 | 911 |
if self.user_id and user and str(self.user_id) == str(user.id): |
912 | 912 |
return True |
913 | 913 |
if get_session() and get_session().is_anonymous_submitter(self): |
914 | 914 |
return True |
915 | 915 |
return False |
916 | 916 | |
917 |
def is_for_current_user(self, to): |
|
918 |
from wcs.workflows import get_role_translation |
|
919 |
if not to: |
|
920 |
return True |
|
921 |
if not get_request(): |
|
922 |
return False |
|
923 |
user = get_request().user |
|
924 |
for role in to or []: |
|
925 |
if role == '_submitter': |
|
926 |
if self.is_submitter(user): |
|
927 |
return True |
|
928 |
elif user: |
|
929 |
role = get_role_translation(self, role) |
|
930 |
if role in user.get_roles(): |
|
931 |
return True |
|
932 |
return False |
|
933 | ||
917 | 934 |
def is_draft(self, status=None): |
918 | 935 |
if status is None: |
919 | 936 |
status = self.status |
920 | 937 |
return status == 'draft' |
921 | 938 | |
922 | 939 |
def get_concerned_roles(self): |
923 | 940 |
if self.is_draft(): |
924 | 941 |
# 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/wf/register_comment.py | ||
---|---|---|
48 | 48 |
# treat it as html, escape strings from ezt variables |
49 | 49 |
self.content = template_on_formdata(formdata, message, |
50 | 50 |
ezt_format=ezt.FORMAT_HTML) |
51 | 51 |
return |
52 | 52 | |
53 | 53 |
# treat is as text/plain |
54 | 54 |
self.content = template_on_formdata(formdata, message) |
55 | 55 | |
56 |
def is_for_current_user(self, filled): |
|
57 |
if not self.to: |
|
58 |
return True |
|
59 |
if not get_request(): |
|
60 |
return False |
|
61 |
user = get_request().user |
|
62 |
for role in self.to or []: |
|
63 |
if role == '_submitter': |
|
64 |
if filled.is_submitter(user): |
|
65 |
return True |
|
66 |
elif user: |
|
67 |
role = get_role_translation(filled, role) |
|
68 |
if role in user.get_roles(): |
|
69 |
return True |
|
70 |
return False |
|
71 | ||
72 | 56 |
def view(self, filled): |
73 |
if not (self.content and self.is_for_current_user(filled)):
|
|
57 |
if not (self.content and filled.is_for_current_user(self.to)):
|
|
74 | 58 |
return '' |
75 | 59 |
if self.content.startswith('<'): |
76 | 60 |
return htmltext(self.content) |
77 | 61 |
else: |
78 | 62 |
# use empty lines to mark paragraphs |
79 | 63 |
return htmltext('<p>') + \ |
80 | 64 |
htmltext('\n').join( |
81 | 65 |
[(x or htmltext('</p><p>')) for x in self.content.splitlines()]) + \ |
wcs/workflows.py | ||
---|---|---|
2898 | 2898 |
elif self.position == 'bottom': |
2899 | 2899 |
parts.append(_('bottom of page')) |
2900 | 2900 |
elif self.position == 'actions': |
2901 | 2901 |
parts.append(_('with actions')) |
2902 | 2902 |
if self.to: |
2903 | 2903 |
parts.append(_('for %s') % self.render_list_of_roles(self.to)) |
2904 | 2904 |
return ', '.join(parts) |
2905 | 2905 | |
2906 |
def is_for_current_user(self, filled): |
|
2907 |
if not self.to: |
|
2908 |
return True |
|
2909 |
if not get_request(): |
|
2910 |
return False |
|
2911 |
user = get_request().user |
|
2912 |
for role in self.to or []: |
|
2913 |
if role == '_submitter': |
|
2914 |
if filled.is_submitter(user): |
|
2915 |
return True |
|
2916 |
elif user: |
|
2917 |
role = get_role_translation(filled, role) |
|
2918 |
if role in user.get_roles(): |
|
2919 |
return True |
|
2920 |
return False |
|
2921 | ||
2922 | 2906 |
def get_message(self, filled, position='top'): |
2923 |
if not (self.message and self.position == position and self.is_for_current_user(filled)):
|
|
2907 |
if not (self.message and self.position == position and filled.is_for_current_user(self.to)):
|
|
2924 | 2908 |
return '' |
2925 | 2909 | |
2926 | 2910 |
dict = copy.copy(get_publisher().substitutions.get_context_variables('lazy')) |
2927 | 2911 |
dict['date'] = misc.localstrftime(filled.receipt_time) |
2928 | 2912 |
dict['number'] = filled.id |
2929 | 2913 |
handling_role = filled.get_handling_role() |
2930 | 2914 |
if handling_role and handling_role.details: |
2931 | 2915 |
dict['receiver'] = handling_role.details.replace('\n', '<br />') |
2932 |
- |