revert homeroom course schema changes
because something broke in the CI system :( This reverts commit982515a123
. This reverts commit74da1a5fa9
. Change-Id: Ie82085d5f6eaf654c42b78a4fb85507468b1ae16 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/266281 Reviewed-by: James Butters <jbutters@instructure.com> Reviewed-by: Andrea Cirulli <andrea.cirulli@instructure.com> Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> QA-Review: Jeremy Stanley <jeremy@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
parent
982515a123
commit
2715e2621e
|
@ -591,9 +591,6 @@ class AccountsController < ApplicationController
|
|||
# or both the course's end_at and the enrollment term's end_at are set to null.
|
||||
# The value should be formatted as: yyyy-mm-dd or ISO 8601 YYYY-MM-DDTHH:MM:SSZ.
|
||||
#
|
||||
# @argument homeroom [Optional, Boolean]
|
||||
# If set, only return homeroom courses.
|
||||
#
|
||||
# @returns [Course]
|
||||
def courses_api
|
||||
return unless authorized_action(@account, @current_user, :read_course_list)
|
||||
|
@ -669,10 +666,6 @@ class AccountsController < ApplicationController
|
|||
@courses = @courses.not_associated_courses
|
||||
end
|
||||
|
||||
if value_to_boolean(params[:homeroom])
|
||||
@courses = @courses.homeroom
|
||||
end
|
||||
|
||||
if starts_before || ends_after
|
||||
@courses = @courses.joins(:enrollment_term)
|
||||
if starts_before
|
||||
|
|
|
@ -653,9 +653,6 @@ class CoursesController < ApplicationController
|
|||
# When set, only return courses where the user has an enrollment with the given state.
|
||||
# This will respect section/course/term date overrides.
|
||||
#
|
||||
# @argument homeroom [Optional, Boolean]
|
||||
# If set, only return homeroom courses.
|
||||
#
|
||||
# @returns [Course]
|
||||
def user_index
|
||||
GuardRail.activate(:secondary) do
|
||||
|
@ -1419,9 +1416,9 @@ class CoursesController < ApplicationController
|
|||
can_do(@context, @current_user, :manage_grades)
|
||||
|
||||
@homeroom_courses = if can_do(@context.account, @current_user, :manage_courses, :manage_courses_admin)
|
||||
@context.account.courses.active.homeroom.to_a
|
||||
@context.account.courses.active.select(&:homeroom_course)
|
||||
else
|
||||
@current_user.courses_for_enrollments(@current_user.teacher_enrollments).homeroom.to_a
|
||||
@current_user.courses_for_enrollments(@current_user.teacher_enrollments).select(&:homeroom_course)
|
||||
end
|
||||
|
||||
@alerts = @context.alerts
|
||||
|
@ -3518,11 +3515,6 @@ class CoursesController < ApplicationController
|
|||
enrollments.reject!{|e| mc_ids.include?(e.course_id)}
|
||||
end
|
||||
|
||||
if value_to_boolean(params[:homeroom])
|
||||
homeroom_ids = Course.homeroom.where(id: enrollments.map(&:course_id)).pluck(:id)
|
||||
enrollments.reject!{|e| homeroom_ids.exclude?(e.course_id)}
|
||||
end
|
||||
|
||||
Canvas::Builders::EnrollmentDateBuilder.preload_state(enrollments)
|
||||
enrollments_by_course = enrollments.group_by(&:course_id).values
|
||||
enrollments_by_course.sort_by! do |course_enrollments|
|
||||
|
|
|
@ -56,8 +56,6 @@ class Course < ActiveRecord::Base
|
|||
has_many :templated_courses, :class_name => 'Course', :foreign_key => 'template_course_id'
|
||||
has_many :templated_accounts, class_name: 'Account', foreign_key: 'course_template_id'
|
||||
|
||||
belongs_to :linked_homeroom_course, class_name: 'Course', foreign_key: 'homeroom_course_id'
|
||||
|
||||
has_many :course_sections
|
||||
has_many :active_course_sections, -> { where(workflow_state: 'active') }, class_name: 'CourseSection'
|
||||
has_many :enrollments, -> { where("enrollments.workflow_state<>'deleted'") }, inverse_of: :course
|
||||
|
@ -825,8 +823,7 @@ class Course < ActiveRecord::Base
|
|||
|
||||
scope :templates, -> { where(template: true) }
|
||||
|
||||
scope :homeroom, -> { where(homeroom_course: true) }
|
||||
scope :sync_homeroom_enrollments_enabled, -> { where(sync_enrollments_from_homeroom: true) }
|
||||
scope :sync_homeroom_enrollments_enabled, -> { where('settings LIKE ?', '%sync_enrollments_from_homeroom: true%') }
|
||||
|
||||
def potential_collaborators
|
||||
current_users
|
||||
|
@ -3290,6 +3287,9 @@ class Course < ActiveRecord::Base
|
|||
|
||||
add_setting :usage_rights_required, :boolean => true, :default => false, :inherited => true
|
||||
|
||||
add_setting :homeroom_course, :boolean => true, :default => false
|
||||
add_setting :sync_enrollments_from_homeroom, :boolean => true, :default => false
|
||||
add_setting :homeroom_course_id
|
||||
add_setting :course_color
|
||||
|
||||
def elementary_enabled?
|
||||
|
@ -3301,7 +3301,7 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def elementary_subject_course?
|
||||
!homeroom_course? && elementary_enabled?
|
||||
!homeroom_course && elementary_enabled?
|
||||
end
|
||||
|
||||
def lock_all_announcements?
|
||||
|
@ -3313,10 +3313,13 @@ class Course < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def sync_homeroom_enrollments(progress=nil)
|
||||
return false unless elementary_subject_course? && sync_enrollments_from_homeroom && linked_homeroom_course
|
||||
return false unless elementary_subject_course? && sync_enrollments_from_homeroom && homeroom_course_id.present?
|
||||
|
||||
progress&.calculate_completion!(0, linked_homeroom_course.enrollments.size)
|
||||
linked_homeroom_course.all_enrollments.find_each do |enrollment|
|
||||
homeroom_course = account.courses.find_by(id: homeroom_course_id)
|
||||
return false if homeroom_course.nil?
|
||||
|
||||
progress&.calculate_completion!(0, homeroom_course.enrollments.size)
|
||||
homeroom_course.all_enrollments.find_each do |enrollment|
|
||||
course_enrollment = all_enrollments.find_or_initialize_by(type: enrollment.type, user_id: enrollment.user_id, role_id: enrollment.role_id)
|
||||
course_enrollment.workflow_state = enrollment.workflow_state
|
||||
course_enrollment.start_at = enrollment.start_at
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2021 - present 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 AddHomeroomCourseColumns < ActiveRecord::Migration[6.0]
|
||||
tag :predeploy
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
new_pg = connection.postgresql_version >= 110000
|
||||
defaults = new_pg ? { default: false, null: false } : {}
|
||||
|
||||
add_column :courses, :homeroom_course, :boolean, if_not_exists: true, **defaults
|
||||
add_column :courses, :sync_enrollments_from_homeroom, :boolean, if_not_exists: true, **defaults
|
||||
add_reference :courses, :homeroom_course, if_not_exists: true, index: false, foreign_key: { to_table: :courses }
|
||||
|
||||
unless new_pg
|
||||
change_column_default :courses, :homeroom_course, false
|
||||
change_column_default :courses, :sync_enrollments_from_homeroom, false
|
||||
DataFixup::BackfillNulls.run(Course, [:homeroom_course, :sync_enrollments_from_homeroom], default_value: false)
|
||||
change_column_null :courses, :homeroom_course, false
|
||||
change_column_null :courses, :sync_enrollments_from_homeroom, false
|
||||
end
|
||||
|
||||
add_index :courses, :homeroom_course, where: "homeroom_course=TRUE", algorithm: :concurrently, if_not_exists: true
|
||||
add_index :courses, :sync_enrollments_from_homeroom, where: "sync_enrollments_from_homeroom=TRUE", algorithm: :concurrently, if_not_exists: true
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :courses, :homeroom_course
|
||||
remove_column :courses, :sync_enrollments_from_homeroom
|
||||
remove_column :courses, :homeroom_course_id
|
||||
end
|
||||
end
|
|
@ -1,30 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2021 - present 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 PopulateHomeroomCourseColumns < ActiveRecord::Migration[6.0]
|
||||
tag :predeploy
|
||||
disable_ddl_transaction!
|
||||
|
||||
def up
|
||||
DataFixup::MigrateHomeroomSettingsToColumns.run
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2021 - present 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/>.
|
||||
|
||||
module DataFixup
|
||||
module MigrateHomeroomSettingsToColumns
|
||||
def self.run
|
||||
Course.where("settings like '%homeroom%'").find_each do |course|
|
||||
settings = course.settings
|
||||
if settings[:homeroom_course] || settings[:sync_enrollments_from_homeroom] || settings[:homeroom_course_id].present?
|
||||
Course.where(id: course.id).update_all(
|
||||
:homeroom_course => settings[:homeroom_course] || false,
|
||||
:sync_enrollments_from_homeroom => settings[:sync_enrollments_from_homeroom] || false,
|
||||
:homeroom_course_id => settings[:homeroom_course_id].presence)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1016,17 +1016,6 @@ describe "Accounts API", type: :request do
|
|||
end
|
||||
end
|
||||
|
||||
it "limits the response to homeroom courses if requested" do
|
||||
@c1 = course_factory(account: @a1, course_name: 'c1')
|
||||
@c2 = course_factory(account: @a1, course_name: 'c2')
|
||||
@c2.homeroom_course = true
|
||||
@c2.save!
|
||||
json = api_call_as_user(account_admin_user(account: @a1), :get, "/api/v1/accounts/#{@a1.id}/courses?homeroom=1",
|
||||
controller: 'accounts', action: 'courses_api', account_id: @a1.to_param,
|
||||
format: 'json', homeroom: '1')
|
||||
expect(json.map { |c| c['name'] }).to match_array(['c2'])
|
||||
end
|
||||
|
||||
describe 'sort' do
|
||||
before :once do
|
||||
@me = @user
|
||||
|
|
|
@ -727,17 +727,6 @@ describe CoursesController, type: :request do
|
|||
entry = json.detect { |course| course['id'] == @course.id }
|
||||
expect(entry['name']).to eq 'meh'
|
||||
end
|
||||
|
||||
it "limits the response to homeroom courses if requested" do
|
||||
c1 = course_with_teacher(course_name: 'not homeroom', active_all: true).course
|
||||
c2 = course_with_teacher(user: @teacher, course_name: 'homeroom frd', active_all: true).course
|
||||
c2.homeroom_course = true
|
||||
c2.save!
|
||||
json = api_call_as_user(@teacher, :get, "/api/v1/users/self/courses?homeroom=true",
|
||||
user_id: 'self', controller: 'courses', action: 'user_index', homeroom: 'true',
|
||||
format: 'json')
|
||||
expect(json.map{|c|c['name']}).to eq(['homeroom frd'])
|
||||
end
|
||||
end
|
||||
|
||||
describe "user_progress" do
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
#
|
||||
# Copyright (C) 2019 - present 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 'spec_helper'
|
||||
|
||||
describe DataFixup::MigrateHomeroomSettingsToColumns do
|
||||
before :once do
|
||||
@c1 = course_factory
|
||||
@c1.settings_frd[:homeroom_course] = true
|
||||
@c1.save!
|
||||
|
||||
@c2 = course_factory
|
||||
@c2.settings_frd[:sync_enrollments_from_homeroom] = true
|
||||
@c2.settings_frd[:homeroom_course_id] = @c1.id
|
||||
@c2.save!
|
||||
end
|
||||
|
||||
it "migrates settings to columns" do
|
||||
DataFixup::MigrateHomeroomSettingsToColumns.run
|
||||
expect(Course.homeroom).to eq([@c1])
|
||||
expect(Course.sync_homeroom_enrollments_enabled).to eq([@c2])
|
||||
expect(@c2.reload.linked_homeroom_course).to eq @c1
|
||||
end
|
||||
end
|
|
@ -5045,6 +5045,12 @@ describe Course, "#sync_homeroom_enrollments" do
|
|||
@course.save!
|
||||
expect(@course.sync_homeroom_enrollments).not_to eq(false)
|
||||
end
|
||||
|
||||
it "returns false unless the homeroom_course_id is accessible within the account" do
|
||||
@course.homeroom_course_id = 0
|
||||
@course.save!
|
||||
expect(@course.sync_homeroom_enrollments).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
describe Course, "user_is_instructor?" do
|
||||
|
|
|
@ -96,7 +96,7 @@ describe CourseForMenuPresenter do
|
|||
|
||||
context 'with `homeroom_course` setting enabled' do
|
||||
before do
|
||||
course.update! homeroom_course: true
|
||||
course.update! settings: course.settings.merge(homeroom_course: true)
|
||||
end
|
||||
|
||||
it 'sets `isHomeroom` to `true`' do
|
||||
|
|
Loading…
Reference in New Issue