Fixed Attract link not showing up in sidebar
This commit is contained in:
@@ -166,11 +166,12 @@ class AttractExtension(PillarExtension):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def sidebar_links(self, project):
|
def sidebar_links(self, project):
|
||||||
|
from pillar.api.utils import str2id
|
||||||
|
|
||||||
if not self.is_attract_project(project):
|
if not self.is_attract_project(project):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
if not self.auth.current_user_may(auth.Actions.VIEW):
|
if not self.auth.current_user_may(auth.Actions.VIEW, str2id(project['_id'])):
|
||||||
return ''
|
return ''
|
||||||
|
|
||||||
return flask.render_template('attract/sidebar.html',
|
return flask.render_template('attract/sidebar.html',
|
||||||
|
@@ -61,7 +61,7 @@ class Auth(object):
|
|||||||
intersection = require_roles.intersection(user_roles)
|
intersection = require_roles.intersection(user_roles)
|
||||||
return bool(intersection)
|
return bool(intersection)
|
||||||
|
|
||||||
def current_user_may(self, action: Actions) -> bool:
|
def current_user_may(self, action: Actions, project_id: bson.ObjectId=None) -> bool:
|
||||||
"""Returns True iff the user is authorised to use/view Attract on the current project.
|
"""Returns True iff the user is authorised to use/view Attract on the current project.
|
||||||
|
|
||||||
Requires that determine_user_rights() was called before.
|
Requires that determine_user_rights() was called before.
|
||||||
@@ -70,10 +70,14 @@ class Auth(object):
|
|||||||
try:
|
try:
|
||||||
attract_rights = flask.g.attract_rights
|
attract_rights = flask.g.attract_rights
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
|
if not project_id:
|
||||||
self._log.error('current_user_may() called without previous call '
|
self._log.error('current_user_may() called without previous call '
|
||||||
'to current_user_rights()')
|
'to current_user_rights()')
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
self.determine_user_rights(project_id)
|
||||||
|
attract_rights = flask.g.attract_rights
|
||||||
|
|
||||||
return action in attract_rights
|
return action in attract_rights
|
||||||
|
|
||||||
def determine_user_rights(self, project_id: bson.ObjectId):
|
def determine_user_rights(self, project_id: bson.ObjectId):
|
||||||
|
Reference in New Issue
Block a user