mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-05 10:53:28 -05:00
first of a two step process to remove invited user objects from the session. we're removing them because they're of variable size, and with a lot of folder permissions they can cause the session to exceed the 4kb cookie size limit and not save properly. this commit looks at invited org users only. in this step, start saving the invited org user's id to the session alongside the session object. Then, if the invited_org_user_id is present in the next step of the invite flow, fetch the user object from the API instead of from the session. If it's not present (due to a session set by an older instance of the admin app), then just use the old code to get the entire object out of the session. For invites where the user is small enough to persist to the cookie, this will still save both the old and the new way, but will always make an extra check to the API, I think this minor performance hit is totally fine. For invites where the user is too big to persist, they'll still fail for now, and will need to wait until the next PR comes along and stops saving the large invited user object to the session entirely.
53 lines
1.7 KiB
Python
53 lines
1.7 KiB
Python
from app.notify_client import NotifyAdminAPIClient, _attach_current_user
|
|
|
|
|
|
class OrgInviteApiClient(NotifyAdminAPIClient):
|
|
|
|
def init_app(self, app):
|
|
super().init_app(app)
|
|
|
|
self.admin_url = app.config['ADMIN_BASE_URL']
|
|
|
|
def create_invite(self, invite_from_id, org_id, email_address):
|
|
data = {
|
|
'email_address': email_address,
|
|
'invited_by': invite_from_id,
|
|
'invite_link_host': self.admin_url,
|
|
}
|
|
data = _attach_current_user(data)
|
|
resp = self.post(url='/organisation/{}/invite'.format(org_id), data=data)
|
|
return resp['data']
|
|
|
|
def get_invites_for_organisation(self, org_id):
|
|
endpoint = '/organisation/{}/invite'.format(org_id)
|
|
resp = self.get(endpoint)
|
|
return resp['data']
|
|
|
|
def get_invited_user_for_org(self, org_id, invited_org_user_id):
|
|
return self.get(
|
|
f'/organisation/{org_id}/invite/{invited_org_user_id}'
|
|
)['data']
|
|
|
|
def get_invited_user(self, invited_user_id):
|
|
return self.get(
|
|
f'/invite/organisation/{invited_user_id}'
|
|
)['data']
|
|
|
|
def check_token(self, token):
|
|
resp = self.get(url='/invite/organisation/{}'.format(token))
|
|
return resp['data']
|
|
|
|
def cancel_invited_user(self, org_id, invited_user_id):
|
|
data = {'status': 'cancelled'}
|
|
data = _attach_current_user(data)
|
|
self.post(url='/organisation/{0}/invite/{1}'.format(org_id, invited_user_id),
|
|
data=data)
|
|
|
|
def accept_invite(self, org_id, invited_user_id):
|
|
data = {'status': 'accepted'}
|
|
self.post(url='/organisation/{0}/invite/{1}'.format(org_id, invited_user_id),
|
|
data=data)
|
|
|
|
|
|
org_invite_api_client = OrgInviteApiClient()
|