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 enterprise guard to create and update custom field contracts
Ivan Kuchin281430a2d5da
diff --git a/app/contracts/custom_fields/create_contract.rb b/app/contracts/custom_fields/create_contract.rbindex 357d2a9200c..5a9e9f75364 100644--- a/app/contracts/custom_fields/create_contract.rb+++ b/app/contracts/custom_fields/create_contract.rb@@ -30,5 +30,6 @@module CustomFieldsclass CreateContract < BaseContract+ include CustomFields::EnterpriseGuardendenddiff --git a/app/contracts/custom_fields/enterprise_guard.rb b/app/contracts/custom_fields/enterprise_guard.rbnew file mode 100644index 00000000000..7f4c172dd5f--- /dev/null+++ b/app/contracts/custom_fields/enterprise_guard.rb@@ -0,0 +1,42 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 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.+#++++module CustomFields+ module EnterpriseGuard+ extend ActiveSupport::Concern++ include ::RequiresEnterpriseGuard++ included do+ self.enterprise_action = :calculated_values+ self.enterprise_condition = ->(*) { model.field_format_calculated_value? }+ end+ end+enddiff --git a/app/contracts/custom_fields/update_contract.rb b/app/contracts/custom_fields/update_contract.rbindex d87f045c4fa..1f220c320c7 100644--- a/app/contracts/custom_fields/update_contract.rb+++ b/app/contracts/custom_fields/update_contract.rb@@ -30,5 +30,6 @@module CustomFieldsclass UpdateContract < BaseContract+ include CustomFields::EnterpriseGuardendenddiff --git a/spec/contracts/custom_fields/create_contract_spec.rb b/spec/contracts/custom_fields/create_contract_spec.rbindex 0ead8ddc477..a412d7ab23b 100644--- a/spec/contracts/custom_fields/create_contract_spec.rb+++ b/spec/contracts/custom_fields/create_contract_spec.rb@@ -40,4 +40,17 @@ RSpec.describe CustomFields::CreateContract doendit_behaves_like "contract is valid for active admins and invalid for regular users"++ context "for calculated value custom field" do+ let(:cf) { build_stubbed(:calculated_value_project_custom_field) }+ let(:current_user) { build_stubbed(:admin) }++ context "without calculated_values enterprise feature" do+ it_behaves_like "contract is invalid", base: :error_enterprise_only+ end++ context "with calculated_values enterprise feature", with_ee: %i[calculated_values] do+ it_behaves_like "contract is valid"+ end+ endenddiff --git a/spec/contracts/custom_fields/update_contract_spec.rb b/spec/contracts/custom_fields/update_contract_spec.rbindex cbca7cf8f2e..c3eaad81601 100644--- a/spec/contracts/custom_fields/update_contract_spec.rb+++ b/spec/contracts/custom_fields/update_contract_spec.rb@@ -40,4 +40,17 @@ RSpec.describe CustomFields::UpdateContract doendit_behaves_like "contract is valid for active admins and invalid for regular users"++ context "for calculated value custom field" do+ let(:cf) { build_stubbed(:calculated_value_project_custom_field) }+ let(:current_user) { build_stubbed(:admin) }++ context "without calculated_values enterprise feature" do+ it_behaves_like "contract is invalid", base: :error_enterprise_only+ end++ context "with calculated_values enterprise feature", with_ee: %i[calculated_values] do+ it_behaves_like "contract is valid"+ end+ endend