Skip to content

Instantly share code, notes, and snippets.

@RoRElessar
Created July 25, 2017 16:17
Show Gist options
  • Select an option

  • Save RoRElessar/f0b29f77f04f01b88d55512bbeb0bed4 to your computer and use it in GitHub Desktop.

Select an option

Save RoRElessar/f0b29f77f04f01b88d55512bbeb0bed4 to your computer and use it in GitHub Desktop.

Revisions

  1. RoRElessar created this gist Jul 25, 2017.
    77 changes: 77 additions & 0 deletions WikiPage.handlebars
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,77 @@
    //app/views/jst/wiki/WikiPage.handlebars

    {{#if CAN.VIEW_TOOLBAR}}
    <div class="header-bar-outer-container">
    <div class="header-bar-container sticky-toolbar" data-sticky>
    <div class="header-bar flex-container">
    <div class="header-bar-left header-left-flex">
    {{#if course_home}}
    <h2 class="course-title ellipsis" title="{{course_title}}">{{course_title}}</h2>
    {{else}}
    {{#if CAN.VIEW_ALL_PAGES}}
    //REMOVED CODE FROM HERE
    {{/if}}
    {{/if}}
    </div>
    <div class="header-bar-right header-right-flex">
    {{#unless course_home}}
    {{#if front_page}}
    <span class="front-page label">{{#t 'labels.front_page'}}Front Page{{/t}}</span>
    {{/if}}
    {{#if CAN.PUBLISH}}
    <span class="publish-button"></span>
    {{else}}
    {{#if CAN.VIEW_UNPUBLISHED}}
    {{#if published}}
    <span class='published-status published'>
    <i class="icon-publish"></i> {{#t 'published_indicator'}}Published{{/t}}
    </span>
    {{else}}
    <span class='published-status unpublished'>
    <i class="icon-unpublished"></i> {{#t 'unpublished_indicator'}}Not Published{{/t}}
    </span>
    {{/if}}
    {{/if}}
    {{/if}}
    {{/unless}}
    {{#if CAN.UPDATE_CONTENT}}
    <a href="{{wiki_page_edit_path}}" class="btn edit-wiki"><i class="icon-edit"></i> {{#t 'buttons.edit'}}Edit{{/t}}</a>
    {{/if}}
    {{#if CAN.ACCESS_GEAR_MENU}}
    <div class="inline-block">
    <a class="btn al-trigger" tabindex="0" role="button" href="#">
    <i class="icon-settings"></i><i class="icon-mini-arrow-down"></i>
    <span class="screenreader-only">{{#t 'toolbar_menu.settings'}}Settings{{/t}}</span>
    </a>
    <ul class="al-options">
    {{#unless cannot_edit_by_master_course}}
    {{#if CAN.DELETE}}
    <li><a href="#" class="icon-trash delete_page{{#unless deletable}} disabled{{/unless}}" {{#unless deletable}}aria-disabled="true"{{/unless}}>{{#t "delete_wiki"}}Delete{{/t}}</a></li>
    {{/if}}
    {{/unless}}
    {{#if CAN.READ_REVISIONS}}
    <li><a href="{{wiki_page_history_path}}" class="icon-clock view_page_history">{{#t "view_page_history_wiki"}}View Page History{{/t}}</a></li>
    {{/if}}
    {{#unless front_page}}
    <li><a href="#" class="icon-document use-as-front-page-menu-item{{#unless published}} disabled{{/unless}}" title="{{#t 'menu.use_front_page'}}Use as Front Page{{/t}}" {{#unless published}}aria-disabled="true"{{/unless}}>{{#t 'menu.use_front_page'}}Use as Front Page{{/t}}</a></li>
    {{/unless}}
    {{>ExternalTools/external_tools_menu wiki_page_menu_tools}}
    </ul>
    </div>
    {{/if}}
    </div>
    </div>
    <div class="page-changed-alert" role="alert" aria-atomic="true" aria-live="polite"></div>
    </div>
    </div>
    {{/if}}

    <div class="show-content user_content clearfix">
    <h1 class="page-title">{{title}}</h1>
    {{#if locked_for_user}}
    <div class="spinner"></div>
    <div class="lock_explanation"></div>
    {{else}}
    {{convertApiUserContent body}}
    {{/if}}
    </div>
    20 changes: 20 additions & 0 deletions section_tab_helper.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #app/helpers/section_tab_helper.rb

    def section_tabs
    @section_tabs ||= begin
    if @context && available_section_tabs(@context).any?
    content_tag(:nav, {
    :role => 'navigation',
    :'aria-label' => nav_name
    }) do
    concat(content_tag(:ul, id: 'section-tabs') do
    available_section_tabs(@context).map do |tab|
    #add if statement to section_tab_tag below
    section_tab_tag(tab, @context, @active_tab) if tab[:css_class] != 'pages'
    end
    end)
    end
    end
    end
    raw(@section_tabs)
    end
    186 changes: 186 additions & 0 deletions wiki_changes_controller.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,186 @@
    #app/controllers/wiki_pages_controller.rb

    #
    # Copyright (C) 2011 - present 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 WikiPagesController < ApplicationController
    include Api::V1::WikiPage
    include KalturaHelper
    include SubmittableHelper

    before_action :require_context
    before_action :get_wiki_page, :except => [:front_page]
    before_action :set_front_page, :only => [:front_page]
    before_action :set_pandapub_read_token
    before_action :set_js_rights
    before_action :set_js_wiki_data
    before_action :rich_content_service_config, only: [:edit, :index]
    before_action :page_crumbs

    # add_crumb(proc { t '#crumbs.wiki_pages', "Pages"}) do |c|
    # add_crumb(proc { t "Modules"}) do |c|
    # context = c.instance_variable_get('@context')
    # current_user = c.instance_variable_get('@current_user')
    # if context.grants_right?(current_user, :read)
    # # c.send :polymorphic_path, [context, :wiki_pages]
    # c.send :polymorphic_path, [context, :wiki_pages]
    # end
    # end


    # before_action { |c| c.active_tab = "pages" }
    before_action { |c| c.active_tab = "modules" }

    def js_rights
    [:wiki, :page]
    end

    def set_pandapub_read_token
    if @page && @page.grants_right?(@current_user, session, :read)
    if CanvasPandaPub.enabled?
    channel = "/private/wiki_page/#{@page.global_id}/update"
    js_env :WIKI_PAGE_PANDAPUB => {
    :CHANNEL => channel,
    :TOKEN => CanvasPandaPub.generate_token(channel, true)
    }
    end
    end
    end

    def set_front_page
    @wiki = @context.wiki
    @page = @wiki.front_page
    end

    def front_page
    return unless authorized_action(@context.wiki, @current_user, :read) && tab_enabled?(@context.class::TAB_PAGES)

    if @page && !@page.new_record?
    wiki_page_jsenv(@context)
    @padless = true
    render template: 'wiki_pages/show'
    else
    redirect_to polymorphic_url([@context, :wiki_pages])
    end
    end

    def index
    if authorized_action(@context.wiki, @current_user, :read) && tab_enabled?(@context.class::TAB_PAGES)
    log_asset_access([ "pages", @context ], "pages", "other")
    js_env ConditionalRelease::Service.env_for @context
    if @context.root_account.feature_enabled?(:student_planner)
    js_env :student_planner_enabled => @context.grants_any_right?(@current_user, session, :manage)
    end
    js_env :wiki_page_menu_tools => external_tools_display_hashes(:wiki_page_menu)
    set_tutorial_js_env
    @padless = true
    end
    end

    def show
    if @page.new_record?
    if @page.grants_any_right?(@current_user, session, :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)
    encoded_name = @page_name && CGI.escape(@page_name).gsub("+", " ")
    redirect_to polymorphic_url([@context, :wiki_page], id: encoded_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?
    flash[:warning] = t('notices.page_deleted', 'The page "%{title}" has been deleted.', :title => @page.title)
    else
    flash[:warning] = t('notices.page_does_not_exist', 'The page "%{title}" does not exist.', :title => @page.title)
    end
    redirect_to polymorphic_url([@context, :wiki_pages])
    end
    return
    end

    if authorized_action(@page, @current_user, :read)
    if !@context.feature_enabled?(:conditional_release) || enforce_assignment_visible(@page)
    add_crumb(@page.title)
    log_asset_access(@page, 'wiki', @wiki)
    wiki_page_jsenv(@context)
    set_master_course_js_env_data(@page, @context)
    @mark_done = MarkDonePresenter.new(self, @context, params["module_item_id"], @current_user, @page)
    @padless = true
    end
    end
    end

    def edit
    if @page.grants_any_right?(@current_user, session, :update, :update_content)
    set_master_course_js_env_data(@page, @context)

    js_env ConditionalRelease::Service.env_for @context
    if @context.root_account.feature_enabled?(:student_planner)
    js_env :student_planner_enabled => @page.context.grants_any_right?(@current_user, session, :manage)
    end
    if !ConditionalRelease::Service.enabled_in_context?(@context) ||
    enforce_assignment_visible(@page)
    add_crumb(@page.title)
    @padless = true
    end
    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, @page])
    end
    end
    end

    def revisions
    if @page.grants_right?(@current_user, session, :read_revisions)
    if !@context.feature_enabled?(:conditional_release) || enforce_assignment_visible(@page)
    add_crumb(@page.title, polymorphic_url([@context, @page]))
    add_crumb(t("#crumbs.revisions", "Revisions"))

    @padless = true
    end
    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, @page])
    end
    end
    end

    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

    private
    def rich_content_service_config
    rce_js_env(:sidebar)
    end

    def wiki_page_jsenv(context)
    js_env :wiki_page_menu_tools => external_tools_display_hashes(:wiki_page_menu)
    js_env :DISPLAY_SHOW_ALL_LINK => tab_enabled?(context.class::TAB_PAGES, {no_render: true})
    end

    #New method
    def page_crumbs
    id = params[:course_id]
    add_crumb('Modules', "/courses/#{id}/modules")
    end

    end