deprecate hide_from_students on wiki pages
hide_from_students is being deprecated in lieu of the workflow states 'active' (published) and 'unpublished' test plan: (draft state and legacy) special attention should be given to areas related to hiding wiki pages from students (legacy: hide from students checkbox; draft state: published/unpublished items) items that are hidden from students or unpublished should show for teachers, but should not show for students - areas to test: - pages api and ui (regression) - validate hide_from_students and published values in all api calls - course migrations (specifically course copy) - wiki sidebar in other parts of canvas fixes CNVS-10354, CNVS-10366 Change-Id: I70f4d8c07c2be4150163279f0673377bad6e9c48 Reviewed-on: https://gerrit.instructure.com/28375 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins <jenkins@instructure.com> QA-Review: Nathan Rogowski <nathan@instructure.com> QA-Review: Matt Fairbourn <mfairbourn@instructure.com> Reviewed-by: Jeremy Stanley <jeremy@instructure.com> Product-Review: Bracken Mosbacker <bracken@instructure.com>
This commit is contained in:
parent
f0d89fb0bf
commit
0152fa52fa
|
@ -166,7 +166,8 @@ class WikiPagesApiController < ApplicationController
|
|||
# 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 true.
|
||||
# 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>' \
|
||||
|
@ -206,13 +207,12 @@ class WikiPagesApiController < ApplicationController
|
|||
# omit body from selection, since it's not included in index results
|
||||
scope = @context.wiki.wiki_pages.select(WikiPage.column_names - ['body']).includes(:user)
|
||||
if params.has_key?(:published)
|
||||
scope = value_to_boolean(params[:published]) ? scope.active.not_hidden : scope.unpublished
|
||||
scope = value_to_boolean(params[:published]) ? scope.published : scope.unpublished
|
||||
else
|
||||
scope = scope.not_deleted
|
||||
end
|
||||
# published parameter notwithstanding, hide unpublished items if the user doesn't have permission to see them
|
||||
scope = scope.active unless @context.grants_right?(@current_user, session, :view_unpublished_items)
|
||||
scope = scope.not_hidden unless @context.grants_right?(@current_user, session, :view_hidden_items)
|
||||
scope = scope.published unless @context.grants_right?(@current_user, session, :view_unpublished_items)
|
||||
|
||||
scope = WikiPage.search_by_attribute(scope, :title, params[:search_term])
|
||||
|
||||
|
@ -267,7 +267,8 @@ class WikiPagesApiController < ApplicationController
|
|||
# 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 true.
|
||||
# will be ignored and the value returned will always be the inverse of the
|
||||
# +hide_from_students+ value.
|
||||
#
|
||||
# @argument wiki_page[front_page] [Optional, Boolean]
|
||||
# Set an unhidden page as the front page (if true)
|
||||
|
@ -345,7 +346,8 @@ class WikiPagesApiController < ApplicationController
|
|||
# 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 true.
|
||||
# will be ignored and the value returned will always be the inverse of the
|
||||
# +hide_from_students+ value.
|
||||
#
|
||||
# @argument wiki_page[front_page] [Optional, Boolean]
|
||||
# Set an unhidden page as the front page (if true)
|
||||
|
@ -537,10 +539,12 @@ class WikiPagesApiController < ApplicationController
|
|||
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[:hide_from_students] = value_to_boolean(page_params[:hide_from_students]) if page_params.has_key?(:hide_from_students)
|
||||
|
||||
hide_from_students_provided = page_params.has_key?(:hide_from_students)
|
||||
if page_params.has_key?(:published)
|
||||
workflow_state = value_to_boolean(page_params.delete(:published)) ? 'active' : 'unpublished'
|
||||
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)
|
||||
|
@ -565,7 +569,13 @@ class WikiPagesApiController < ApplicationController
|
|||
if @wiki.grants_right?(@current_user, session, :manage)
|
||||
allowed_fields.clear
|
||||
else
|
||||
rejected_fields << :published if workflow_state && workflow_state != @page.workflow_state
|
||||
if workflow_state && workflow_state != @page.workflow_state
|
||||
if hide_from_students_provided
|
||||
rejected_fields << :hide_from_students
|
||||
else
|
||||
rejected_fields << :published
|
||||
end
|
||||
end
|
||||
|
||||
if editing_roles
|
||||
existing_editing_roles = (@page.editing_roles || '').split(',')
|
||||
|
@ -574,8 +584,6 @@ class WikiPagesApiController < ApplicationController
|
|||
rejected_fields << :editing_roles if editing_roles_changed
|
||||
end
|
||||
|
||||
rejected_fields << :hide_from_students if page_params.include?(:hide_from_students) && value_to_boolean(page_params[:hide_from_students]) != @page.hide_from_students
|
||||
|
||||
unless @page.grants_right?(@current_user, session, :update)
|
||||
allowed_fields << :body
|
||||
rejected_fields << :title if page_params.include?(:title) && page_params[:title] != @page.title
|
||||
|
@ -598,18 +606,6 @@ class WikiPagesApiController < ApplicationController
|
|||
|
||||
# check for a valid front page
|
||||
valid_front_page = true
|
||||
|
||||
if change_front_page || page_params.include?(:hide_from_students)
|
||||
new_front_page = change_front_page ? @set_as_front_page : @page.is_front_page?
|
||||
new_hide_from_students = page_params.include?(:hide_from_students) ? value_to_boolean(page_params[:hide_from_students]) : @page.hide_from_students
|
||||
if new_front_page && new_hide_from_students
|
||||
valid_front_page = false
|
||||
error_message = t(:cannot_hide_front_page, 'The front page cannot be hidden from students')
|
||||
@page.errors.add(:front_page, error_message) if change_front_page
|
||||
@page.errors.add(:hide_from_students, error_message) if page_params.include?(:hide_from_students)
|
||||
end
|
||||
end
|
||||
|
||||
if change_front_page || workflow_state
|
||||
new_front_page = change_front_page ? @set_as_front_page : @page.is_front_page?
|
||||
new_workflow_state = workflow_state ? workflow_state : @page.workflow_state
|
||||
|
@ -618,7 +614,11 @@ 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
|
||||
@page.errors.add(:published, error_message) if workflow_state
|
||||
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
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -104,6 +104,15 @@ class WikiPagesController < ApplicationController
|
|||
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?
|
||||
|
|
|
@ -995,7 +995,7 @@ class Course < ActiveRecord::Base
|
|||
|
||||
# Active admins (Teacher/TA/Designer)
|
||||
given { |user, session| (self.available? || self.created? || self.claimed?) && user && user.cached_not_ended_enrollments.any?{|e| e.course_id == self.id && e.participating_admin? } && (!session || !session["role_course_#{self.id}"]) }
|
||||
can :read_as_admin and can :read and can :manage and can :update and can :use_student_view and can :read_outcomes and can :view_hidden_items and can :view_unpublished_items and can :manage_feature_flags
|
||||
can :read_as_admin and can :read and can :manage and can :update and can :use_student_view and can :read_outcomes and can :view_unpublished_items and can :manage_feature_flags
|
||||
|
||||
# Teachers and Designers can delete/reset, but not TAs
|
||||
given { |user, session| !self.deleted? && !self.sis_source_id && user && user.cached_not_ended_enrollments.any?{|e| e.course_id == self.id && e.participating_content_admin? } && (!session || !session["role_course_#{self.id}"]) }
|
||||
|
@ -1066,7 +1066,7 @@ class Course < ActiveRecord::Base
|
|||
can :read_as_admin
|
||||
|
||||
given { |user, session| self.account_membership_allows(user, session, :manage_courses) }
|
||||
can :read_as_admin and can :manage and can :update and can :delete and can :use_student_view and can :reset_content and can :view_hidden_items and can :view_unpublished_items and can :manage_feature_flags
|
||||
can :read_as_admin and can :manage and can :update and can :delete and can :use_student_view and can :reset_content and can :view_unpublished_items and can :manage_feature_flags
|
||||
|
||||
given { |user, session| self.account_membership_allows(user, session, :read_course_content) }
|
||||
can :read and can :read_outcomes
|
||||
|
|
|
@ -388,8 +388,7 @@ class Group < ActiveRecord::Base
|
|||
can :send_messages and
|
||||
can :send_messages_all and
|
||||
can :follow and
|
||||
can :view_unpublished_items and
|
||||
can :view_hidden_items
|
||||
can :view_unpublished_items
|
||||
|
||||
# if I am a member of this group and I can moderate_forum in the group's context
|
||||
# (makes it so group members cant edit each other's discussion entries)
|
||||
|
@ -426,8 +425,7 @@ class Group < ActiveRecord::Base
|
|||
can :read and
|
||||
can :read_roster and
|
||||
can :update and
|
||||
can :view_unpublished_items and
|
||||
can :view_hidden_items
|
||||
can :view_unpublished_items
|
||||
|
||||
given { |user, session| self.context && self.context.grants_right?(user, session, :view_group_pages) }
|
||||
can :read and can :read_roster
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#
|
||||
|
||||
class WikiPage < ActiveRecord::Base
|
||||
attr_accessible :title, :body, :url, :user_id, :hide_from_students, :editing_roles, :notify_of_update
|
||||
attr_readonly :wiki_id
|
||||
attr_accessible :title, :body, :url, :user_id, :editing_roles, :notify_of_update
|
||||
attr_readonly :wiki_id, :hide_from_students
|
||||
validates_length_of :body, :maximum => maximum_long_text_length, :allow_nil => true, :allow_blank => true
|
||||
validates_presence_of :wiki_id
|
||||
include Workflow
|
||||
|
@ -41,7 +41,7 @@ class WikiPage < ActiveRecord::Base
|
|||
SIMPLY_VERSIONED_EXCLUDE_FIELDS = [:workflow_state, :hide_from_students, :editing_roles, :notify_of_update]
|
||||
|
||||
def validate_front_page_visibility
|
||||
if self.hide_from_students && self.is_front_page?
|
||||
if !published? && self.is_front_page?
|
||||
self.errors.add(:hide_from_students, t(:cannot_hide_page, "cannot hide front page"))
|
||||
end
|
||||
end
|
||||
|
@ -69,27 +69,26 @@ class WikiPage < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
# sync hide_from_students with published state
|
||||
def sync_hidden_and_unpublished
|
||||
return if (context rescue nil).nil?
|
||||
|
||||
WikiPage.skip_callback(:after_find) do
|
||||
if context.feature_enabled?(:draft_state)
|
||||
if self.hide_from_students # hide_from_students overrides published
|
||||
self.hide_from_students = false
|
||||
self.workflow_state = 'unpublished'
|
||||
end
|
||||
else
|
||||
if self.workflow_state.to_s == 'unpublished' # unpublished overrides hide_from_students
|
||||
self.workflow_state = 'active'
|
||||
self.hide_from_students = true
|
||||
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
|
||||
before_save :sync_hidden_and_unpublished
|
||||
alias_method :after_find, :sync_hidden_and_unpublished
|
||||
private :sync_hidden_and_unpublished
|
||||
alias_method :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')
|
||||
|
@ -168,11 +167,8 @@ class WikiPage < ActiveRecord::Base
|
|||
state :post_delayed do
|
||||
event :delayed_post, :transitions_to => :active
|
||||
end
|
||||
|
||||
state :deleted
|
||||
|
||||
end
|
||||
|
||||
alias_method :published?, :active?
|
||||
|
||||
def restore
|
||||
|
@ -209,6 +205,7 @@ 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)
|
||||
|
||||
# needed for ensure_unique_url
|
||||
|
@ -216,8 +213,6 @@ class WikiPage < ActiveRecord::Base
|
|||
!deleted?
|
||||
end
|
||||
|
||||
scope :not_hidden, where('wiki_pages.hide_from_students<>?', true)
|
||||
|
||||
scope :order_by_id, order(:id)
|
||||
|
||||
def locked_for?(user, opts={})
|
||||
|
@ -242,10 +237,16 @@ class WikiPage < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def set_as_front_page!
|
||||
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"))
|
||||
return false
|
||||
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
|
||||
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
|
||||
|
@ -286,7 +287,7 @@ class WikiPage < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def can_read_page?(user, session=nil)
|
||||
self.wiki.grants_right?(user, session, :manage) || (!hide_from_students && self.active?)
|
||||
self.wiki.grants_right?(user, session, :manage) || (self.active?)
|
||||
end
|
||||
|
||||
def can_edit_page?(user, session=nil)
|
||||
|
@ -319,15 +320,10 @@ class WikiPage < ActiveRecord::Base
|
|||
set_broadcast_policy do |p|
|
||||
p.dispatch :updated_wiki_page
|
||||
p.to { participants }
|
||||
p.whenever { |record|
|
||||
record.created_at < Time.now - (30*60) &&
|
||||
((
|
||||
record.active? && @wiki_page_changed && record.prior_version
|
||||
) ||
|
||||
(
|
||||
record.changed_state(:active)
|
||||
))
|
||||
}
|
||||
p.whenever do |record|
|
||||
return false unless record.created_at < Time.now - 30.minutes
|
||||
(record.published? && @wiki_page_changed && record.prior_version) || record.changed_state(:active)
|
||||
end
|
||||
end
|
||||
|
||||
def context(user=nil)
|
||||
|
@ -339,7 +335,7 @@ class WikiPage < ActiveRecord::Base
|
|||
def participants
|
||||
res = []
|
||||
if context && context.available?
|
||||
if self.hide_from_students || !self.active?
|
||||
if !self.active?
|
||||
res += context.participating_admins
|
||||
else
|
||||
res += context.participants
|
||||
|
@ -425,8 +421,10 @@ class WikiPage < ActiveRecord::Base
|
|||
item = front_page
|
||||
end
|
||||
end
|
||||
if state = hash[:workflow_state]
|
||||
if state == 'active'
|
||||
hide_from_students = hash[:hide_from_students] if !hash[:hide_from_students].nil?
|
||||
state = hash[:workflow_state]
|
||||
if state || !hide_from_students.nil?
|
||||
if state == 'active' && Canvas::Plugin.value_to_boolean(hide_from_students) == false
|
||||
item.workflow_state = 'active'
|
||||
else
|
||||
item.workflow_state = 'unpublished'
|
||||
|
@ -537,7 +535,6 @@ class WikiPage < ActiveRecord::Base
|
|||
hash[:missing_links][:body] = []
|
||||
item.body = ImportedHtmlConverter.convert(hash[:text] || "", context, {:missing_links => hash[:missing_links][:body]})
|
||||
item.editing_roles = hash[:editing_roles] if hash[:editing_roles].present?
|
||||
item.hide_from_students = hash[:hide_from_students] if !hash[:hide_from_students].nil?
|
||||
item.notify_of_update = hash[:notify_of_update] if !hash[:notify_of_update].nil?
|
||||
else
|
||||
allow_save = false
|
||||
|
|
|
@ -42,7 +42,7 @@
|
|||
<div>
|
||||
<ul class="wiki_pages page_list">
|
||||
<% (@wiki_sidebar_data[:wiki_pages]).each do |wiki_page| %>
|
||||
<% if can_do(@wiki, @current_user, :manage) || (!wiki_page.hide_from_students && wiki_page.active?) %>
|
||||
<% 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, context_url(@context, :context_wiki_page_url, wiki_page.url) rescue "" %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -3,8 +3,8 @@
|
|||
<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>
|
||||
<% elsif skip_front_page && wiki_page.is_front_page? %>
|
||||
<% else %>
|
||||
<% if can_do(@context, @current_user, :manage_content) || (!wiki_page.hide_from_students && wiki_page.active?) %>
|
||||
<li class="ellipsis" style="<%= 'display: none;' if hidden %><%= 'font-weight: bold;' if @page && wiki_page == @page %><%= 'font-style: italic;' if wiki_page.hide_from_students %>" title="<%= t(:link_hidden_from_students_warning, "Students won't see this link") if wiki_page.hide_from_students %>"><%= link_to wiki_page.title, context_url(
|
||||
<% 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
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
class DeprecateHideFromStudentsOnWikiPages < ActiveRecord::Migration
|
||||
tag :postdeploy
|
||||
|
||||
def self.up
|
||||
change_column_default(:wiki_pages, :hide_from_students, nil)
|
||||
DataFixup::DeprecateHideFromStudentsOnWikiPages.send_later_if_production_enqueue_args(:run, :priority => Delayed::LOW_PRIORITY, :max_attempts => 1)
|
||||
end
|
||||
|
||||
def self.down
|
||||
change_column_default(:wiki_pages, :hide_from_students, false)
|
||||
end
|
||||
end
|
|
@ -21,15 +21,15 @@ module Api::V1::WikiPage
|
|||
include Api::V1::User
|
||||
include Api::V1::Locked
|
||||
|
||||
WIKI_PAGE_JSON_ATTRS = %w(url title created_at updated_at hide_from_students editing_roles)
|
||||
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)
|
||||
hash = api_json(wiki_page, current_user, session, :only => WIKI_PAGE_JSON_ATTRS, :methods => WIKI_PAGE_JSON_METHODS)
|
||||
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?
|
||||
hash['hide_from_students'] = !hash['published']
|
||||
else
|
||||
hash['published'] = true
|
||||
end
|
||||
|
|
|
@ -38,9 +38,9 @@ module CC::Importer::Canvas
|
|||
wiki[:title] = title
|
||||
wiki[:migration_id] = meta['identifier']
|
||||
wiki[:editing_roles] = meta['editing_roles']
|
||||
wiki[:hide_from_students] = meta['hide_from_students'] == 'true'
|
||||
wiki[:notify_of_update] = meta['notify_of_update'] == 'true'
|
||||
wiki[:workflow_state] = meta['workflow_state']
|
||||
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
|
||||
wiki[:url_name] = wiki_name
|
||||
|
|
|
@ -31,9 +31,9 @@ module CC
|
|||
path = File.join(wiki_folder, file_name)
|
||||
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
|
||||
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|
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
module DataFixup::DeprecateHideFromStudentsOnWikiPages
|
||||
def self.run
|
||||
WikiPage.find_ids_in_ranges do |min_id, max_id|
|
||||
WikiPage.where(id: min_id..max_id)
|
||||
.where("hide_from_students IS NOT NULL")
|
||||
.update_all("hide_from_students=NULL, workflow_state=CASE WHEN hide_from_students AND workflow_state='active' THEN 'unpublished' ELSE workflow_state END")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -260,8 +260,8 @@ describe "Modules API", :type => :integration do
|
|||
@test_modules.map { |tm| tm.workflow_state }.should == %w(active active unpublished unpublished)
|
||||
@modules_to_update = [@test_modules[1], @test_modules[3]]
|
||||
|
||||
@wiki_page = @course.wiki.front_page
|
||||
@wiki_page.workflow_state = 'unpublished'; @wiki_page.save!
|
||||
@wiki_page = @course.wiki.wiki_pages.create(:title => 'Wiki Page Title')
|
||||
@wiki_page.unpublish!
|
||||
@wiki_page_tag = @test_modules[3].add_item(:id => @wiki_page.id, :type => 'wiki_page')
|
||||
|
||||
@ids_to_update = @modules_to_update.map(&:id)
|
||||
|
@ -357,8 +357,8 @@ describe "Modules API", :type => :integration do
|
|||
@module1.workflow_state = 'unpublished'
|
||||
@module1.save!
|
||||
|
||||
@wiki_page = @course.wiki.front_page
|
||||
@wiki_page.workflow_state = 'unpublished'; @wiki_page.save!
|
||||
@wiki_page = @course.wiki.wiki_pages.create(:title => 'Wiki Page Title')
|
||||
@wiki_page.unpublish!
|
||||
@wiki_page_tag = @module1.add_item(:id => @wiki_page.id, :type => 'wiki_page')
|
||||
|
||||
@module2 = @course.context_modules.create!(:name => "published")
|
||||
|
|
|
@ -57,7 +57,8 @@ describe "Pages API", :type => :integration do
|
|||
@front_page.workflow_state = 'active'
|
||||
@front_page.save!
|
||||
@front_page.set_as_front_page!
|
||||
@hidden_page = @wiki.wiki_pages.create!(:title => "Hidden Page", :hide_from_students => true, :body => "Body of hidden page")
|
||||
@hidden_page = @wiki.wiki_pages.create!(:title => "Hidden Page", :body => "Body of hidden page")
|
||||
@hidden_page.unpublish!
|
||||
end
|
||||
|
||||
context 'versions' do
|
||||
|
@ -96,12 +97,6 @@ describe "Pages API", :type => :integration do
|
|||
@page.versions.count.should == 1
|
||||
end
|
||||
|
||||
example 'does not create a version when hide_from_students changes' do
|
||||
@page.hide_from_students = true
|
||||
@page.save!
|
||||
@page.versions.count.should == 1
|
||||
end
|
||||
|
||||
example 'does not create a version when editing_roles changes' do
|
||||
@page.editing_roles = 'teachers,students,public'
|
||||
@page.save!
|
||||
|
@ -420,7 +415,7 @@ describe "Pages API", :type => :integration do
|
|||
end
|
||||
|
||||
it "should revert page content only" do
|
||||
@vpage.hide_from_students = true
|
||||
@vpage.workflow_state = 'unpublished'
|
||||
@vpage.title = 'booga!'
|
||||
@vpage.body = 'booga booga!'
|
||||
@vpage.editing_roles = 'teachers,students,public'
|
||||
|
@ -654,7 +649,7 @@ describe "Pages API", :type => :integration do
|
|||
json['hide_from_students'].should be_true
|
||||
|
||||
@test_page.reload
|
||||
@test_page.should be_active
|
||||
@test_page.should be_unpublished
|
||||
@test_page.hide_from_students.should be_true
|
||||
end
|
||||
|
||||
|
@ -697,7 +692,7 @@ describe "Pages API", :type => :integration do
|
|||
|
||||
@test_page.reload
|
||||
@test_page.should be_unpublished
|
||||
@test_page.hide_from_students.should be_false
|
||||
@test_page.hide_from_students.should be_true
|
||||
end
|
||||
|
||||
it 'should ignore hide_from_students' do
|
||||
|
@ -781,8 +776,11 @@ describe "Pages API", :type => :integration do
|
|||
|
||||
describe "notify_of_update" do
|
||||
before do
|
||||
@notify_page = @hidden_page
|
||||
@notify_page.publish!
|
||||
|
||||
@front_page.update_attribute(:created_at, 1.hour.ago)
|
||||
@hidden_page.update_attribute(:created_at, 1.hour.ago)
|
||||
@notify_page.update_attribute(:created_at, 1.hour.ago)
|
||||
@notification = Notification.create! :name => "Updated Wiki Page"
|
||||
@teacher.communication_channels.create(:path => "teacher@instructure.com").confirm!
|
||||
@teacher.email_channel.notification_policies.
|
||||
|
@ -790,14 +788,14 @@ describe "Pages API", :type => :integration do
|
|||
update_attribute(:frequency, 'immediately')
|
||||
end
|
||||
|
||||
it "should notify iff the notify_of_update flag is sent" do
|
||||
it "should notify iff the notify_of_update flag is set" do
|
||||
api_call(:put, "/api/v1/courses/#{@course.id}/pages/#{@front_page.url}?wiki_page[body]=updated+front+page",
|
||||
:controller => 'wiki_pages_api', :action => 'update', :format => 'json', :course_id => @course.to_param,
|
||||
:url => @front_page.url, :wiki_page => { "body" => "updated front page" })
|
||||
api_call(:put, "/api/v1/courses/#{@course.id}/pages/#{@hidden_page.url}?wiki_page[body]=updated+hidden+page&wiki_page[notify_of_update]=true",
|
||||
:controller => 'wiki_pages_api', :action => 'update', :format => 'json', :course_id => @course.to_param,
|
||||
:url => @hidden_page.url, :wiki_page => { "body" => "updated hidden page", "notify_of_update" => 'true' })
|
||||
@teacher.messages.map(&:context_id).should == [@hidden_page.id]
|
||||
:url => @notify_page.url, :wiki_page => { "body" => "updated hidden page", "notify_of_update" => 'true' })
|
||||
@teacher.messages.map(&:context_id).should == [@notify_page.id]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -829,7 +827,7 @@ describe "Pages API", :type => :integration do
|
|||
|
||||
context "unpublished pages" do
|
||||
before do
|
||||
@deleted_page = @wiki.wiki_pages.create! :title => "Deleted page", :hide_from_students => true
|
||||
@deleted_page = @wiki.wiki_pages.create! :title => "Deleted page"
|
||||
@deleted_page.destroy
|
||||
@course.account.allow_feature!(:draft_state)
|
||||
@course.enable_feature!(:draft_state)
|
||||
|
|
|
@ -117,7 +117,7 @@ describe WikiPagesController do
|
|||
page.should_not be_nil
|
||||
page.should_not be_new_record
|
||||
page.title.should == "Some Secret Page"
|
||||
page.hide_from_students = true
|
||||
page.workflow_state = 'unpublished'
|
||||
page.save
|
||||
page.reload
|
||||
student = user()
|
||||
|
|
|
@ -56,8 +56,7 @@ describe WikiPagesController do
|
|||
it "should permit the student to view the page history if they have permissions" do
|
||||
@wiki_page = @course.wiki.wiki_pages.create :title => "Some random wiki page",
|
||||
:body => "this is the content of the wikipage body asdfasdf",
|
||||
:editing_roles => "teachers,students",
|
||||
:hide_from_students => false
|
||||
:editing_roles => "teachers,students"
|
||||
student = user()
|
||||
enrollment = @course.enroll_student(student)
|
||||
enrollment.accept!
|
||||
|
|
|
@ -609,9 +609,10 @@ describe "Canvas Cartridge importing" do
|
|||
<div><img src="http://www.instructure.com/images/header-logo.png"></div>
|
||||
<div><img src="http://www.instructure.com/images/header-logo.png"></div>
|
||||
</div>}
|
||||
page = @copy_from.wiki.wiki_pages.create!(:title => "some page", :body => body_with_link % [ @copy_from.id, @copy_from.id, @copy_from.id, @copy_from.id, @copy_from.id, mod.id, @copy_from.id, from_att.id ], :editing_roles => "teachers", :hide_from_students => true, :notify_of_update => true)
|
||||
page = @copy_from.wiki.wiki_pages.create!(:title => "some page", :body => body_with_link % [ @copy_from.id, @copy_from.id, @copy_from.id, @copy_from.id, @copy_from.id, mod.id, @copy_from.id, from_att.id ], :editing_roles => "teachers", :notify_of_update => true)
|
||||
page.workflow_state = 'unpublished'
|
||||
@copy_from.save!
|
||||
|
||||
|
||||
#export to html file
|
||||
migration_id = CC::CCHelper.create_key(page)
|
||||
meta_fields = {:identifier => migration_id}
|
||||
|
@ -635,7 +636,7 @@ describe "Canvas Cartridge importing" do
|
|||
page_2.hide_from_students.should == page.hide_from_students
|
||||
page_2.notify_of_update.should == page.notify_of_update
|
||||
page_2.body.should == (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">')
|
||||
page_2.active?.should == true
|
||||
page_2.unpublished?.should == true
|
||||
end
|
||||
|
||||
it "should import migrate inline external tool URLs in wiki pages" do
|
||||
|
|
|
@ -59,18 +59,18 @@ describe WikiPage do
|
|||
course_with_teacher(:active_all => true)
|
||||
front_page = @course.wiki.front_page
|
||||
front_page.save!
|
||||
front_page.hide_from_students = true
|
||||
front_page.workflow_state = 'unpublished'
|
||||
front_page.valid?.should_not be_true
|
||||
|
||||
new_front_page = @course.wiki.wiki_pages.create!(:title => "asdf")
|
||||
new_front_page.set_as_front_page!
|
||||
|
||||
front_page.reload
|
||||
front_page.hide_from_students = true
|
||||
front_page.workflow_state = 'unpublished'
|
||||
front_page.valid?.should be_true
|
||||
|
||||
new_front_page.reload
|
||||
new_front_page.hide_from_students = true
|
||||
new_front_page.workflow_state = 'unpublished'
|
||||
new_front_page.valid?.should_not be_true
|
||||
end
|
||||
|
||||
|
@ -168,7 +168,8 @@ describe WikiPage do
|
|||
describe '#can_edit_page?' do
|
||||
it 'is true if the user has manage_wiki rights' do
|
||||
course_with_teacher(:active_all => true)
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'teachers', :hide_from_students => true)
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'teachers')
|
||||
page.workflow_state = 'unpublished'
|
||||
page.can_edit_page?(@teacher).should be_true
|
||||
end
|
||||
|
||||
|
@ -181,13 +182,15 @@ describe WikiPage do
|
|||
end
|
||||
|
||||
it 'does not grant teachers or TAs edit rights when editing roles are "Only teachers"' do
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'teachers', :hide_from_students => true)
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'teachers')
|
||||
page.workflow_state = 'unpublished'
|
||||
page.can_edit_page?(@teacher).should be_false
|
||||
page.can_edit_page?(@ta).should be_false
|
||||
end
|
||||
|
||||
it 'grants teachers and TAs edit rights when editing roles are "Teachers and students"' do
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'teachers,students', :hide_from_students => true)
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'teachers,students')
|
||||
page.workflow_state = 'unpublished'
|
||||
page.can_edit_page?(@teacher).should be_true
|
||||
page.can_edit_page?(@ta).should be_true
|
||||
end
|
||||
|
@ -195,79 +198,19 @@ describe WikiPage do
|
|||
|
||||
it 'is true for students who are in the course' do
|
||||
course_with_student(:active_all => true)
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'students', :hide_from_students => false)
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'students')
|
||||
student = @course.students.first
|
||||
page.can_edit_page?(student).should be_true
|
||||
end
|
||||
|
||||
it 'is true for users who are not in the course' do
|
||||
course(:active_all => true)
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'public', :hide_from_students => false)
|
||||
page = @course.wiki.wiki_pages.create(:title => "some page", :editing_roles => 'public')
|
||||
user(:active_all => true)
|
||||
page.can_edit_page?(@user).should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context '#sync_hidden_and_unpublished' do
|
||||
before :each do
|
||||
course :active_all => true
|
||||
@page = @course.wiki.wiki_pages.build(:title => 'Test Page', :url => 'test-page')
|
||||
end
|
||||
|
||||
context 'with draft state disabled' do
|
||||
before :each do
|
||||
@course.account.disable_feature!(:draft_state)
|
||||
end
|
||||
|
||||
it 'should be performed on save' do
|
||||
@page.workflow_state = 'unpublished'
|
||||
@page.hide_from_students = false
|
||||
@page.save!
|
||||
@page.workflow_state.should == 'active'
|
||||
@page.hide_from_students.should be_true
|
||||
@page.reload
|
||||
@page.workflow_state.should == 'active'
|
||||
@page.hide_from_students.should be_true
|
||||
end
|
||||
|
||||
it 'should be performed on load' do
|
||||
@page.save!
|
||||
WikiPage.update_all({:workflow_state => 'unpublished', :hide_from_students => false}, {:id => @page.id})
|
||||
|
||||
@page = @course.wiki.wiki_pages.last
|
||||
@page.workflow_state.should == 'active'
|
||||
@page.hide_from_students.should be_true
|
||||
end
|
||||
end
|
||||
|
||||
context 'with draft state enabled' do
|
||||
before :each do
|
||||
@course.account.allow_feature!(:draft_state)
|
||||
@course.enable_feature!(:draft_state)
|
||||
end
|
||||
|
||||
it 'should be performed on save' do
|
||||
@page.workflow_state = 'active'
|
||||
@page.hide_from_students = true
|
||||
@page.save!
|
||||
@page.workflow_state.should == 'unpublished'
|
||||
@page.hide_from_students.should be_false
|
||||
@page.reload
|
||||
@page.workflow_state.should == 'unpublished'
|
||||
@page.hide_from_students.should be_false
|
||||
end
|
||||
|
||||
it 'should be performed on load' do
|
||||
@page.save!
|
||||
WikiPage.update_all({:workflow_state => 'active', :hide_from_students => true}, {:id => @page.id})
|
||||
|
||||
@page = @course.wiki.wiki_pages.last
|
||||
@page.workflow_state.should == 'unpublished'
|
||||
@page.hide_from_students.should be_false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'initialize_wiki_page' do
|
||||
context 'on a course' do
|
||||
before do
|
||||
|
@ -384,7 +327,7 @@ describe WikiPage do
|
|||
end
|
||||
|
||||
it 'should be given read rights, unless hidden from students' do
|
||||
@page.hide_from_students = true
|
||||
@page.workflow_state = 'unpublished'
|
||||
@page.grants_right?(@user, :read).should be_false
|
||||
end
|
||||
|
||||
|
|
|
@ -66,8 +66,10 @@ require File.expand_path(File.dirname(__FILE__) + '/../common')
|
|||
end
|
||||
end
|
||||
|
||||
def create_wiki_page(title, hfs, edit_roles)
|
||||
@course.wiki.wiki_pages.create(:title => title, :hide_from_students => hfs, :editing_roles => edit_roles, :notify_of_update => true)
|
||||
def create_wiki_page(title, unpublished, edit_roles)
|
||||
wiki_page = @course.wiki.wiki_pages.create(:title => title, :editing_roles => edit_roles, :notify_of_update => true)
|
||||
wiki_page.unpublish! if unpublished
|
||||
wiki_page
|
||||
end
|
||||
|
||||
def select_all_wiki
|
||||
|
|
|
@ -64,11 +64,11 @@ describe "Wiki pages and Tiny WYSIWYG editor" do
|
|||
it "should validate correct permissions for #{permission}" do
|
||||
title = "test_page"
|
||||
title2 = "test_page2"
|
||||
hfs = false
|
||||
unpublished = false
|
||||
edit_roles = "public"
|
||||
validations = ["teachers", "teachers,students", "teachers,students,public"]
|
||||
|
||||
p = create_wiki_page(title, hfs, edit_roles)
|
||||
p = create_wiki_page(title, unpublished, edit_roles)
|
||||
get "/courses/#{@course.id}/wiki/#{p.title}"
|
||||
|
||||
keep_trying_until { f("#wiki_page_new").should be_displayed }
|
||||
|
@ -89,10 +89,10 @@ describe "Wiki pages and Tiny WYSIWYG editor" do
|
|||
|
||||
it "should take user to page history" do
|
||||
title = "test_page"
|
||||
hfs = false
|
||||
unpublished = false
|
||||
edit_roles = "public"
|
||||
|
||||
p = create_wiki_page(title, hfs, edit_roles)
|
||||
p = create_wiki_page(title, unpublished, edit_roles)
|
||||
#sets body
|
||||
p.update_attributes(:body => "test")
|
||||
|
||||
|
@ -107,11 +107,11 @@ describe "Wiki pages and Tiny WYSIWYG editor" do
|
|||
|
||||
it "should load the previous version of the page and roll-back page" do
|
||||
title = "test_page"
|
||||
hfs = false
|
||||
unpublished = false
|
||||
edit_roles = "public"
|
||||
body = "test"
|
||||
|
||||
p = create_wiki_page(title, hfs, edit_roles)
|
||||
p = create_wiki_page(title, unpublished, edit_roles)
|
||||
#sets body and then resets it for history verification
|
||||
p.update_attributes(:body => body)
|
||||
p.update_attributes(:body => "sample")
|
||||
|
@ -133,10 +133,10 @@ describe "Wiki pages and Tiny WYSIWYG editor" do
|
|||
|
||||
it "should restore the latest version of the page" do
|
||||
title = "test_page"
|
||||
hfs = false
|
||||
unpublished = false
|
||||
edit_roles = "public"
|
||||
|
||||
p = create_wiki_page(title, hfs, edit_roles)
|
||||
p = create_wiki_page(title, unpublished, edit_roles)
|
||||
#sets body and then resets it for history verification
|
||||
p.update_attributes(:body => "test")
|
||||
p.update_attributes(:body => "sample")
|
||||
|
@ -155,10 +155,10 @@ describe "Wiki pages and Tiny WYSIWYG editor" do
|
|||
|
||||
it "should take user back to revision history" do
|
||||
title = "test_page"
|
||||
hfs = false
|
||||
unpublished = false
|
||||
edit_roles = "public"
|
||||
|
||||
p = create_wiki_page(title, hfs, edit_roles)
|
||||
p = create_wiki_page(title, unpublished, edit_roles)
|
||||
#sets body and then resets it for history verification
|
||||
p.update_attributes(:body => "test")
|
||||
version = p.versions[1].id
|
||||
|
|
|
@ -162,10 +162,10 @@ describe "Wiki pages and Tiny WYSIWYG editor features" do
|
|||
|
||||
it "should add and remove links" do
|
||||
title = "test_page"
|
||||
hfs = false
|
||||
unpublished = false
|
||||
edit_roles = "public"
|
||||
|
||||
create_wiki_page(title, hfs, edit_roles)
|
||||
create_wiki_page(title, unpublished, edit_roles)
|
||||
|
||||
get "/courses/#{@course.id}/wiki"
|
||||
wait_for_tiny(keep_trying_until { f("#new_wiki_page") })
|
||||
|
|
Loading…
Reference in New Issue