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
Add project journal attribute for visibility
Mir Bhatia328c17f69ef1
diff --git a/app/models/journal.rb b/app/models/journal.rbindex 6028b508b34..2ea1b284f01 100644--- a/app/models/journal.rb+++ b/app/models/journal.rb@@ -41,6 +41,8 @@ class Journal < ApplicationRecordregister_journal_formatter :ignore_non_working_days, OpenProject::JournalFormatter::IgnoreNonWorkingDaysregister_journal_formatter :active_status, OpenProject::JournalFormatter::ActiveStatusregister_journal_formatter :template, OpenProject::JournalFormatter::Template+ register_journal_formatter :visibility, OpenProject::JournalFormatter::Visibility+# Make sure each journaled model instance only has unique version idsvalidates :version, uniqueness: { scope: %i[journable_id journable_type] }diff --git a/app/models/project.rb b/app/models/project.rbindex 6b12e5b9560..c625ff742a8 100644--- a/app/models/project.rb+++ b/app/models/project.rb@@ -109,6 +109,7 @@ class Project < ApplicationRecordregister_on_journal_formatter(:plaintext, 'identifier')register_on_journal_formatter(:plaintext, 'name')register_on_journal_formatter(:diff, 'description')+ register_on_journal_formatter(:visibility, 'public')has_paper_traildiff --git a/lib/open_project/journal_formatter/visibility.rb b/lib/open_project/journal_formatter/visibility.rbnew file mode 100644index 00000000000..bc6289c5e19--- /dev/null+++ b/lib/open_project/journal_formatter/visibility.rb@@ -0,0 +1,36 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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-2013 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 COPYRIGHT and LICENSE files for more details.+#++++class OpenProject::JournalFormatter::Visibility < JournalFormatter::Base+ def render(_key, values, options = { html: true })+ label_text = options[:html] ? content_tag('strong', "Visibility") : "Visibility"+ activated_text = "set to #{values.last ? 'public' : 'private'}"++ I18n.t(:text_journal_label_value, label: label_text, value: activated_text)+ end+enddiff --git a/spec/lib/journal_formatter/visibility_spec.rb b/spec/lib/journal_formatter/visibility_spec.rbnew file mode 100644index 00000000000..07a197bc6e2--- /dev/null+++ b/spec/lib/journal_formatter/visibility_spec.rb@@ -0,0 +1,47 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2023 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-2013 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 COPYRIGHT and LICENSE files for more details.+#++++require File.expand_path("#{File.dirname(__FILE__)}/../../spec_helper.rb")++describe OpenProject::JournalFormatter::Visibility do+ let(:instance) { described_class.new(build(:journal)) }++ it "renders correctly when changing visibility" do+ html = instance.render("public", [nil, true], html: true)+ expect(html).to eq("<strong>Visibility</strong> set to public")++ html = instance.render("public", [nil, true], html: false)+ expect(html).to eq("Visibility set to public")++ html = instance.render("public", [nil, false], html: true)+ expect(html).to eq("<strong>Visibility</strong> set to private")++ html = instance.render("public", [nil, false], html: false)+ expect(html).to eq("Visibility set to private")+ end+end