Commit Graph

30 Commits

Author SHA1 Message Date
Rebecca Law
795a035fac When the organisation updates the crown attribute it should update all the services associated with that organisation too. 2020-09-09 10:43:16 +01:00
Leo Hemsted
53b80b931f fix the sql
"if you want something done right, then do it yourself"

The ORM was building a weird and inefficient query to get all the users
for a given organisation_id:

old query:

```sql
SELECT users.*
FROM users
WHERE (
    EXISTS (
        SELECT 1
        FROM user_to_organisation, organisation
        WHERE users.id = user_to_organisation.user_id AND
        organisation.id = user_to_organisation.organisation_id AND
        organisation.id = '63b9557c-22ea-42ac-bcba-edaa50e3ae51'
    )
) AND
users.state = 'active'
ORDER BY users.created_at
```

Note the cross join on users_to_org and org, there are a lot of users in
organisations on preview, as one is added every functional test run.
Even though they're all filtered out and the query returns the correct
data, it still does the nested loop under the hood.

new query:

```sql
SELECT users.*
FROM users
JOIN user_to_organisation AS user_to_organisation_1 ON users.id = user_to_organisation_1.user_id
JOIN organisation ON organisation.id = user_to_organisation_1.organisation_id
WHERE organisation.id = '63b9557c-22ea-42ac-bcba-edaa50e3ae51' AND users.state = 'active' ORDER BY users.created_at;
```

Much more straightforward.
2020-03-30 17:47:15 +01:00
Rebecca Law
b1b457eea0 Only return the usage data for live services.
The list of trail mode services is only for platform admins, therefore the usage isn't needed for that page.
2020-02-24 14:23:05 +00:00
Rebecca Law
49533d7792 Fix typo in function name 2020-02-24 11:26:16 +00:00
Chris Hill-Scott
f63565695a Refactor for reuse
Makes one resuable function, instead of 3 repetetive ones.
2019-09-25 15:36:55 +01:00
Chris Hill-Scott
1e82484dfb Update service branding when setting org branding
When a service asks for branding I often go and:
- set the branding on the organisation as well
- set the branding on all the organisation’s services

The latter can be quite time consuming, but it does save effort since
existing services from the same organisation won’t have to request
branding. It also improves the consistency of the communications that
users are receiving.

This commit automates that process by applying the branding update to
any services belonging to the organisation, if those services don’t
already have their own custom branding set up.
2019-09-25 15:36:11 +01:00
Rebecca Law
55dc7184cc Add organisation_id to Service.
This is the second commit in the series to add organisation_id to Service.
- Data migration to update services.organisation_id from data in organisation_to_service
 (The rollback will lose any updates to organisation unless the script is updated to set organistion_to_service from service.organisation_id )
- Update Service.organisation relationship to a ForeignKey relationship to Organisation.
- Update Organisation.services to a backref relationship to Service.
2019-08-13 17:25:30 +01:00
Rebecca Law
12f305bf86 - Migration to add Service.organisation_id
- Add oranisation_id to Service data model.
- Update methods to create service and associate service to organisation to set the organisation_id on the Service.
- Create the missing test, if the service user email matches a domain for an organisation then associate the service to the organisation and inherit crown and organisation_type from the organisation.
2019-08-12 16:03:02 +01:00
Pea Tyczynska
d89ef0594f nhs_central is crown org and also we do not update org type while
updating service anymore.
2019-07-18 17:05:24 +01:00
Pea Tyczynska
9dfc550f46 Add org types table 2019-07-18 17:05:22 +01:00
Katie Smith
1671221642 Set org_type of a service when adding/updating org org type
The organisation_type of a service should match the organisation_type of
the service's organisation (if there is one). This changes
dao_update_organisation and dao_add_service_to_organisation to set the
organisation_type of any services when adding / updating an org.
2019-07-12 16:43:37 +01:00
Leo Hemsted
8e32995c8d only send emails if a user signed the MOU
the agreement_signed field can also be edited by a platform admin - if
that happened we might not have details for who signed it, and even if
we did they shouldn't find out about, and we don't need an email since
we were the ones who clicked the button.

the `agreement_signed_by` field is only set when a user confirms that
they are signing the MOU on the admin page - not if a platform admin
modifies the page from the platform admin page
2019-07-12 15:08:55 +01:00
Chris Hill-Scott
6bfd999de2 Add method to count of live services and orgs
So that we don’t have to update the home page manually any more.
2019-04-11 13:54:43 +01:00
Rebecca Law
36b4a344fc Update the dao_get_organisation_by_email_address to ignore .gsi in the email address. 2019-04-05 15:47:16 +01:00
Chris Hill-Scott
9783ab56b7 Don’t wipe domains when updating other attributes
The domains for an organisation should only be updated (or wiped) if a
new list is explicitly passed in by the admin app.
2019-03-20 12:21:25 +00:00
Chris Hill-Scott
73ca8b73f9 Make sure domains are always lowercased
Because otherwise we might get garbage duplicate data.
2019-03-08 14:51:23 +00:00
Chris Hill-Scott
6e8ce78603 Choose most specific domains first
If we had organisations for GDS and Cabinet Office, then we’d always
want someone whose email address ends in `@cabinet-office.gov.uk` to
match to `cabinet-office.gov.uk` before matching to
`digital.cabinet-office.gov.uk`.

Sorting the list by shortest first addresses this.
2019-03-08 13:30:51 +00:00
Chris Hill-Scott
c0fb9267bd Automatically associate new service with an org
This is the same thing we do in the admin app at the moment with YAML:
2f4e933b65/app/utils.py (L556-L562)
2019-03-08 13:30:42 +00:00
Chris Hill-Scott
d7e03e00d3 Storing more info about an organisation
Currently we have
- a thing in the database called an ‘organisation’ which we don’t use
- the idea of an organisation which we derive from the user’s email
  address and is used to set the default branding for their service and
  determine whether they’ve signed the MOU

We should make these two things into one thing, by storing everything
we know about an organisation against that organisation in the database.
This will be much less laborious than storing it in a YAML file that
needs a deploy every time it’s updated.

An organisation can now have:
- domains which we can use to automatically associate services with it
  (eg anyone whose email address ends in `dwp.gsi.gov.uk` gets services
  they create associated to the DWP organisation)
- default letter branding for any new services
- default email branding for any new services
2019-03-08 13:30:32 +00:00
Rebecca Law
446e76f1f3 Remove users relationship in organisations 2018-02-23 13:36:42 +00:00
Rebecca Law
69cc33f77f Removed the check for active user when adding a user to an organisation 2018-02-23 10:45:18 +00:00
Rebecca Law
70f9dfc0f6 Added more tests 2018-02-23 10:45:18 +00:00
Rebecca Law
011f93c495 Adding more unit tests 2018-02-23 10:45:18 +00:00
Rebecca Law
13ef2d7bae - new endpoint to check the token for an org invitation.
- new endpoint to add user to organisation
- new endpoint to return users for an organisation
2018-02-23 10:45:18 +00:00
Ken Tsang
085110417f Refactor organisation_dao 2018-02-13 14:06:43 +00:00
Ken Tsang
60f96ab598 Organisation service DAO 2018-02-13 14:06:43 +00:00
Katie Smith
4a14225d04 Change Organisation DAO update method
- Changed the organisation DAO update method to only make 1 query
- Updated the update rest endpoint to not return an organisation when
the update is successful
2018-02-09 11:17:13 +00:00
Katie Smith
6a79eedbce Add Organisation DAO 2018-02-08 14:44:40 +00:00
Ken Tsang
c743e52fe8 Add organisations model and create dao 2017-07-12 12:01:50 +01:00
Leo Hemsted
e631333a34 add GET /organisation and GET /organisation/id endpoints 2016-08-09 15:59:22 +01:00