remove default_wiki_wiki_pages relations fixes #10993

it was a has_many :through that is broken for auto-created wikis

existing specs cover all changes except /undelete page, which
is unsupported

test plan:
 * ensure user's rss feed can be opened correctly
 * ensure wiki sidebar loads and has wiki pages in it

Change-Id: I7c3f0f68641b67f602e6b412ab5a386140bb68b2
Reviewed-on: https://gerrit.instructure.com/14023
Tested-by: Jenkins <jenkins@instructure.com>
Reviewed-by: Jeremy Stanley <jeremy@instructure.com>
This commit is contained in:
Cody Cutrer 2012-09-28 09:52:32 -06:00
parent 68d6268752
commit a993ba3cbb
6 changed files with 22 additions and 22 deletions

View File

@ -398,22 +398,22 @@ class ContextController < ApplicationController
def undelete_index
if authorized_action(@context, @current_user, :manage_content)
@item_types = {
:discussion_topics => ['workflow_state = ?', 'deleted'],
:assignments => ['workflow_state = ?', 'deleted'],
:assignment_groups => ['workflow_state = ?', 'deleted'],
:enrollments => ['workflow_state = ?', 'deleted'],
:default_wiki_wiki_pages => ['workflow_state = ?', 'deleted'],
:attachments => ['file_state = ?', 'deleted'],
:rubrics => ['workflow_state = ?', 'deleted'],
:collaborations => ['workflow_state = ?', 'deleted'],
:quizzes => ['workflow_state = ?', 'deleted'],
:context_modules => ['workflow_state = ?', 'deleted']
}
@item_types = [
@context.discussion_topics,
@context.assignments,
@context.assignment_groups,
@context.enrollments,
@context.wiki.wiki_pages,
@context.rubrics,
@context.collaborations,
@context.quizzes,
@context.context_modules
]
@deleted_items = []
@item_types.each do |type, conditions|
@deleted_items += @context.send(type).find(:all, :conditions => conditions, :limit => 25) rescue []
@item_types.each do |scope|
@deleted_items += scope.find(:all, :conditions => "workflow_state='deleted'", :limit => 25)
end
@deleted_items += @context.attachments.find(:all, :conditions => "file_state='deleted'", :limit => 25)
@deleted_items.sort_by{|item| item.read_attribute(:deleted_at) || item.created_at }.reverse
end
end
@ -423,8 +423,9 @@ class ContextController < ApplicationController
type = params[:asset_string].split("_")
id = type.pop
type = type.join("_")
type = 'default_wiki_wiki_pages' if type == 'wiki_pages'
@item = @context.send(type.pluralize).find(id)
scope = @context
scope = @context.wiki if type == 'wiki_pages'
@item = scope.send(type.pluralize).find(id)
@item.restore
render :json => @item
end

View File

@ -1134,7 +1134,7 @@ class UsersController < ApplicationController
@entries.concat context.assignments.active
@entries.concat context.calendar_events.active
@entries.concat context.discussion_topics.active
@entries.concat context.default_wiki_wiki_pages.select{|p| !p.deleted? }
@entries.concat context.wiki.wiki_pages.not_deleted
end
@entries = @entries.select{|e| e.updated_at > 1.weeks.ago }
@entries.each do |entry|

View File

@ -275,9 +275,11 @@ module ApplicationHelper
return if @wiki_sidebar_data
logger.warn "database lookups happening in view code instead of controller code for wiki sidebar (load_wiki_sidebar)"
@wiki_sidebar_data = {}
includes = [:default_wiki_wiki_pages, :active_assignments, :active_discussion_topics, :active_quizzes, :active_context_modules]
includes = [:active_assignments, :active_discussion_topics, :active_quizzes, :active_context_modules]
includes.each{|i| @wiki_sidebar_data[i] = @context.send(i).scoped({:limit => 150}) if @context.respond_to?(i) }
includes.each{|i| @wiki_sidebar_data[i] ||= [] }
@wiki_sidebar_data[:wiki_pages] = @context.wiki.wiki_pages.active.scoped(:order => 'title', :limit => 150) if @context.respond_to?(:wiki)
@wiki_sidebar_data[:wiki_pages] ||= []
@wiki_sidebar_data[:root_folders] = Folder.root_folders(@context)
@wiki_sidebar_data
end

View File

@ -138,7 +138,6 @@ class Course < ActiveRecord::Base
has_many :messages, :as => :context, :dependent => :destroy
has_many :context_external_tools, :as => :context, :dependent => :destroy, :order => 'name'
belongs_to :wiki
has_many :default_wiki_wiki_pages, :class_name => 'WikiPage', :through => :wiki, :source => :wiki_pages, :conditions => ['wiki_pages.workflow_state != ?', 'deleted'], :order => 'wiki_pages.view_count DESC'
has_many :quizzes, :as => :context, :dependent => :destroy, :order => 'lock_at, title'
has_many :active_quizzes, :class_name => 'Quiz', :as => :context, :include => :assignment, :conditions => ['quizzes.workflow_state != ?', 'deleted'], :order => 'created_at'
has_many :assessment_questions, :through => :assessment_question_banks

View File

@ -51,8 +51,6 @@ class Group < ActiveRecord::Base
has_many :external_feeds, :as => :context, :dependent => :destroy
has_many :messages, :as => :context, :dependent => :destroy
belongs_to :wiki
has_many :default_wiki_wiki_pages, :class_name => 'WikiPage', :through => :wiki, :source => :wiki_pages
has_many :active_default_wiki_wiki_pages, :class_name => 'WikiPage', :through => :wiki, :source => :wiki_pages, :conditions => ['wiki_pages.workflow_state = ?', 'active']
has_many :web_conferences, :as => :context, :dependent => :destroy
has_many :collaborations, :as => :context, :order => 'title, created_at', :dependent => :destroy
has_one :scribd_account, :as => :scribdable

View File

@ -41,7 +41,7 @@
<h5 class="header"><a href="#"><%= t('links_to.wiki_pages', %{Wiki Pages}) %></a></h5>
<div>
<ul class="wiki_pages page_list">
<% (@wiki_sidebar_data[:default_wiki_wiki_pages].select{|p| p.active? }.sort_by{|p| p.title || "" } rescue []).each do |wiki_page| %>
<% (@wiki_sidebar_data[:wiki_pages]).each do |wiki_page| %>
<% if !wiki_page.hide_from_students || can_do(@context, @current_user, :manage_content) %>
<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 %>