mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-05-05 16:38:59 -04:00
Extend user client to count users with permission
One of the things we need to know for a service to go live is whether they have at least two users with the ‘manage service’ permission. So this commit adds a method to the client to count how many users have a given permission. We can do logic on this count later. But having the counting done in the client feels like a cleaner separation of concerns. Meant some refactoring of the way `service_id` is extracted from the request, in order to make it easier to mock.
This commit is contained in:
@@ -131,6 +131,12 @@ class UserApiClient(NotifyAdminAPIClient):
|
||||
resp = self.get(endpoint)
|
||||
return [User(data) for data in resp['data']]
|
||||
|
||||
def get_count_of_users_with_permission(self, service_id, permission):
|
||||
return len([
|
||||
user for user in self.get_users_for_service(service_id)
|
||||
if user.has_permissions(permission, any_=True)
|
||||
])
|
||||
|
||||
def add_user_to_service(self, service_id, user_id, permissions):
|
||||
endpoint = '/service/{}/users/{}'.format(service_id, user_id)
|
||||
data = [{'permission': x} for x in permissions]
|
||||
|
||||
Reference in New Issue
Block a user