remove non-draft state wiki pages

test plan:
* regression test wiki pages

closes CNVS-16203

Change-Id: Ic37c69c8696151dc99f1df6f3cc9b013835b12a4
Reviewed-on: https://gerrit.instructure.com/42552
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
Tested-by: Jenkins <jenkins@instructure.com>
Product-Review: James Williams  <jamesw@instructure.com>
QA-Review: James Williams  <jamesw@instructure.com>
This commit is contained in:
Mark Severson 2014-10-09 20:18:35 -06:00 committed by James Williams
parent 8d79af994a
commit 1a245e6bdd
53 changed files with 171 additions and 1178 deletions

View File

@ -1142,7 +1142,6 @@ class ApplicationController < ActionController::Base
@wiki.check_has_front_page
@page_name = params[:wiki_page_id] || params[:id] || (params[:wiki_page] && params[:wiki_page][:title])
@page_name ||= (@wiki.get_front_page_url || Wiki::DEFAULT_FRONT_PAGE_URL) unless @context.feature_enabled?(:draft_state)
if(params[:format] && !['json', 'html'].include?(params[:format]))
@page_name += ".#{params[:format]}"
params[:format] = 'html'
@ -1160,17 +1159,12 @@ class ApplicationController < ActionController::Base
end
end
def context_wiki_page_url
page_name = @page.url
named_context_url(@context, :context_wiki_page_url, page_name)
end
def content_tag_redirect(context, tag, error_redirect_symbol, tag_type=nil)
url_params = { :module_item_id => tag.id }
if tag.content_type == 'Assignment'
redirect_to named_context_url(context, :context_assignment_url, tag.content_id, url_params)
elsif tag.content_type == 'WikiPage'
redirect_to named_context_url(context, :context_named_page_url, tag.content.url, url_params)
redirect_to polymorphic_url([context, tag.content], url_params)
elsif tag.content_type == 'Attachment'
redirect_to named_context_url(context, :context_file_url, tag.content_id, url_params)
elsif tag.content_type_quiz?
@ -1779,7 +1773,7 @@ class ApplicationController < ActionController::Base
hash = {}
hash[:DEFAULT_EDITING_ROLES] = @context.default_wiki_editing_roles if @context.respond_to?(:default_wiki_editing_roles)
hash[:WIKI_PAGES_PATH] = polymorphic_path([@context, :pages])
hash[:WIKI_PAGES_PATH] = polymorphic_path([@context, :wiki_pages])
if opts[:course_home]
hash[:COURSE_HOME] = true
hash[:COURSE_TITLE] = @context.name
@ -1788,9 +1782,9 @@ class ApplicationController < ActionController::Base
if @page
hash[:WIKI_PAGE] = wiki_page_json(@page, @current_user, session)
hash[:WIKI_PAGE_REVISION] = (current_version = @page.versions.current) ? Api.stringify_json_id(current_version.number) : nil
hash[:WIKI_PAGE_SHOW_PATH] = polymorphic_path([@context, :named_page], :wiki_page_id => @page)
hash[:WIKI_PAGE_EDIT_PATH] = polymorphic_path([@context, :edit_named_page], :wiki_page_id => @page)
hash[:WIKI_PAGE_HISTORY_PATH] = polymorphic_path([@context, @page, :wiki_page_revisions])
hash[:WIKI_PAGE_SHOW_PATH] = named_context_url(@context, :context_wiki_page_path, @page)
hash[:WIKI_PAGE_EDIT_PATH] = named_context_url(@context, :edit_context_wiki_page_path, @page)
hash[:WIKI_PAGE_HISTORY_PATH] = named_context_url(@context, :context_wiki_page_revisions_path, @page)
if @context.is_a?(Course) && @context.grants_right?(@current_user, :read)
hash[:COURSE_ID] = @context.id

View File

@ -1,93 +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/>.
#
class WikiPageRevisionsController < ApplicationController
before_filter :require_context, :except => :latest_version_number
before_filter :get_wiki_page, :except => :latest_version_number
add_crumb(proc { t '#crumbs.wiki_pages', "Pages"}, :except => [:latest_version_number]) { |c| c.send :named_context_url, c.instance_variable_get("@context"), :context_wiki_pages_url }
before_filter { |c| c.active_tab = "pages" }
def index
if @context.feature_enabled?(:draft_state)
redirect_to polymorphic_url([@context, :named_page_revisions], :wiki_page_id => @page)
return
end
if authorized_action(@page, @current_user, :update_content)
respond_to do |format|
format.html {
add_crumb(@page.title, named_context_url(@context, :context_wiki_page_url, @page))
add_crumb(t("#crumbs.revisions", "Revisions"))
log_asset_access(@page, "wiki", @wiki)
}
format.json { render :json => @page.version_history.map{ |v| v.as_json(methods: :version_number) }}
end
end
end
def latest_version_number
# Technically this method leaks information. We're avoiding doing
# a permission check to keep this lookup fast, since its only purpose is
# to make sure somebody hasn't edited the page from underneath somebody
# else. It does divulge the page id, and current version number, though.
# If we're not ok with that, we can add a permission check.
@version = params[:wiki_page_id].to_i.to_s == params[:wiki_page_id] &&
Version.where(:versionable_type => 'WikiPage', :versionable_id => params[:wiki_page_id]).order('number DESC').first
if !@version
get_context
get_wiki_page
@version = @page.versions[0] rescue nil
end
@version_number = @version.number rescue 0
@id = @version.versionable_id rescue nil
render :json => {:wiki_page => {:id => @id, :version_number => @version_number} }
end
def show
if @context.feature_enabled?(:draft_state)
redirect_to polymorphic_url([@context, :named_page_revisions], :wiki_page_id => @page)
return
end
if authorized_action(@page, @current_user, :update_content)
if params[:id] == "latest"
@revision = @page.versions[0]
else
@revision = @page.versions.find(params[:id])
end
respond_to do |format|
format.html {
add_crumb(@page.title, named_context_url(@context, :context_wiki_page_url, @page))
log_asset_access(@page, "wiki", @wiki)
}
@model = @revision.model rescue nil
format.json { render :json => @model.as_json(:methods => :version_number) }
end
end
end
def update
if authorized_action(@page, @current_user, :update)
@revision = @page.versions.find(params[:id])
except_fields = [:id] + WikiPage.new.attributes.keys - WikiPage.accessible_attributes.to_a
@page.revert_to_version @revision, :except => except_fields
flash[:notice] = t('notices.page_rolled_back', 'Page was successfully rolled-back to previous version.')
redirect_to polymorphic_url([@context, @page])
end
end
end

View File

@ -47,7 +47,7 @@
# "type": "datetime"
# },
# "hide_from_students": {
# "description": "whether this page is hidden from students (note: students will never see this true; pages hidden from them will be omitted from results)",
# "description": "(DEPRECATED) whether this page is hidden from students (note: this is always reflected as the inverse of the published value)",
# "example": false,
# "type": "boolean"
# },
@ -166,13 +166,6 @@ class WikiPagesApiController < ApplicationController
# @argument wiki_page[body] [String]
# The content for the new page.
#
# @argument wiki_page[hide_from_students] [Boolean]
# Whether the page should be hidden from students.
#
# *Note:* when draft state is enabled, attempts to set +hide_from_students+
# will be ignored and the value returned will always be the inverse of the
# +published+ value.
#
# @argument wiki_page[editing_roles] [String, "teachers"|"students"|"members"|"public"]
# Which user roles are allowed to edit this page. Any combination
# of these roles is allowed (separated by commas).
@ -188,10 +181,6 @@ class WikiPagesApiController < ApplicationController
# @argument wiki_page[published] [Boolean]
# Whether the page is published (true) or draft state (false).
#
# *Note:* when draft state is disabled, attempts to set +published+
# will be ignored and the value returned will always be the inverse of the
# +hide_from_students+ value.
#
# @example_request
# curl -X PUT -H 'Authorization: Bearer <token>' \
# https://<canvas>/api/v1/courses/123/front_page \
@ -268,13 +257,6 @@ class WikiPagesApiController < ApplicationController
# @argument wiki_page[body] [String]
# The content for the new page.
#
# @argument wiki_page[hide_from_students] [Boolean]
# Whether the page should be hidden from students.
#
# *Note:* when draft state is enabled, attempts to set +hide_from_students+
# will be ignored and the value returned will always be the inverse of the
# +published+ value.
#
# @argument wiki_page[editing_roles] [String, "teachers"|"students"|"members"|"public"]
# Which user roles are allowed to edit this page. Any combination
# of these roles is allowed (separated by commas).
@ -290,10 +272,6 @@ class WikiPagesApiController < ApplicationController
# @argument wiki_page[published] [Boolean]
# Whether the page is published (true) or draft state (false).
#
# *Note:* when draft state is disabled, attempts to set +published+
# will be ignored and the value returned will always be the inverse of the
# +hide_from_students+ value.
#
# @argument wiki_page[front_page] [Boolean]
# Set an unhidden page as the front page (if true)
#
@ -312,6 +290,7 @@ class WikiPagesApiController < ApplicationController
@page = @wiki.build_wiki_page(@current_user, initial_params)
if authorized_action(@page, @current_user, :create)
update_params = get_update_params(Set[:title, :body])
if !update_params.is_a?(Symbol) && @page.update_attributes(update_params) && process_front_page
log_asset_access(@page, "wiki", @wiki, 'participate')
render :json => wiki_page_json(@page, @current_user, session)
@ -349,13 +328,6 @@ class WikiPagesApiController < ApplicationController
# @argument wiki_page[body] [String]
# The content for the new page.
#
# @argument wiki_page[hide_from_students] [Boolean]
# Whether the page should be hidden from students.
#
# *Note:* when draft state is enabled, attempts to set +hide_from_students+
# will be ignored and the value returned will always be the inverse of the
# +published+ value.
#
# @argument wiki_page[editing_roles] [String, "teachers"|"students"|"members"|"public"]
# Which user roles are allowed to edit this page. Any combination
# of these roles is allowed (separated by commas).
@ -371,10 +343,6 @@ class WikiPagesApiController < ApplicationController
# @argument wiki_page[published] [Boolean]
# Whether the page is published (true) or draft state (false).
#
# *Note:* when draft state is disabled, attempts to set +published+
# will be ignored and the value returned will always be the inverse of the
# +hide_from_students+ value.
#
# @argument wiki_page[front_page] [Boolean]
# Set an unhidden page as the front page (if true)
#
@ -521,18 +489,17 @@ class WikiPagesApiController < ApplicationController
@wiki.check_has_front_page
# attempt to find an existing page
is_front_page_action = is_front_page_action?
url = is_front_page_action ? Wiki::DEFAULT_FRONT_PAGE_URL : params[:url]
@page = if is_front_page_action
@wiki.front_page
url = params[:url]
if is_front_page_action?
@page = @wiki.front_page
else
@wiki.find_page(url)
@page = @wiki.find_page(url)
end
# create a new page if the page was not found
unless @page
@page = @wiki.build_wiki_page(@current_user, :url => url)
if is_front_page_action
if is_front_page_action?
@page.workflow_state = 'active'
@set_front_page = true
@set_as_front_page = true
@ -559,22 +526,13 @@ class WikiPagesApiController < ApplicationController
def get_update_params(allowed_fields=Set[])
# normalize parameters
page_params = params[:wiki_page] || {}
if @context.feature_enabled?(:draft_state)
page_params.slice!(*%w(title body notify_of_update published front_page editing_roles))
else
page_params.slice!(*%w(title body hide_from_students notify_of_update front_page editing_roles))
workflow_state = 'active' if @page.new_record?
end
page_params = (params[:wiki_page] || {}).slice(*%w(title body notify_of_update published front_page editing_roles))
hide_from_students_provided = page_params.has_key?(:hide_from_students)
if page_params.has_key?(:published)
published_value = page_params.delete(:published)
if published_value != ''
workflow_state = value_to_boolean(published_value) ? 'active' : 'unpublished'
end
elsif hide_from_students_provided
workflow_state = value_to_boolean(page_params.delete(:hide_from_students)) ? 'unpublished' : 'active'
end
if page_params.has_key?(:editing_roles)
@ -600,11 +558,7 @@ class WikiPagesApiController < ApplicationController
allowed_fields.clear
else
if workflow_state && workflow_state != @page.workflow_state
if hide_from_students_provided
rejected_fields << :hide_from_students
else
rejected_fields << :published
end
rejected_fields << :published
end
if editing_roles
@ -627,7 +581,6 @@ class WikiPagesApiController < ApplicationController
unless rejected_fields.empty?
@page.errors.add(:published, t(:cannot_update_published, 'You are not allowed to update the published state of this wiki page')) if rejected_fields.include?(:published)
@page.errors.add(:title, t(:cannot_update_title, 'You are not allowed to update the title of this wiki page')) if rejected_fields.include?(:title)
@page.errors.add(:hide_from_students, t(:cannot_update_hide_from_students, 'You are not allowed to update the hidden from students flag of this wiki page')) if rejected_fields.include?(:hide_from_students)
@page.errors.add(:editing_roles, t(:cannot_update_editing_roles, 'You are not allowed to update the editing roles of this wiki page')) if rejected_fields.include?(:editing_roles)
@page.errors.add(:front_page, t(:cannot_update_front_page, 'You are not allowed to change the wiki front page')) if rejected_fields.include?(:front_page)
@ -644,11 +597,7 @@ class WikiPagesApiController < ApplicationController
valid_front_page = false
error_message = t(:cannot_have_unpublished_front_page, 'The front page cannot be unpublished')
@page.errors.add(:front_page, error_message) if change_front_page
if hide_from_students_provided
@page.errors.add(:hide_from_students, t(:cannot_have_hidden_front_page, 'The front page cannot be hidden'))
elsif workflow_state
@page.errors.add(:published, error_message)
end
@page.errors.add(:published, error_message) if workflow_state
end
end
@ -682,9 +631,7 @@ class WikiPagesApiController < ApplicationController
end
end
if !@context.feature_enabled?(:draft_state)
@page.set_as_front_page! if !@wiki.has_front_page? && @page.is_front_page? && !@page.deleted?
end
@page.set_as_front_page! if !@wiki.has_front_page? && @page.is_front_page? && !@page.deleted?
return true
end

View File

@ -20,22 +20,18 @@ class WikiPagesController < ApplicationController
include KalturaHelper
before_filter :require_context
before_filter :get_wiki_page
before_filter :get_wiki_page, :except => [:front_page]
before_filter :set_front_page, :only => [:front_page]
before_filter :set_pandapub_read_token
before_filter :set_js_rights, :only => [:pages_index, :show_page, :edit_page, :page_revisions]
before_filter :set_js_wiki_data, :only => [:pages_index, :show_page, :edit_page, :page_revisions]
before_filter :set_js_rights
before_filter :set_js_wiki_data
add_crumb(proc { t '#crumbs.wiki_pages', "Pages"}) do |c|
url = nil
context = c.instance_variable_get('@context')
current_user = c.instance_variable_get('@current_user')
if context.grants_right?(current_user, :read)
if context.feature_enabled?(:draft_state)
url = c.send :polymorphic_path, [context, :pages]
else
url = c.send :named_context_url, c.instance_variable_get("@context"), :context_wiki_pages_url
end
c.send :polymorphic_path, [context, :wiki_pages]
end
url
end
before_filter { |c| c.active_tab = "pages" }
@ -55,158 +51,35 @@ class WikiPagesController < ApplicationController
end
end
def show
if @context.feature_enabled?(:draft_state)
redirect_to polymorphic_url([@context, :named_page], :wiki_page_id => @page_name || @page, :titleize => params[:titleize], :module_item_id => params[:module_item_id])
return
end
@editing = true if Canvas::Plugin.value_to_boolean(params[:edit])
hash = { :CONTEXT_ACTION_SOURCE => :wiki,
:WIKI_PAGE_EDITING => @editing}
append_sis_data(hash)
js_env(hash)
def set_front_page
@wiki = @context.wiki
@page = @wiki.front_page
end
unless is_authorized_action?(@page, @current_user, [:update, :update_content]) || @page.is_front_page?
wiki_page = @wiki.wiki_pages.deleted_last.where(url: @page.url).first if @page.new_record?
if wiki_page && wiki_page.deleted?
flash[:warning] = t('notices.page_deleted', 'The page "%{title}" has been deleted.', :title => @page.title)
return redirect_to named_context_url(@context, :context_wiki_page_url, @wiki.get_front_page_url)
end
end
def front_page
return unless authorized_action(@context.wiki, @current_user, :read) && tab_enabled?(@context.class::TAB_PAGES)
if is_authorized_action?(@page, @current_user, :read)
add_crumb(@page.title)
@page.increment_view_count(@current_user, @context)
log_asset_access(@page, "wiki", @wiki)
respond_to do |format|
format.html {render :action => "show" }
format.json {render :json => @page }
end
if @page && !@page.new_record?
@padless = true
render template: 'wiki_pages/show'
else
render_unauthorized_action
redirect_to polymorphic_url([@context, :wiki_pages])
end
end
def index
return unless tab_enabled?(@context.class::TAB_PAGES)
if @context.feature_enabled?(:draft_state)
front_page
else
redirect_to named_context_url(@context, :context_wiki_page_url, @context.wiki.get_front_page_url || Wiki::DEFAULT_FRONT_PAGE_URL)
end
end
def update
if authorized_action(@page, @current_user, :update_content)
unless @page.grants_right?(@current_user, session, :update)
params[:wiki_page] = {:body => params[:wiki_page][:body]}
end
perform_update
end
end
def create
if authorized_action(@page, @current_user, :create)
perform_update
unless @wiki.grants_right?(@current_user, session, :manage)
@page.workflow_state = 'active'
@page.editing_roles = (@context.default_wiki_editing_roles rescue nil) || @page.default_roles
@page.save!
end
end
end
def perform_update
if params[:wiki_page].include?(:hide_from_students)
hide_from_students = Canvas::Plugin::value_to_boolean(params[:wiki_page].delete(:hide_from_students))
if hide_from_students
@page.workflow_state = 'unpublished'
else
@page.workflow_state = 'published'
end
end
if @page.update_attributes(params[:wiki_page].merge(:user_id => @current_user.id))
unless @page.context.feature_enabled?(:draft_state)
@page.set_as_front_page! if @page.is_front_page?
end
log_asset_access(@page, "wiki", @wiki, 'participate')
@page.context_module_action(@current_user, @context, :contributed)
flash[:notice] = t('notices.page_updated', 'Page was successfully updated.')
respond_to do |format|
format.html { return_to(params[:return_to], context_wiki_page_url(:edit => params[:action] == 'create')) }
format.json {
json = @page.as_json
json[:success_url] = context_wiki_page_url(:edit => params[:action] == 'create')
render :json => json
}
end
else
respond_to do |format|
format.html { render :action => "show" }
format.json { render :json => @page.errors, :status => :bad_request }
end
end
end
def destroy
if authorized_action(@page, @current_user, :delete)
if !@page.is_front_page?
flash[:notice] = t('notices.page_deleted', 'The page "%{title}" has been deleted.', :title => @page.title)
@page.workflow_state = 'deleted'
@page.save
respond_to do |format|
format.html { redirect_to(named_context_url(@context, :context_wiki_pages_url)) }
end
else #they dont have permissions to destroy this page
respond_to do |format|
format.html {
flash[:error] = t('errors.cannot_delete_front_page', 'You cannot delete the front page.')
redirect_to(named_context_url(@context, :context_wiki_pages_url))
}
end
end
end
end
def front_page
return unless tab_enabled?(@context.class::TAB_PAGES)
front_page = @context.wiki.front_page if @context.wiki.has_front_page?
if front_page && !front_page.new_record?
redirect_to polymorphic_url([@context, :named_page], :wiki_page_id => @context.wiki.front_page)
else
redirect_to polymorphic_url([@context, :pages])
end
end
def pages_index
return unless tab_enabled?(@context.class::TAB_PAGES)
if !@context.feature_enabled?(:draft_state)
redirect_to polymorphic_url([@context, :wiki_pages])
return
end
if authorized_action(@context.wiki, @current_user, :read)
if authorized_action(@context.wiki, @current_user, :read) && tab_enabled?(@context.class::TAB_PAGES)
log_asset_access("pages:#{@context.asset_string}", "pages", "other")
js_env :wiki_page_menu_tools => external_tools_display_hashes(:wiki_page_menu)
@padless = true
end
end
def show_page
if !@context.feature_enabled?(:draft_state)
redirect_to polymorphic_url([@context, :named_wiki_page], :id => @page_name || @page, :titleize => params[:titleize])
return
end
def show
if @page.new_record?
if is_authorized_action?(@page, @current_user, [:update, :update_content])
flash[:info] = t('notices.create_non_existent_page', 'The page "%{title}" does not exist, but you can create it below', :title => @page.title)
redirect_to polymorphic_url([@context, :edit_named_page], :wiki_page_id => @page_name || @page, :titleize => params[:titleize])
return
redirect_to polymorphic_url([@context, :wiki_page], id: @page_name || @page, titleize: params[:titleize], action: :edit)
else
wiki_page = @wiki.wiki_pages.deleted_last.where(url: @page.url).first
if wiki_page && wiki_page.deleted?
@ -214,8 +87,9 @@ class WikiPagesController < ApplicationController
else
flash[:warning] = t('notices.page_does_not_exist', 'The page "%{title}" does not exist.', :title => @page.title)
end
return front_page # delegate to front_page logic
redirect_to polymorphic_url([@context, :wiki_pages])
end
return
end
if authorized_action(@page, @current_user, :read)
@ -226,58 +100,41 @@ class WikiPagesController < ApplicationController
js_env :wiki_page_menu_tools => external_tools_display_hashes(:wiki_page_menu)
@padless = true
render
end
end
def edit_page
if !@context.feature_enabled?(:draft_state)
redirect_to polymorphic_url([@context, :named_wiki_page], :id => @page) + '#edit'
return
end
def edit
if is_authorized_action?(@page, @current_user, [:update, :update_content])
add_crumb(@page.title)
@padless = true
render
else
if authorized_action(@page, @current_user, :read)
flash[:warning] = t('notices.cannot_edit', 'You are not allowed to edit the page "%{title}".', :title => @page.title)
redirect_to polymorphic_url([@context, :named_page], :wiki_page_id => @page)
redirect_to polymorphic_url([@context, @page])
end
end
end
def page_revisions
if !@context.feature_enabled?(:draft_state)
redirect_to polymorphic_url([@context, @page, :wiki_page_revisions])
return
end
def revisions
if is_authorized_action?(@page, @current_user, :read_revisions)
add_crumb(@page.title, polymorphic_url([@context, :named_page], :wiki_page_id => @page))
add_crumb(@page.title, polymorphic_url([@context, @page]))
add_crumb(t("#crumbs.revisions", "Revisions"))
@padless = true
render
else
if authorized_action(@page, @current_user, :read)
flash[:warning] = t('notices.cannot_read_revisions', 'You are not allowed to review the historical revisions of "%{title}".', :title => @page.title)
redirect_to polymorphic_url([@context, :named_page], :wiki_page_id => @page)
redirect_to polymorphic_url([@context, @page])
end
end
end
protected
def context_wiki_page_url(opts={})
page_name = @page.url
res = named_context_url(@context, :context_wiki_page_url, page_name)
if opts && opts[:edit]
res += "#edit"
end
res
def show_redirect
redirect_to polymorphic_url([@context, @page], :titleize => params[:titleize],
:module_item_id => params[:module_item_id]), status: :moved_permanently
end
def revisions_redirect
redirect_to polymorphic_url([@context, @page, :revisions]), status: :moved_permanently
end
end

View File

@ -2250,7 +2250,7 @@ class Course < ActiveRecord::Base
{ :id => TAB_DISCUSSIONS, :label => t('#tabs.discussions', "Discussions"), :css_class => 'discussions', :href => :course_discussion_topics_path },
{ :id => TAB_GRADES, :label => t('#tabs.grades', "Grades"), :css_class => 'grades', :href => :course_grades_path, :screenreader => t('#tabs.course_grades', "Course Grades") },
{ :id => TAB_PEOPLE, :label => t('#tabs.people', "People"), :css_class => 'people', :href => :course_users_path },
{ :id => TAB_PAGES, :label => t('#tabs.pages', "Pages"), :css_class => 'pages', :href => :course_wiki_pages_path },
{ :id => TAB_PAGES, :label => t('#tabs.pages', "Pages"), :css_class => 'pages', :href => :course_wiki_path },
{ :id => TAB_FILES, :label => t('#tabs.files', "Files"), :css_class => 'files', :href => :course_files_path },
{ :id => TAB_SYLLABUS, :label => t('#tabs.syllabus', "Syllabus"), :css_class => 'syllabus', :href => :syllabus_course_assignments_path },
{ :id => TAB_OUTCOMES, :label => t('#tabs.outcomes', "Outcomes"), :css_class => 'outcomes', :href => :course_outcomes_path },

View File

@ -554,7 +554,7 @@ class Group < ActiveRecord::Base
available_tabs = [
{ :id => TAB_HOME, :label => t("#group.tabs.home", "Home"), :css_class => 'home', :href => :group_path },
{ :id => TAB_ANNOUNCEMENTS, :label => t('#tabs.announcements', "Announcements"), :css_class => 'announcements', :href => :group_announcements_path },
{ :id => TAB_PAGES, :label => t("#group.tabs.pages", "Pages"), :css_class => 'pages', :href => :group_wiki_pages_path },
{ :id => TAB_PAGES, :label => t("#group.tabs.pages", "Pages"), :css_class => 'pages', :href => :group_wiki_path },
{ :id => TAB_PEOPLE, :label => t("#group.tabs.people", "People"), :css_class => 'people', :href => :group_users_path },
{ :id => TAB_DISCUSSIONS, :label => t("#group.tabs.discussions", "Discussions"), :css_class => 'discussions', :href => :group_discussion_topics_path },
{ :id => TAB_FILES, :label => t("#group.tabs.files", "Files"), :css_class => 'files', :href => :group_files_path },

View File

@ -43,13 +43,14 @@ module Importers
item.url = hash[:url_name].to_url
item.only_when_blank = true
end
if hash[:root_folder] && ['folder', 'FOLDER_TYPE'].member?(hash[:type])
if hash[:root_folder].present? && ['folder', 'FOLDER_TYPE'].member?(hash[:type])
front_page = context.wiki.front_page
if front_page.id
if front_page && front_page.id
hash[:root_folder] = false
else
# If there is no id there isn't a front page yet
item = front_page
item.url ||= Wiki::DEFAULT_FRONT_PAGE_URL
item.title ||= item.url.titleize
item.set_as_front_page!
end
end
hide_from_students = hash[:hide_from_students] if !hash[:hide_from_students].nil?

View File

@ -4,7 +4,7 @@
# 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
# the terms of the GNU Affero General Public License as published by the Fr
# Software Foundation, version 3 of the License.
#
# Canvas is distributed in the hope that it will be useful, but WITHOUT ANY

View File

@ -41,7 +41,7 @@ class Wiki < ActiveRecord::Base
def set_has_no_front_page_default
if self.has_no_front_page.nil? && self.id && context
self.has_no_front_page = true if context.feature_enabled?(:draft_state)
self.has_no_front_page = true
end
end
private :set_has_no_front_page_default
@ -102,8 +102,7 @@ class Wiki < ActiveRecord::Base
end
def get_front_page_url
return nil unless self.has_front_page? || !context.feature_enabled?(:draft_state)
self.front_page_url || DEFAULT_FRONT_PAGE_URL
self.front_page_url if self.has_front_page?
end
def unset_front_page!

View File

@ -18,7 +18,7 @@
class WikiPage < ActiveRecord::Base
attr_accessible :title, :body, :url, :user_id, :editing_roles, :notify_of_update
attr_readonly :wiki_id, :hide_from_students
attr_readonly :wiki_id
validates_length_of :body, :maximum => maximum_long_text_length, :allow_nil => true, :allow_blank => true
validates_presence_of :wiki_id
include Workflow
@ -34,7 +34,7 @@ class WikiPage < ActiveRecord::Base
belongs_to :user
EXPORTABLE_ATTRIBUTES = [
:id, :wiki_id, :title, :body, :workflow_state, :recent_editors, :user_id, :created_at, :updated_at, :url, :delayed_post_at, :protected_editing, :hide_from_students,
:id, :wiki_id, :title, :body, :workflow_state, :recent_editors, :user_id, :created_at, :updated_at, :url, :delayed_post_at, :protected_editing,
:editing_roles, :view_count, :revised_at, :could_be_locked, :cloned_item_id, :wiki_page_comments_count
]
@ -49,7 +49,7 @@ class WikiPage < ActiveRecord::Base
after_save :touch_wiki_context
TITLE_LENGTH = WikiPage.columns_hash['title'].limit rescue 255
SIMPLY_VERSIONED_EXCLUDE_FIELDS = [:workflow_state, :hide_from_students, :editing_roles, :notify_of_update]
SIMPLY_VERSIONED_EXCLUDE_FIELDS = [:workflow_state, :editing_roles, :notify_of_update]
def touch_wiki_context
self.wiki.touch_context if self.wiki && self.wiki.context
@ -57,7 +57,7 @@ class WikiPage < ActiveRecord::Base
def validate_front_page_visibility
if !published? && self.is_front_page?
self.errors.add(:hide_from_students, t(:cannot_hide_page, "cannot hide front page"))
self.errors.add(:published, t(:cannot_unpublish_front_page, "cannot unpublish front page"))
end
end
@ -85,27 +85,6 @@ class WikiPage < ActiveRecord::Base
end
end
def normalize_hide_from_students
workflow_state = self.read_attribute('workflow_state')
hide_from_students = self.read_attribute('hide_from_students')
if !workflow_state.nil? && !hide_from_students.nil?
self.workflow_state = 'unpublished' if hide_from_students && workflow_state == 'active'
self.write_attribute('hide_from_students', nil)
end
end
after_find :normalize_hide_from_students
private :normalize_hide_from_students
def hide_from_students
self.workflow_state == 'unpublished'
end
def hide_from_students=(v)
self.workflow_state = 'unpublished' if v && self.workflow_state == 'active'
self.workflow_state = 'active' if !v && self.workflow_state = 'unpublished'
hide_from_students
end
def self.title_order_by_clause
best_unicode_collation_key('wiki_pages.title')
end
@ -188,7 +167,7 @@ class WikiPage < ActiveRecord::Base
alias_method :published?, :active?
def restore
self.workflow_state = context.feature_enabled?(:draft_state) ? 'unpublished' : 'active'
self.workflow_state = 'unpublished'
self.save
end
@ -221,8 +200,8 @@ class WikiPage < ActiveRecord::Base
scope :not_deleted, -> { where("wiki_pages.workflow_state<>'deleted'") }
scope :published, -> { where("wiki_pages.workflow_state='active' AND (wiki_pages.hide_from_students=? OR wiki_pages.hide_from_students IS NULL)", false) }
scope :unpublished, -> { where("wiki_pages.workflow_state='unpublished' OR (wiki_pages.hide_from_students=? AND wiki_pages.workflow_state<>'deleted')", true) }
scope :published, -> { where("wiki_pages.workflow_state='active'", false) }
scope :unpublished, -> { where("wiki_pages.workflow_state='unpublished'", true) }
# needed for ensure_unique_url
def not_deleted
@ -245,20 +224,14 @@ class WikiPage < ActiveRecord::Base
def is_front_page?
return false if self.deleted?
self.url == self.wiki.get_front_page_url # wiki.get_front_page_url checks has_front_page? and context.feature_enabled?(:draft_state)
self.url == self.wiki.get_front_page_url # wiki.get_front_page_url checks has_front_page?
end
def set_as_front_page!
can_set_front_page = true
if self.unpublished?
self.errors.add(:front_page, t(:cannot_set_unpublished_front_page, 'could not set as front page because it is unpublished'))
can_set_front_page = false
return false
end
if self.hide_from_students
self.errors.add(:front_page, t(:cannot_set_hidden_front_page, 'could not set as front page because it is hidden'))
can_set_front_page = false
end
return false unless can_set_front_page
self.wiki.set_front_page_url!(self.url)
end
@ -417,7 +390,7 @@ class WikiPage < ActiveRecord::Base
def initialize_wiki_page(user)
is_privileged_user = wiki.grants_right?(user, :manage)
if is_privileged_user && context.feature_enabled?(:draft_state) && !context.is_a?(Group)
if is_privileged_user && !context.is_a?(Group)
self.workflow_state = 'unpublished'
else
self.workflow_state = 'active'

View File

@ -184,7 +184,7 @@
<% end %>
<% if @context.feature_enabled?(:draft_state)
has_front_page = @context.wiki && @context.wiki.has_front_page? %>
has_front_page = @context.wiki && @context.wiki.front_page %>
<% content_for :right_side do %>
<div id="edit_course_home_content" style="display: none;">
<h2><%= t('draft_state.headings.set_layout', %{Set Home Page Layout}) %></h2>
@ -196,9 +196,9 @@
<label class="radio"><input type="radio" name="course[default_view]" value="wiki" <%= 'checked' if has_front_page && @context.default_view == 'wiki' %><%= 'disabled' unless has_front_page %>>
<span class="<%= 'ui-state-disabled' unless has_front_page %>"><%= t('draft_state.options.custom_page', %{Pages Front Page}) %></span></label>
<% if has_front_page %>
<small>&emsp;<%= @context.wiki.front_page.title %>&emsp;[ <%= link_to t('change_home_page', 'Change'), context_url(@context, :context_pages_url) %> ]</small>
<small>&emsp;<%= @context.wiki.front_page.title %>&emsp;[ <%= link_to t('change_home_page', 'Change'), polymorphic_url([@context, :wiki_pages]) %> ]</small>
<% else %>
<small>&emsp;[ <%= link_to t('front_page_not_set', 'Front page must be set first'), context_url(@context, :context_pages_url) %> ]</small>
<small>&emsp;[ <%= link_to t('front_page_not_set', 'Front page must be set first'), polymorphic_url([@context, :wiki_pages]) %> ]</small>
<% end %>
</div>
<div class="form_group"><label class="radio"><input type="radio" name="course[default_view]" value="modules" <%= 'checked' if @context.default_view == 'modules' %>><%= t('draft_state.options.modules', %{Course Modules}) %></label></div>

View File

@ -138,9 +138,8 @@
</select>
</div>
<div class="new" style="margin-top: 5px;">
<%= before_label :page_name, "Page Name" %>
<input type="text" name="wiki_page[title]" class="item_title" aria-label="<%= before_label :page_name, "Page Name" %>"/>
<a href="<%= context_url(@context, :context_wiki_pages_url) %>" style="display: none;" class="add_item_url">&nbsp;</a>
<a href="<%= polymorphic_url([:api_v1, @context, :wiki_pages]) %>" style="display: none;" class="add_item_url">&nbsp;</a>
</div>
</div>
<% end %>

View File

@ -20,23 +20,23 @@
<%= t('click_links', %{Click any page to insert a link to that page.}) %>
<div id="pages_accordion" role="tabpanel">
<% if @context.respond_to?(:wiki) %>
<a href="<%= context_url(@context, :context_wiki_page_url, '{{ page_url }}') %>" id="wiki_sidebar_wiki_url" style="display: none;">&nbsp;</a>
<a href="<%= polymorphic_url([@context, :wiki_page], id: '{{ page_url }}') %>" id="wiki_sidebar_wiki_url" style="display: none;">&nbsp;</a>
<div>
<div class="header" aria-controls="pages_tab_panel" role="tab"><a href="#"><%= t('links_to.wiki_pages', %{Wiki Pages}) %></a></div>
<div id="pages_tab_panel" role="tabpanel">
<ul class="wiki_pages page_list">
<% (@wiki_sidebar_data[:wiki_pages]).each do |wiki_page| %>
<% if can_do(@wiki, @current_user, :manage) || wiki_page.published? %>
<li title="<%= t('insert.wiki_pages', %{Click to insert a link to this page}) %>"><%= link_to wiki_page.title.titleize, polymorphic_path([@context, :named_page], wiki_page_id: wiki_page), :role => "button"%></li>
<li title="<%= t('insert.wiki_pages', %{Click to insert a link to this page}) %>"><%= link_to wiki_page.title.titleize, polymorphic_path([@context, wiki_page]), :role => "button"%></li>
<% end %>
<% end %>
</ul>
<%= link_to t('links.new_page', "Link to a New Page"), context_url(@context, :new_context_wiki_page_url), :id => 'new_page_link', :class => "add" %>
<%= link_to t('links.new_page', "Link to a New Page"), polymorphic_url([@context, :wiki_page], action: :new), :id => 'new_page_link', :class => "add" %>
<form id="new_page_drop_down" style="display:none; margin: 5px;">
<div class="row-fluid">
<label for="new_page_name"><%= t('new_page_name', %{What would you like to call the new page?}) %></label><br />
<input type="text" name="new_page_name" id="new_page_name" class="span12">
<input type="hidden" name="new_page_url_prefix" value="<%= polymorphic_path([@context, :pages]) %>" id="new_page_url_prefix" />
<input type="hidden" name="new_page_url_prefix" value="<%= polymorphic_path([@context, :wiki_pages]) %>" id="new_page_url_prefix" />
<button id="new_page_submit" class="btn btn-small" type="submit"><%= t('buttons.insert_link', %{Insert Link}) %></button>
</div>
</form>
@ -119,7 +119,7 @@
<li title="<%= t('insert.assignments_page', %{Click to insert a link to the assignments page}) %>"><%= link_to t('links.assignments_page', "Assignment List"), context_url(@context, :context_assignments_url)%></li>
<% end %>
<% if @context.respond_to?(:wiki) %>
<li title="<%= t('insert.wiki_pages_index', %{Click to insert a link to the wiki}) %>"><%= link_to t('links.wiki_pages_index', "Wiki Home"), context_url(@context, :context_wiki_pages_url)%></li>
<li title="<%= t('insert.wiki_pages_index', %{Click to insert a link to the wiki}) %>"><%= link_to t('links.wiki_pages_index', "Wiki Home"), polymorphic_url([@context, :wiki_pages]) %></li>
<% end %>
<% if @context.respond_to?(:discussion_topics) %>
<li title="<%= t('insert.discussions_page', %{Click to insert a link to the discussions page}) %>"><%= link_to t('links.discussions_page', "Discussions Index"), context_url(@context, :context_discussion_topics_url)%></li>

View File

@ -1,28 +0,0 @@
<% content_for :page_title do %><%= t 'titles.revisions_for_page', "Revisions for: %{title}", :title => @page.title.titleize %><% end %>
<% content_for :right_side do %>
<div class="rs-margin-lr rs-margin-top">
<a href="<%= context_url(@context, :context_wiki_page_url, @page) %>" class="btn button-sidebar-wide"><i class="icon-arrow-left"></i> <%= t 'links.back_to_current_version', 'Back to Current Version' %></a>
</div>
<% end %>
<% unless @page.versions.empty? %>
<h2><%= t 'titles.revisions_for_page', "Revisions for: %{title}", :title => @page.title.titleize %></h2>
<table style="margin-left: 30px;">
<% @page.versions.each do |version| %>
<tr>
<td>
<%= link_to (datetime_string(version.model.updated_at) || t('#time.unknown_date', "Unknown date")), context_url(@context, :context_wiki_page_wiki_page_revision_url, @page, version), :title => time_ago_in_words_with_ago(version.model.updated_at) %>
<span style="font-size: 0.8em;">
<% if version.model.user %>
<%= mt :page_edited_by_with_link, 'by [%{user_name}](%{link})', :user_name => context_user_name(@context, version.model.user), :link => context_url(@context, :context_user_url, version.model.user) %>
<% else %>
<%= t :page_imported, 'by Content Importer' %>
<% end %>
</span>
</td>
</tr>
<% end %>
</table>
<% end %>

View File

@ -1,54 +0,0 @@
<%
add_crumb(t('#crumbs.wiki_page_revisions', "Revisions"), context_url(@context, :context_wiki_page_wiki_page_revisions_url, @page))
add_crumb(datetime_string(@revision.model.updated_at), context_url(@context, :context_wiki_page_wiki_page_revision_url, @page, @revision))
%>
<% content_for :page_title do %><%= @page.title.titleize %><% end %>
<% content_for :right_side do %>
<div class="rs-margin-lr rs-margin-top">
<ul class="unstyled_list wide_spacing">
<% if can_do(@page, @current_user, :update) %>
<li>
<%= form_for(@revision, :url => context_url(@context, :context_wiki_page_wiki_page_revision_url, @page, @revision)) do |f| %>
<div class="button-container">
<button type="submit" class="btn"><%= image_tag "reply.png", :alt => "Rollback" %> <%= t 'buttons.roll_back_version', 'Roll-back to this Version' %></button><br /><br />
</div>
<% end %>
</li>
<% end %>
<li>
<div>
<a href="<%= context_url(@context, :context_wiki_page_url, @page) %>" class="forward"><%= t 'links.go_to_latest', 'Go to Latest Version' %></a>
<ul class="item_list" style='line-height: 14px; font-size: 11px; padding-left:21px; '>
<% if @revision.model.user %>
<li><%= t 'labels.by_user', 'by %{user}', :user => context_user_name(@context, @page.user) %></li>
<% else %>
<li><%= t 'labels.by_content_importer', 'by Content Importer' %></li>
<% end %>
<li><%= t 'labels.on_date', 'on *%{date_time}*', :date_time => datetime_string(@page.updated_at),
:wrapper => "<span title='#{time_ago_in_words_with_ago @page.updated_at}'>\\1</span>" %></li>
</ul>
</div>
</li>
<li><a href="<%= context_url(@context, :context_wiki_page_wiki_page_revisions_url, @page) %>" class="history"><%= t 'links.back_to_history', 'Back to Revision history' %></a></li>
</ul>
</div>
<% end %>
<div id="wiki_show_view_main">
<div id="last_edited_by" class="clearfix">
<h2><%= t 'not_most_recent_version_warning', 'This is NOT the most recent version' %></h2>
<% if @revision.model.user %>
<h3><%= t 'saved_by', 'Saved: *%{time_ago}* by %{user}', :user => @revision.model.user_name,
:time_ago => time_ago_in_words_with_ago(@revision.model.updated_at),
:wrapper => "<span title='#{datetime_string(@revision.model.updated_at)}'>\\1</span>" %></h3>
<% else %>
<h3><%= t('imported_at', 'Imported: *%{time_ago}*',
:time_ago => time_ago_in_words_with_ago(@revision.model.updated_at),
:wrapper => "<span title='#{datetime_string(@revision.model.updated_at)}'>\\1</span>") %></h3>
<% end %>
</div>
<div id="wiki_body">
<%= user_content(@revision.model.body) %>
</div>
</div>

View File

@ -1,143 +0,0 @@
<% course_home ||= false %>
<% if course_home %>
<div class="h2"><%= @context.name %></div>
<% end %>
<a href="<%= context_url(@context, :context_wiki_page_wiki_page_revision_path, @page.new_record? ? @page : @page.id, 'latest') %>" id="latest_page_version" style="display: none;">&nbsp;</a>
<div id="wiki_show_view_main">
<% if @page.new_record? %>
<div class="someone_else_edited" style="display: none; font-size: 0.8em;">
<%= mt 'notices.page_edited_while_viewing', 'This page has been updated by someone else since you started viewing it. [Click here to reload the page.](%{link})', :link => request.url %>
</div>
<% if @page.is_front_page? && can_do(@page, @current_user, :update) %>
<% if !course_home %>
<h3><%= t :welcome_message, 'Welcome to the Course Wiki' %></h3>
<% end %>
<% if course_home %>
<p><%= t :course_home_wiki_page_description, 'You can use this page to organize or introduce your course however you like. You can easily link to assignments, files, etc. using the "Page Tools" section you\'ll see on the right once you start editing.' %></p>
<% else %>
<p>
<%= t :course_wiki_page_description, <<-EOT
You can use this wiki to create supplemental pages or descriptions for your
course material. You can easily link to wiki pages from assignments, or link
to other course material and files from any wiki page. This makes it a great
place for explaining hard concepts, allowing group projects, or creating just
about any kind of page you could need in your course.
EOT
%>
</p>
<% end %>
<p>
<%= t :default_wiki_page_description, <<-EOT
This page is the default wiki page, and students will see it when they
click the "Pages" tab for this course.
EOT
%>
<% if @context.default_view == 'wiki' %>
<%= mt :default_wiki_page_is_course_home_page_warning, <<-EOT, :link => context_url(@context, :context_url)
Right now this is also set as the default course page, so visitors to your
course will see this page first. You can change that from [the course home page](%{link}).
EOT
%>
<% end %>
</p>
<% else %>
<%= t 'notices.page_does_not_exist', 'This page doesn\'t exist yet.' %>
<% end %>
<div class="button-container" style="margin-bottom:10px;">
<% if can_do(@page, @current_user, :update_content) %>
<%= link_to t('buttons.start_editing', "Start Editing It now"), context_url(@context, :edit_context_wiki_page_url, @page), :id => "page_doesnt_exist_so_start_editing_it_now", :class => ("btn btn-large " + (@wiki.wiki_pages.length > 2 || !course_home ? "" : "dont_click")) %>
<% end %>
</div>
<% else %>
<div id="last_edited_by" class="clearfix">
<% last_version = @page.versions.current.model rescue @page %>
<% if can_do(@page, @current_user, :update_content) %>
<a href="<%= context_url(@context, :context_wiki_page_wiki_page_revisions_path, @page) %>" id="page_history"><i class="icon-clock"></i> <%= t 'links.page_history', 'Page history' %></a>
<% end %>
<% if @page.user %>
<%= t 'labels.last_edited', 'Last edited by %{name} %{time_ago} ago', :name => @page.user_name, :time_ago => (time_ago_in_words(last_version.updated_at) rescue "???") %>
<% end %>
<% if (@context.context.is_a?(Course) rescue false) %>
<div><%= image_tag "warning.png", :style => "height: 10px;" %>
<%= mt :group_wiki_warning, "This page is part of the group wiki, *not* your course wiki. If you're looking for the course wiki, [click here](%{link}).",
:link => context_url(@context.context, :context_wiki_pages_url) %>
</div>
<% end %>
</div>
<div class="someone_else_edited" style="display: none; font-size: 0.8em;">
<%= image_tag "warning.png", :style => "height: 12px;" %>
<%= mt 'notices.page_edited_while_viewing', 'This page has been updated by someone else since you started viewing it. [Click here to reload the page.](%{link})', :link => request.url %>
</div>
<div class="course_id" style="display: none;"><%= @context.id if @context && @context.is_a?(Course) %></div>
<% if @page.deleted? %>
<div id="deleted_message" class="user_content" style="margin-top: 10px;">
<%= t 'notices.page_deleted', 'This page has been deleted.' %>
</div>
<% else %>
<div id="wiki_body" class="user_content">
<% if @editing %>
<%= t('editing_content', 'Editing Content.') %>
<% else %>
<% cache(['wiki_page_body_render', @page].cache_key) do %>
<%= user_content(@page.body) %>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
</div>
<div id="wiki_edit_view_main" style="display:none; text-align: right;">
<div>
<a href="#" class="wiki_switch_views_link"><%= t '#editor.switch_editor_html', "HTML Editor" %></a>
<a href="#" class="wiki_switch_views_link" style="display:none;"><%= t '#editor.switch_editor_rich_text', "Rich Content Editor" %></a>
</div>
<div class="clear"></div>
<%= form_for(@page, :url => (@page.new_record?) ? context_url(@context, :context_wiki_pages_url) : context_url(@context, :context_wiki_page_url, @page)) do |f| -%>
<%= f.hidden_field :title %>
<%= f.text_area :body, :style => "width:99%;" %>
<% if course_home %>
<input type="hidden" name="return_to" value="<%= request.url %>"/>
<% end %>
<div id="below_editor">
<% if can_do(@page, @current_user, :update) %>
<div style="text-align: left; <%= hidden if @page.is_front_page? %>">
<%= f.check_box :hide_from_students %>
<%= f.label :hide_from_students, :en => "Hide this Page from Students" %>
</div>
<div style="text-align: left; <%= hidden if @page.is_front_page? %>">
<%
select_html = if @context.is_a?(Course)
f.select :editing_roles, [
[t('course_editing_roles.only_teachers', "Only Teachers"), "teachers"],
[t('course_editing_roles.teachers_and_students', "Teacher and Students"), "teachers,students"],
[t('course_editing_roles.anyone', "Anyone"), "teachers,students,public"]]
else
f.select :editing_roles, [
[t('editing_roles.only_members', "Only Members"), "members"],
[t('editing_roles.anyone', "Anyone"), "members,public"]]
end
%>
<%= t 'editing_roles.prompt', '%{options} can edit this page', :options => select_html %>
</div>
<% end %>
<div class="someone_else_edited" style="display: none; text-align: left;">
<%= image_tag "warning.png" %>
<%= t 'notices.page_edited_while_viewing_detailed', <<-EOT
Someone else has edited this page since you first loaded it, and if you submit now you will overwrite their changes.
You may want to reload the page and re-enter your changes to make sure you don't lose someone else's work.
EOT
%>
</div>
<div style="text-align: left; <%= hidden if @page.new_record? %>">
<%= f.check_box :notify_of_update %>
<%= f.label :notify_of_update, :en => "Notify users that this content has changed" %>
</div>
<div class="form-actions">
<button type="button" id="cancel_editing" class="btn cancel_button"><%= t '#buttons.cancel', 'Cancel' %></button>
<button type="submit" name="commit" id="wiki_page_submit" class="btn btn-primary"><%= t 'buttons.save_changes', 'Save Changes' %></button>
</div>
</div>
<% end -%>
<% js_bundle 'legacy/wiki_pages_content' %>
</div>
<div id="wiki_page_version_number" style="display: none;"><%= @page.version_number %></div>

View File

@ -1,14 +1,10 @@
<% skip_front_page ||= false; page_link ||= nil; wiki_page = page_link; hidden ||= false %>
<% if !wiki_page %>
<li class="ellipsis" style="<%= 'display: none;' if hidden %>"><%= link_to t('#wiki_pages.front_page', "Front Page"), context_url(@context, :context_wiki_page_url, @context.wiki.get_front_page_url) %></li>
<li class="ellipsis" style="<%= 'display: none;' if hidden %>"><%= link_to t('#wiki_pages.front_page', "Front Page"), polymorphic_url([@context, @context.wiki.front_page]) %></li>
<% elsif skip_front_page && wiki_page.is_front_page? %>
<% else %>
<% if can_do(@context, @current_user, :manage_content) || wiki_page.published? %>
<li class="ellipsis" style="<%= 'display: none;' if hidden %><%= 'font-weight: bold;' if @page && wiki_page == @page %><%= 'font-style: italic;' unless wiki_page.published? %>" title="<%= t(:link_hidden_from_students_warning, "Students won't see this link") unless wiki_page.published? %>"><%= link_to wiki_page.title, context_url(
@context,
:context_wiki_page_url,
wiki_page.url
) rescue "" %>
<li class="ellipsis" style="<%= 'display: none;' if hidden %><%= 'font-weight: bold;' if @page && wiki_page == @page %><%= 'font-style: italic;' unless wiki_page.published? %>" title="<%= t(:link_hidden_from_students_warning, "Students won't see this link") unless wiki_page.published? %>"><%= link_to wiki_page.title, polymorphic_url([@context, wiki_page]) rescue "" %>
</li>
<% end %>
<% end %>

View File

@ -69,10 +69,7 @@
<% if can_do(@page, @current_user, :update_content)%>
<%= link_to ('<i class="icon-edit"></i>').html_safe + " " + t('links.edit_page', "Edit this Page"), "#edit", :class => "edit_link btn button-sidebar-wide" %>
<% end %>
<% if can_do(@page, @current_user, :delete) && !@page.new_record? && !@page.is_front_page? && !@page.deleted? %>
<%= link_to ('<i class="icon-trash"></i>').html_safe + " " + t('links.delete_page', "Delete this Page"), context_url(@context, :context_wiki_page_url, @page.url), :method => :delete, :confirm => t('delete_page_confirmation', 'Are you sure you want to delete this page? This cannot be undone!'), :class => "btn button-sidebar-wide" %>
<% end %>
<a href="<%= context_url(@context, :context_wiki_page_url, @page) %>" class="wiki_page_url" style="display: none;">&nbsp;</a>
<a href="<%= polymorphic_url([@context, @page]) %>" class="wiki_page_url" style="display: none;">&nbsp;</a>
<% if can_do(@wiki, @current_user, :create_page) %>
<div id="wiki_page_new">
<a class="new btn button-sidebar-wide element_toggler" aria-controls="add_wiki_page_form" href="#"><i class="icon-add"></i> <%= t 'links.create_page', 'Create a New Page' %></a>
@ -97,7 +94,7 @@
<li>
<a id="wiki_page_rename_link" class="icon-note-dark element_toggler" aria-controls="wiki_page_rename_section" href="#"><%= t 'links.rename_page', 'Rename this page' %></a>
<div id="wiki_page_rename_section" style="display:none;">
<%= form_for(@page, :url => context_url(@context, :context_wiki_page_url, @page), :html => {:id => 'rename_wiki_page_form'}) do |f| -%>
<%= form_for(@page, :url => polymorphic_url([@context, @page]), :html => {:id => 'rename_wiki_page_form'}) do |f| -%>
<div class="input-append">
<%= f.text_field :title, :style => "width: 157px;", :placeholder => t(:title, "New page title"), :maxlength => "255" %>
<button class="btn" type="submit"><%= t 'buttons.rename', 'Rename' %></button>
@ -107,7 +104,7 @@
</li>
<% unless @page.new_record? || !can_do(@page, @current_user, :delete) %>
<li>
<%= link_to t('links.delete_page', 'Delete this Page'), context_url(@context, :context_wiki_page_url, @page), :confirm => t('delete_page_confirmation', 'Are you sure you want to delete this page? This cannot be undone!'), :method => :delete, :id => "wiki_page_delete", :class => "icon-trash" %>
<%= link_to t('links.delete_page', 'Delete this Page'), polymorphic_url([@context, @page]), :confirm => t('delete_page_confirmation', 'Are you sure you want to delete this page? This cannot be undone!'), :method => :delete, :id => "wiki_page_delete", :class => "icon-trash" %>
</li>
<% end %>
<% end %>

View File

@ -1,15 +1,5 @@
<%
js_bundle :wiki
jammit_css :tinymce
<%
content_for :page_title, join_title(@page.title.to_s, @context.name)
content_for :right_side, render(:partial => 'wiki_pages/wiki_right_side')
js_bundle :wiki_page_show
%>
<% if reason = @page.locked_for?(@current_user, :context => @context) %>
<h2><%= @page.title %></h2>
<%= lock_explanation(reason, 'page', @context) %>
<% else %>
<%= render :partial => "wiki_pages/content" %>
<% end %>
<%= render :partial => "shared/sequence_footer", :locals => {:asset => @page} if @page.context_module_tag_for(@context) %>
<div id="wiki_page_show"></div>

View File

@ -1,5 +0,0 @@
<%
content_for :page_title, join_title(@page.title.to_s, @context.name)
js_bundle :wiki_page_show
%>
<div id="wiki_page_show"></div>

View File

@ -48,7 +48,8 @@ class ActiveRecord::Base
'quizzes' => %w(root_quiz_id),
'stream_items' => %w{context_code item_asset_string},
'stream_item_instances' => %w(context_code),
'submissions' => %w(changed_since_publish late)
'submissions' => %w(changed_since_publish late),
'wiki_pages' => %w(hide_from_students)
}.freeze
def self.columns_with_remove_dropped_columns

View File

@ -117,43 +117,15 @@ CanvasRails::Application.routes.draw do
resources :discussion_entries
end
concern :wikis do
####
## Leaving these routes here for when we need them later :)
##
## Aside from the /wiki route itself, all new routes will be /pages. The /wiki route will be reused to redirect
## the user to the wiki front page, if configured, or the wiki page list otherwise.
####
# get 'wiki' => 'wiki_pages#front_page'
####
## Placing these routes above the /wiki routes below will cause the helper functions to generate urls and paths
## pointing to /pages rather than the legacy /wiki.
####
# resources :wiki_pages, path: :pages do
# get 'revisions/latest' => 'wiki_page_revisions#latest_version_number', as: :latest_version_number
# resources :wiki_page_revisions, as: "revisions"
# end
#
####
## We'll just do specific routes below until we can swap /pages and /wiki completely.
####
get 'pages' => 'wiki_pages#pages_index'
get 'pages/:wiki_page_id' => 'wiki_pages#show_page', wiki_page_id: /[^\/]+/, as: :named_page
get 'pages/:wiki_page_id/edit' => 'wiki_pages#edit_page', wiki_page_id: /[^\/]+/, as: :edit_named_page
get 'pages/:wiki_page_id/revisions' => 'wiki_pages#page_revisions', wiki_page_id: /[^\/]+/, as: :named_page_revisions
resources :wiki_pages, path: :wiki do
get 'revisions/latest' => 'wiki_page_revisions#latest_version_number', as: :latest_version_number
resources :wiki_page_revisions, path: :revisions
concern :pages do
resources :wiki_pages, path: :pages, except: [:update, :destroy] do
get 'revisions' => 'wiki_pages#revisions', as: :revisions
end
####
## This will cause the helper functions to generate /pages urls, but will still allow /wiki routes to work properly
####
#get 'pages/:id' => 'wiki_pages#show', id: /[^\/]+/, as: :named_wiki_page
get 'wiki/:id' => 'wiki_pages#show', as: :named_wiki_page, id: /[^\/]+/
get 'wiki' => 'wiki_pages#front_page', as: :wiki
get 'wiki/:id' => 'wiki_pages#show_redirect', id: /[^\/]+/
get 'wiki/:id/revisions' => 'wiki_pages#revisions_redirect', id: /[^\/]+/
get 'wiki/:id/revisions/:revision_id' => 'wiki_pages#revisions_redirect', id: /[^\/]+/
end
concern :conferences do
@ -293,7 +265,7 @@ CanvasRails::Application.routes.draw do
concerns :files, :file_images, :relative_files, :folders
concerns :groups
concerns :wikis
concerns :pages
concerns :conferences
concerns :question_banks
@ -480,7 +452,7 @@ CanvasRails::Application.routes.draw do
end
end
concerns :wikis
concerns :pages
concerns :conferences
concerns :media

View File

@ -0,0 +1,11 @@
class RemoveHideFromStudentsFromWikiPages < ActiveRecord::Migration
tag :postdeploy
def up
remove_column :wiki_pages, :hide_from_students
end
def down
add_column :wiki_pages, :hide_from_students, :boolean
end
end

View File

@ -22,24 +22,16 @@ module Api::V1::WikiPage
include Api::V1::Locked
WIKI_PAGE_JSON_ATTRS = %w(url title created_at updated_at editing_roles)
WIKI_PAGE_JSON_METHODS = %w(hide_from_students)
def wiki_page_json(wiki_page, current_user, session, include_body = true)
hash = api_json(wiki_page, current_user, session, :only => WIKI_PAGE_JSON_ATTRS, :methods => WIKI_PAGE_JSON_METHODS)
hash = api_json(wiki_page, current_user, session, :only => WIKI_PAGE_JSON_ATTRS)
hash['page_id'] = wiki_page.id
hash['editing_roles'] ||= 'teachers'
hash['last_edited_by'] = user_display_json(wiki_page.user, wiki_page.context) if wiki_page.user
if wiki_page.context.feature_enabled?(:draft_state)
hash['published'] = wiki_page.active?
else
hash['published'] = true
end
hash['published'] = wiki_page.active?
hash['hide_from_students'] = !hash['published'] # deprecated, but still here for now
hash['front_page'] = wiki_page.is_front_page?
if wiki_page.context.feature_enabled?(:draft_state)
hash['html_url'] = polymorphic_url([wiki_page.context, :named_page], :wiki_page_id => wiki_page)
else
hash['html_url'] = polymorphic_url([wiki_page.context, :named_wiki_page], :id => wiki_page)
end
hash['html_url'] = polymorphic_url([wiki_page.context, wiki_page])
locked_json(hash, wiki_page, current_user, 'page')
hash['body'] = api_user_content(wiki_page.body) if include_body && !hash['locked_for_user'] && !hash['lock_info']
hash

View File

@ -40,6 +40,7 @@ module CC::Importer::Canvas
wiki[:editing_roles] = meta['editing_roles']
wiki[:notify_of_update] = meta['notify_of_update'] == 'true'
wiki[:workflow_state] = meta['workflow_state']
# should keep in case we import old packages
wiki[:workflow_state] = 'unpublished' if meta['hide_from_students'] == 'true' && (wiki[:workflow_state].nil? || wiki[:workflow_state] == 'active')
wiki[:front_page] = meta['front_page'] == 'true'
wiki[:text] = body

View File

@ -33,7 +33,6 @@ module CC
meta_fields[:editing_roles] = page.editing_roles
meta_fields[:notify_of_update] = page.notify_of_update
meta_fields[:workflow_state] = page.workflow_state
meta_fields[:workflow_state] = 'unpublished' if page.hide_from_students && page.workflow_state == 'active'
meta_fields[:front_page] = page.is_front_page?
File.open(path, 'w') do |file|

View File

@ -201,15 +201,19 @@ $(document).ready(function() {
var callback = function(data) {
var obj;
// discussion_topics will come from real api v1 and so wont be nested behind a `discussion_topic` root object
if (item_data['item[type]'] === 'discussion_topic') {
// discussion_topics will come from real api v1 and so wont be nested behind a `discussion_topic` or 'wiki_page' root object
if (item_data['item[type]'] === 'discussion_topic' || item_data['item[type]'] === 'wiki_page') {
obj = data;
} else {
obj = data[item_data['item[type]']]; // e.g. data['wiki_page'] for wiki pages
}
$("#select_context_content_dialog").loadingImage('remove');
item_data['item[id]'] = obj.id;
if (item_data['item[type]'] === 'wiki_page') {
item_data['item[id]'] = obj.page_id;
} else {
item_data['item[id]'] = obj.id;
}
if (item_data['item[type]'] === 'attachment') {
// some browsers return a fake path in the file input value, so use the name returned by the server
item_data['item[title]'] = obj.display_name;

View File

@ -235,7 +235,7 @@ describe UserContent, type: :request do
end
it "should not choke on funny email addresses" do
@wiki_page = @course.wiki.front_page
@wiki_page = @course.wiki.wiki_pages.build(:title => "title")
@wiki_page.body = "<a href='mailto:djmankiewicz@homestarrunner,com'>e-nail</a>"
@wiki_page.workflow_state = 'active'
@wiki_page.save!
@ -247,7 +247,7 @@ describe UserContent, type: :request do
context "data api endpoints" do
context "course context" do
it "should process links to each type of object" do
@wiki_page = @course.wiki.front_page
@wiki_page = @course.wiki.wiki_pages.build(:title => "title")
@wiki_page.body = <<-HTML
<p>
<a href='/courses/#{@course.id}/assignments'>assignments index</a>
@ -294,7 +294,7 @@ describe UserContent, type: :request do
context "group context" do
it "should process links to each type of object" do
group_with_user(:active_all => true)
@wiki_page = @group.wiki.front_page
@wiki_page = @group.wiki.wiki_pages.build(:title => "title")
@wiki_page.body = <<-HTML
<p>
<a href='/groups/#{@group.id}/wiki'>wiki index</a>

View File

@ -53,7 +53,7 @@ describe "Module Items API", type: :request do
:unlock_at => @christmas,
:require_sequential_progress => true)
@module2.prerequisites = "module_#{@module1.id}"
@wiki_page = @course.wiki.front_page
@wiki_page = @course.wiki.wiki_pages.create!(:title => "wiki title", :body => "")
@wiki_page.workflow_state = 'active'; @wiki_page.save!
@wiki_page_tag = @module2.add_item(:id => @wiki_page.id, :type => 'wiki_page')
@attachment = attachment_model(:context => @course)

View File

@ -51,7 +51,7 @@ describe "Modules API", type: :request do
:unlock_at => @christmas,
:require_sequential_progress => true)
@module2.prerequisites = "module_#{@module1.id}"
@wiki_page = @course.wiki.front_page
@wiki_page = @course.wiki.wiki_pages.create!(:title => "Front Page", :body => "")
@wiki_page.workflow_state = 'active'; @wiki_page.save!
@wiki_page_tag = @module2.add_item(:id => @wiki_page.id, :type => 'wiki_page')
@attachment = attachment_model(:context => @course)

View File

@ -32,6 +32,7 @@ describe "Pages API", type: :request do
let(:locked_item) do
wiki = @course.wiki
wiki.set_front_page_url!('front-page')
front_page = wiki.front_page
front_page.workflow_state = 'active'
front_page.save!
@ -53,6 +54,7 @@ describe "Pages API", type: :request do
course
@course.offer!
@wiki = @course.wiki
@wiki.set_front_page_url!('front-page')
@front_page = @wiki.front_page
@front_page.workflow_state = 'active'
@front_page.save!
@ -405,7 +407,7 @@ describe "Pages API", type: :request do
:controller=>"wiki_pages_api", :action=>"revert", :format=>"json", :course_id=>@course.to_param,
:url=>@vpage.url, :revision_id=>'3')
@vpage.reload
expect(@vpage.hide_from_students).to be_truthy
expect(@vpage.editing_roles).to eq 'teachers,students,public'
expect(@vpage.title).to eq 'version test page' # <- reverted
expect(@vpage.body).to eq 'revised by ta' # <- reverted
@ -470,18 +472,6 @@ describe "Pages API", type: :request do
expect(json['front_page']).to eq true
end
it "should not set hidden page as front page" do
json = api_call(:post, "/api/v1/courses/#{@course.id}/pages",
{ :controller => 'wiki_pages_api', :action => 'create', :format => 'json', :course_id => @course.to_param },
{ :wiki_page => { :title => 'hidden page', :hide_from_students => true,
:body => 'Information wants to be free', :front_page => true }}, {},
{:expected_status => 400})
wiki = @course.wiki
wiki.reload
expect(wiki.get_front_page_url).to eq Wiki::DEFAULT_FRONT_PAGE_URL
end
it "should create a new page in published state" do
json = api_call(:post, "/api/v1/courses/#{@course.id}/pages",
{ :controller => 'wiki_pages_api', :action => 'create', :format => 'json', :course_id => @course.to_param },
@ -549,7 +539,7 @@ describe "Pages API", type: :request do
@hidden_page.reload
expect(@hidden_page.title).to eq 'No Longer Hidden Page'
expect(@hidden_page.body).to eq 'Information wants to be free'
expect(@hidden_page.user_id).to eq @teacher.id
expect(@hidden_page.user_id).to eq @teacher.id
end
it "should update front_page" do
@ -573,10 +563,11 @@ describe "Pages API", type: :request do
wiki = @course.wiki
expect(wiki.unset_front_page!).to eq true
json = api_call(:put, "/api/v1/courses/#{@course.id}/pages/#{@hidden_page.url}",
{ :controller => 'wiki_pages_api', :action => 'update', :format => 'json', :course_id => @course.to_param,
:url => @hidden_page.url },
{ :wiki_page => { :title => 'No Longer Hidden Page', :hide_from_students => false,
{ :wiki_page => { :title => 'No Longer Hidden Page',
:body => 'Information wants to be free', :front_page => true, :published => true}})
no_longer_hidden_page = @hidden_page
no_longer_hidden_page.reload
@ -599,8 +590,7 @@ describe "Pages API", type: :request do
json = api_call(:put, "/api/v1/courses/#{@course.id}/pages/#{front_page.url}",
{ :controller => 'wiki_pages_api', :action => 'update', :format => 'json', :course_id => @course.to_param,
:url => front_page.url },
{ :wiki_page => { :title => 'No Longer Front Page', :hide_from_students => false,
:body => 'Information wants to be free', :front_page => false }})
{ :wiki_page => { :title => 'No Longer Front Page', :body => 'Information wants to be free', :front_page => false }})
front_page.reload
expect(front_page.is_front_page?).to be_falsey
@ -687,7 +677,6 @@ describe "Pages API", type: :request do
@test_page.reload
expect(@test_page).to be_unpublished
expect(@test_page.hide_from_students).to be_truthy
end
it 'should ignore hide_from_students' do
@ -701,7 +690,6 @@ describe "Pages API", type: :request do
@test_page.reload
expect(@test_page).to be_active
expect(@test_page.hide_from_students).to be_falsey
end
end
end
@ -903,7 +891,7 @@ describe "Pages API", type: :request do
expect(json.size).to eq 1
urls += json.collect{ |page| page['url'] }
expect(urls).to eq @wiki.wiki_pages.select{ |p| !p.hide_from_students }.sort_by(&:id).collect(&:url)
expect(urls).to eq @wiki.wiki_pages.select{ |p| p.published? }.sort_by(&:id).collect(&:url)
end
it "should refuse to show a hidden page" do
@ -924,6 +912,7 @@ describe "Pages API", type: :request do
other_course = course
other_course.offer!
other_wiki = other_course.wiki
other_wiki.set_front_page_url!('front-page')
other_page = other_wiki.front_page
other_page.workflow_state = 'active'
other_page.save!
@ -942,6 +931,7 @@ describe "Pages API", type: :request do
other_course.is_public = true
other_course.offer!
other_wiki = other_course.wiki
other_wiki.set_front_page_url!('front-page')
other_page = other_wiki.front_page
other_page.workflow_state = 'active'
other_page.save!
@ -1023,7 +1013,7 @@ describe "Pages API", type: :request do
@editable_page.reload
expect(@editable_page).to be_active
expect(@editable_page.hide_from_students).to be_falsey
expect(@editable_page.published?).to be_truthy
expect(@editable_page.title).to eq 'Editable Page'
expect(@editable_page.user_id).not_to eq @student.id
expect(@editable_page.editing_roles).to eq 'students'
@ -1097,12 +1087,10 @@ describe "Pages API", type: :request do
@vpage.workflow_state = 'unpublished'
@vpage.save! # rev 1
@vpage.hide_from_students = true
@vpage.workflow_state = 'active'
@vpage.body = 'published but hidden'
@vpage.save! # rev 2
@vpage.hide_from_students = false
@vpage.body = 'now visible to students'
@vpage.save! # rev 3
end
@ -1196,7 +1184,6 @@ describe "Pages API", type: :request do
:controller=>"wiki_pages_api", :action=>"revert", :format=>"json", :course_id=>@course.to_param,
:url=>@vpage.url, :revision_id=>'2')
@vpage.reload
expect(@vpage.hide_from_students).to be_falsey # permissions aren't (conceptually) versioned
expect(@vpage.body).to eq 'published but hidden'
end
end

View File

@ -417,7 +417,7 @@ describe WikiPagesController do
course_with_teacher_logged_in :active_all => true
controller.instance_variable_set(:@context, @course)
get 'pages_index', :course_id => @course.id
get 'index', :course_id => @course.id
expect(controller.js_env).to include(:WIKI_RIGHTS)
expect(controller.js_env[:WIKI_RIGHTS]).to eq Hash[@course.wiki.check_policy(@teacher).map { |right| [right, true] }]

View File

@ -1,70 +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')
describe WikiPageRevisionsController do
before :each do
course_with_teacher_logged_in(:active_all => true)
@course.enable_feature!(:draft_state)
@page = @course.wiki.wiki_pages.create!(:title => 'Course page')
end
describe 'GET index' do
it "should redirect with draft state enabled" do
get 'index', :course_id => @course.id, :wiki_page_id => @page.id
expect(response).to be_redirect
expect(response.location).to match(%r{/courses/#{@course.id}/pages/#{@page.url}/revisions})
end
end
describe 'GET show' do
it "should redirect with draft state enabled" do
get 'show', :course_id => @course.id, :wiki_page_id => @page.id, :id => 'latest'
expect(response).to be_redirect
expect(response.location).to match(%r{/courses/#{@course.id}/pages/#{@page.url}/revisions})
end
end
describe "PUT 'update'" do
it "should redirect to the right course wiki page" do
@page.title = "a better page title"
@page.save!
@version = @page.reload.versions.first
put 'update', :course_id => @course.id, :wiki_page_id => @page.id, :id => @version.id
expect(response).to be_redirect
expect(response.location).to match(%r{/courses/#{@course.id}/wiki})
end
it "should redirect to the right group wiki page" do
gcs = group_category
@group = gcs.groups.create(:context => @course)
@page = @group.wiki.wiki_pages.create!(:title => "a page")
@page.title = "a better page title"
@page.save!
@version = @page.reload.versions.first
put 'update', :group_id => @group.id, :wiki_page_id => @page.id, :id => @version.id
expect(response).to be_redirect
expect(response.location).to match(%r{/groups/#{@group.id}/wiki})
end
end
end

View File

@ -19,169 +19,24 @@
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
describe WikiPagesController do
describe "GET 'index'" do
describe "GET 'front_page'" do
it "should redirect with draft state enabled" do
course_with_teacher_logged_in(:active_all => true)
@course.enable_feature!(:draft_state)
get 'index', :course_id => @course.id
get 'front_page', :course_id => @course.id
expect(response).to be_redirect
expect(response.location).to match(%r{/courses/#{@course.id}/pages})
end
end
describe "GET 'show'" do
describe "GET 'show_redirect'" do
it "should redirect with draft state enabled" do
course_with_teacher_logged_in(:active_all => true)
@course.enable_feature!(:draft_state)
get 'show', :course_id => @course.id, :id => "some-page"
page = @course.wiki.wiki_pages.create!(:title => "blah", :body => "")
get 'show_redirect', :course_id => @course.id, :id => page.url
expect(response).to be_redirect
expect(response.location).to match(%r{/courses/#{@course.id}/pages})
end
end
describe "POST 'create'" do
it "should require authorization" do
course_with_teacher(:active_all => true)
post 'create', :course_id => @course.id, :wiki_page => {:title => "Some Great Page"}
assert_unauthorized
end
it "should create page" do
course_with_teacher_logged_in(:active_all => true)
post 'create', :course_id => @course.id, :wiki_page => {:title => "Some Great Page"}
expect(response).to be_redirect
expect(assigns[:page]).not_to be_nil
expect(assigns[:page]).not_to be_new_record
expect(assigns[:page].title).to eql("Some Great Page")
end
it "should allow users to create a page" do
group_with_user_logged_in(:active_all => true)
post 'create', :group_id => @group.id, :wiki_page => {:title => "Some Great Page"}
expect(response).to be_redirect
expect(assigns[:page]).not_to be_nil
expect(assigns[:page]).not_to be_new_record
expect(assigns[:page].title).to eql("Some Great Page")
end
end
describe "PUT 'update'" do
it "should require authorization" do
course_with_teacher(:active_all => true)
put 'update', :course_id => @course.id, :id => 1, :wiki_page => {:title => "Some Great Page"}
assert_unauthorized
end
it "should update page" do
course_with_teacher_logged_in(:active_all => true)
@course.wiki.wiki_pages.create!(:title => 'Test')
put 'update', :course_id => @course.id, :id => @course.wiki.wiki_pages.first.url, :wiki_page => {:title => "Some Great Page"}
expect(response).to be_redirect
expect(assigns[:page]).not_to be_nil
expect(assigns[:page].title).to eql("Some Great Page")
page = assigns[:page]
put 'update', :course_id => @course.id, :id => page.url, :wiki_page => {:title => "New Name"}
expect(response).to be_redirect
expect(assigns[:page]).not_to be_nil
expect(assigns[:page].title).to eql("New Name")
end
describe 'when the user is not a teacher' do
before do
group_with_user_logged_in(:active_all => true)
@group.wiki.wiki_pages.create!(:title => 'Test')
put 'update', :group_id => @group.id, :id => @group.wiki.wiki_pages.first.url, :wiki_page => {:title => "Some Great Page"}
@page = assigns[:page]
end
it 'redirects on success' do
expect(response).to be_redirect
end
it 'creates the new page on the first put' do
expect(@page).not_to be_nil
expect(@page.title).to eql("Some Great Page")
end
describe 'and is updating an existing page' do
before do
Setting.set('enable_page_views', 'db')
put 'update', :group_id => @group.id, :id => @page.url, :wiki_page => {:title => "New Name" }
@page = assigns[:page]
end
after do
Setting.set('enable_page_views', 'false')
end
it 'redirects on success' do
expect(response).to be_redirect
end
it 'updates the page attributes' do
expect(@page).not_to be_nil
expect(@page.title).to eq 'New Name'
end
it 'logs an asset access record for the discussion topic' do
accessed_asset = assigns[:accessed_asset]
expect(accessed_asset[:category]).to eq 'wiki'
expect(accessed_asset[:level]).to eq 'participate'
end
it 'registers a page view' do
page_view = assigns[:page_view]
expect(page_view).not_to be_nil
expect(page_view.http_method).to eq 'put'
expect(page_view.url).to match %r{^http://test\.host/groups/\d+/wiki/test}
expect(page_view.participated).to be_truthy
end
end
end
end
describe "DELETE 'destroy'" do
it "should require authorization" do
course_with_teacher(:active_all => true)
page = @course.wiki.front_page
page.save!
delete 'destroy', :course_id => @course.id, :id => page.url
assert_unauthorized
end
it "should redirect on deleting front page" do
course_with_teacher_logged_in(:active_all => true)
page = @course.wiki.front_page
page.save!
delete 'destroy', :course_id => @course.id, :id => page.url
expect(flash[:error]).to eql('You cannot delete the front page.')
expect(response).to be_redirect
end
it "should delete page" do
course_with_teacher_logged_in(:active_all => true)
page = @course.wiki.wiki_pages.create(:title => "a page")
page.save!
delete 'destroy', :course_id => @course.id, :id => page.url
expect(response).to be_redirect
expect(assigns[:page]).to eql(page)
expect(assigns[:page]).to be_deleted #frozen
expect(@course.wiki.wiki_pages).to be_include(page)
end
it "should allow users to delete a page" do
group_with_user_logged_in(:active_all => true)
page = @group.wiki.wiki_pages.create(:title => "a page")
page.save!
delete 'destroy', :group_id => @group.id, :id => page.url
expect(response).to be_redirect
expect(assigns[:page]).to eql(page)
expect(assigns[:page]).to be_deleted #frozen
expect(@group.wiki.wiki_pages).to be_include(page)
expect(response.location).to match(%r{/courses/#{@course.id}/pages/#{page.url}})
end
end

View File

@ -91,8 +91,7 @@ describe ContextModule do
@page = @course.wiki.wiki_pages.create!(:title => "talk page", :body => 'ohai', :editing_roles => 'teachers,students')
@tag = @module.add_item(:type => 'wiki_page', :id => @page.id)
before_after do
put "/courses/#{@course.id}/wiki/#{@page.url}", :wiki_page => { :body => 'i agree', :title => 'talk page' }
expect(response).to be_redirect
put "/api/v1/courses/#{@course.id}/pages/#{@page.url}", :wiki_page => { :body => 'i agree', :title => 'talk page' }
end
end

View File

@ -876,6 +876,7 @@ describe "security" do
it 'read_course_content' do
@course.assignments.create!
@course.wiki.set_front_page_url!("front-page")
@course.wiki.front_page.save!
@course.quizzes.create!
@course.attachments.create!(:uploaded_data => default_uploaded_data)
@ -890,9 +891,7 @@ describe "security" do
assert_status(401)
get "/courses/#{@course.id}/wiki"
expect(response).to be_redirect
follow_redirect!
expect(response).to be_redirect
assert_status(401)
get "/courses/#{@course.id}/quizzes"
assert_status(401)
@ -941,9 +940,6 @@ describe "security" do
expect(response).to be_success
get "/courses/#{@course.id}/wiki"
expect(response).to be_redirect
follow_redirect!
expect(response).to be_success
get "/courses/#{@course.id}/quizzes"

View File

@ -61,7 +61,6 @@ describe WikiPagesController do
context "draft state forwarding" do
before do
@front = @course.wiki.front_page
@wiki_page = create_page :title => "a-page", :body => "body"
@base_url = "/courses/#{@course.id}/"
@course.reload
@ -76,34 +75,34 @@ describe WikiPagesController do
@course.wiki.has_no_front_page = true
@course.wiki.save!
get @base_url + "wiki"
expect(response).to redirect_to(course_pages_url(@course))
expect(response).to redirect_to(course_wiki_pages_url(@course))
end
it "should forward /wiki to /pages/front-page" do
@front.save!
@front.set_as_front_page!
it "should render /wiki as the front page if there is one" do
@wiki_page.set_as_front_page!
get @base_url + "wiki"
expect(response).to redirect_to(course_named_page_url(@course, "front-page"))
expect(response).to be_success
expect(assigns[:page]).to eq @wiki_page
end
it "should forward /wiki/name to /pages/name" do
get @base_url + "wiki/a-page"
expect(response).to redirect_to(course_named_page_url(@course, "a-page"))
expect(response).to redirect_to(course_wiki_page_url(@course, "a-page"))
end
it "should forward module_item_id parameter" do
get @base_url + "wiki/a-page?module_item_id=123"
expect(response).to redirect_to(course_named_page_url(@course, "a-page") + "?module_item_id=123")
expect(response).to redirect_to(course_wiki_page_url(@course, "a-page") + "?module_item_id=123")
end
it "should forward /wiki/name/revisions to /pages/name/revisions" do
get @base_url + "wiki/a-page/revisions"
expect(response).to redirect_to(course_named_page_revisions_url(@course, "a-page"))
expect(response).to redirect_to(course_wiki_page_revisions_url(@course, "a-page"))
end
it "should forward /wiki/name/revisions/revision to /pages/name/revisions" do
get @base_url + "wiki/a-page/revisions/42"
expect(response).to redirect_to(course_named_page_revisions_url(@course, "a-page"))
expect(response).to redirect_to(course_wiki_page_revisions_url(@course, "a-page"))
end
end

View File

@ -423,7 +423,7 @@ describe "Common Cartridge exporting" do
CC::CCHelper.stubs(:media_object_info).returns({asset: {id: 1, status: '2'}, filename: 'blah.flv'})
obj = @course.media_objects.create! media_id: '0_deadbeef'
track = obj.media_tracks.create! kind: 'subtitles', locale: 'tlh', content: "Hab SoSlI' Quch!"
page = @course.wiki.front_page
page = @course.wiki.wiki_pages.create!(:title => "wiki", :body => "ohai")
page.body = %Q{<a id="media_comment_0_deadbeef" class="instructure_inline_media_comment video_comment"></a>}
page.save!
@ce.export_type = ContentExport::COMMON_CARTRIDGE

View File

@ -618,8 +618,8 @@ describe "Canvas Cartridge importing" do
migration_id = CC::CCHelper.create_key(page)
meta_fields = {:identifier => migration_id}
meta_fields[:editing_roles] = page.editing_roles
meta_fields[:hide_from_students] = page.hide_from_students
meta_fields[:notify_of_update] = page.notify_of_update
meta_fields[:workflow_state] = page.workflow_state
exported_html = CC::CCHelper::HtmlContentExporter.new(@copy_from, @from_teacher).html_page(page.body, page.title, meta_fields)
#convert to json
doc = Nokogiri::HTML(exported_html)
@ -634,7 +634,6 @@ describe "Canvas Cartridge importing" do
expect(page_2.title).to eq page.title
expect(page_2.url).to eq page.url
expect(page_2.editing_roles).to eq page.editing_roles
expect(page_2.hide_from_students).to eq page.hide_from_students
expect(page_2.notify_of_update).to eq page.notify_of_update
expect(page_2.body).to eq (body_with_link % [ @copy_to.id, @copy_to.id, @copy_to.id, @copy_to.id, @copy_to.id, mod2.id, @copy_to.id, to_att.id ]).gsub(/png" \/>/, 'png">')
expect(page_2.unpublished?).to eq true

View File

@ -21,6 +21,7 @@ describe ContentMigration do
# simulating what happens when the user clicks "link to new page" and enters a title that isn't
# urlified the same way by the client vs. the server. this doesn't break navigation because
# ApplicationController#get_wiki_page can match by urlified title, but it broke import (see #9945)
@copy_from.wiki.set_front_page_url!('front-page')
main_page = @copy_from.wiki.front_page
main_page.body = %{<a href="/courses/#{@copy_from.id}/wiki/online:-unit-pages">wut</a>}
main_page.save!
@ -77,19 +78,6 @@ describe ContentMigration do
expect(@copy_to.wiki.has_no_front_page).to eq true
end
it "should set retain default behavior if front page is missing and draft state is not enabled" do
@copy_to.wiki.front_page.save!
@copy_from.default_view = 'wiki'
@copy_from.save!
@copy_from.wiki.set_front_page_url!('haha not here')
run_course_copy
expect(@copy_to.wiki.has_front_page?).to eq true
expect(@copy_to.wiki.get_front_page_url).to eq 'front-page'
end
it "should set default view to feed if wiki front page is missing and draft state is enabled" do
@copy_from.root_account.enable_feature!(:draft_state)

View File

@ -450,6 +450,7 @@ describe Course do
@course.discussion_topics.create!
@course.quizzes.create!
@course.assignments.create!
@course.wiki.set_front_page_url!('front-page')
@course.wiki.front_page.save!
@course.self_enrollment = true
@course.sis_source_id = 'sis_id'

View File

@ -57,6 +57,7 @@ describe WikiPage do
it "should validate that the front page is always visible" do
course_with_teacher(:active_all => true)
@course.wiki.set_front_page_url!('front-page')
front_page = @course.wiki.front_page
front_page.save!
front_page.workflow_state = 'unpublished'
@ -76,6 +77,7 @@ describe WikiPage do
it "shouldn't allow the front page to be unpublished" do
course_with_teacher(active_all: true, draft_state: true)
@course.wiki.set_front_page_url!('front-page')
front_page = @course.wiki.front_page
expect(front_page).not_to be_can_unpublish
# the data model doesn't actually disallow this (yet)
@ -222,7 +224,8 @@ describe WikiPage do
end
it 'should set the front page body' do
front_page = @course.wiki.wiki_pages.new(:title => 'Front Page', :url => 'front-page')
@course.wiki.set_front_page_url!('front-page')
front_page = @course.wiki.front_page
expect(front_page.body).to be_nil
front_page.initialize_wiki_page(@teacher)
expect(front_page.body).not_to be_empty
@ -235,7 +238,8 @@ describe WikiPage do
end
it 'should publish the front page' do
front_page = @course.wiki.wiki_pages.new(:title => 'Front Page', :url => 'front-page')
@course.wiki.set_front_page_url!('front-page')
front_page = @course.wiki.front_page
front_page.initialize_wiki_page(@teacher)
expect(front_page).to be_published
end
@ -248,7 +252,8 @@ describe WikiPage do
end
it 'should set the front page body' do
front_page = @group.wiki.wiki_pages.new(:title => 'Front Page', :url => 'front-page')
@group.wiki.set_front_page_url!('front-page')
front_page = @group.wiki.front_page
expect(front_page.body).to be_nil
front_page.initialize_wiki_page(@user)
expect(front_page.body).not_to be_empty

View File

@ -24,12 +24,6 @@ describe Wiki do
@wiki = @course.wiki
end
context "get_front_page_url" do
it "should return default url if front_page_url is not set" do
expect(@wiki.get_front_page_url).to eq Wiki::DEFAULT_FRONT_PAGE_URL # 'front-page'
end
end
context "unset_front_page!" do
it "should unset front page" do
@wiki.unset_front_page!
@ -51,14 +45,6 @@ describe Wiki do
end
context "front_page" do
it "should build a default page if not found" do
expect(@wiki.wiki_pages.count).to eq 0
page = @wiki.front_page
expect(page.new_record?).to eq true
expect(page.url).to eq @wiki.get_front_page_url
end
it "should build a custom front page if not found" do
new_url = "whyyyyy"
@wiki.set_front_page_url!(new_url)

View File

@ -1014,7 +1014,7 @@ describe "context_modules" do
@quiz = @course.quizzes.create!(:title => "score 10")
@quiz.publish!
@quiz_tag = @module1.add_item(:id => @quiz.id, :type => 'quiz')
@wiki_page = @course.wiki.front_page
@wiki_page = @course.wiki.wiki_pages.create!(:title => 'title', :body => '')
@wiki_page.workflow_state = 'active'; @wiki_page.save!
@wiki_page_tag = @module1.add_item(:id => @wiki_page.id, :type => 'wiki_page')
@subheader_tag = @module1.add_item(:type => 'context_module_sub_header', :title => 'subheader')

View File

@ -7,7 +7,7 @@ describe "enhanceable_content" do
stub_kaltura
course_with_teacher_logged_in
page = @course.wiki.front_page
page = @course.wiki.wiki_pages.build(:title => 'title')
page.body = %{
<div id="dialog_for_link1" class="enhanceable_content dialog">dialog for link 1</div>
<a href="#dialog_for_link1" id="link1">link 1</a>

View File

@ -12,8 +12,8 @@ describe "Navigating to wiki pages" do
it "navigates to the wiki pages edit page from the show page" do
wikiPage = @course.wiki.wiki_pages.create!(:title => "Foo")
edit_url = course_edit_named_page_url(@course, wikiPage)
get course_named_page_path(@course, wikiPage)
edit_url = edit_course_wiki_page_url(@course, wikiPage)
get course_wiki_page_path(@course, wikiPage)
f(".edit-wiki").click
@ -50,6 +50,7 @@ describe "Navigating to wiki pages" do
@tool.wiki_page_menu = {:url => "http://www.example.com", :text => "Export Wiki Page"}
@tool.save!
@course.wiki.set_front_page_url!('front-page')
@wiki_page = @course.wiki.front_page
@wiki_page.workflow_state = 'active'; @wiki_page.save!
end

View File

@ -1,35 +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')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/wiki_page_revisions/index" do
it "should show user editing link and content import name" do
course_with_student
view_context
assigns[:wiki] = @course.wiki
assigns[:page] = assigns[:wiki].front_page
assigns[:page].save!
assigns[:page].update_attributes(:body => "oi", :user_id => @user.id)
render "wiki_page_revisions/index"
expect(response.body).to match /Content Importer/
expect(response.body).to match %r{/users/#{@user.id}}
end
end

View File

@ -1,42 +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')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/wiki_page_revisions/show" do
before do
course_with_student
view_context
assigns[:wiki] = @course.wiki
assigns[:page] = assigns[:wiki].front_page
assigns[:page].save!
end
it "should say imported for no user edit" do
assigns[:revision] = assigns[:page].versions.first
render "wiki_page_revisions/show"
expect(response.body).to match /Imported:/
end
it "should say username of editor" do
assigns[:page].update_attributes(:body => "oi", :user_id => @user.id)
assigns[:revision] = assigns[:page].versions[0]
render "wiki_page_revisions/show"
expect(response.body).to match /Saved: .* by #{@user.name}/
end
end

View File

@ -1,38 +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')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/wiki_pages/_wiki_right_side" do
it "should render" do
group_with_user
view_context
page = @group.wiki.wiki_pages.create(:title => "a page")
assigns[:wiki] = @group.wiki
assigns[:page] = page
assigns[:page].save!
assigns[:context] = @group
render :partial => "wiki_pages/wiki_right_side"
expect(response).not_to be_nil
expect(response.body).to match(/Edit this Page/)
expect(response.body).to match(/Delete this Page/)
expect(response.body).to match(/Create a New Page/)
end
end

View File

@ -1,48 +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')
require File.expand_path(File.dirname(__FILE__) + '/../views_helper')
describe "/wiki_pages/show" do
before do
course_with_student
view_context
assigns[:wiki] = @course.wiki
assigns[:page] = assigns[:wiki].front_page
assigns[:page].body = "my awesome content"
assigns[:page].save!
assigns[:context] = @course
end
it "should render" do
render "wiki_pages/show"
doc = Nokogiri::HTML(response.body)
expect(doc.css('#wiki_body').text.index(assigns[:page].body)).not_to be_nil
end
it "should not render user content when editing" do
assigns[:editing] = true
render "wiki_pages/show"
doc = Nokogiri::HTML(response.body)
expect(doc.css('#wiki_body').text.index(assigns[:page].body)).to be_nil
expect(doc.css('#wiki_body').text.index('Editing Content')).not_to be_nil
end
end