Merge pull request #3013 from alphagov/org-client-refactor

Wrap get org methods in class method on model
This commit is contained in:
Chris Hill-Scott
2019-06-14 16:56:02 +01:00
committed by GitHub
3 changed files with 10 additions and 8 deletions

View File

@@ -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)

View File

@@ -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):

View File

@@ -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):