-
Notifications
You must be signed in to change notification settings - Fork 5
Support instruction steps #953
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| class AddInstructionStepsToProjects < ActiveRecord::Migration[8.1] | ||
| def change | ||
| add_column :projects, :instruction_steps, :jsonb | ||
| end | ||
| end | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,11 +3,11 @@ | |
| class Project | ||
| class Update | ||
| class << self | ||
| def call(project:, update_hash:, current_user:) | ||
| def call(project:, update_hash:) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious, why are we removing the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's detail in the commit message:
I think it's simpler to do this in the controller and let Rails manage unexpected parameters rather than special casing this. Having it in the update required more complexity to see if the instructions had changed which was added in the first commit. |
||
| response = setup_response(project) | ||
|
|
||
| setup_deletions(response, update_hash) | ||
| update_project_attributes(response, update_hash, current_user) | ||
| update_project_attributes(response, update_hash) | ||
| update_component_attributes(response, update_hash) | ||
| persist_changes(response) | ||
| response | ||
|
|
@@ -42,21 +42,7 @@ def validate_deletions(response) | |
| response[:error] = I18n.t 'errors.project.editing.delete_default_component' | ||
| end | ||
|
|
||
| def student_project_instructions_updated?(response, update_hash, current_user) | ||
| is_school_project = response[:project].school.present? | ||
| user_is_student = current_user.student? | ||
| instructions_updated = response[:project].instructions != update_hash[:instructions] | ||
| is_school_project && user_is_student && instructions_updated | ||
| end | ||
|
|
||
| def validate_update(response, update_hash, current_user) | ||
| return unless student_project_instructions_updated?(response, update_hash, current_user) | ||
|
|
||
| response[:error] = I18n.t 'errors.project.editing.student_update_instructions' | ||
| end | ||
|
|
||
| def update_project_attributes(response, update_hash, current_user) | ||
| validate_update(response, update_hash, current_user) | ||
| def update_project_attributes(response, update_hash) | ||
| return if response.failure? | ||
|
|
||
| response[:project].assign_attributes(update_hash.slice(:name, :instructions)) | ||
|
|
||
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.
What made you decide to add the extra column rather than modify and use the current instructions column?
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.
Good question, there's some details in the commit message:
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.
This isn't true for all type changes, but was for this one when I tested it because Rails treats jsonb differently.