0002-formdata-hold-is_for_current_user-function-38254.patch
wcs/formdata.py | ||
---|---|---|
979 | 979 | |
980 | 980 |
def is_submitter(self, user): |
981 | 981 |
if self.user_id and user and str(self.user_id) == str(user.id): |
982 | 982 |
return True |
983 | 983 |
if get_session() and get_session().is_anonymous_submitter(self): |
984 | 984 |
return True |
985 | 985 |
return False |
986 | 986 | |
987 |
def is_for_current_user(self, to): |
|
988 |
if not to: |
|
989 |
return True |
|
990 |
if not get_request(): |
|
991 |
return False |
|
992 |
user = get_request().user |
|
993 |
for role in to or []: |
|
994 |
if role == '_submitter': |
|
995 |
if self.is_submitter(user): |
|
996 |
return True |
|
997 |
elif user: |
|
998 |
role = self.get_role_translation(role) |
|
999 |
if role in user.get_roles(): |
|
1000 |
return True |
|
1001 |
return False |
|
1002 | ||
987 | 1003 |
def is_draft(self, status=None): |
988 | 1004 |
if status is None: |
989 | 1005 |
status = self.status |
990 | 1006 |
return status == 'draft' |
991 | 1007 | |
992 | 1008 |
def get_concerned_roles(self): |
993 | 1009 |
if self.is_draft(): |
994 | 1010 |
# drafts are only visible to submitter |
wcs/forms/common.py | ||
---|---|---|
354 | 354 |
if url is None: |
355 | 355 |
url = get_request().get_frontoffice_url() |
356 | 356 |
status = self.filled.get_status() |
357 | 357 |
top_alert = False |
358 | 358 |
for item in status.items or []: |
359 | 359 |
if ( |
360 | 360 |
item.key == 'displaymsg' |
361 | 361 |
and item.position == 'top' |
362 |
and item.is_for_current_user(self.filled)
|
|
362 |
and self.filled.is_for_current_user(item.to)
|
|
363 | 363 |
): |
364 | 364 |
top_alert = True |
365 | 365 |
break |
366 | 366 |
if top_alert: |
367 | 367 |
# prevent an existing anchor client side to take effect |
368 | 368 |
url += '#' |
369 | 369 |
else: |
370 | 370 |
url += '#action-zone' |
wcs/workflows.py | ||
---|---|---|
3128 | 3128 |
elif self.position == 'bottom': |
3129 | 3129 |
parts.append(_('bottom of page')) |
3130 | 3130 |
elif self.position == 'actions': |
3131 | 3131 |
parts.append(_('with actions')) |
3132 | 3132 |
if self.to: |
3133 | 3133 |
parts.append(_('for %s') % self.render_list_of_roles(self.to)) |
3134 | 3134 |
return ', '.join(parts) |
3135 | 3135 | |
3136 |
def is_for_current_user(self, filled): |
|
3137 |
if not self.to: |
|
3138 |
return True |
|
3139 |
if not get_request(): |
|
3140 |
return False |
|
3141 |
user = get_request().user |
|
3142 |
for role in self.to or []: |
|
3143 |
if role == '_submitter': |
|
3144 |
if filled.is_submitter(user): |
|
3145 |
return True |
|
3146 |
elif user: |
|
3147 |
role = filled.get_role_translation(role) |
|
3148 |
if role in user.get_roles(): |
|
3149 |
return True |
|
3150 |
return False |
|
3151 | ||
3152 | 3136 |
def get_message(self, filled, position='top'): |
3153 |
if not (self.message and self.position == position and self.is_for_current_user(filled)):
|
|
3137 |
if not (self.message and self.position == position and filled.is_for_current_user(self.to)):
|
|
3154 | 3138 |
return '' |
3155 | 3139 | |
3156 | 3140 |
dict = copy.copy(get_publisher().substitutions.get_context_variables('lazy')) |
3157 | 3141 |
dict['date'] = misc.localstrftime(filled.receipt_time) |
3158 | 3142 |
dict['number'] = filled.id |
3159 | 3143 |
handling_role = filled.get_handling_role() |
3160 | 3144 |
if handling_role and handling_role.details: |
3161 | 3145 |
dict['receiver'] = handling_role.details.replace('\n', '<br />') |
3162 |
- |