actually create the dummy course for course templates

fixes FOO-1962

Change-Id: Ia95ed7df67af812ad63fcd16103cf3c9c157851d
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/264717
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
Reviewed-by: Simon Williams <simon@instructure.com>
QA-Review: Nate Armstrong <narmstrong@instructure.com>
Product-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
Cody Cutrer 2021-05-11 14:11:13 -06:00
parent 140a6e31d0
commit 0e7429b116
4 changed files with 31 additions and 2 deletions

View File

@ -1605,7 +1605,7 @@ class AccountsController < ApplicationController
@account.course_template_id = nil
elsif param.to_s == '0'
return if @account.course_template_id == 0
return :unauthorized unless @account.grants_right?(@current_user, :delete_course_template, :edit_course_template)
return :unauthorized unless @account.grants_any_right?(@current_user, :delete_course_template, :edit_course_template)
@account.course_template_id = 0
else

View File

@ -257,7 +257,7 @@ class Course < ActiveRecord::Base
validate :validate_course_dates
validate :validate_course_image
validate :validate_default_view
validate :validate_template, if: :template_changed?
validate :validate_template
validates :sis_source_id, uniqueness: {scope: :root_account}, allow_nil: true
validates_presence_of :account_id, :root_account_id, :enrollment_term_id, :workflow_state
validates_length_of :syllabus_body, :maximum => maximum_long_text_length, :allow_nil => true, :allow_blank => true
@ -486,6 +486,9 @@ class Course < ActiveRecord::Base
end
def validate_template
return unless self.class.columns_hash.key?('template')
return unless template_changed?
if template? && !can_become_template?
errors.add(:template, t("Courses with enrollments can't become templates"))
elsif !template? && !can_stop_being_template?

View File

@ -0,0 +1,25 @@
# 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 EnsureDummyCourse < ActiveRecord::Migration[6.0]
tag :predeploy
def up
Course.ensure_dummy_course
end
end

View File

@ -20,6 +20,7 @@
module CdcFixtures
def self.create_profile
Course.find_or_create_by!(id: 1)
Profile.new(context_id: 1, context_type: 'Course', root_account_id: 1)
end
end