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
[58360] Disable statuses "read-only" checkbox when "default" is checked
Christophe Bliard160e1d9c53ff
diff --git a/app/forms/statuses/form.rb b/app/forms/statuses/form.rbindex 37ac7d9760f..522755be2aa 100644--- a/app/forms/statuses/form.rb+++ b/app/forms/statuses/form.rb@@ -64,18 +64,26 @@ module Statusesname: :is_closed)- unless already_default_status?- statuses_form.check_box(- label: attribute_name(:is_default),- name: :is_default- )- end+ statuses_form.check_box(+ label: attribute_name(:is_default),+ name: :is_default,+ disabled: already_default_status?,+ caption: I18n.t("statuses.edit.status_default_text"),+ data: {+ "admin--statuses-target": "isDefaultCheckbox",+ action: "admin--statuses#updateReadonlyCheckboxDisabledState"+ }+ )statuses_form.check_box(label: attribute_name(:is_readonly),name: :is_readonly,- disabled: readonly_work_packages_restricted?,- caption: I18n.t("statuses.edit.status_readonly_html").html_safe+ disabled: readonly_disabled?,+ caption: I18n.t("statuses.edit.status_readonly_html").html_safe,+ data: {+ "admin--statuses-target": "isReadonlyCheckbox",+ restricted: readonly_work_packages_restricted?+ })if readonly_work_packages_restricted?@@ -112,17 +120,21 @@ module Statusesmodelend+ def percent_complete_field_caption+ I18n.t("statuses.edit.status_percent_complete_text",+ href: url_helpers.admin_settings_progress_tracking_path).html_safe+ end+def already_default_status?status.is_default_was == trueend- def percent_complete_field_caption- I18n.t("statuses.edit.status_percent_complete_text",- href: url_helpers.admin_settings_progress_tracking_path).html_safe+ def readonly_disabled?+ readonly_work_packages_restricted? || already_default_status?enddef readonly_work_packages_restricted?- !EnterpriseToken.allows_to?(:readonly_work_packages)+ !status.can_readonly?endendenddiff --git a/app/views/statuses/edit.html.erb b/app/views/statuses/edit.html.erbindex 8bd69c03d6f..965700cba2e 100644--- a/app/views/statuses/edit.html.erb+++ b/app/views/statuses/edit.html.erb@@ -41,6 +41,14 @@ See COPYRIGHT and LICENSE files for more details.<%= error_messages_for :status %>-<%= primer_form_with(model: @status) do |f| %>- <%= render Statuses::Form.new(f) %>-<% end %>+<%=+primer_form_with(+ model: @status,+ data: {+ application_target: "dynamic",+ controller: "admin--statuses"+ }+) do |f|+ render Statuses::Form.new(f)+end+%>diff --git a/app/views/statuses/new.html.erb b/app/views/statuses/new.html.erbindex 417e959dd7c..f21775827a5 100644--- a/app/views/statuses/new.html.erb+++ b/app/views/statuses/new.html.erb@@ -41,6 +41,14 @@ See COPYRIGHT and LICENSE files for more details.<%= error_messages_for :status %>-<%= primer_form_with(model: @status) do |f| %>- <%= render Statuses::Form.new(f, submit_label: I18n.t(:button_create)) %>-<% end %>+<%=+primer_form_with(+ model: @status,+ data: {+ application_target: "dynamic",+ controller: "admin--statuses"+ }+) do |f|+ render Statuses::Form.new(f, submit_label: I18n.t(:button_create))+end+%>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 81979583af5..cb927cd37c2 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -532,6 +532,8 @@ en:status_color_text: |Click to assign or change the color of this status.It is shown in the status button and can be used for highlighting work packages in the table.+ status_default_text: |-+ New work packages are by default set to this type. They cannot be read-only.status_excluded_from_totals_text: |-Check this option to exclude work packages with this status from totals of Work,Remaining work, and % Complete in a hierarchy.diff --git a/frontend/src/stimulus/controllers/dynamic/admin/statuses.controller.ts b/frontend/src/stimulus/controllers/dynamic/admin/statuses.controller.tsnew file mode 100644index 00000000000..4a88148ed56--- /dev/null+++ b/frontend/src/stimulus/controllers/dynamic/admin/statuses.controller.ts@@ -0,0 +1,56 @@+/*+ * -- 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.+ * +++ */++import { Controller } from '@hotwired/stimulus';++export default class StatusesController extends Controller {+ static targets = [+ 'isDefaultCheckbox',+ 'isReadonlyCheckbox',+ ];++ declare readonly isDefaultCheckboxTarget:HTMLInputElement;+ declare readonly isReadonlyCheckboxTarget:HTMLInputElement;++ updateReadonlyCheckboxDisabledState() {+ // do nothing if the readonly checkbox is restricted due to enterprise+ // edition not being available+ if (this.isReadonlyCheckboxTarget.dataset.restricted === 'true') {+ return;+ }++ if (this.isDefaultCheckboxTarget.checked) {+ this.isReadonlyCheckboxTarget.checked = false;+ this.isReadonlyCheckboxTarget.disabled = true;+ } else {+ this.isReadonlyCheckboxTarget.disabled = false;+ }+ }+}diff --git a/spec/features/admin/statuses_spec.rb b/spec/features/admin/statuses_spec.rbnew file mode 100644index 00000000000..2c09f32d07a--- /dev/null+++ b/spec/features/admin/statuses_spec.rb@@ -0,0 +1,137 @@+# 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.+#++++require "spec_helper"++RSpec.describe "Statuses admin page", :js, :with_cuprite do+ shared_let(:admin) { create(:admin) }+ shared_let(:status_new) { create(:status, name: "New", default_done_ratio: 0, is_default: true) }+ shared_let(:status_in_progress) { create(:status, name: "In Progress", default_done_ratio: 40) }+ shared_let(:status_done) { create(:status, name: "Done", default_done_ratio: 100, is_closed: true, is_readonly: true) }++ before do+ login_as(admin)+ end++ describe "create page" do+ context "with enterprise edition", with_ee: %i[readonly_work_packages] do+ it "has 'is read-only' checkbox unchecked and disabled only when 'is default' is checked (mutually exclusive)" do+ visit new_status_path++ expect(page).not_to have_enterprise_banner+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly))+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_default))++ # given read-only is checked, when is_default is checked then read-only should become unchecked and disabled+ page.check(Status.human_attribute_name(:is_readonly))+ expect(page).to have_checked_field(Status.human_attribute_name(:is_readonly))+ page.check(Status.human_attribute_name(:is_default))+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: true)++ # given read-only is disabled, when is_default is unchecked then read-only should become enabled+ page.uncheck(Status.human_attribute_name(:is_default))+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: false)+ end+ end++ context "with commmunity edition", with_ee: false do+ it "has 'is read-only' checkbox always disabled" do+ visit new_status_path++ expect(page).to have_enterprise_banner+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: true)++ # check that it remains unchecked+ page.check(Status.human_attribute_name(:is_default))+ page.uncheck(Status.human_attribute_name(:is_default))+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: true)+ end+ end+ end++ describe "edit page" do+ it "has 'is default' checkbox disabled for the default status (cannot be unchecked)" do+ visit statuses_path++ click_on "New"+ expect(page).to have_checked_field(Status.human_attribute_name(:is_default), disabled: true)++ page.go_back+ click_on "In Progress"+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_default), disabled: false)+ end++ context "with enterprise edition", with_ee: %i[readonly_work_packages] do+ it "has 'is read-only' checkbox unchecked and disabled only when 'is default' is checked (mutually exclusive)" do+ visit statuses_path++ click_on "New"+ expect(page).not_to have_enterprise_banner+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: true)++ page.go_back+ click_on "In Progress"+ expect(page).not_to have_enterprise_banner+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_default))++ # given read-only is checked, when is_default is checked then read-only should become unchecked and disabled+ page.check(Status.human_attribute_name(:is_readonly))+ expect(page).to have_checked_field(Status.human_attribute_name(:is_readonly))+ page.check(Status.human_attribute_name(:is_default))+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: true)++ # given read-only is disabled, when is_default is unchecked then read-only should become enabled+ page.uncheck(Status.human_attribute_name(:is_default))+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: false)+ end+ end++ context "with commmunity edition", with_ee: false do+ it "has 'is read-only' checkbox always disabled" do+ visit statuses_path++ click_on "In Progress"+ expect(page).to have_enterprise_banner+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: true)++ # check that it remains unchecked+ page.check(Status.human_attribute_name(:is_default))+ page.uncheck(Status.human_attribute_name(:is_default))+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: true)++ # readonly statuses are no longer readonly if enterprise edition is not enabled+ page.go_back+ click_on "Done"+ expect(page).to have_enterprise_banner+ expect(page).to have_unchecked_field(Status.human_attribute_name(:is_readonly), disabled: true)+ end+ end+ end+end