Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude retired apps from User#authorisations
We shouldn't ever need to use access tokens for retired applications and so `User#authorisations` should not include them. To this end I've added this `joins(:application)` scope to the `User#authorisations` `has_many` association so that it picks up the default scope on `Doorkeeper::Application`, i.e. `not_retired`. c.f. `User#application_permissions` & `User#supported_permissions`. I don't think the `joins` scope itself will change which `Doorkeeper::AccessToken` records are returned, because `oauth_access_tokens.application_id` has a `NOT NULL` and a foreign key constraint. The `joins` scope just serves to include the default scope on `Doorkeeper::Application` in the query. I've tried to tests to highlight behaviour changes in the wider codebase: * Access tokens for retired apps no longer appear on the API user edit page. * No longer send SSO Push requests to retired apps. Addresses this Trello card [1]. * No longer include token expiry times to Prometheus for retired apps. This should mean that 2nd Line Tech do not see alerts for such tokens. At least partly addresses this Trello card [2]. I've had to change the assertion in the `should "not allow editing permissions for retired application"` test in `ApiUsersControllerTest`, because the template no longer displays the table at all (as opposed to displaying an empty table) and I think the new behaviour is correct. The `should "not show API user's access tokens for retired applications"` test in `ApiUsersControllerTest` was actually passing prior to this commit but only by accident, because the `app/views/api_users/edit.html.erb` template calls `Doorkeeper::AccessToken.ordered_by_application_name` which calls `Doorkeeper::Application.ordered_by_name` which triggers the default scope in `Doorkeeper::Application` which includes `Doorkeeper::Application.not_retired`. The change to `User#authorisations` in this commit makes the behaviour more intentional. [1]: https://trello.com/c/pN8KOiQV [2]: https://trello.com/c/huqPdMv8
- Loading branch information