-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Check if course id is provided for series create #4617
Conversation
respond_to do |format| | ||
if @series.save | ||
if @series.course.present? && @series.save | ||
format.html { redirect_to edit_series_path(@series), notice: I18n.t('controllers.created', model: Series.model_name.human) } |
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.
I am not entirely convinced this was the best solution, primarily because:
- We now do validation directly in the controller: the model itself should validate the presence of the course, not the controller.
- The check is done twice in the controller: once on line 111 and again on 117. I'm also not sure why 117 is necessary: if there are validation errors (as there are here, since we manually add them on line 114), the save method should not succeed.
Besides those, some more thoughts:
- This isn't something that this PR did, but why do we authorise here on the
Course
policy, instead of thecreate?
method of theSeries
policy (they seem to do the same thing)? Or, the other way around then, why is there acreate?
method on theSeries
policy if it isn't used here? - If we were to authorise on the
Series
policy, the crash would have also gone away, but the response would be 403 instead of 422. While maybe not the best response, it is more consistent with how we do it in other controllers (e.g. theevaluation
controller) I think.
(The current code does work however, so this isn't very urgent)
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.
You're right, authorizing on series would make more sense
This pull requests prevents series create from crashing when no course id is provided.
Closes #4147