backoffice: don't lock if lock was acquired by deleted user (#55970)

This commit is contained in:
Frédéric Péters 2021-08-04 12:32:16 +02:00
parent 41cf01ccd9
commit 6923f4ff4b
2 changed files with 10 additions and 3 deletions

View File

@ -3978,6 +3978,13 @@ def test_backoffice_advisory_lock(pub):
assert 'advisory-lock' not in app2.get('/backoffice/management/form-title/')
assert 'advisory-lock' in app.get('/backoffice/management/form-title/')
# don't lock a form on removed users
second_user.remove_self()
assert 'advisory-lock' in app.get('/backoffice/management/form-title/') # still marked in listing
resp = app.get('/backoffice/management/form-title/' + first_link)
assert 'Be warned forms of this user are also being looked' not in resp.text # but not on view
assert resp.forms['wf-actions'] # and the action form is available
def test_backoffice_advisory_lock_related_formdatas(pub):
if not pub.is_using_postgresql():

View File

@ -592,7 +592,6 @@ class FormStatusPage(Directory, FormTemplateMixin):
if form:
all_visitors = get_session().get_object_visitors(self.filled)
visitors = [x for x in all_visitors if x[0] != get_session().user]
me_in_visitors = bool(get_session().user in [x[0] for x in all_visitors])
if visitors:
current_timestamp = time.time()
visitor_users = []
@ -609,18 +608,19 @@ class FormStatusPage(Directory, FormTemplateMixin):
visitor_users.append('%s (%s)' % (visitor_name, time_ago))
if visitor_users:
r += htmltext('<div id="lock-notice" class="infonotice"><p>')
r += _('Be warned forms of this user are also being looked at by: ' '%s.') % ', '.join(
r += _('Be warned forms of this user are also being looked at by: %s.') % ', '.join(
visitor_users
)
r += ' '
r += htmltext('</p>')
me_in_visitors = bool(get_session().user in [x[0] for x in all_visitors])
if not me_in_visitors:
locked = True
r += htmltext('<p class="action"><a href="?unlock">%s</a></p>') % _(
'(unlock actions)'
)
r += htmltext('</div>')
if not visitors or me_in_visitors:
if not locked:
r += htmltext(self.actions_workflow_messages())
r += form.render()
get_session().mark_visited_object(self.filled)