mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-14 10:58:58 -04:00
Refactor model to put add_to… methods on user
An invited user can’t be added to an organisation or service, only a real user can. So the methods to do this should be on the user model, and take the details of the invite as arguments.
This commit is contained in:
@@ -65,7 +65,11 @@ def accept_invite(token):
|
||||
invited_user.auth_type == 'email_auth'
|
||||
):
|
||||
existing_user.update(auth_type=invited_user.auth_type)
|
||||
invited_user.add_to_service(existing_user_id=existing_user.id)
|
||||
existing_user.add_to_service(
|
||||
service_id=invited_user.service,
|
||||
permissions=invited_user.permissions,
|
||||
folder_permissions=invited_user.folder_permissions,
|
||||
)
|
||||
return redirect(url_for('main.service_dashboard', service_id=service.id))
|
||||
else:
|
||||
return redirect(url_for('main.register_from_invite'))
|
||||
@@ -105,7 +109,7 @@ def accept_org_invite(token):
|
||||
if existing_user:
|
||||
invited_org_user.accept_invite()
|
||||
if existing_user not in organisation_users:
|
||||
invited_org_user.add_to_organisation(existing_user.id)
|
||||
existing_user.add_to_organisation(organisation_id=invited_org_user.organisation)
|
||||
return redirect(url_for('main.organisation_dashboard', org_id=invited_org_user.organisation))
|
||||
else:
|
||||
return redirect(url_for('main.register_from_org_invite'))
|
||||
|
||||
@@ -389,6 +389,20 @@ class User(JSONModel, UserMixin):
|
||||
self.current_session_id = user_api_client.get_user(self.id).get('current_session_id')
|
||||
session['current_session_id'] = self.current_session_id
|
||||
|
||||
def add_to_service(self, service_id, permissions, folder_permissions):
|
||||
user_api_client.add_user_to_service(
|
||||
service_id,
|
||||
self.id,
|
||||
permissions,
|
||||
folder_permissions,
|
||||
)
|
||||
|
||||
def add_to_organisation(self, organisation_id):
|
||||
user_api_client.add_user_to_organisation(
|
||||
organisation_id,
|
||||
self.id,
|
||||
)
|
||||
|
||||
|
||||
class InvitedUser(JSONModel):
|
||||
|
||||
@@ -430,14 +444,6 @@ class InvitedUser(JSONModel):
|
||||
def accept_invite(self):
|
||||
invite_api_client.accept_invite(self.service, self.id)
|
||||
|
||||
def add_to_service(self, existing_user_id):
|
||||
user_api_client.add_user_to_service(
|
||||
self.service,
|
||||
existing_user_id,
|
||||
self.permissions,
|
||||
self.folder_permissions,
|
||||
)
|
||||
|
||||
@property
|
||||
def permissions(self):
|
||||
return self._permissions
|
||||
@@ -584,9 +590,6 @@ class InvitedOrgUser(JSONModel):
|
||||
def accept_invite(self):
|
||||
org_invite_api_client.accept_invite(self.organisation, self.id)
|
||||
|
||||
def add_to_organisation(self, user_id):
|
||||
user_api_client.add_user_to_organisation(self.organisation, user_id)
|
||||
|
||||
|
||||
class AnonymousUser(AnonymousUserMixin):
|
||||
# set the anonymous user so that if a new browser hits us we don't error http://stackoverflow.com/a/19275188
|
||||
|
||||
Reference in New Issue
Block a user