add hide_final_grades to course api closes #10575
test plan * hide final grades in a course * the should be shown in the get course api * create a course with hide final grades set to true through the api * update the hide final grades through the api * all api calls should reflect course UI setting Change-Id: Iebd4c42ebb7c8f11285c5c85d1749348331fa8f8 Reviewed-on: https://gerrit.instructure.com/13685 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
db969be605
commit
41c3b5089d
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2012 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2012 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -152,6 +152,7 @@ class CoursesController < ApplicationController
|
|||
# @argument course[restrict_enrollments_to_course_dates] [Boolean] [optional] Set to true to restrict user enrollments to the start and end dates of the course.
|
||||
# @argument course[enroll_me] [Boolean] [optional] Set to true to enroll the current user as the teacher.
|
||||
# @argument course[sis_course_id] [String] [optional] The unique SIS identifier.
|
||||
# @argument course[hide_final_grades] [Boolean] [optional] If this option is set to true, the totals in student grades summary will be hidden.
|
||||
# @argument offer [Boolean] [optional] If this option is set to true, the course will be available to students immediately.
|
||||
#
|
||||
# @returns Course
|
||||
|
@ -195,7 +196,7 @@ class CoursesController < ApplicationController
|
|||
:is_public, :allow_student_assignment_edits, :allow_wiki_comments,
|
||||
:allow_student_forum_attachments, :open_enrollment, :self_enrollment,
|
||||
:root_account_id, :account_id, :public_description,
|
||||
:restrict_enrollments_to_course_dates, :workflow_state], nil)
|
||||
:restrict_enrollments_to_course_dates, :workflow_state, :hide_final_grades], nil)
|
||||
}
|
||||
else
|
||||
flash[:error] = t('errors.create_failed', "Course creation failed")
|
||||
|
@ -777,6 +778,7 @@ class CoursesController < ApplicationController
|
|||
if authorized_action(@context, @current_user, :read)
|
||||
enrollments = @context.current_enrollments.all(:conditions => { :user_id => @current_user.id })
|
||||
includes = Set.new(Array(params[:include]))
|
||||
includes << :hide_final_grades
|
||||
render :json => course_json(@context, @current_user, session, includes, enrollments)
|
||||
end
|
||||
return
|
||||
|
@ -1124,6 +1126,9 @@ class CoursesController < ApplicationController
|
|||
end
|
||||
end
|
||||
end
|
||||
unless (hide_final_grades = params[:course].delete(:hide_final_grades)).nil?
|
||||
@course.hide_final_grades = value_to_boolean(hide_final_grades)
|
||||
end
|
||||
params[:course][:event] = :offer if params[:offer].present?
|
||||
@course.process_event(params[:course].delete(:event)) if params[:course][:event] && @course.grants_right?(@current_user, session, :change_course_state)
|
||||
params[:course][:conclude_at] = params[:course].delete(:end_at) if api_request? && params[:course].has_key?(:end_at)
|
||||
|
@ -1138,7 +1143,7 @@ class CoursesController < ApplicationController
|
|||
format.html { redirect_to((!params[:continue_to] || params[:continue_to].empty?) ? course_url(@course) : params[:continue_to]) }
|
||||
format.json do
|
||||
if api_request?
|
||||
render :json => course_json(@course, @current_user, session, [], nil)
|
||||
render :json => course_json(@course, @current_user, session, [:hide_final_grades], nil)
|
||||
else
|
||||
render :json => @course.to_json(:methods => [:readable_license, :quota, :account_name, :term_name, :grading_standard_title, :storage_quota_mb]), :status => :ok
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2012 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2012 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -57,6 +57,7 @@ class Course < ActiveRecord::Base
|
|||
:grading_standard,
|
||||
:grading_standard_enabled,
|
||||
:locale,
|
||||
:hide_final_grades,
|
||||
:settings
|
||||
|
||||
serialize :tab_configuration
|
||||
|
@ -2698,6 +2699,19 @@ class Course < ActiveRecord::Base
|
|||
# the course settings page
|
||||
add_setting :hide_final_grade, :boolean => true
|
||||
|
||||
def hide_final_grades
|
||||
self.settings[:hide_final_grade]
|
||||
end
|
||||
|
||||
def hide_final_grades=(hide_final_grade)
|
||||
self.settings[:hide_final_grade] = hide_final_grade
|
||||
end
|
||||
|
||||
def filter_attributes_for_user(hash, user, session)
|
||||
hash.delete(:hide_final_grade) unless grants_right? user, :update
|
||||
hash
|
||||
end
|
||||
|
||||
def settings=(hash)
|
||||
|
||||
if hash.is_a?(Hash)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2011 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2012 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -27,8 +27,10 @@ module Api::V1::Course
|
|||
include_description = includes.include?('public_description')
|
||||
|
||||
base_attributes = %w(id name course_code account_id start_at)
|
||||
methods = ['end_at']
|
||||
methods << 'hide_final_grades' if includes.include?(:hide_final_grades)
|
||||
allowed_attributes = includes.is_a?(Array) ? base_attributes + includes : base_attributes
|
||||
hash = api_json(course, user, session, :only => allowed_attributes, :methods => 'end_at')
|
||||
hash = api_json(course, user, session, :only => allowed_attributes, :methods => methods)
|
||||
hash['sis_course_id'] = course.sis_source_id if course.root_account.grants_rights?(user, :read_sis, :manage_sis).values.any?
|
||||
if enrollments
|
||||
hash['enrollments'] = enrollments.map do |e|
|
||||
|
@ -52,6 +54,7 @@ module Api::V1::Course
|
|||
if include_description
|
||||
hash['public_description'] = course.public_description
|
||||
end
|
||||
hash['hide_final_grades'] = (course.hide_final_grades.to_s == 'true')
|
||||
request = self.respond_to?(:request) ? self.request : nil
|
||||
hash['html_url'] = course_url(course, :host => HostUrl.context_host(course, request.try(:host_with_port))) if include_url
|
||||
hash
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2011 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2012 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -33,7 +33,7 @@ describe "API", :type => :integration do
|
|||
describe "as_json extensions" do
|
||||
it "should skip attribute filtering if obj doesn't respond" do
|
||||
course_with_teacher
|
||||
@course.respond_to?(:filter_attributes_for_user).should be_false
|
||||
@course.respond_to?(:filter_attributes_for_user).should be_true
|
||||
@course.as_json(:include_root => false, :permissions => { :user => @user }, :only => %w(name sis_source_id)).keys.sort.should == %w(name permissions sis_source_id)
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2011 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2012 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -102,6 +102,7 @@ describe "Accounts API", :type => :integration do
|
|||
'course_code' => 'c1',
|
||||
'sis_course_id' => nil,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@c1.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => @c1.start_at.as_json,
|
||||
'end_at' => @c1.end_at.as_json
|
||||
},
|
||||
|
@ -112,6 +113,7 @@ describe "Accounts API", :type => :integration do
|
|||
'course_code' => 'c2',
|
||||
'sis_course_id' => 'sis2',
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@c2.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => @c2.start_at.as_json,
|
||||
'end_at' => @c2.end_at.as_json
|
||||
}
|
||||
|
@ -128,6 +130,7 @@ describe "Accounts API", :type => :integration do
|
|||
'course_code' => 'c2',
|
||||
'sis_course_id' => 'sis2',
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@c2.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => @c2.start_at.as_json,
|
||||
'end_at' => @c2.end_at.as_json
|
||||
}
|
||||
|
@ -144,6 +147,7 @@ describe "Accounts API", :type => :integration do
|
|||
'course_code' => 'c2',
|
||||
'sis_course_id' => 'sis2',
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@c2.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => @c2.start_at.as_json,
|
||||
'end_at' => @c2.end_at.as_json
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2012 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2012 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -89,6 +89,7 @@ describe CoursesController, :type => :integration do
|
|||
'enrollments' => [{'type' => 'teacher'}],
|
||||
'sis_course_id' => nil,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course1.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
},
|
||||
|
@ -100,6 +101,7 @@ describe CoursesController, :type => :integration do
|
|||
'enrollments' => [{'type' => 'student'}],
|
||||
'sis_course_id' => 'TEST-SIS-ONE.2011',
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course2.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
},
|
||||
|
@ -133,6 +135,7 @@ describe CoursesController, :type => :integration do
|
|||
'open_enrollment' => true,
|
||||
'self_enrollment' => true,
|
||||
'restrict_enrollments_to_course_dates' => true,
|
||||
'hide_final_grades' => true,
|
||||
'license' => 'Creative Commons',
|
||||
'sis_course_id' => '12345',
|
||||
'public_description' => 'Nature is lethal but it doesn\'t hold a candle to man.'
|
||||
|
@ -222,6 +225,7 @@ describe CoursesController, :type => :integration do
|
|||
'allow_student_forum_attachments' => true,
|
||||
'open_enrollment' => true,
|
||||
'self_enrollment' => true,
|
||||
'hide_final_grades' => false,
|
||||
'restrict_enrollments_to_course_dates' => true
|
||||
}, 'offer' => true }
|
||||
end
|
||||
|
@ -383,6 +387,7 @@ describe CoursesController, :type => :integration do
|
|||
'enrollments' => [{'type' => 'teacher'}],
|
||||
'sis_course_id' => nil,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course1.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
},
|
||||
|
@ -397,6 +402,7 @@ describe CoursesController, :type => :integration do
|
|||
'computed_final_grade' => expected_final_grade}],
|
||||
'sis_course_id' => 'TEST-SIS-ONE.2011',
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course2.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
},
|
||||
|
@ -421,6 +427,7 @@ describe CoursesController, :type => :integration do
|
|||
'enrollments' => [{'type' => 'teacher'}],
|
||||
'sis_course_id' => nil,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course1.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
},
|
||||
|
@ -432,6 +439,7 @@ describe CoursesController, :type => :integration do
|
|||
'enrollments' => [{'type' => 'student'}],
|
||||
'sis_course_id' => 'TEST-SIS-ONE.2011',
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course2.uuid}.ics" },
|
||||
'hide_final_grades' => true,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
}
|
||||
|
@ -450,6 +458,7 @@ describe CoursesController, :type => :integration do
|
|||
'enrollments' => [{'type' => 'teacher'}],
|
||||
'sis_course_id' => nil,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course1.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
}
|
||||
|
@ -809,6 +818,7 @@ describe CoursesController, :type => :integration do
|
|||
'needs_grading_count' => 1,
|
||||
'sis_course_id' => nil,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course1.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
},
|
||||
|
@ -830,6 +840,7 @@ describe CoursesController, :type => :integration do
|
|||
'syllabus_body' => @course1.syllabus_body,
|
||||
'sis_course_id' => nil,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course1.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'start_at' => nil,
|
||||
'end_at' => nil
|
||||
},
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (C) 2011 Instructure, Inc.
|
||||
# Copyright (C) 2011 - 2012 Instructure, Inc.
|
||||
#
|
||||
# This file is part of Canvas.
|
||||
#
|
||||
|
@ -291,6 +291,7 @@ describe UsersController, :type => :integration do
|
|||
'id' => @course.id,
|
||||
'course_code' => @course.course_code,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'html_url' => course_url(@course, :host => HostUrl.context_host(@course)),
|
||||
},
|
||||
|
||||
|
@ -376,6 +377,7 @@ describe UsersController, :type => :integration do
|
|||
'id' => @course.id,
|
||||
'course_code' => @course.course_code,
|
||||
'calendar' => { 'ics' => "http://www.example.com/feeds/calendars/course_#{@course.uuid}.ics" },
|
||||
'hide_final_grades' => false,
|
||||
'html_url' => course_url(@course, :host => HostUrl.context_host(@course)),
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in New Issue