Added p.a.project.utils.user_rights_in_project()

This returns the allowed HTTP method for the current user in the given
project. This is used for access control on Flamenco, for example.
This commit is contained in:
Sybren A. Stüvel 2017-05-10 12:09:48 +02:00
parent a139e8c41a
commit c66a6e67c8

View File

@ -58,6 +58,19 @@ def get_admin_group(project: dict) -> dict:
return group
def user_rights_in_project(project_id: ObjectId) -> frozenset:
"""Returns the set of HTTP methods allowed on the given project for the current user."""
from pillar.api.utils import authorization
assert isinstance(project_id, ObjectId)
proj_coll = current_app.db().projects
proj = proj_coll.find_one({'_id': project_id})
return frozenset(authorization.compute_allowed_methods('projects', proj))
def abort_with_error(status):
"""Aborts with the given status, or 500 if the status doesn't indicate an error.