finish fixing the spelling of limit_privileges_to_course_section
test plan: * ensure specs pass * test around gradebook and teachers that should only be able to see their section(s) Change-Id: I86e431388a414f4edef7e59329c8a5e449f26e7f Reviewed-on: https://gerrit.instructure.com/11709 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
e3380e1e67
commit
0f41f9b3eb
|
@ -41,7 +41,7 @@ class Enrollment < ActiveRecord::Base
|
|||
after_save :cancel_future_appointments
|
||||
after_save :update_linked_enrollments
|
||||
|
||||
attr_accessible :user, :course, :workflow_state, :course_section, :limit_priveleges_to_course_section, :limit_privileges_to_course_section
|
||||
attr_accessible :user, :course, :workflow_state, :course_section, :limit_privileges_to_course_section
|
||||
|
||||
def self.active_student_conditions(prefix = 'enrollments')
|
||||
"(#{prefix}.type IN ('StudentEnrollment', 'StudentViewEnrollment') AND #{prefix}.workflow_state = 'active')"
|
||||
|
@ -811,20 +811,6 @@ class Enrollment < ActiveRecord::Base
|
|||
read_attribute(:uuid)
|
||||
end
|
||||
|
||||
# overwrite the accessors to limit_priveleges and limit_privileges to return the value wherever
|
||||
# it exists.
|
||||
[:limit_privileges_to_course_section, :limit_priveleges_to_course_section].each do |method_name|
|
||||
define_method(method_name) do
|
||||
read_attribute(:limit_privileges_to_course_section).nil? ?
|
||||
read_attribute(:limit_priveleges_to_course_section) :
|
||||
read_attribute(:limit_privileges_to_course_section)
|
||||
end
|
||||
end
|
||||
|
||||
def limit_priveleges_to_course_section=(value)
|
||||
self.limit_privileges_to_course_section = value
|
||||
end
|
||||
|
||||
def self.limit_privileges_to_course_section!(course, user, limit)
|
||||
Enrollment.update_all({:limit_privileges_to_course_section => !!limit}, {:course_id => course.id, :user_id => user.id})
|
||||
user.touch
|
||||
|
|
|
@ -30,7 +30,7 @@ class ActiveRecord::Base
|
|||
'courses' => %w(section hidden_tabs sis_name sis_course_code),
|
||||
'discussion_topics' => %w(authorization_list_id),
|
||||
'enrollment_terms' => %w(sis_data sis_name),
|
||||
'enrollments' => %w(invitation_email can_participate_before_start_at),
|
||||
'enrollments' => %w(invitation_email can_participate_before_start_at limit_priveleges_to_course_sections),
|
||||
'groups' => %w(sis_name type groupable_id groupable_type),
|
||||
'notification_policies' => %w(user_id),
|
||||
'pseudonyms' => %w(sis_update_data deleted_unique_id sis_source_id crypted_webdav_access_code),
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
class MigrateToLimitPrivilegesToCourseSection < ActiveRecord::Migration
|
||||
tag :predeploy, :postdeploy
|
||||
self.transactional = false
|
||||
|
||||
def self.up
|
||||
Enrollment.find_ids_in_ranges do |(start_id, end_id)|
|
||||
Enrollment.update_all 'limit_privileges_to_course_section=limit_priveleges_to_course_section', ["limit_privileges_to_course_section IS NULL AND id>=? AND id<=?", start_id, end_id]
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class DropLimitPrivelegesToCourseSectionFromEnrollments < ActiveRecord::Migration
|
||||
tag :postdeploy
|
||||
|
||||
def self.up
|
||||
remove_column :enrollments, :limit_priveleges_to_course_section
|
||||
end
|
||||
|
||||
def self.down
|
||||
add_column :enrollments, :limit_priveleges_to_course_section, :boolean
|
||||
end
|
||||
end
|
|
@ -1,74 +0,0 @@
|
|||
#
|
||||
# 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/>.
|
||||
#
|
||||
|
||||
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper.rb')
|
||||
require 'db/migrate/20111209000047_fix_spelling_of_privileges_column_on_enrollments.rb'
|
||||
|
||||
describe 'FixSpellingOfPrivilegesColumnOnEnrollments' do
|
||||
describe "existing records" do
|
||||
before do
|
||||
course_with_teacher
|
||||
@enrollment = @course.enroll_user @user, 'StudentEnrollment'
|
||||
FixSpellingOfPrivilegesColumnOnEnrollments.down
|
||||
Enrollment.reset_column_information
|
||||
end
|
||||
|
||||
context "get values" do
|
||||
it "should preserve a true value across the migration" do
|
||||
Enrollment.update_all({ :limit_priveleges_to_course_section => true }, { :id => @enrollment.id } )
|
||||
run_migration(@enrollment)
|
||||
@enrollment.limit_priveleges_to_course_section.should eql true
|
||||
@enrollment.limit_privileges_to_course_section.should eql true
|
||||
end
|
||||
|
||||
it "should preserve a false value across the migration" do
|
||||
Enrollment.update_all({ :limit_priveleges_to_course_section => false }, { :id => @enrollment.id } )
|
||||
run_migration(@enrollment)
|
||||
@enrollment.limit_priveleges_to_course_section.should eql false
|
||||
@enrollment.limit_privileges_to_course_section.should eql false
|
||||
end
|
||||
end
|
||||
|
||||
context "set values" do
|
||||
it "should allow setting of properly spelled column" do
|
||||
Enrollment.update_all({ :limit_priveleges_to_course_section => true }, { :id => @enrollment.id } )
|
||||
run_migration(@enrollment)
|
||||
@enrollment.limit_privileges_to_course_section = false
|
||||
@enrollment.save
|
||||
@enrollment.limit_priveleges_to_course_section.should eql false
|
||||
@enrollment.limit_privileges_to_course_section.should eql false
|
||||
end
|
||||
|
||||
it "should allow setting of improperly spelled column" do
|
||||
Enrollment.update_all({ :limit_priveleges_to_course_section => true }, { :id => @enrollment.id } )
|
||||
run_migration(@enrollment)
|
||||
@enrollment.limit_priveleges_to_course_section = false
|
||||
@enrollment.limit_priveleges_to_course_section.should eql false
|
||||
@enrollment.limit_privileges_to_course_section.should eql false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# helpers
|
||||
def run_migration(enrollment)
|
||||
FixSpellingOfPrivilegesColumnOnEnrollments.up
|
||||
Enrollment.reset_column_information
|
||||
enrollment.reload if enrollment.present?
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue