OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Remove patches for document links generation and re-add meetings
Oliver Günther90f2b5157af2
diff --git a/docs/user-guide/wysiwyg/README.md b/docs/user-guide/wysiwyg/README.mdindex c1712b959f5..f56353a48f2 100644--- a/docs/user-guide/wysiwyg/README.md+++ b/docs/user-guide/wysiwyg/README.md@@ -122,6 +122,7 @@ As with the textile formatting syntax, you can link to other resources within Op- **version by ID or name**: `version#3`, `version:"Release 1.0.0"`- **project by ID/name**: `project#12` , `project:"My project name"`- **attachment by filename**: `attachment:filename.zip`+- **meeting by ID/name**: `meeting#12` , `meeting:"My meeting name"`- **document by ID/name**: `document#12` , `document:"My document name"`- **user by id or login**: `user#4` , `user:"johndoe"`- **a forum message by ID**: `message#1218`diff --git a/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb b/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rbindex 536c618d2e4..328aabfb4ae 100644--- a/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb+++ b/lib/open_project/text_formatting/matchers/link_handlers/colon_separator.rb@@ -32,7 +32,7 @@ module OpenProject::TextFormatting::Matchersmodule LinkHandlersclass ColonSeparator < Basedef self.allowed_prefixes- %w(commit source export version project user attachment)+ %w(commit source export version project user attachment document meeting)end##@@ -141,6 +141,36 @@ module OpenProject::TextFormatting::Matcherslink_to_user(user, only_path: context[:only_path], class: 'user-mention')endend++ def render_document+ scope = project ? project.documents : Document+ document = scope+ .visible+ .where(['LOWER(title) = :s', { s: oid.downcase }])+ .first++ if document+ link_to document.title,+ { only_path: context[:only_path],+ controller: '/documents',+ action: 'show',+ id: document.id },+ class: 'document'+ end+ end++ def render_meeting+ scope = project ? project.meetings : Meeting+ meeting = scope+ .where(['LOWER(title) = :s', { s: oid.downcase }])+ .first++ if meeting && meeting.visible?(User.current)+ link_to meeting.title,+ { only_path: context[:only_path], controller: '/meetings', action: 'show', id: meeting.id },+ class: 'meeting'+ end+ endendendenddiff --git a/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb b/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rbindex 08401b7c719..2070dcb8c59 100644--- a/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb+++ b/lib/open_project/text_formatting/matchers/link_handlers/hash_separator.rb@@ -33,7 +33,7 @@ module OpenProject::TextFormatting::Matchersclass HashSeparator < Basedef self.allowed_prefixes- %w(version message project user group)+ %w(version message project user group document meeting)end##@@ -68,6 +68,29 @@ module OpenProject::TextFormatting::Matchersendend+ def render_document+ if document = Document.visible.find_by_id(oid)+ link_to document.title,+ { only_path: context[:only_path],+ controller: '/documents',+ action: 'show',+ id: document },+ class: 'document'+ end+ end++ def render_meeting+ meeting = Meeting.find_by_id(oid)+ if meeting&.visible?(User.current)+ link_to meeting.title,+ { only_path: context[:only_path],+ controller: '/meetings',+ action: 'show',+ id: oid },+ class: 'meeting'+ end+ end+def render_messagemessage = Message.includes(:parent).find_by(id: oid)if messagediff --git a/modules/documents/lib/open_project/documents/engine.rb b/modules/documents/lib/open_project/documents/engine.rbindex 368aff0be03..ac0886a810c 100644--- a/modules/documents/lib/open_project/documents/engine.rb+++ b/modules/documents/lib/open_project/documents/engine.rb@@ -82,9 +82,6 @@ module OpenProject::Documentsrequire_dependency 'document_category'require_dependency 'document_category_custom_field'- ::OpenProject::Documents::Patches::ColonSeparatorPatch.mixin!- ::OpenProject::Documents::Patches::HashSeparatorPatch.mixin!-require_dependency 'open_project/documents/patches/textile_converter_patch'endenddiff --git a/modules/documents/lib/open_project/documents/patches/colon_separator_patch.rb b/modules/documents/lib/open_project/documents/patches/colon_separator_patch.rbdeleted file mode 100644index 13c0f2b8660..00000000000--- a/modules/documents/lib/open_project/documents/patches/colon_separator_patch.rb+++ /dev/null@@ -1,57 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2020 the OpenProject GmbH-#-# 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.-#++--module OpenProject::Documents::Patches- module ColonSeparatorPatch- def self.mixin!- base = ::OpenProject::TextFormatting::Matchers::LinkHandlers::ColonSeparator- base.prepend InstanceMethods- base.singleton_class.prepend ClassMethods- end-- module InstanceMethods- def render_document- name = identifier.gsub(%r{^"(.*)"$}, "\\1")- if document = project.documents.visible.find_by_title(name)- link_to document.title,- { only_path: context[:only_path],- controller: '/documents',- action: 'show',- id: document },- class: 'document'- end- end- end-- module ClassMethods- def allowed_prefixes- super + %w[document]- end- end- end-enddiff --git a/modules/documents/lib/open_project/documents/patches/hash_separator_patch.rb b/modules/documents/lib/open_project/documents/patches/hash_separator_patch.rbdeleted file mode 100644index 5b3190b82ee..00000000000--- a/modules/documents/lib/open_project/documents/patches/hash_separator_patch.rb+++ /dev/null@@ -1,56 +0,0 @@-#-- copyright-# OpenProject is an open source project management software.-# Copyright (C) 2012-2020 the OpenProject GmbH-#-# 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.-#++--module OpenProject::Documents::Patches- module HashSeparatorPatch- def self.mixin!- base = ::OpenProject::TextFormatting::Matchers::LinkHandlers::HashSeparator- base.prepend InstanceMethods- base.singleton_class.prepend ClassMethods- end-- module InstanceMethods- def render_document- if document = Document.visible.find_by_id(oid)- link_to document.title,- { only_path: context[:only_path],- controller: '/documents',- action: 'show',- id: document },- class: 'document'- end- end- end-- module ClassMethods- def allowed_prefixes- super + %w[document]- end- end- end-enddiff --git a/modules/documents/spec/lib/open_project/markdown_formatting_spec.rb b/modules/documents/spec/lib/open_project/markdown_formatting_spec.rbnew file mode 100644index 00000000000..bd1610c18ef--- /dev/null+++ b/modules/documents/spec/lib/open_project/markdown_formatting_spec.rb@@ -0,0 +1,108 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# 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 OpenProject::TextFormatting,+ 'Document links',+ # Speeds up the spec by avoiding event mailers to be procssed+ with_settings: { notified_events: [] } do++ include ActionView::Helpers::UrlHelper # soft-dependency+ include ActionView::Context+ include OpenProject::StaticRouting::UrlHelpers++ def controller+ # no-op+ end++ shared_let(:project) do+ FactoryBot.create :project, enabled_module_names: %w[documents]+ end++ shared_let(:document) do+ FactoryBot.create :document, project: project, title: 'My document'+ end++ subject do+ ::OpenProject::TextFormatting::Renderer.format_text(text, only_path: true)+ end++ before do+ login_as user+ end++ let(:text) do+ <<~TEXT+ document##{document.id}++ document:"My document"+ TEXT+ end++ context 'when visible' do+ let(:role) { FactoryBot.create :role, permissions: %i[view_documents view_project] }+ let(:user) { FactoryBot.create :user, member_in_project: project, member_through_role: role }++ let(:expected) do+ <<~HTML+ <p>#{document_link}</p>++ <p>#{document_link}</p>+ HTML+ end++ let(:document_link) do+ link_to(+ 'My document',+ { controller: '/documents', action: 'show', id: document.id, only_path: true },+ class: 'document'+ )+ end++ it 'renders the links' do+ expect(subject).to be_html_eql(expected)+ end+ end++ context 'when not visible' do+ let(:user) { FactoryBot.create :user }++ let(:expected) do+ <<~HTML+ <p>document##{document.id}</p>++ <p>document:"My document"</p>+ HTML+ end++ it 'renders the raw text' do+ expect(subject).to be_html_eql(expected)+ end+ end+enddiff --git a/modules/meeting/spec/lib/open_project/markdown_formatting_spec.rb b/modules/meeting/spec/lib/open_project/markdown_formatting_spec.rbnew file mode 100644index 00000000000..c2e74dcd8d9--- /dev/null+++ b/modules/meeting/spec/lib/open_project/markdown_formatting_spec.rb@@ -0,0 +1,114 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2020 the OpenProject GmbH+#+# 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 OpenProject::TextFormatting,+ 'Meeting links',+ # Speeds up the spec by avoiding event mailers to be procssed+ with_settings: { notified_events: [] } do++ include ActionView::Helpers::UrlHelper # soft-dependency+ include ActionView::Context+ include OpenProject::StaticRouting::UrlHelpers++ def controller+ # no-op+ end++ shared_let(:project) do+ FactoryBot.create :project, enabled_module_names: %w[meetings]+ end++ shared_let(:meeting) do+ FactoryBot.create :meeting, project: project, title: 'Monthly coordination'+ end++ subject do+ ::OpenProject::TextFormatting::Renderer.format_text(text, only_path: true)+ end++ before do+ login_as user+ end++ let(:text) do+ <<~TEXT+ meeting##{meeting.id}++ meeting:"monthly coordination"++ meeting:"Monthly coordination"+ TEXT+ end++ context 'when visible' do+ let(:role) { FactoryBot.create :role, permissions: %i[view_meetings view_project] }+ let(:user) { FactoryBot.create :user, member_in_project: project, member_through_role: role }++ let(:expected) do+ <<~HTML+ <p>#{meeting_link}</p>++ <p>#{meeting_link}</p>++ <p>#{meeting_link}</p>+ HTML+ end++ let(:meeting_link) do+ link_to(+ 'Monthly coordination',+ { controller: '/meetings', action: 'show', id: meeting.id, only_path: true },+ class: 'meeting'+ )+ end++ it 'renders the links' do+ expect(subject).to be_html_eql(expected)+ end+ end++ context 'when not visible' do+ let(:user) { FactoryBot.create :user }++ let(:expected) do+ <<~HTML+ <p>meeting##{meeting.id}</p>++ <p>meeting:"monthly coordination"</p>++ <p>meeting:"Monthly coordination"</p>+ HTML+ end++ it 'renders the raw text' do+ expect(subject).to be_html_eql(expected)+ end+ end+end