-
Notifications
You must be signed in to change notification settings - Fork 258
Issue 6225: Allow multiple periods in Assignments API routes #8128
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
base: master
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -48,11 +48,10 @@ def show | |
| # Creates a new assignment | ||
| # Requires: short_identifier, due_date, description | ||
| # Optional: repository_folder, group_min, group_max, tokens_per_period, | ||
| # submission_rule_type, allow_web_submits, | ||
| # submission_rule_type, submission_rule_periods, allow_web_submits, | ||
| # display_grader_names_to_students, enable_test, assign_graders_to_criteria, | ||
| # message, allow_remarks, remark_due_date, remark_message, student_form_groups, | ||
| # group_name_autogenerated, submission_rule_deduction, submission_rule_hours, | ||
| # submission_rule_interval | ||
| # group_name_autogenerated | ||
| def create | ||
| if has_missing_params?([:short_identifier, :due_date, :description]) | ||
| # incomplete/invalid HTTP params | ||
|
|
@@ -101,11 +100,10 @@ def create | |
| # Updates an existing assignment | ||
| # Requires: id | ||
| # Optional: short_identifier, due_date,repository_folder, group_min, group_max, | ||
| # tokens_per_period, submission_rule_type, allow_web_submits, | ||
| # tokens_per_period, submission_rule_type, submission_rule_periods, allow_web_submits, | ||
| # display_grader_names_to_students, enable_test, assign_graders_to_criteria, | ||
| # description, message, allow_remarks, remark_due_date, remark_message, | ||
| # student_form_groups, group_name_autogenerated, submission_rule_deduction, | ||
| # submission_rule_hours, submission_rule_interval, starter_file_type, | ||
| # student_form_groups, group_name_autogenerated, starter_file_type, | ||
| # default_starter_file_group_id | ||
| def update | ||
| # If no assignment is found, render an error. | ||
|
|
@@ -138,15 +136,19 @@ def update | |
| # Update the submission rule if provided | ||
| unless params[:submission_rule_type].nil? | ||
| submission_rule = get_submission_rule(params) | ||
|
|
||
| if submission_rule.nil? | ||
| render 'shared/http_status', locals: { code: '500', message: | ||
| HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error | ||
| return | ||
| elsif submission_rule.valid? | ||
| # If it's a valid submission rule, replace the existing one | ||
| assignment.submission_rule.destroy | ||
| assignment.submission_rule = submission_rule | ||
| end | ||
|
|
||
| unless assignment.update(submission_rule: submission_rule) | ||
|
Collaborator
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. Catching |
||
| render 'shared/http_status', locals: { code: '500', message: | ||
| HttpStatusHelper::ERROR_CODE['message']['500'] }, status: :internal_server_error | ||
| return | ||
| end | ||
|
|
||
| end | ||
|
|
||
| unless assignment.save | ||
|
|
@@ -230,22 +232,66 @@ def update_test_specs | |
| # Defaults to NoLateSubmissionRule | ||
| def get_submission_rule(params) | ||
| if params[:submission_rule_type] == 'GracePeriod' | ||
| if params[:submission_rule_periods].nil? || | ||
|
Collaborator
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. So overall we can make use of Rails support for nested attributes to have a more nested structure for these params: {
submission_rule_attributes: {
type: ...,
period_attributes: [
{ hours: ..., ... },
...
]
}
}This should allow you to create a new |
||
| !params[:submission_rule_periods].is_a?(Array) || | ||
| params[:submission_rule_periods].empty? | ||
| return | ||
| end | ||
|
|
||
| rule_periods = params[:submission_rule_periods] | ||
|
|
||
| # If hours is missing from any of the periods, return | ||
| if rule_periods.any? { |period| !period.respond_to?(:to_h) || !period.key?('hours') } | ||
| return | ||
| end | ||
|
|
||
| submission_rule = GracePeriodSubmissionRule.new | ||
| period = Period.new(hours: params[:submission_rule_hours]) | ||
| submission_rule.periods << period | ||
| submission_rule.periods = rule_periods.map do |period| | ||
| Period.new(hours: period[:hours]) | ||
| end | ||
|
|
||
| elsif params[:submission_rule_type] == 'PenaltyDecayPeriod' | ||
| submission_rule = PenaltyDecayPeriodSubmissionRule.new | ||
| period = Period.new(hours: params[:submission_rule_hours], | ||
| deduction: params[:submission_rule_deduction], | ||
| interval: params[:submission_rule_interval]) | ||
| submission_rule.periods << period | ||
| if params[:submission_rule_periods].nil? || | ||
| !params[:submission_rule_periods].is_a?(Array) || | ||
| params[:submission_rule_periods].empty? | ||
| return | ||
| end | ||
| rule_periods = params[:submission_rule_periods] | ||
|
|
||
| # If any of the required keys are missing, return | ||
| if rule_periods.any? do |period| | ||
| !period.respond_to?(:to_h) || !period.key?('hours') || | ||
| !period.key?('deduction') || !period.key?('interval') | ||
| end | ||
| return | ||
| end | ||
|
|
||
| submission_rule = PenaltyDecayPeriodSubmissionRule.new | ||
| submission_rule.periods = rule_periods.map do |period| | ||
| Period.new(hours: period[:hours], | ||
| deduction: period[:deduction], | ||
| interval: period[:interval]) | ||
| end | ||
| elsif params[:submission_rule_type] == 'PenaltyPeriod' | ||
| if params[:submission_rule_periods].nil? || | ||
| !params[:submission_rule_periods].is_a?(Array) || | ||
| params[:submission_rule_periods].empty? | ||
| return | ||
| end | ||
|
|
||
| rule_periods = params[:submission_rule_periods] | ||
| # If any of the required keys are missing, return | ||
| if rule_periods.any? do |period| | ||
| !period.respond_to?(:to_h) || !period.key?('hours') || !period.key?('deduction') | ||
| end | ||
| return | ||
| end | ||
|
|
||
| submission_rule = PenaltyPeriodSubmissionRule.new | ||
| period = Period.new(hours: params[:submission_rule_hours], | ||
| deduction: params[:submission_rule_deduction]) | ||
| submission_rule.periods << period | ||
| submission_rule.periods = rule_periods.map do |period| | ||
| Period.new(hours: period[:hours], | ||
| deduction: period[:deduction]) | ||
| end | ||
|
|
||
| else | ||
| submission_rule = NoLateSubmissionRule.new | ||
|
|
||
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.
Remove this blank line