mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-11 09:28:27 -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:
@@ -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