mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-28 03:39:29 -04:00
has_permissions() now checks user's orgs for <org_id> view args
view args are parameters within the route. for example, `/organisation/<org_id>/users`. If there is an org_id, then check that the user is part of that organisation (users.organisations is a list of all orgs that user is a member of). * platform admins ignore this check if restrict_admin_usage=False * if an endpoint has both org_id and service_id, org_id takes precedence, but we should probably revisit this if we ever need to create such an endpoint. * you now call `@user_has_permissions()` with no arguments for organisation endpoints - we can look at this if we decide we want more clarity. * you should never call user_has_permissions without any arguments for endpoints that aren't organisation-based. We'll raise NotImplementedError if you do.
This commit is contained in:
@@ -418,19 +418,17 @@ def load_organisation_before_request():
|
||||
_request_ctx_stack.top.organisation = None
|
||||
|
||||
if request.view_args:
|
||||
org_id = request.view_args.get('org_id', session.get('org_id'))
|
||||
else:
|
||||
org_id = session.get('org_id')
|
||||
org_id = request.view_args.get('org_id')
|
||||
|
||||
if org_id:
|
||||
try:
|
||||
_request_ctx_stack.top.organisation = organisations_client.get_organisation(org_id)
|
||||
except HTTPError as exc:
|
||||
# if org id isn't real, then 404 rather than 500ing later because we expect org to be set
|
||||
if exc.status_code == 404:
|
||||
abort(404)
|
||||
else:
|
||||
raise
|
||||
if org_id:
|
||||
try:
|
||||
_request_ctx_stack.top.organisation = organisations_client.get_organisation(org_id)
|
||||
except HTTPError as exc:
|
||||
# if org id isn't real, then 404 rather than 500ing later because we expect org to be set
|
||||
if exc.status_code == 404:
|
||||
abort(404)
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
def save_service_after_request(response):
|
||||
|
||||
Reference in New Issue
Block a user