default has_no_front_page to true for new wikis
also fixup old ones test plan: * export a course with a wiki page set as the front page * create a new course * import the exported package * should be set as the front page closes #CNVS-14601 Change-Id: Icb660f2c84ab9a9c208d0fc092cf348d69edcab7 Reviewed-on: https://gerrit.instructure.com/52245 Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: Jeremy Stanley <jeremy@instructure.com> Tested-by: Jenkins QA-Review: Jahnavi Yetukuri <jyetukuri@instructure.com>
This commit is contained in:
parent
67e9eb1853
commit
e4666edf09
|
@ -1144,7 +1144,6 @@ class ApplicationController < ActionController::Base
|
|||
# the page title.
|
||||
def get_wiki_page
|
||||
@wiki = @context.wiki
|
||||
@wiki.check_has_front_page
|
||||
|
||||
@page_name = params[:wiki_page_id] || params[:id] || (params[:wiki_page] && params[:wiki_page][:title])
|
||||
if(params[:format] && !['json', 'html'].include?(params[:format]))
|
||||
|
|
|
@ -1492,7 +1492,6 @@ class CoursesController < ApplicationController
|
|||
|
||||
# make sure the wiki front page exists
|
||||
if @course_home_view == 'wiki'
|
||||
@context.wiki.check_has_front_page
|
||||
@course_home_view = 'feed' if @context.wiki.front_page.nil?
|
||||
end
|
||||
|
||||
|
|
|
@ -485,7 +485,6 @@ class WikiPagesApiController < ApplicationController
|
|||
|
||||
def get_wiki_page
|
||||
@wiki = @context.wiki
|
||||
@wiki.check_has_front_page
|
||||
|
||||
# attempt to find an existing page
|
||||
url = params[:url]
|
||||
|
|
|
@ -137,7 +137,6 @@ module Importers
|
|||
end
|
||||
|
||||
# be very explicit about draft state courses, but be liberal toward legacy courses
|
||||
course.wiki.check_has_front_page
|
||||
if course.wiki.has_no_front_page
|
||||
if migration.for_course_copy? && (source = migration.source_course || Course.where(id: migration.migration_settings[:source_course_id]).first)
|
||||
mig_id = CC::CCHelper.create_key(source.wiki.front_page)
|
||||
|
|
|
@ -42,7 +42,7 @@ class Wiki < ActiveRecord::Base
|
|||
DEFAULT_FRONT_PAGE_URL = 'front-page'
|
||||
|
||||
def set_has_no_front_page_default
|
||||
if self.has_no_front_page.nil? && self.id && context
|
||||
if self.has_no_front_page.nil?
|
||||
self.has_no_front_page = true
|
||||
end
|
||||
end
|
||||
|
@ -72,15 +72,6 @@ class Wiki < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def check_has_front_page
|
||||
return unless self.has_no_front_page.nil?
|
||||
|
||||
url = DEFAULT_FRONT_PAGE_URL
|
||||
self.has_no_front_page = !self.wiki_pages.not_deleted.where(:url => url).exists?
|
||||
self.front_page_url = url unless self.has_no_front_page
|
||||
self.save
|
||||
end
|
||||
|
||||
def front_page
|
||||
url = self.get_front_page_url
|
||||
return nil if url.nil?
|
||||
|
@ -129,7 +120,7 @@ class Wiki < ActiveRecord::Base
|
|||
|
||||
def context
|
||||
shard.activate do
|
||||
@context ||= Course.where(wiki_id: self).first || Group.where(wiki_id: self).first
|
||||
@context ||= self.id && (Course.where(wiki_id: self).first || Group.where(wiki_id: self).first)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
class SetWikiHasNoFrontPage < ActiveRecord::Migration
|
||||
tag :postdeploy
|
||||
|
||||
def up
|
||||
DataFixup::SetWikiHasNoFrontPage.send_later_if_production_enqueue_args(:run,
|
||||
:priority => Delayed::LOWER_PRIORITY)
|
||||
end
|
||||
|
||||
def down
|
||||
end
|
||||
end
|
|
@ -0,0 +1,9 @@
|
|||
module DataFixup::SetWikiHasNoFrontPage
|
||||
def self.run
|
||||
while Wiki.where(:has_no_front_page => nil, :front_page_url => nil).
|
||||
where("NOT EXISTS (SELECT 1 FROM wiki_pages WHERE id=wiki_pages.wiki_id AND wiki_pages.url = ?)",
|
||||
Wiki::DEFAULT_FRONT_PAGE_URL).
|
||||
limit(1000).update_all(:has_no_front_page => true) > 0
|
||||
end
|
||||
end
|
||||
end
|
|
@ -50,14 +50,23 @@ describe ContentMigration do
|
|||
|
||||
context "wiki front page" do
|
||||
it "should copy wiki front page setting if there is no front page" do
|
||||
page = @copy_from.wiki.wiki_pages.create!(:title => "stuff and stuff")
|
||||
@copy_from.wiki.set_front_page_url!(page.url)
|
||||
fake_front_page = @copy_from.wiki.wiki_pages.create!(:title => "Front Page")
|
||||
real_front_page = @copy_from.wiki.wiki_pages.create!(:title => "actual front page")
|
||||
@copy_from.wiki.set_front_page_url!(real_front_page.url)
|
||||
|
||||
@copy_to.wiki.unset_front_page!
|
||||
run_course_copy
|
||||
|
||||
new_page = @copy_to.wiki.wiki_pages.where(migration_id: mig_id(page)).first
|
||||
expect(@copy_to.wiki.front_page).to eq new_page
|
||||
new_front_page = @copy_to.wiki.wiki_pages.where(migration_id: mig_id(real_front_page)).first
|
||||
expect(@copy_to.wiki.front_page).to eq new_front_page
|
||||
end
|
||||
|
||||
it "should not set 'Front Page' as the front page" do
|
||||
fake_front_page = @copy_from.wiki.wiki_pages.create!(:title => "Front Page")
|
||||
|
||||
run_course_copy
|
||||
|
||||
@copy_to.reload
|
||||
expect(@copy_to.wiki.front_page).to be_nil
|
||||
end
|
||||
|
||||
it "should not overwrite current front page" do
|
||||
|
|
Loading…
Reference in New Issue