allow DesignerEnrollments in the API; fixes #CNVS-2147
the API was created without the ability to enroll Designers. we think this was an oversight. test plan: - enroll a designer via the API - enroll a custom role based on designer via the API Change-Id: Idee15513dd001500a710ecf73eed56f92cac47c4 Reviewed-on: https://gerrit.instructure.com/16029 Reviewed-by: Bracken Mosbacker <bracken@instructure.com> QA-Review: Adam Phillipps <adam@instructure.com> Tested-by: Jenkins <jenkins@instructure.com>
This commit is contained in:
parent
7bb1c2b5f4
commit
b7ba47f680
|
@ -31,7 +31,6 @@ class EnrollmentsApiController < ApplicationController
|
|||
:concluded_course => 'Can\'t add an enrollment to a concluded course.'
|
||||
|
||||
}
|
||||
@@valid_types = %w{StudentEnrollment TeacherEnrollment TaEnrollment ObserverEnrollment}
|
||||
|
||||
include Api::V1::User
|
||||
# @API List enrollments
|
||||
|
@ -165,7 +164,7 @@ class EnrollmentsApiController < ApplicationController
|
|||
# Create a new user enrollment for a course or section.
|
||||
#
|
||||
# @argument enrollment[user_id] [String] The ID of the user to be enrolled in the course.
|
||||
# @argument enrollment[type] [String] [StudentEnrollment|TeacherEnrollment|TaEnrollment|ObserverEnrollment] Enroll the user as a student, teacher, TA, or observer. If no value is given, 'StudentEnrollment' will be used.
|
||||
# @argument enrollment[type] [String] [StudentEnrollment|TeacherEnrollment|TaEnrollment|ObserverEnrollment|DesignerEnrollment] Enroll the user as a student, teacher, TA, observer, or designer. If no value is given, the type will be inferred by enrollment[role] if supplied, otherwise 'StudentEnrollment' will be used.
|
||||
# @argument enrollment[role] [String] [Optional] Assigns a custom course-level role to the user.
|
||||
# @argument enrollment[enrollment_state] [String] [Optional, active|invited] [String] If set to 'active,' student will be immediately enrolled in the course. Otherwise they will be required to accept a course invitation. Default is 'invited.'
|
||||
# @argument enrollment[course_section_id] [Integer] [Optional] The ID of the course section to enroll the student in. If the section-specific URL is used, this argument is redundant and will be ignored
|
||||
|
@ -198,7 +197,7 @@ class EnrollmentsApiController < ApplicationController
|
|||
end
|
||||
|
||||
if type.present?
|
||||
errors << @@errors[:bad_type] unless @@valid_types.include?(type)
|
||||
errors << @@errors[:bad_type] unless Enrollment.valid_type?(type)
|
||||
else
|
||||
type = 'StudentEnrollment'
|
||||
end
|
||||
|
|
|
@ -215,6 +215,10 @@ class Enrollment < ActiveRecord::Base
|
|||
self.role_name || Enrollment.sis_type(self.type)
|
||||
end
|
||||
|
||||
def self.valid_type?(type)
|
||||
SIS_TYPES.has_key?(type)
|
||||
end
|
||||
|
||||
TYPES_WITH_INDEFINITE_ARTICLE = {
|
||||
'TeacherEnrollment' => t('#enrollment.roles.teacher_with_indefinite_article', "A Teacher"),
|
||||
'TaEnrollment' => t('#enrollment.roles.ta_with_indefinite_article', "A TA"),
|
||||
|
|
|
@ -160,6 +160,12 @@ describe EnrollmentsApiController, :type => :integration do
|
|||
JSON.parse(response.body)['message'].should eql 'Invalid type'
|
||||
end
|
||||
|
||||
it "should enroll a designer" do
|
||||
json = api_call :post, @path, @path_options, { :enrollment => { :user_id => @unenrolled_user.id, :type => 'DesignerEnrollment' } }
|
||||
json['type'].should eql 'DesignerEnrollment'
|
||||
@unenrolled_user.enrollments.find(json['id']).should be_an_instance_of(DesignerEnrollment)
|
||||
end
|
||||
|
||||
it "should return an error if no user_id is given" do
|
||||
raw_api_call :post, @path, @path_options, { :enrollment => { :type => 'StudentEnrollment' } }
|
||||
response.code.should eql '403'
|
||||
|
|
Loading…
Reference in New Issue