mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-25 08:44:23 -04:00
Make a model collection for organisations
This makes returning a user’s organisations consistent with how we return their services.
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
from flask import abort
|
from flask import abort
|
||||||
from werkzeug.utils import cached_property
|
from werkzeug.utils import cached_property
|
||||||
|
|
||||||
from app.models import JSONModel, ModelList
|
from app.models import JSONModel, ModelList, SerialisedModelCollection
|
||||||
from app.notify_client.email_branding_client import email_branding_client
|
from app.notify_client.email_branding_client import email_branding_client
|
||||||
from app.notify_client.letter_branding_client import letter_branding_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.organisations_api_client import organisations_client
|
||||||
@@ -204,6 +204,9 @@ class Organisation(JSONModel):
|
|||||||
return organisations_client.get_services_and_usage(self.id, financial_year)
|
return organisations_client.get_services_and_usage(self.id, financial_year)
|
||||||
|
|
||||||
|
|
||||||
class AllOrganisations(ModelList):
|
class Organisations(SerialisedModelCollection):
|
||||||
client_method = organisations_client.get_organisations
|
|
||||||
model = Organisation
|
model = Organisation
|
||||||
|
|
||||||
|
|
||||||
|
class AllOrganisations(ModelList, Organisations):
|
||||||
|
client_method = organisations_client.get_organisations
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ from app.event_handlers import (
|
|||||||
create_set_user_permissions_event,
|
create_set_user_permissions_event,
|
||||||
)
|
)
|
||||||
from app.models import JSONModel, ModelList
|
from app.models import JSONModel, ModelList
|
||||||
from app.models.organisation import Organisation
|
from app.models.organisation import Organisation, Organisations
|
||||||
from app.models.webauthn_credential import WebAuthnCredentials
|
from app.models.webauthn_credential import WebAuthnCredentials
|
||||||
from app.notify_client import InviteTokenError
|
from app.notify_client import InviteTokenError
|
||||||
from app.notify_client.invite_api_client import invite_api_client
|
from app.notify_client.invite_api_client import invite_api_client
|
||||||
@@ -320,10 +320,7 @@ class User(JSONModel, UserMixin):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def organisations(self):
|
def organisations(self):
|
||||||
return [
|
return Organisations(self.orgs_and_services['organisations'])
|
||||||
Organisation(organisation)
|
|
||||||
for organisation in self.orgs_and_services['organisations']
|
|
||||||
]
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def organisation_ids(self):
|
def organisation_ids(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user