From a96fdd1de130f51d520049ea652886db048ae490 Mon Sep 17 00:00:00 2001 From: Dombi Attila <83396+dombesz@users.noreply.github.com> Date: Tue, 17 Dec 2024 16:57:13 +0200 Subject: [PATCH] Address CR comments --- config/locales/en.yml | 4 +-- frontend/src/turbo/turbo-global-listeners.ts | 2 +- .../open_project/forms/date_picker.html.erb | 29 +++++++++++++++++++ lib/primer/open_project/forms/date_picker.rb | 28 ++++++++++++++++++ .../forms/dsl/range_date_picker_input.rb | 28 ++++++++++++++++++ .../forms/dsl/single_date_picker_input.rb | 28 ++++++++++++++++++ .../sections/edit_component.rb | 4 --- .../sections/edit_dialog_component.html.erb | 4 +-- .../sections/edit_dialog_component.rb | 4 +++ .../project_life_cycles/show_component.rb | 20 +++++-------- .../sections/show_component.html.erb | 2 +- .../sections/show_component.rb | 3 +- modules/overviews/lib/overviews/engine.rb | 3 +- .../base_contract_spec.rb | 4 +-- .../overview_page/dialog/permission_spec.rb | 1 + .../overview_page/dialog/permission_spec.rb | 1 - spec/models/project/stage_spec.rb | 3 ++ spec/support/pages/projects/show.rb | 4 +-- 18 files changed, 141 insertions(+), 31 deletions(-) diff --git a/config/locales/en.yml b/config/locales/en.yml index de8d83c86a23..9d8817ed940e 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1235,12 +1235,12 @@ en: type: type_and_class_name_mismatch: "must be a Project::Gate" date: - non_continuous_dates: "can’t be earlier than the previous %{step}'s end date." + non_continuous_dates: "can't be earlier than the previous %{step}'s end date." project/stage: attributes: date_range: start_date_must_be_before_end_date: "start date must be before the end date." - non_continuous_dates: "can’t be earlier than the previous %{step}'s end date." + non_continuous_dates: "can't be earlier than the previous %{step}'s end date." incomplete: "is incomplete." type: type_and_class_name_mismatch: "must be a Project::Stage" diff --git a/frontend/src/turbo/turbo-global-listeners.ts b/frontend/src/turbo/turbo-global-listeners.ts index 0f379be56818..8ad1914e8fdc 100644 --- a/frontend/src/turbo/turbo-global-listeners.ts +++ b/frontend/src/turbo/turbo-global-listeners.ts @@ -69,7 +69,7 @@ export function addTurboGlobalListeners() { const element = event.target as HTMLElement; // In case the element is an OpenProject custom dom element, morphing is prevented. - if (element.tagName.startsWith('OPCE-')) { + if (element.tagName.toUpperCase().startsWith('OPCE-')) { event.preventDefault(); } }); diff --git a/lib/primer/open_project/forms/date_picker.html.erb b/lib/primer/open_project/forms/date_picker.html.erb index 0483d34c9515..7b55923f0a48 100644 --- a/lib/primer/open_project/forms/date_picker.html.erb +++ b/lib/primer/open_project/forms/date_picker.html.erb @@ -1,3 +1,32 @@ +<%#-- 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. + +++#%> + <%= render(FormControl.new(input: @input, tag: :"primer-datepicker-field")) do %> <%= content_tag(:div, **@field_wrap_arguments) do %> <%# leading spinner implies a leading visual %> diff --git a/lib/primer/open_project/forms/date_picker.rb b/lib/primer/open_project/forms/date_picker.rb index f3089f101f77..6c7de2fc830c 100644 --- a/lib/primer/open_project/forms/date_picker.rb +++ b/lib/primer/open_project/forms/date_picker.rb @@ -1,5 +1,33 @@ # 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 Primer module OpenProject module Forms diff --git a/lib/primer/open_project/forms/dsl/range_date_picker_input.rb b/lib/primer/open_project/forms/dsl/range_date_picker_input.rb index e3a5710228de..0b79a36b068c 100644 --- a/lib/primer/open_project/forms/dsl/range_date_picker_input.rb +++ b/lib/primer/open_project/forms/dsl/range_date_picker_input.rb @@ -1,5 +1,33 @@ # 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 Primer module OpenProject module Forms diff --git a/lib/primer/open_project/forms/dsl/single_date_picker_input.rb b/lib/primer/open_project/forms/dsl/single_date_picker_input.rb index d62eed45b220..7a356bdfba4c 100644 --- a/lib/primer/open_project/forms/dsl/single_date_picker_input.rb +++ b/lib/primer/open_project/forms/dsl/single_date_picker_input.rb @@ -1,5 +1,33 @@ # 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 Primer module OpenProject module Forms diff --git a/modules/overviews/app/components/project_life_cycles/sections/edit_component.rb b/modules/overviews/app/components/project_life_cycles/sections/edit_component.rb index d0016f8b313d..69e395d772f7 100644 --- a/modules/overviews/app/components/project_life_cycles/sections/edit_component.rb +++ b/modules/overviews/app/components/project_life_cycles/sections/edit_component.rb @@ -32,10 +32,6 @@ class EditComponent < ApplicationComponent include ApplicationHelper include OpTurbo::Streamable include OpPrimer::ComponentHelpers - - def life_cycle_steps - model.life_cycle_steps.active.eager_load(:definition).order(position: :asc) - end end end end diff --git a/modules/overviews/app/components/project_life_cycles/sections/edit_dialog_component.html.erb b/modules/overviews/app/components/project_life_cycles/sections/edit_dialog_component.html.erb index 7ff822ece821..a2eab213ea09 100644 --- a/modules/overviews/app/components/project_life_cycles/sections/edit_dialog_component.html.erb +++ b/modules/overviews/app/components/project_life_cycles/sections/edit_dialog_component.html.erb @@ -1,7 +1,7 @@ <%= render(Primer::Alpha::Dialog.new(title: t("label_life_cycle_step_plural"), size: :large, - id: "edit-project-life-cycles-dialog")) do |d| + id: dialog_id)) do |d| d.with_header(variant: :large) d.with_body(classes: "Overlay-body_autocomplete_height") do render(::ProjectLifeCycles::Sections::EditComponent.new(model)) @@ -10,7 +10,7 @@ component_collection do |footer_collection| footer_collection.with_component(Primer::ButtonComponent.new( data: { - 'close-dialog-id': "edit-project-life-cycles-dialog" + "close-dialog-id": dialog_id } )) do t("button_cancel") diff --git a/modules/overviews/app/components/project_life_cycles/sections/edit_dialog_component.rb b/modules/overviews/app/components/project_life_cycles/sections/edit_dialog_component.rb index 584b01af793b..45f2689421ea 100644 --- a/modules/overviews/app/components/project_life_cycles/sections/edit_dialog_component.rb +++ b/modules/overviews/app/components/project_life_cycles/sections/edit_dialog_component.rb @@ -32,6 +32,10 @@ class EditDialogComponent < ApplicationComponent include ApplicationHelper include OpTurbo::Streamable include OpPrimer::ComponentHelpers + + def dialog_id + "edit-project-life-cycles-dialog" + end end end end diff --git a/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb b/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb index 4c2e552c8d84..43e1f19da34f 100644 --- a/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb +++ b/modules/overviews/app/components/project_life_cycles/sections/project_life_cycles/show_component.rb @@ -40,18 +40,14 @@ def not_set? end def render_value - case model - when Project::Gate - render(Primer::Beta::Text.new) do - concat helpers.format_date(model.date) - end - when Project::Stage - render(Primer::Beta::Text.new) do - concat [ - helpers.format_date(model.start_date), - helpers.format_date(model.end_date) - ].join(" - ") - end + render(Primer::Beta::Text.new) do + concat [ + model.start_date, + model.end_date + ] + .compact + .map { |d| helpers.format_date(d) } + .join(" - ") end end diff --git a/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb b/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb index 0aa8e9678fe6..c8a801c9f9dd 100644 --- a/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb +++ b/modules/overviews/app/components/project_life_cycles/sections/show_component.html.erb @@ -21,7 +21,7 @@ flex_layout do |details_container| @life_cycle_steps.each_with_index do |life_cycle_step, i| - margin = i == @life_cycle_steps.size - 1 ? 0 : 3 + margin = i == @life_cycle_steps.size - 1 ? 0 : 3 details_container.with_row(mb: margin) do render(ProjectLifeCycles::Sections::ProjectLifeCycles::ShowComponent.new( life_cycle_step diff --git a/modules/overviews/app/components/project_life_cycles/sections/show_component.rb b/modules/overviews/app/components/project_life_cycles/sections/show_component.rb index f7af8e54be14..f848609e596f 100644 --- a/modules/overviews/app/components/project_life_cycles/sections/show_component.rb +++ b/modules/overviews/app/components/project_life_cycles/sections/show_component.rb @@ -37,8 +37,7 @@ def initialize(project:) super @project = project - @life_cycle_steps = - @project.life_cycle_steps.active.eager_load(:definition).order(position: :asc) + @life_cycle_steps = @project.available_life_cycle_steps end private diff --git a/modules/overviews/lib/overviews/engine.rb b/modules/overviews/lib/overviews/engine.rb index e9ba90c450d7..f9e5988c90b8 100644 --- a/modules/overviews/lib/overviews/engine.rb +++ b/modules/overviews/lib/overviews/engine.rb @@ -47,8 +47,7 @@ class Engine < ::Rails::Engine OpenProject::AccessControl.permission(:view_project) .controller_actions .push( - "overviews/overviews/show", - "overviews/overviews/project_life_cycles_sidebar" + "overviews/overviews/show" ) OpenProject::AccessControl.permission(:view_project_attributes) diff --git a/spec/contracts/project_life_cycle_steps/base_contract_spec.rb b/spec/contracts/project_life_cycle_steps/base_contract_spec.rb index 0b928f849f42..8bb93c4a5b65 100644 --- a/spec/contracts/project_life_cycle_steps/base_contract_spec.rb +++ b/spec/contracts/project_life_cycle_steps/base_contract_spec.rb @@ -37,7 +37,7 @@ let(:contract) { described_class.new(project, user) } let(:project) { build_stubbed(:project) } - context "with authorised user" do + context "with authorized user" do let(:user) { build_stubbed(:user) } let(:project) { build_stubbed(:project, available_life_cycle_steps: steps) } let(:steps) { [] } @@ -145,7 +145,7 @@ end end - context "with unauthorised user" do + context "with unauthorized user" do let(:user) { build_stubbed(:user) } it_behaves_like "contract user is unauthorized" diff --git a/spec/features/projects/life_cycle/overview_page/dialog/permission_spec.rb b/spec/features/projects/life_cycle/overview_page/dialog/permission_spec.rb index 1623d8ae85d6..85da512cea9a 100644 --- a/spec/features/projects/life_cycle/overview_page/dialog/permission_spec.rb +++ b/spec/features/projects/life_cycle/overview_page/dialog/permission_spec.rb @@ -60,6 +60,7 @@ expect(page).to have_text("Project lifecycle") end end + end describe "with Edit project permissions" do let(:permissions) { [:view_project, :view_project_stages_and_gates, :edit_project] } diff --git a/spec/features/projects/project_custom_fields/overview_page/dialog/permission_spec.rb b/spec/features/projects/project_custom_fields/overview_page/dialog/permission_spec.rb index ba44fca7a034..579893825534 100644 --- a/spec/features/projects/project_custom_fields/overview_page/dialog/permission_spec.rb +++ b/spec/features/projects/project_custom_fields/overview_page/dialog/permission_spec.rb @@ -31,7 +31,6 @@ RSpec.describe "Edit project custom fields on project overview page", :js do include_context "with seeded projects, members and project custom fields" - let(:overview_page) { Pages::Projects::Show.new(project) } describe "with insufficient View attributes permissions" do diff --git a/spec/models/project/stage_spec.rb b/spec/models/project/stage_spec.rb index 5fc4234345a2..99388f780f89 100644 --- a/spec/models/project/stage_spec.rb +++ b/spec/models/project/stage_spec.rb @@ -139,6 +139,9 @@ .and_return([]) expect(subject.working_days_count).to eq(0) + + expect(Day).to have_received(:working).with(no_args) + expect(Day).to have_received(:from_range).with(from: subject.start_date, to: subject.end_date) end end end diff --git a/spec/support/pages/projects/show.rb b/spec/support/pages/projects/show.rb index bae1d5210bb2..4877c69ab00e 100644 --- a/spec/support/pages/projects/show.rb +++ b/spec/support/pages/projects/show.rb @@ -51,12 +51,12 @@ def visit_page def expect_no_visible_sidebar expect_angular_frontend_initialized - expect(page).to have_no_css(".op-grid-page--grid-container") + expect(page).to have_no_css(".op-grid-page--sidebar") end def expect_visible_sidebar expect_angular_frontend_initialized - expect(page).to have_css(".op-grid-page--grid-container") + expect(page).to have_css(".op-grid-page--sidebar") end def within_project_attributes_sidebar(&)