mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
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:
@@ -261,3 +261,13 @@ class AnonymousUser(AnonymousUserMixin):
|
||||
# set the anonymous user so that if a new browser hits us we don't error http://stackoverflow.com/a/19275188
|
||||
def logged_in_elsewhere(self):
|
||||
return False
|
||||
|
||||
|
||||
class Service(dict):
|
||||
|
||||
def __init__(self, _dict):
|
||||
# in the case of a bad request current service may be `None`
|
||||
super().__init__(_dict or {})
|
||||
|
||||
def has_permission(self, permission):
|
||||
return permission in self['permissions']
|
||||
|
||||
Reference in New Issue
Block a user