mirror of
https://github.com/GSA/notifications-admin.git
synced 2025-12-15 09:34:25 -05:00
Refactor filtering out accepted invites to client
None of our model or view layer code should need to know about accepted invites. We don’t use them anywhere because once an invite is accepted that person is now a user. Putting this logic in the client means that: - none of the code calling the client needs to care about accepted invites - it’s easier to (if we want) update the API code to not return accepted invites
This commit is contained in:
@@ -28,11 +28,16 @@ class InviteApiClient(NotifyAdminAPIClient):
|
||||
return InvitedUser(**resp['data'])
|
||||
|
||||
def get_invites_for_service(self, service_id):
|
||||
endpoint = '/service/{}/invite'.format(service_id)
|
||||
resp = self.get(endpoint)
|
||||
invites = resp['data']
|
||||
invited_users = self._get_invited_users(invites)
|
||||
return invited_users
|
||||
return [
|
||||
InvitedUser(**invite)
|
||||
for invite in self._get_invites_for_service(service_id)
|
||||
if invite['status'] != 'accepted'
|
||||
]
|
||||
|
||||
def _get_invites_for_service(self, service_id):
|
||||
return self.get(
|
||||
'/service/{}/invite'.format(service_id)
|
||||
)['data']
|
||||
|
||||
def check_token(self, token):
|
||||
resp = self.get(url='/invite/service/{}'.format(token))
|
||||
@@ -51,12 +56,5 @@ class InviteApiClient(NotifyAdminAPIClient):
|
||||
self.post(url='/service/{0}/invite/{1}'.format(service_id, invited_user_id),
|
||||
data=data)
|
||||
|
||||
def _get_invited_users(self, invites):
|
||||
invited_users = []
|
||||
for invite in invites:
|
||||
invited_user = InvitedUser(**invite)
|
||||
invited_users.append(invited_user)
|
||||
return invited_users
|
||||
|
||||
|
||||
invite_api_client = InviteApiClient()
|
||||
|
||||
Reference in New Issue
Block a user