misc: move is_for_current_user function to formdata (#38254)

This commit is contained in:
Nicolas Roche 2020-12-12 10:46:58 +01:00
parent e4c5bea0d8
commit a6bb719413
3 changed files with 18 additions and 18 deletions

View File

@ -984,6 +984,22 @@ class FormData(StorableObject):
return True
return False
def is_for_current_user(self, to):
if not to:
return True
if not get_request():
return False
user = get_request().user
for role in to or []:
if role == '_submitter':
if self.is_submitter(user):
return True
elif user:
role = self.get_role_translation(role)
if role in user.get_roles():
return True
return False
def is_draft(self, status=None):
if status is None:
status = self.status

View File

@ -359,7 +359,7 @@ class FormStatusPage(Directory, FormTemplateMixin):
if (
item.key == 'displaymsg'
and item.position == 'top'
and item.is_for_current_user(self.filled)
and self.filled.is_for_current_user(item.to)
):
top_alert = True
break

View File

@ -3133,24 +3133,8 @@ class DisplayMessageWorkflowStatusItem(WorkflowStatusItem):
parts.append(_('for %s') % self.render_list_of_roles(self.to))
return ', '.join(parts)
def is_for_current_user(self, filled):
if not self.to:
return True
if not get_request():
return False
user = get_request().user
for role in self.to or []:
if role == '_submitter':
if filled.is_submitter(user):
return True
elif user:
role = filled.get_role_translation(role)
if role in user.get_roles():
return True
return False
def get_message(self, filled, position='top'):
if not (self.message and self.position == position and self.is_for_current_user(filled)):
if not (self.message and self.position == position and filled.is_for_current_user(self.to)):
return ''
dict = copy.copy(get_publisher().substitutions.get_context_variables('lazy'))