mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-02-10 21:34:10 -05:00
Merge pull request #3013 from alphagov/org-client-refactor
Wrap get org methods in class method on model
This commit is contained in:
@@ -27,6 +27,14 @@ class Organisation(JSONModel):
|
||||
def from_id(cls, org_id):
|
||||
return cls(organisations_client.get_organisation(org_id))
|
||||
|
||||
@classmethod
|
||||
def from_domain(cls, domain):
|
||||
return cls(organisations_client.get_organisation_by_domain(domain))
|
||||
|
||||
@classmethod
|
||||
def from_service(cls, service_id):
|
||||
return cls(organisations_client.get_service_organisation(service_id))
|
||||
|
||||
def __init__(self, _dict):
|
||||
|
||||
super().__init__(_dict)
|
||||
|
||||
@@ -12,7 +12,6 @@ from app.notify_client.inbound_number_client import inbound_number_client
|
||||
from app.notify_client.invite_api_client import invite_api_client
|
||||
from app.notify_client.job_api_client import job_api_client
|
||||
from app.notify_client.letter_branding_client import letter_branding_client
|
||||
from app.notify_client.organisations_api_client import organisations_client
|
||||
from app.notify_client.service_api_client import service_api_client
|
||||
from app.notify_client.template_folder_api_client import (
|
||||
template_folder_api_client,
|
||||
@@ -401,9 +400,7 @@ class Service(JSONModel):
|
||||
|
||||
@cached_property
|
||||
def organisation(self):
|
||||
return Organisation(
|
||||
organisations_client.get_service_organisation(self.id)
|
||||
)
|
||||
return Organisation.from_service(self.id)
|
||||
|
||||
@cached_property
|
||||
def inbound_number(self):
|
||||
|
||||
@@ -15,7 +15,6 @@ from app.models.roles_and_permissions import (
|
||||
from app.notify_client import InviteTokenError
|
||||
from app.notify_client.invite_api_client import invite_api_client
|
||||
from app.notify_client.org_invite_api_client import org_invite_api_client
|
||||
from app.notify_client.organisations_api_client import organisations_client
|
||||
from app.notify_client.user_api_client import user_api_client
|
||||
from app.utils import is_gov_user
|
||||
|
||||
@@ -306,9 +305,7 @@ class User(JSONModel, UserMixin):
|
||||
|
||||
@cached_property
|
||||
def default_organisation(self):
|
||||
return Organisation(
|
||||
organisations_client.get_organisation_by_domain(self.email_domain)
|
||||
)
|
||||
return Organisation.from_domain(self.email_domain)
|
||||
|
||||
@property
|
||||
def default_organisation_type(self):
|
||||
|
||||
Reference in New Issue
Block a user