Add computed_final_score_with_muted field to submissions API #254

Closed
wants to merge 1 commit into
from

Projects

None yet

2 participants

@christopher-b

I had to make a change to the submissions API to allow it to show final computed grades, including grades for muted assignments. I'd love to see this merged into the trunk. Thanks.

@christopher-b

These changes don't work with the latest code, but I would still like to see this as a feature.

@cmatheson
Contributor

I think the change that broke your commit might also solve your problem (or hopefully get you most of the way there). The gradebook CSV now includes muted assignments (see https://github.com/instructure/canvas-lms/blob/stable/app/models/course.rb#L1439). You could just grab the csv or pass the :ignore_muted option to GradeCalculator. We don't currently save the ignore_muted value to the database.

@cmatheson
Contributor

Oh, one other note on the proposed API change: the grade including muted assignments should get filtered out for students (otherwise they would be able to infer the grade on the muted assignment the computed_final_score_with_muted grade change).

@christopher-b

Thanks Cameron. Can you give me a sense of how I can filter this out for students?

If anyone else is interested, here are the changes I needed to make to get it working.

lib/grade_calculator.rb, line 63, just after def save_scores:

def final_score_with_muted(user_id, submissions)
  @ignore_muted = false
  group_sums = create_group_sums(submissions, false)
  calculate_total_from_group_scores(group_sums)
end

app/model/enrollment.rb, line 779, after computed_final_grade:

def computed_final_score_with_muted
  user_ids = [user_id]
  submissions = course.submissions.for_user(user_id).to_a
  calc = GradeCalculator.new(user_ids, course_id)
  calc.final_score_with_muted(user_id, submissions)
end

app/controllers/submissions_api_controller.rb, line 132, in def for_students:

if includes.include?('total_scores') && params[:grouped].present?
hash.merge!(
  :computed_final_score => enrollment.computed_final_score,
  :computed_final_score_with_muted => enrollment.computed_final_score_with_muted,
  :computed_current_score => enrollment.computed_current_score)
end
@cmatheson
Contributor

Hey Christopher, our api_json stuff calls filter_attributes_for_user on the model if it is defined. See https://github.com/instructure/canvas-lms/blob/stable/app/models/submission.rb#L1130 for an example of how it is used.

@christopher-b

In this case, the api change I made is in SubmissionsApiController#for_students, which seems to required permission to view / manage grades:

if authorized_action(@context, @current_user, [:manage_grades, :view_all_grades])

So student access to this shouldn't be a problem, right?

@cmatheson
Contributor

Sorry you're right Christopher. You shouldn't have any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment