diff --git a/app/models/enrollment.rb b/app/models/enrollment.rb index 0741eeb9223..75358f30222 100644 --- a/app/models/enrollment.rb +++ b/app/models/enrollment.rb @@ -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 diff --git a/config/initializers/dropped_columns.rb b/config/initializers/dropped_columns.rb index 0c285ed8dbe..cac3d0310ea 100644 --- a/config/initializers/dropped_columns.rb +++ b/config/initializers/dropped_columns.rb @@ -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), diff --git a/db/migrate/20120620184804_migrate_to_limit_privileges_to_course_section.rb b/db/migrate/20120620184804_migrate_to_limit_privileges_to_course_section.rb new file mode 100644 index 00000000000..f4c1363e498 --- /dev/null +++ b/db/migrate/20120620184804_migrate_to_limit_privileges_to_course_section.rb @@ -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 diff --git a/db/migrate/20120620185247_drop_limit_priveleges_to_course_section_from_enrollments.rb b/db/migrate/20120620185247_drop_limit_priveleges_to_course_section_from_enrollments.rb new file mode 100644 index 00000000000..f63eee0de27 --- /dev/null +++ b/db/migrate/20120620185247_drop_limit_priveleges_to_course_section_from_enrollments.rb @@ -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 diff --git a/spec/migrations/fix_spelling_of_privileges_spec.rb b/spec/migrations/fix_spelling_of_privileges_spec.rb deleted file mode 100644 index fac3bf6c121..00000000000 --- a/spec/migrations/fix_spelling_of_privileges_spec.rb +++ /dev/null @@ -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 . -# - -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 -