-
Notifications
You must be signed in to change notification settings - Fork 5
Allow ExperienceCS admins to create public projects v2 #551
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
Closed
floehopper
wants to merge
12
commits into
main
from
allow-experience-cs-admins-to-create-public-projects-v2
Closed
Allow ExperienceCS admins to create public projects v2 #551
floehopper
wants to merge
12
commits into
main
from
allow-experience-cs-admins-to-create-public-projects-v2
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I'm planning to introduce another role-related predicate method in a subsequent commit. Extracting this method first will make that change easier. I'm pretty convinced the call to `#to_s` was made redundant when the safe navigation operator was introduced in this commit [1]. However, I suppose it's theoretically possible for the parsed JSON returned from `HydraPublicApiClient.fetch_oauth_user` via `User.from_token` to contain non-String values, so I'm going to leave it in place for now. [1]: 9a1fdb1
I'm planning to make use of this to grant access to `Api::PublicProjectsController#create` so that admin users on the `experience-cs` website can create public Scratch projects via the `editor-api` API.
I plan to use this to restrict creating public projects to experience-cs admin users.
* Remove redundant `create_project_with_content`. I suspect this was introduced due to a misunderstanding of how `subject` & `let` blocks are evaluated. The relevant difference is achieved through a variation of the `project_hash` `let` block in the two `context` blocks. * Move `subject`, `let` & `before` blocks into the `describe` or `context` blocks where they make the most sense. * Consistently use `Hash` vs `ActionController::Parameters`. Even though the latter is more realistic, it seems like an unnecessary complication. * Remove unneccessary call to `ActionController::Parameters.permit_all_parameters = true`. This was introduced in this commit [1] without explanation.
I'm planning to make some changes to these methods and these changes will make that easier.
I found the previous name confusing.
The `saved_project` wasn't really being used and it's sufficient to assert the final state of `Project#identifier` rather than aserting that it's changed.
When creating a public project we want the admin user to be able to specify the identifier and apply validation rules against it. However, prior to this change, if the supplied identifier was `nil`, the `before_validation` callback, `Project#generate_identifier`, would kick in and generate an identifier. Thus the presence validation on `Project#identifier` never failed. The new `Project#skip_identifier_generation` attribute gives us the ability in specific contexts to prevent the identifier being generated and thus allow the presence validation to fail.
This is more idiomatic and easier to follow.
I'm about to make a change to how this works and I want to be sure the change won't break anything.
There's no need to explicitly set `Project#identifier` here as well as in the `generate_identifier` `before_validation` in `Project`. While I'm not very convinced about the use of the `before_validation` callback, removing that would be a bigger and riskier piece of work. So instead I'm removing it here safe and relying on the `before_validation` to do its thing. Note that I added feature spec coverage to check the project is assigned a generated identifier in a previous commit.
I want to make some new behaviour conditional on the type of user. This change will make that easier. Note that I've used the `Identifiable#current_user` method (included into `ApiController`) to access the user unlike _some_ places in the `Api::ProjectsController` which use the `@current_user` instance variable directly. The latter feels dangerous, because the instance variable is only defined after the first time in a request that `Identifiable#current_user` is called and the value is memoized. Thus the places that are using the instance variable directly are relying on an earlier call to `Identifiable#current_user` (probably in `load_and_authorize_resource`) which feels risky and confusing. This seems like a fairly widespread problem across the API controllers, so I'm not going to attempt to fix it here.
Superseded by #552. Closing. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
No description provided.