workflows: possibility to hide some status from the user (#1588)
This commit is contained in:
parent
a94cc30625
commit
77773d3748
|
@ -272,7 +272,7 @@ class WorkflowItemsDir(Directory):
|
|||
|
||||
class WorkflowStatusPage(Directory):
|
||||
_q_exports = ['', 'delete', 'newitem', ('items', 'items_dir'),
|
||||
'update_order', 'edit', 'reassign']
|
||||
'update_order', 'edit', 'reassign', 'visibility']
|
||||
|
||||
def __init__(self, workflow, status_id):
|
||||
self.workflow = workflow
|
||||
|
@ -299,6 +299,14 @@ class WorkflowStatusPage(Directory):
|
|||
select='%s' % self.status.id))
|
||||
'</div>'
|
||||
|
||||
if self.status.visibility == ['_receiver']:
|
||||
'<div class="bo-block">'
|
||||
_('This status is hidden from the user.')
|
||||
if not str(self.workflow.id).startswith(str('_')):
|
||||
' '
|
||||
'(<a href="visibility" rel="popup">%s</a>)' % _('change')
|
||||
'</div>'
|
||||
|
||||
'<div class="bo-block">'
|
||||
if not self.status.items:
|
||||
'<p>%s</p>' % _('There are not yet any items in this status.')
|
||||
|
@ -342,6 +350,7 @@ class WorkflowStatusPage(Directory):
|
|||
else:
|
||||
'<ul>'
|
||||
'<li><a href="edit">%s</a></li>' % _('Change Status Name')
|
||||
'<li><a href="visibility" rel="popup">%s</a></li>' % _('Change Status Visibility')
|
||||
'<li><a href="delete" rel="popup">%s</a></li>' % _('Delete')
|
||||
'</ul>'
|
||||
'<div id="new-field">'
|
||||
|
@ -517,6 +526,30 @@ class WorkflowStatusPage(Directory):
|
|||
get_logger().info('admin - delete status "%s" in workflow "%s": %d forms deleted' % (
|
||||
self.status.name, self.workflow.name, nb_forms))
|
||||
|
||||
def visibility [html] (self):
|
||||
form = Form(enctype = 'multipart/form-data')
|
||||
form.add(CheckboxWidget, 'hide_status_from_user',
|
||||
title=_('Hide status from user'),
|
||||
value=(self.status.visibility == ['_receiver']))
|
||||
form.add_submit('submit', _('Submit'))
|
||||
form.add_submit('cancel', _('Cancel'))
|
||||
if form.get_widget('cancel').parse():
|
||||
return redirect('..')
|
||||
|
||||
if form.is_submitted() and not form.has_errors():
|
||||
hide_status = form.get_widget('hide_status_from_user').parse()
|
||||
if hide_status:
|
||||
self.status.visibility = [str('_receiver')]
|
||||
else:
|
||||
self.status.visibility = None
|
||||
self.workflow.store()
|
||||
return redirect('.')
|
||||
|
||||
html_top('workflows', title = _('Edit Workflow Status Visibility'))
|
||||
get_response().breadcrumb.append( ('visibility', _('Visibility')) )
|
||||
'<h2>%s</h2>' % _('Edit Workflow Status Visibility')
|
||||
form.render()
|
||||
|
||||
|
||||
class WorkflowStatusDirectory(Directory):
|
||||
_q_exports = ['']
|
||||
|
|
|
@ -164,15 +164,21 @@ class FormData(StorableObject):
|
|||
return status.get_message(self)
|
||||
return ''
|
||||
|
||||
def get_status_label(self, status = None):
|
||||
def get_status(self, status = None):
|
||||
if not status:
|
||||
status = self.status
|
||||
if not self.formdef:
|
||||
return _('Unknown')
|
||||
return None
|
||||
try:
|
||||
status_id = status.split('-')[1]
|
||||
wf_status = [x for x in self.formdef.workflow.possible_status if x.id == status_id][0]
|
||||
except IndexError:
|
||||
return None
|
||||
return wf_status
|
||||
|
||||
def get_status_label(self, status = None):
|
||||
wf_status = self.get_status(status)
|
||||
if not wf_status:
|
||||
return _('Unknown')
|
||||
return wf_status.name
|
||||
|
||||
|
|
|
@ -151,7 +151,17 @@ class FormStatusPage(Directory):
|
|||
'<div class="bo-block">'
|
||||
'<h2>%s</h2>' % _('Log')
|
||||
'<dl id="evolutions">'
|
||||
hidden = False
|
||||
for evo in self.filled.evolution:
|
||||
if evo.status:
|
||||
wf_status = self.filled.get_status(evo.status)
|
||||
if not wf_status.is_visible(self.filled, get_request().user):
|
||||
hidden = True
|
||||
else:
|
||||
hidden = False
|
||||
if hidden:
|
||||
continue
|
||||
|
||||
"<dt>%s" % misc.localstrftime(evo.time)
|
||||
if evo.who:
|
||||
evo_author = None
|
||||
|
|
|
@ -314,6 +314,7 @@ class WorkflowStatus:
|
|||
id = None
|
||||
name = None
|
||||
items = None
|
||||
visibility = None
|
||||
|
||||
def __init__(self, name = None):
|
||||
self.name = name
|
||||
|
@ -431,6 +432,25 @@ class WorkflowStatus:
|
|||
item.directory_class(formdata, item, self)))
|
||||
return subdirectories
|
||||
|
||||
def is_visible(self, formdata, user):
|
||||
if not self.visibility: # no restriction -> visible
|
||||
return True
|
||||
if user and user.is_admin:
|
||||
return True
|
||||
|
||||
if user:
|
||||
user_roles = set(user.roles or [])
|
||||
user_roles.add(logged_users_role().id)
|
||||
else:
|
||||
user_roles = set([])
|
||||
|
||||
for role in self.visibility:
|
||||
if role == '_receiver':
|
||||
role = formdata.formdef.receiver_id
|
||||
if role in user_roles:
|
||||
return True
|
||||
return False
|
||||
|
||||
def __getstate__(self):
|
||||
odict = self.__dict__.copy()
|
||||
if odict.has_key('parent'):
|
||||
|
|
Loading…
Reference in New Issue