From da1c9dd97b9a729db09d0007458abcc9b2a53040 Mon Sep 17 00:00:00 2001 From: Mark Severson Date: Fri, 26 Jul 2013 16:34:06 -0600 Subject: [PATCH] add new page functionality to pages test plan (course wiki and group wiki): - ensure that enable_draft is set for the account - navigate to the pages index * click the add Page button - ensure the page behaves as expected * editing permissions defaults to the course's setting * enter key (invokes the Save button, unless editing the body) * Save button (creates and navigates to the page) * Cancel button (navigates back to the index, hiding the sidebar) fixes #CNVS-7167 Change-Id: Ib72f4c60e77420197d6e53efbe21ec46d4caf51f Reviewed-on: https://gerrit.instructure.com/22701 Tested-by: Jenkins QA-Review: August Thornton Reviewed-by: Sterling Cobb Product-Review: Matt Goodwin --- .../bundles/wiki_page_edit.coffee | 4 + .../bundles/wiki_page_index.coffee | 2 + app/coffeescripts/models/WikiPage.coffee | 4 +- .../views/wiki/WikiPageEditView.coffee | 9 +- .../views/wiki/WikiPageIndexItemView.coffee | 1 + .../views/wiki/WikiPageIndexView.coffee | 46 +++- app/controllers/application_controller.rb | 23 +- app/controllers/wiki_pages_api_controller.rb | 2 + app/controllers/wiki_pages_controller.rb | 8 +- app/stylesheets/g_wiki.sass | 8 +- app/views/jst/wiki/WikiPageEdit.handlebars | 8 +- app/views/jst/wiki/WikiPageIndex.handlebars | 4 +- app/views/wiki_pages/edit_page.html.erb | 4 - app/views/wiki_pages/pages_index.html.erb | 2 + .../application_controller_spec.rb | 206 ++++++++++++++++++ spec/selenium/wiki_pages_spec.rb | 8 +- 16 files changed, 300 insertions(+), 39 deletions(-) diff --git a/app/coffeescripts/bundles/wiki_page_edit.coffee b/app/coffeescripts/bundles/wiki_page_edit.coffee index 0c9c64e33f1..4aa4ebf6f48 100644 --- a/app/coffeescripts/bundles/wiki_page_edit.coffee +++ b/app/coffeescripts/bundles/wiki_page_edit.coffee @@ -15,4 +15,8 @@ require [ PAGE_RIGHTS: ENV.PAGE_RIGHTS $('#content').append(wikiPageEditView.$el) + wikiPageEditView.on 'cancel', -> + html_url = wikiPage.get('html_url') + window.location.href = html_url if html_url + wikiPageEditView.render() diff --git a/app/coffeescripts/bundles/wiki_page_index.coffee b/app/coffeescripts/bundles/wiki_page_index.coffee index 9b862713c95..93ee80105a3 100644 --- a/app/coffeescripts/bundles/wiki_page_index.coffee +++ b/app/coffeescripts/bundles/wiki_page_index.coffee @@ -15,11 +15,13 @@ require [ view = new WikiPageIndexView collection: new WikiPageCollection contextAssetString: ENV.context_asset_string + default_editing_roles: ENV.DEFAULT_EDITING_ROLES WIKI_RIGHTS: ENV.WIKI_RIGHTS view.collection.fetch({data: {sort:'title',per_page:30}}).then -> view.fetched = true # Re-render after fetching is complete, but only if there are no pages in the collection view.render() if view.collection.models.length == 0 + $('#content').append(view.$el) view.render() diff --git a/app/coffeescripts/models/WikiPage.coffee b/app/coffeescripts/models/WikiPage.coffee index beade11b77d..0bba91398c0 100644 --- a/app/coffeescripts/models/WikiPage.coffee +++ b/app/coffeescripts/models/WikiPage.coffee @@ -9,7 +9,7 @@ define [ resourceName: 'pages' @mixin DefaultUrlMixin - url: -> "#{@_defaultUrl()}/#{@get('url')}" + url: -> "#{@_defaultUrl()}" + if @get('url') then "/#{@get('url')}" else '' initialize: (attributes, options) -> super @@ -33,7 +33,7 @@ define [ # Returns a json representation suitable for presenting present: -> - _.extend _.omit(@toJSON(), 'id'), contextName: @contextName, contextId: @contextId + _.extend _.omit(@toJSON(), 'id'), contextName: @contextName, contextId: @contextId, new_record: !@get('url') # Uses the api to perform a publish on the page publish: -> diff --git a/app/coffeescripts/views/wiki/WikiPageEditView.coffee b/app/coffeescripts/views/wiki/WikiPageEditView.coffee index 17021e4ab79..17b6bb1fceb 100644 --- a/app/coffeescripts/views/wiki/WikiPageEditView.coffee +++ b/app/coffeescripts/views/wiki/WikiPageEditView.coffee @@ -23,7 +23,7 @@ define [ events: 'click a.switch_views': 'switchViews' 'click .delete_page': 'deleteWikiPage' - 'click .form-actions .cancel': 'navigateToPageView' + 'click .form-actions .cancel': 'cancel' @optionProperty 'wiki_pages_path' @optionProperty 'WIKI_RIGHTS' @@ -59,6 +59,8 @@ define [ wikiSidebar.init() $.scrollSidebar() wikiSidebar.attachToEditor(@$wikiPageBody).show() + $ -> + wikiSidebar.show() switchViews: (event) -> event?.preventDefault() @@ -79,10 +81,9 @@ define [ errors - navigateToPageView: (event) -> + cancel: (event) -> event?.preventDefault() - html_url = @model.get('html_url') - window.location.href = html_url if html_url + @trigger('cancel') deleteWikiPage: (event) -> event?.preventDefault() diff --git a/app/coffeescripts/views/wiki/WikiPageIndexItemView.coffee b/app/coffeescripts/views/wiki/WikiPageIndexItemView.coffee index 0812bd22bda..41b1602dfef 100644 --- a/app/coffeescripts/views/wiki/WikiPageIndexItemView.coffee +++ b/app/coffeescripts/views/wiki/WikiPageIndexItemView.coffee @@ -10,6 +10,7 @@ define [ @mixin template: template tagName: 'tr' + className: 'clickable' attributes: role: 'row' els: diff --git a/app/coffeescripts/views/wiki/WikiPageIndexView.coffee b/app/coffeescripts/views/wiki/WikiPageIndexView.coffee index 7bff2c3cd6f..c81cb9c8f73 100644 --- a/app/coffeescripts/views/wiki/WikiPageIndexView.coffee +++ b/app/coffeescripts/views/wiki/WikiPageIndexView.coffee @@ -1,17 +1,19 @@ define [ + 'jquery' + 'wikiSidebar' + 'compiled/models/WikiPage' 'compiled/views/PaginatedCollectionView' + 'compiled/views/wiki/WikiPageEditView' 'compiled/views/wiki/WikiPageIndexItemView' 'jst/wiki/WikiPageIndex' - 'jquery' 'compiled/views/StickyHeaderMixin' 'compiled/str/splitAssetString' 'jquery.disableWhileLoading' -], (PaginatedCollectionView, itemView, template,$, StickyHeaderMixin, splitAssetString) -> +], ($, wikiSidebar, WikiPage, PaginatedCollectionView, WikiPageEditView, itemView, template, StickyHeaderMixin, splitAssetString) -> class WikiPageIndexView extends PaginatedCollectionView @mixin StickyHeaderMixin @mixin - el: '#content' template: template itemView: itemView @@ -19,6 +21,11 @@ define [ 'click .new_page': 'createNewPage' 'click .canvas-sortable-header-row a[data-sort-field]': 'sort' + els: + '.no-pages': '$noPages' + '.no-pages a:first-child': '$noPagesLink' + + @optionProperty 'default_editing_roles' @optionProperty 'WIKI_RIGHTS' initialize: (options) -> @@ -37,10 +44,14 @@ define [ @itemViewOptions ||= {} @itemViewOptions.WIKI_RIGHTS = @WIKI_RIGHTS - contextAssetString = options?.contextAssetString - [@contextName, @contextId] = splitAssetString(contextAssetString) if contextAssetString + @contextAssetString = options?.contextAssetString + [@contextName, @contextId] = splitAssetString(@contextAssetString) if @contextAssetString @itemViewOptions.contextName = @contextName + afterRender: -> + super + @$noPages.redirectClickTo(@$noPagesLink) + sort: (event) -> currentTarget = $(event.currentTarget) currentSortField = @collection.options.params?.sort or "title" @@ -59,7 +70,30 @@ define [ createNewPage: (ev) -> ev?.preventDefault() - alert('This will eventually create a new page') + @$el.hide() + $('body').removeClass('index') + $('body').addClass('edit') + + @editModel = new WikiPage {editing_roles: @default_editing_roles}, contextAssetString: @contextAssetString + @editView = new WikiPageEditView + model: @editModel + wiki_pages_path: ENV.WIKI_PAGES_PATH + WIKI_RIGHTS: ENV.WIKI_RIGHTS + PAGE_RIGHTS: + update: ENV.WIKI_RIGHTS.update_page + update_content: ENV.WIKI_RIGHTS.update_page_content + @$el.parent().append(@editView.$el) + + @editView.render() + + # override the cancel behavior + @editView.on 'cancel', => + @editView.$el.remove() + wikiSidebar.hide() + + $('body').removeClass('edit') + $('body').addClass('index') + @$el.show() toJSON: -> json = super diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 5341afb4c98..c86dca85d81 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1001,14 +1001,23 @@ class ApplicationController < ActionController::Base :title => page_name.titleize, :url => page_name.to_url ) - if @page.new_record? - if @domain_root_account.enable_draft? && !@context.is_a?(Group) - @page.workflow_state = 'unpublished' - else - @page.workflow_state = 'active' - end + initialize_wiki_page + end + + # Initializes the state of @page, but only if it is a new page + def initialize_wiki_page + return unless @page.new_record? || @page.deleted? + + is_privileged_user = is_authorized_action?(@page.wiki, @current_user, :manage) + if is_privileged_user && @domain_root_account.enable_draft? && !@context.is_a?(Group) + @page.workflow_state = 'unpublished' + else + @page.workflow_state = 'active' end - if @page.is_front_page? && @page.new_record? + + @page.editing_roles = (@context.default_wiki_editing_roles rescue nil) || @page.default_roles + + if @page.is_front_page? @page.body = t "#application.wiki_front_page_default_content_course", "Welcome to your new course wiki!" if @context.is_a?(Course) @page.body = t "#application.wiki_front_page_default_content_group", "Welcome to your new group wiki!" if @context.is_a?(Group) end diff --git a/app/controllers/wiki_pages_api_controller.rb b/app/controllers/wiki_pages_api_controller.rb index c304049e085..becc23bb240 100644 --- a/app/controllers/wiki_pages_api_controller.rb +++ b/app/controllers/wiki_pages_api_controller.rb @@ -267,6 +267,8 @@ class WikiPagesApiController < ApplicationController end def get_update_params(allowed_fields=Set[]) + initialize_wiki_page + # normalize parameters page_params = params[:wiki_page] || {} diff --git a/app/controllers/wiki_pages_controller.rb b/app/controllers/wiki_pages_controller.rb index c3c124f448c..90c7a44b0c7 100644 --- a/app/controllers/wiki_pages_controller.rb +++ b/app/controllers/wiki_pages_controller.rb @@ -96,11 +96,8 @@ class WikiPagesController < ApplicationController end def perform_update - if @page.deleted? && @domain_root_account.enable_draft? && !@context.is_a?(Group) - @page.workflow_state = 'unpublished' - elsif @page.deleted? - @page.workflow_state = 'active' - end + initialize_wiki_page + if @page.update_attributes(params[:wiki_page].merge(:user_id => @current_user.id)) log_asset_access(@page, "wiki", @wiki, 'participate') generate_new_page_view @@ -207,6 +204,7 @@ class WikiPagesController < ApplicationController def set_js_wiki_data 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]) if @page diff --git a/app/stylesheets/g_wiki.sass b/app/stylesheets/g_wiki.sass index 46668b9bef7..dcd7e2adc49 100644 --- a/app/stylesheets/g_wiki.sass +++ b/app/stylesheets/g_wiki.sass @@ -95,7 +95,7 @@ $shadow: 0 1px 0 rgba(0,0,0,0.15) :background $item-background :text-decoration inherit :color inherit - &:hover + &.clickable:hover :background $item-hover-background :text-decoration inherit :color inherit @@ -136,6 +136,9 @@ $shadow: 0 1px 0 rgba(0,0,0,0.15) .icon-unpublished :color $unpublished-icon-color + .table .no-pages .no-pages-cell + :border 1px dashed $border-color + .pages.show .toolbar-buttons .publish-button @@ -158,6 +161,9 @@ $shadow: 0 1px 0 rgba(0,0,0,0.15) :color $published-text-color .unpublished :color $unpublished-text-color + .published, .unpublished + :display inline-block + :margin 5px 8px 5px 5px .edit-form :margin 0 diff --git a/app/views/jst/wiki/WikiPageEdit.handlebars b/app/views/jst/wiki/WikiPageEdit.handlebars index 0a45278fed2..05c20a876c5 100644 --- a/app/views/jst/wiki/WikiPageEdit.handlebars +++ b/app/views/jst/wiki/WikiPageEdit.handlebars @@ -25,12 +25,12 @@
- {{#if PAGE_RIGHTS.update}} + {{#ifAny new_record PAGE_RIGHTS.update}} - + {{else}}

{{title}}

- {{/if}} + {{/ifAny}} {{#t "#editor.switch_views"}}Switch Views{{/t}}
@@ -72,7 +72,7 @@ {{#t "notify_users_text"}}Notify users that this content has changed{{/t}} - + {{#t "buttons.cancel"}}Cancel{{/t}}
diff --git a/app/views/jst/wiki/WikiPageIndex.handlebars b/app/views/jst/wiki/WikiPageIndex.handlebars index 51ece3e6cc3..5226ff20f19 100644 --- a/app/views/jst/wiki/WikiPageIndex.handlebars +++ b/app/views/jst/wiki/WikiPageIndex.handlebars @@ -1,7 +1,7 @@
{{#if WIKI_RIGHTS.create_page}} - + {{#t 'buttons.new_page'}}Page{{/t}} {{/if}}
@@ -29,7 +29,7 @@ {{#if fetched}} {{#unless collection.length}} - {{#t 'no_pages'}}No pages created yet.{{/t}} {{#t 'add_page'}}Add one!{{/t}} + {{#t 'no_pages'}}No pages created yet.{{/t}}{{#if WIKI_RIGHTS.create_page}} {{#t 'add_page'}}Add one!{{/t}}{{/if}} {{/unless}} {{/if}} diff --git a/app/views/wiki_pages/edit_page.html.erb b/app/views/wiki_pages/edit_page.html.erb index ee8e510c324..83c0b0345f4 100644 --- a/app/views/wiki_pages/edit_page.html.erb +++ b/app/views/wiki_pages/edit_page.html.erb @@ -8,8 +8,4 @@ <% if reason = @page.locked_for?(@current_user, :context => @context) %>

<%= @page.title %>

<%= lock_explanation(reason, 'page', @context) %> -<% else %> -
<% end %> - -<%= render :partial => "shared/sequence_footer", :locals => {:asset => @page} if @page.context_module_tag_for(@context) %> diff --git a/app/views/wiki_pages/pages_index.html.erb b/app/views/wiki_pages/pages_index.html.erb index 93b9e4e72f5..b208c9ab100 100644 --- a/app/views/wiki_pages/pages_index.html.erb +++ b/app/views/wiki_pages/pages_index.html.erb @@ -1,4 +1,6 @@ <% content_for :page_title, join_title(@context.name, t('titles.pages', 'Pages')) + content_for :right_side, render(:partial => "shared/wiki_sidebar") + jammit_css :tinymce js_bundle :wiki_page_index %> diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index ab5de4ef276..00e09bf3bba 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -194,4 +194,210 @@ describe ApplicationController do @controller.send(:complete_request_uri).should == "https://example.com/api/v1/courses?password=[FILTERED]&test=5&Xaccess_token=13&access_token=[FILTERED]" end end + + describe 'initialize_wiki_page' do + context 'course' do + before(:each) do + @domain_root_account = mock() + @stub_enable_draft = @domain_root_account.stubs(:enable_draft?) + + course_with_teacher_logged_in + @page = @course.wiki.wiki_pages.build(:title => 'Front Page', :url => 'front-page') + + @controller.instance_variable_set(:@domain_root_account, @domain_root_account) + @controller.instance_variable_set(:@current_user, @teacher) + @controller.instance_variable_set(:@context, @course) + @controller.instance_variable_set(:@wiki, @course.wiki) + @controller.instance_variable_set(:@page, @page) + end + + it 'should set the front page body' do + @page.body.should be_nil + @controller.send :initialize_wiki_page + @page.body.should_not be_empty + end + + context 'draft not enabled' do + before(:each) do + @stub_enable_draft.returns(false) + end + + it 'should initialize a new page' do + @page.should be_new_record + + @page.expects(:workflow_state=).with('active') + @controller.send :initialize_wiki_page + end + + it 'should initialize a deleted page' do + @page.workflow_state = 'deleted' + @page.save! + @page.should be_deleted + + @page.expects(:workflow_state=).with('active') + @controller.send :initialize_wiki_page + end + + it 'should not initialize an unpublished page' do + @page.workflow_state = 'unpublished' + @page.save! + @page.should be_unpublished + + @page.expects(:workflow_state=).never + @controller.send :initialize_wiki_page + end + + it 'should not initialize an active page' do + @page.workflow_state = 'active' + @page.save! + @page.should be_active + + @page.expects(:workflow_state=).never + @controller.send :initialize_wiki_page + end + end + + context 'draft enabled' do + before(:each) do + @stub_enable_draft.returns(true) + end + + it 'should initialize a new page' do + @page.should be_new_record + + @page.expects(:workflow_state=).with('unpublished') + @controller.send :initialize_wiki_page + end + + it 'should initialize a deleted page' do + @page.workflow_state = 'deleted' + @page.save! + @page.should be_deleted + + @page.expects(:workflow_state=).with('unpublished') + @controller.send :initialize_wiki_page + end + + it 'should not initialize an unpublished page' do + @page.workflow_state = 'unpublished' + @page.save! + @page.should be_unpublished + + @page.expects(:workflow_state=).never + @controller.send :initialize_wiki_page + end + + it 'should not initialize an active page' do + @page.workflow_state = 'active' + @page.save! + @page.should be_active + + @page.expects(:workflow_state=).never + @controller.send :initialize_wiki_page + end + end + end + + context 'group' do + before(:each) do + @domain_root_account = mock() + @stub_enable_draft = @domain_root_account.stubs(:enable_draft?) + + group_with_user_logged_in + @page = @group.wiki.wiki_pages.build(:title => 'Front Page', :url => 'front-page') + + @controller.instance_variable_set(:@domain_root_account, @domain_root_account) + @controller.instance_variable_set(:@current_user, @user) + @controller.instance_variable_set(:@context, @group) + @controller.instance_variable_set(:@wiki, @group.wiki) + @controller.instance_variable_set(:@page, @page) + end + + it 'should set the front page body' do + @page.body.should be_nil + @controller.send :initialize_wiki_page + @page.body.should_not be_empty + end + + context 'draft not enabled' do + before(:each) do + @stub_enable_draft.returns(false) + end + + it 'should initialize a new page' do + @page.should be_new_record + + @page.expects(:workflow_state=).with('active') + @controller.send :initialize_wiki_page + end + + it 'should initialize a deleted page' do + @page.workflow_state = 'deleted' + @page.save! + @page.should be_deleted + + @page.expects(:workflow_state=).with('active') + @controller.send :initialize_wiki_page + end + + it 'should not initialize an unpublished page' do + @page.workflow_state = 'unpublished' + @page.save! + @page.should be_unpublished + + @page.expects(:workflow_state=).never + @controller.send :initialize_wiki_page + end + + it 'should not initialize an active page' do + @page.workflow_state = 'active' + @page.save! + @page.should be_active + + @page.expects(:workflow_state=).never + @controller.send :initialize_wiki_page + end + end + + context 'draft enabled' do + before(:each) do + @stub_enable_draft.returns(true) + end + + it 'should initialize a new page' do + @page.should be_new_record + + @page.expects(:workflow_state=).with('active') + @controller.send :initialize_wiki_page + end + + it 'should initialize a deleted page' do + @page.workflow_state = 'deleted' + @page.save! + @page.should be_deleted + + @page.expects(:workflow_state=).with('active') + @controller.send :initialize_wiki_page + end + + it 'should not initialize an unpublished page' do + @page.workflow_state = 'unpublished' + @page.save! + @page.should be_unpublished + + @page.expects(:workflow_state=).never + @controller.send :initialize_wiki_page + end + + it 'should not initialize an active page' do + @page.workflow_state = 'active' + @page.save! + @page.should be_active + + @page.expects(:workflow_state=).never + @controller.send :initialize_wiki_page + end + end + end + end end diff --git a/spec/selenium/wiki_pages_spec.rb b/spec/selenium/wiki_pages_spec.rb index 8c8afdd1cc7..468f0eb7446 100644 --- a/spec/selenium/wiki_pages_spec.rb +++ b/spec/selenium/wiki_pages_spec.rb @@ -12,11 +12,11 @@ describe "Navigating to wiki pages" 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) - f(".edit-wiki").click - wait_for_dom_ready do - check_domready.should be_true - driver.current_url.should == edit_url + + expect_new_page_load do + f(".edit-wiki").click end + driver.current_url.should == edit_url end end end