Merge pull request #7515 from opf/feature/remove_wiki_include_macro

Feature/remove wiki include macro

[ci skip]
pull/7522/head
Oliver Günther 5 years ago committed by GitHub
commit 57c93971eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/assets/javascripts/vendor/ckeditor/ckeditor.js
  2. 2
      app/assets/javascripts/vendor/ckeditor/ckeditor.js.map
  3. 3
      config/locales/en.yml
  4. 2
      lib/open_project/text_formatting/filters/macros/child_pages/child_pages_context.rb
  5. 46
      lib/open_project/text_formatting/filters/macros/include_wiki_page.rb
  6. 124
      spec/features/wysiwyg/macros/include_wiki_page_spec.rb
  7. 139
      spec/lib/open_project/macros/include_wiki_page_macro_spec.rb

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -1740,9 +1740,10 @@ en:
legacy_warning:
timeline: 'This legacy timeline macro has been removed and is no longer available. You can replace the functionality with an embedded table macro.'
include_wiki_page:
removed: 'The macro does no longer exist.'
wiki_child_pages:
errors:
page_not_found: "Cannot find the wiki page '%{name}'."
circular_inclusion: "Circular inclusion of pages detected."
create_work_package_link:
errors:
no_project_context: 'Calling create_work_package_link macro from outside project context.'

@ -41,7 +41,7 @@ module OpenProject::TextFormatting::Filters::Macros::ChildPages
def check
if @page.nil? || !@user.allowed_to?(:view_wiki_pages, @page.wiki.project)
raise I18n.t('macros.include_wiki_page.errors.page_not_found', name: @page_value)
raise I18n.t('macros.wiki_child_pages.errors.page_not_found', name: @page_value)
end
end

@ -38,50 +38,8 @@ module OpenProject::TextFormatting::Filters::Macros
HTML_CLASS
end
def apply(macro, result:, context:)
args = macro['data-page']
raise I18n.t('macros.errors.missing_or_invalid_parameter') unless args.present?
page = Wiki.find_page(args, project: context[:project])
user = context[:current_user]
if page.nil? || !user.allowed_to?(:view_wiki_pages, page.wiki.project)
raise I18n.t('macros.include_wiki_page.errors.page_not_found', name: args)
end
# We remember the already included wiki pages in this run in:
# - the result object for this current run
# - the context of all contained inclusion runs, since result is reset in each pipeline instance.
result[:included_wiki_pages] ||= context[:included_wiki_pages] || []
if result[:included_wiki_pages].include?(args)
raise I18n.t('macros.include_wiki_page.errors.circular_inclusion')
end
result[:included_wiki_pages] << args
out = format_included_page(page, context, result)
result[:included_wiki_pages].pop
# Wrap result in section so we could, e.g., highlight it
macro.replace ApplicationController.helpers.content_tag :section,
out,
class: 'macros--included-wiki-page',
data: { 'page-name': args }
end
##
# Format included wiki page
def format_included_page(page, context, result)
OpenProject::TextFormatting::Renderer.format_text(
page.content.text,
context.merge(
included_wiki_pages: result[:included_wiki_pages],
# Markdown handler currently does no inline_attachments_parsing. Still needed?
attachments: page.attachments,
headings: false
)
)
def apply(*)
raise I18n.t('macros.include_wiki_page.removed')
end
end
end

@ -1,124 +0,0 @@
#-- encoding: UTF-8
#-- copyright
# OpenProject is a project management system.
# Copyright (C) 2012-2018 the OpenProject Foundation (OPF)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License version 3.
#
# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
# Copyright (C) 2006-2017 Jean-Philippe Lang
# Copyright (C) 2010-2013 the ChiliProject Team
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See docs/COPYRIGHT.rdoc for more details.
#++
require 'spec_helper'
describe 'Wysiwyg include wiki page spec',
type: :feature, js: true do
let(:project) {
FactoryBot.create :project,
enabled_module_names: %w[wiki]
}
let(:role) { FactoryBot.create(:role, permissions: %i[view_wiki_pages edit_wiki_pages]) }
let(:user) {
FactoryBot.create(:user, member_in_project: project, member_through_role: role)
}
let(:wiki_page) {
FactoryBot.create :wiki_page,
title: 'Test',
content: FactoryBot.build(:wiki_content, text: '# My page')
}
let(:included_page) {
FactoryBot.create :wiki_page,
title: 'Included',
content: FactoryBot.build(:wiki_content, text: '# included page')
}
before do
login_as(user)
project.wiki.pages << wiki_page
project.wiki.pages << included_page
project.wiki.save!
end
let(:editor) { ::Components::WysiwygEditor.new }
before do
login_as(user)
end
describe 'in wikis' do
describe 'creating a wiki page' do
before do
visit edit_project_wiki_path(project, :test)
end
it 'can add and edit an include page widget' do
editor.in_editor do |container, editable|
expect(editable).to have_selector('h1', text: 'My page')
# strangely, we need visible: :all here
editor.insert_macro 'Include content of another wiki page'
expect(page).to have_selector('.op-modal--macro-modal')
fill_in 'selected-page', with: 'included'
# Cancel editing
find('.op-modal--cancel-button').click
expect(editable).to have_no_selector('.macro.-wiki_page_include')
editor.insert_macro 'Include content of another wiki page'
fill_in 'selected-page', with: 'included'
# Save widget
find('.op-modal--submit-button').click
# Find widget, click to show toolbar
placeholder = find('.macro.-wiki_page_include')
# Placeholder states `included`
expect(placeholder).to have_text('included')
# Edit widget again
placeholder.click
page.find('.ck-balloon-panel .ck-button', visible: :all, text: 'Edit').click
expect(page).to have_field('selected-page', with: 'included')
find('.op-modal--cancel-button').click
end
# Save wiki page
click_on 'Save'
expect(page).to have_selector('.flash.notice')
within('#content') do
expect(page).to have_selector('section.macros--included-wiki-page')
expect(page).to have_selector('section.macros--included-wiki-page h1', text: 'included page')
expect(page).to have_selector('h1', text: 'My page')
end
end
end
end
end

@ -37,57 +37,13 @@ describe 'OpenProject include wiki page macro' do
# no-op
end
let(:project) {
FactoryBot.create :project,
enabled_module_names: %w[wiki]
}
let(:other_project) {
FactoryBot.create :valid_project,
identifier: 'other-project',
enabled_module_names: %w[wiki]
}
let(:role) { FactoryBot.create(:role, permissions: [:view_wiki_pages]) }
let(:user) {
FactoryBot.create(:user, member_in_project: project, member_through_role: role)
}
let(:included_page_other_project) {
FactoryBot.create :wiki_page,
title: 'Include Test',
content: FactoryBot.build(:wiki_content, text: '# Included from other project')
}
let(:wiki_page) {
FactoryBot.create :wiki_page,
title: 'Test',
content: FactoryBot.build(:wiki_content, text: '# My page')
}
let(:included_page) {
FactoryBot.create :wiki_page,
title: 'Included',
content: FactoryBot.build(:wiki_content, text: '# included from same project')
}
before do
login_as(user)
project.wiki.pages << wiki_page
project.wiki.pages << included_page
project.wiki.save!
other_project.wiki.pages << included_page_other_project
other_project.wiki.save!
let(:project) do
FactoryBot.build_stubbed :project
end
let(:input) { }
let(:input) {}
subject { format_text(input, project: project) }
before do
login_as user
end
def error_html(exception_msg)
"<p><macro class=\"macro-unavailable\" data-macro-name=\"include_wiki_page\">" \
"Error executing the macro include_wiki_page (#{exception_msg})</macro></p>"
@ -98,93 +54,8 @@ describe 'OpenProject include wiki page macro' do
it { is_expected.to be_html_eql("<p>#{input}</p>") }
end
context 'when nothing passed' do
let(:input) { '<macro class="include_wiki_page"></macro>' }
it { is_expected.to be_html_eql(error_html('Missing or invalid macro parameter.')) }
end
context 'with invalid page' do
let(:input) { '<macro class="include_wiki_page" data-page="Invalid"></macro>' }
it { is_expected.to be_html_eql(error_html("Cannot find the wiki page 'Invalid'.")) }
end
context 'with valid page in same project' do
let(:input) { '<macro class="include_wiki_page" data-page="included"></macro>' }
it do
is_expected.to be_html_eql('
<p>
<section class="macros--included-wiki-page" data-page-name="included">
<h1 id="included-from-same-project">
<a class="wiki-anchor icon-paragraph" href="#included-from-same-project" aria-hidden="true">
</a>
included from same project
</h1>
</section>
</p>
')
end
end
context 'with circular inclusion' do
let(:included_page) {
FactoryBot.create :wiki_page,
title: 'Included',
content: FactoryBot.build(:wiki_content,
text: '<macro class="include_wiki_page" data-page="test"></macro>')
}
let(:wiki_page) {
FactoryBot.create :wiki_page,
title: 'Test',
content: FactoryBot.build(:wiki_content,
text: '<macro class="include_wiki_page" data-page="included"></macro>')
}
context 'with the new but also no longer supported syntax' do
let(:input) { '<macro class="include_wiki_page" data-page="included"></macro>' }
it 'includes two pagesuntil it results in a circular dependency' do
is_expected.to be_html_eql('
<p>
<section class="macros--included-wiki-page" data-page-name="included">
<p>
<section class="macros--included-wiki-page" data-page-name="test">
<p>
<macro class="macro-unavailable" data-macro-name="include_wiki_page">
Error executing the macro include_wiki_page (Circular inclusion of pages detected.)
</macro>
</p>
</section>
</p>
</section>
</p>
')
end
end
context 'with link to page in invisible project' do
let(:input) { '<macro class="include_wiki_page" data-page="other-project:include-test"></macro>' }
it { is_expected.to be_html_eql(error_html("Cannot find the wiki page 'other-project:include-test'.")) }
end
context 'with permissions in other project' do
let(:role) { FactoryBot.create(:role, permissions: [:view_wiki_pages]) }
let(:user) {
FactoryBot.create(:user, member_in_projects: [project, other_project], member_through_role: role)
}
context 'can include other page' do
let(:input) { '<macro class="include_wiki_page" data-page="other-project:include-test"></macro>' }
it do
is_expected.to be_html_eql('
<p>
<section class="macros--included-wiki-page" data-page-name="other-project:include-test">
<h1 id="included-from-other-project">
<a class="wiki-anchor icon-paragraph" href="#included-from-other-project" aria-hidden="true">
</a>
Included from other project
</h1>
</section>
</p>
')
end
end
it { is_expected.to be_html_eql(error_html("The macro does no longer exist.")) }
end
end

Loading…
Cancel
Save