Files
notifications-admin/app/models/organization.py

147 lines
4.0 KiB
Python
Raw Normal View History

from collections import OrderedDict
2019-05-23 17:17:26 +01:00
from werkzeug.utils import cached_property
2023-08-25 08:57:24 -07:00
from app.models import JSONModel, ModelList, SerialisedModelCollection, SortByNameMixin
2023-07-12 12:09:44 -04:00
from app.notify_client.organizations_api_client import organizations_client
2023-07-12 12:09:44 -04:00
class Organization(JSONModel, SortByNameMixin):
TYPE_FEDERAL = "federal"
TYPE_STATE = "state"
TYPE_OTHER = "other"
TYPE_LABELS = OrderedDict(
[
(TYPE_FEDERAL, "Federal government"),
(TYPE_STATE, "State government"),
(TYPE_OTHER, "Other"),
]
)
ALLOWED_PROPERTIES = {
"id",
"name",
"active",
"organization_type",
"domains",
"count_of_live_services",
"billing_contact_email_addresses",
"billing_contact_names",
"billing_reference",
"purchase_order_number",
"notes",
}
2019-05-23 17:17:26 +01:00
@classmethod
def from_id(cls, org_id):
if not org_id:
return cls({})
2023-07-12 12:09:44 -04:00
return cls(organizations_client.get_organization(org_id))
2019-05-23 17:17:26 +01:00
@classmethod
def from_domain(cls, domain):
2023-07-12 12:09:44 -04:00
return cls(organizations_client.get_organization_by_domain(domain))
@classmethod
def from_service(cls, service_id):
2023-07-12 12:09:44 -04:00
return cls(organizations_client.get_service_organization(service_id))
@classmethod
def create_from_form(cls, form):
return cls.create(
name=form.name.data,
2023-07-12 12:09:44 -04:00
organization_type=form.organization_type.data,
)
@classmethod
2023-07-12 12:09:44 -04:00
def create(cls, name, organization_type):
return cls(
organizations_client.create_organization(
name=name,
organization_type=organization_type,
)
)
def __init__(self, _dict):
super().__init__(_dict)
if self._dict == {}:
self.name = None
self.domains = []
2023-07-12 12:09:44 -04:00
self.organization_type = None
@property
2023-07-12 12:09:44 -04:00
def organization_type_label(self):
return self.TYPE_LABELS.get(self.organization_type)
@property
def billing_details(self):
billing_details = [
self.billing_contact_email_addresses,
self.billing_contact_names,
self.billing_reference,
self.purchase_order_number,
]
if any(billing_details):
return billing_details
else:
return None
2019-05-23 17:17:26 +01:00
@cached_property
def services(self):
2023-07-12 12:09:44 -04:00
return organizations_client.get_organization_services(self.id)
2019-05-23 17:17:26 +01:00
@cached_property
def service_ids(self):
return [s["id"] for s in self.services]
2019-05-23 17:17:26 +01:00
@property
def live_services(self):
return [s for s in self.services if s["active"] and not s["restricted"]]
2019-05-23 17:17:26 +01:00
@property
def trial_services(self):
return [s for s in self.services if not s["active"] or s["restricted"]]
2019-05-23 17:17:26 +01:00
@cached_property
def invited_users(self):
2023-07-12 12:09:44 -04:00
from app.models.user import OrganizationInvitedUsers
2023-07-12 12:09:44 -04:00
return OrganizationInvitedUsers(self.id)
2019-05-23 17:17:26 +01:00
@cached_property
def active_users(self):
2023-07-12 12:09:44 -04:00
from app.models.user import OrganizationUsers
2023-07-12 12:09:44 -04:00
return OrganizationUsers(self.id)
2019-05-23 17:17:26 +01:00
@cached_property
def team_members(self):
return sorted(
self.invited_users + self.active_users,
key=lambda user: user.email_address.lower(),
2019-05-23 17:17:26 +01:00
)
def update(self, delete_services_cache=False, **kwargs):
2023-07-12 12:09:44 -04:00
response = organizations_client.update_organization(
self.id,
cached_service_ids=self.service_ids if delete_services_cache else None,
**kwargs
)
Add pages to let users accept the agreement online At the moment, the process for accepting the data sharing and financial agreement is: 1. download a pdf * print it out * get someone to sign it * scan it * email it back to us * we rename the file and save it in Google Drive * we then update the organisation to say the MOU is signed * sometimes we also: * print it out and get it counter-signed * scan it again * email it back to the service Let's not do that any more. When the first service for an organisation that doesn't have the agreement in place is in the process of going live, then they should be able to accept the agreement online as part of the go live flow. This commit adds the pages that let someone do that. Where the checklist shows the agreement as **[not completed]** then they can follow a link where they can download it (as happens now). From here, they should then also be able to provide some info to accept it. The info that we need is: **Version** – because we version the agreements occasionally, we need to know which version they are accepting. It may not be the latest one if they downloaded it a while ago and it took time to be signed off **Who is accepting the agreement** – this will often be someone in the finance team, and not necessarily a team member, so we should let the person either accept as themselves, or on behalf of someone else. If it's on behalf of someone else we need to the name and email address of that person so we have that on record. Obvs if it's them accepting it themselves, we have that already (so we just store their user ID and not their name or email address). We then replay the collected info back in a sort of legally binding kind of way pulling in the organisation name too. The wording we’re using is inspired by what GOV.UK Pay have. Then there’s a big green button they can click to accept the agreement, which stores their user ID and and timestamp.
2019-06-18 14:24:29 +01:00
self.__init__(response)
def associate_service(self, service_id):
organizations_client.update_service_organization(service_id, self.id)
def services_and_usage(self, financial_year):
2023-07-12 12:09:44 -04:00
return organizations_client.get_services_and_usage(self.id, financial_year)
2020-02-25 17:49:55 +00:00
2023-07-12 12:09:44 -04:00
class Organizations(SerialisedModelCollection):
model = Organization
2023-07-12 12:09:44 -04:00
class AllOrganizations(ModelList, Organizations):
client_method = organizations_client.get_organizations