-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(161623) Do not show "deleted" projects in application #1478
(161623) Do not show "deleted" projects in application #1478
Conversation
9b42e7c
to
64670bb
Compare
Adding default_scope to models can be problematic as default scopes can conceal issues. However, now that we have a concept of "soft deleted" projects, we do not want to return these projects ANYWHERE in the application - not in the UI, exports or statistics. They should not be seen to exist. To avoid explicitly asking for `active` and/or `completed` projects in all our pages, use `default_scope` to exclude deleted projects. If we want to view deleted projects in future, we will have to explicitly look for them (e.g. using `Project.unscoped.where(state: :deleted)` as opposed to the Project.deleted scope).
…edited We don't want users viewing deleted projects by going to their `show` URL - so ensure this doesn't happen using Policies. This will return a 403 not a 404, which semantically isn't quite correct - the project isn't deleted, so it's "found" but it's not viewable. But the user shouldn't know it's not "deleted". However we think it will be rare for a user to have a project URL and go to it directly. The editing restricton is more of a theoretical need than a practical one, but mark "soft deleted" projects as un-editable, just in case anyone manages to access one and tries to edit it.
We were using ProjectPolicy.show? here but this is actually a project _listing_ page, not a show page for an individual project. The naming on this controller is a little obscure - it is _showing_ an individual month of projects not an individual project. So `index?` is the appropriate Policy to call here.
Add some tests to prove our exports are not including any "soft deleted" projects.
64670bb
to
965ce31
Compare
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ugh! default_scope
again and me reviewing it again (we have a default scope on Note)! 😱
I suspect that, like you, I cannot come up with a good reason not to use it here, 'deleted' projects are a pretty odd concept, it's hard to understand what they are actually for.
For that reason, I am going to go against everything I have read and been told by better developers than me about never using default_scope
and approve this!
Yeah I have so many misgivings. I can see myself in the future frantically debugging something that's been caused by default_scope. But I also don't want to accidentally leave |
Changes
Now that we have the concept of "soft deleted" projects (projects which exist in the database but are in a deleted state) we need to ensure they never appear to users.
To ensure this, we have decided to use a
default_scope
for projects. Default scopes can be problematic as they can conceal issues and cause confusion - but the alternative is to addactive
andcompleted
scopes to ALL calls to Project in the application.This does mean that we lose access to the
Project.deleted
scope, but if we need to call on deleted projects specifically we can unscope the default scope and callProject.unscoped.where(state: :deleted)
We then go on to add some Policy changes and extra specs, to make sure deleted projects do not appear in listing pages, and cannot be shown/edited.
Checklist
CHANGELOG.md
if needed.