Make a service model and use for permissions

Having the service floating about as JSON is a bit flakey. Could easily
introduce a mistake where you mistype the name of a key and silently
get `None`.

Also means doing awkward things like `if 'permission' in
current_service['permissions']`, whereas for users we can do the
much cleaner `user.has_permission()`.

So this commit:
- introduces a model
- adds a `.has_permission` method similar to the one we have for users
This commit is contained in:
Chris Hill-Scott
2018-07-20 08:43:02 +01:00
parent 3056731cbb
commit 036923c382
12 changed files with 47 additions and 31 deletions

View File

@@ -40,6 +40,7 @@ from werkzeug.local import LocalProxy
from app import proxy_fix
from app.config import configs
from app.asset_fingerprinter import AssetFingerprinter
from app.notify_client.models import Service
from app.navigation import (
CaseworkNavigation,
HeaderNavigation,
@@ -94,8 +95,13 @@ billing_api_client = BillingAPIClient()
complaint_api_client = ComplaintApiClient()
platform_stats_api_client = PlatformStatsAPIClient()
# The current service attached to the request stack.
current_service = LocalProxy(partial(_lookup_req_object, 'service'))
def _get_current_service():
return Service(_lookup_req_object('service'))
current_service = LocalProxy(_get_current_service)
# The current organisation attached to the request stack.
current_organisation = LocalProxy(partial(_lookup_req_object, 'organisation'))