mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-26 17:24:23 -04:00
Enforce service permissions
This should catch typos more quickly and obviously.
This commit is contained in:
@@ -58,6 +58,16 @@ class Service(JSONModel):
|
|||||||
'letter',
|
'letter',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
ALL_PERMISSIONS = TEMPLATE_TYPES + (
|
||||||
|
'edit_folder_permissions',
|
||||||
|
'email_auth',
|
||||||
|
'inbound_sms',
|
||||||
|
'international_letters',
|
||||||
|
'international_sms',
|
||||||
|
'upload_document',
|
||||||
|
'upload_letters',
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, _dict):
|
def __init__(self, _dict):
|
||||||
|
|
||||||
super().__init__(_dict)
|
super().__init__(_dict)
|
||||||
@@ -106,6 +116,8 @@ class Service(JSONModel):
|
|||||||
return not self.trial_mode
|
return not self.trial_mode
|
||||||
|
|
||||||
def has_permission(self, permission):
|
def has_permission(self, permission):
|
||||||
|
if permission not in self.ALL_PERMISSIONS:
|
||||||
|
raise KeyError(f'{permission} is not a service permission')
|
||||||
return permission in self.permissions
|
return permission in self.permissions
|
||||||
|
|
||||||
def get_page_of_jobs(self, page):
|
def get_page_of_jobs(self, page):
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from app.models.organisation import Organisation
|
from app.models.organisation import Organisation
|
||||||
from app.models.service import Service
|
from app.models.service import Service
|
||||||
from app.models.user import User
|
from app.models.user import User
|
||||||
@@ -247,3 +249,9 @@ def test_service_without_organisation_doesnt_need_org_api(mocker, service_one):
|
|||||||
|
|
||||||
assert mock_redis_get.called is False
|
assert mock_redis_get.called is False
|
||||||
assert mock_get_organisation.called is False
|
assert mock_get_organisation.called is False
|
||||||
|
|
||||||
|
|
||||||
|
def test_bad_permission_raises(service_one):
|
||||||
|
with pytest.raises(KeyError) as e:
|
||||||
|
Service(service_one).has_permission('foo')
|
||||||
|
assert str(e.value) == "'foo is not a service permission'"
|
||||||
|
|||||||
Reference in New Issue
Block a user