misc: make get_visible_status callable from templates (#75804)
gitea/wcs/pipeline/head Build queued...
Details
gitea/wcs/pipeline/head Build queued...
Details
This commit is contained in:
parent
63d4c99c9d
commit
11625292a0
|
@ -4490,3 +4490,64 @@ def test_fts_display_id(pub):
|
|||
formdata.store()
|
||||
|
||||
assert formdef.data_class().count([FtsMatch('123-4567')]) == 1
|
||||
|
||||
|
||||
def test_get_visible_status(pub, local_user):
|
||||
Workflow.wipe()
|
||||
workflow = Workflow(name='test')
|
||||
st_new = workflow.add_status('New')
|
||||
st_finished = workflow.add_status('Finished')
|
||||
workflow.store()
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.workflow_id = workflow.id
|
||||
formdef.name = 'foo'
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
formdef.data_class().wipe()
|
||||
|
||||
formdata = formdef.data_class()()
|
||||
formdata.evolution = []
|
||||
|
||||
# create evolution [new, empty, finished, empty]
|
||||
for status in (st_new, None, st_finished, None):
|
||||
evo = Evolution()
|
||||
evo.time = time.localtime()
|
||||
if status:
|
||||
evo.status = 'wf-%s' % status.id
|
||||
formdata.evolution.append(evo)
|
||||
|
||||
formdata.store()
|
||||
|
||||
# check visible status is "Finished"
|
||||
formdata = FormDef.get(formdef.id).data_class().get(formdata.id)
|
||||
assert formdata.get_visible_status(user=None).name == 'Finished'
|
||||
|
||||
# mark finished as not visible
|
||||
st_finished.visibility = ['unknown']
|
||||
workflow.store()
|
||||
|
||||
# check "New" is now returned as visible status
|
||||
formdata = FormDef.get(formdef.id).data_class().get(formdata.id)
|
||||
assert formdata.get_visible_status(user=None).name == 'New'
|
||||
assert formdata.get_visible_status(user=local_user).name == 'New'
|
||||
|
||||
# check with user from session
|
||||
pub._request._user = local_user
|
||||
assert formdata.get_visible_status().name == 'New'
|
||||
|
||||
# check from backoffice
|
||||
pub._request.environ['PATH_INFO'] = 'backoffice/test/'
|
||||
assert formdata.get_visible_status().name == 'New'
|
||||
|
||||
# check admin in backoffice gets the real status
|
||||
local_user.is_admin = True
|
||||
local_user.store()
|
||||
assert formdata.get_visible_status().name == 'Finished'
|
||||
|
||||
# check another user in backoffice gets "New"
|
||||
assert formdata.get_visible_status(user=None).name == 'New'
|
||||
|
||||
# check admin in front also gets "New"
|
||||
pub._request.environ['PATH_INFO'] = ''
|
||||
assert formdata.get_visible_status().name == 'New'
|
||||
|
|
|
@ -746,7 +746,9 @@ class FormData(StorableObject):
|
|||
return _('Unknown')
|
||||
return wf_status.name
|
||||
|
||||
def get_visible_status(self, user):
|
||||
def get_visible_status(self, user=Ellipsis):
|
||||
if user is Ellipsis:
|
||||
user = get_request().user
|
||||
if not self.evolution:
|
||||
return self.get_status()
|
||||
for evo in reversed(self.evolution):
|
||||
|
|
Loading…
Reference in New Issue