Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: c5a0eceb87
Fetching contributors…

Cannot retrieve contributors at this time

57 lines (49 sloc) 1.892 kB
#
# Copyright (C) 2011 Instructure, Inc.
#
# This file is part of Canvas.
#
# Canvas is free software: you can redistribute it and/or modify it under
# the terms of the GNU Affero General Public License as published by the Free
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
# A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>.
#
class EnrollmentsFromUserList
class << self
def process(list, course, opts={})
EnrollmentsFromUserList.new(course, opts).process(list)
end
end
attr_reader :students, :course
def initialize(course, opts={})
@course = course
@enrollment_type = opts[:enrollment_type] || 'StudentEnrollment'
@limit = opts[:limit]
@section = (opts[:course_section_id].present? ? @course.course_sections.active.find_by_id(opts[:course_section_id].to_i) : nil) || @course.default_section
@limit_privileges_to_course_section = opts[:limit_privileges_to_course_section]
@enrolled_users = {}
end
def process(list)
raise ArgumentError, "Must provide a UserList" unless list.is_a?(UserList)
@enrollments = []
list.addresses.slice!(0,@limit) if @limit
list.users.each { |user| enroll_user(user) }
@enrollments
end
protected
def enroll_user(user)
return unless user
return if @enrolled_users.has_key?(user.id)
@enrolled_users[user.id] = true
@course.enroll_user(user, @enrollment_type, :section => @section, :limit_privileges_to_course_section => @limit_privileges_to_course_section).tap do |e|
@enrollments << e if e
end
end
end
Jump to Line
Something went wrong with that request. Please try again.