Custom back_to_registering guard (allow roles OR a group) #22005 #30070

This commit is contained in:
Nicolas Demonte 2019-01-31 10:36:08 +01:00
parent 9918598b8f
commit abd293f19c
3 changed files with 25 additions and 8 deletions

View File

@ -1,3 +1,5 @@
# -*- coding: utf8 -*-
from zope.component import getUtility
from zope.intid.interfaces import IIntIds
from zc.relation.interfaces import ICatalog
@ -123,3 +125,24 @@ class CanBeTrashedDmsAppendixFile(grok.View):
def render(self):
return api.content.get_state(self.context) == 'published'
class CanReturnToRegistering(grok.View):
""""""
grok.name('can_return_to_registering')
grok.context(IDmsIncomingMail)
grok.require('zope2.View')
def render(self):
# accept any of these roles
allowed_roles = {'Reviewer', 'Manager', 'Greffier'}
user_roles = api.user.get_roles(obj=self.context)
if allowed_roles.intersection(user_roles):
return True
# or this user group
for group in api.group.get_groups():
if group.id == 'Gestion-secretariat-general':
return True
return False

View File

@ -204,10 +204,7 @@
<transition transition_id="back_to_registering" title="" new_state="registering" trigger="USER" before_script="" after_script="">
<action url="%(content_url)s/content_status_modify?workflow_action=back_to_registering" category="workflow" icon="" i18n:translate="">Back to registering</action>
<guard>
<guard-role>Reviewer</guard-role>
<guard-role>Manager</guard-role>
<guard-role>Greffier</guard-role>
<guard-role>SecretariatGeneralApf</guard-role>
<guard-expression>here/@@can_return_to_registering</guard-expression>
</guard>
</transition>
<transition transition_id="directly_noaction" title="" new_state="noaction" trigger="USER" before_script="" after_script="">

View File

@ -205,10 +205,7 @@
<transition transition_id="back_to_registering" title="" new_state="registering" trigger="USER" before_script="" after_script="">
<action url="%(content_url)s/content_status_modify?workflow_action=back_to_registering" category="workflow" icon="" i18n:translate="">Back to registering</action>
<guard>
<guard-role>Reviewer</guard-role>
<guard-role>Manager</guard-role>
<guard-role>Greffier</guard-role>
<guard-role>SecretariatGeneralAPF</guard-role>
<guard-expression>here/@@can_return_to_registering</guard-expression>
</guard>
</transition>
<transition transition_id="directly_noaction" title="" new_state="noaction" trigger="USER" before_script="" after_script="">