Skip to content

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

[#66122] Initial server rendered widgets support

Alexander Brandon Coles4c55748cd853
diff --git a/app/models/permitted_params.rb b/app/models/permitted_params.rb
index a69bfda4b15..533c873ede5 100644
--- a/app/models/permitted_params.rb
+++ b/app/models/permitted_params.rb
@@ -287,11 +287,9 @@ class PermittedParams
type_ids: [],
enabled_module_names: [])
- if whitelist.has_key?(:status_code) && whitelist[:status_code].blank?
- whitelist[:status_code] = nil
- end
-
- whitelist.merge(custom_field_values(:project))
+ whitelist
+ .tap { nilify_params!(it, :status_code) }
+ .merge(custom_field_values(:project))
end
def new_project
@@ -306,6 +304,12 @@ class PermittedParams
copy_options_params
end
+ def project_status
+ params
+ .expect(project: %i[status_code status_explanation])
+ .tap { nilify_params!(it, :status_code) }
+ end
+
def project_phase
params.require(:project_phase).permit(%i[start_date finish_date])
end
@@ -679,4 +683,9 @@ class PermittedParams
values = key ? object[:custom_field_values] : object
values || ActionController::Parameters.new
end
+
+ def nilify_params!(hash, *keys)
+ keys.each { |k| hash[k] = hash[k].presence if hash.key?(k) }
+ hash
+ end
end
diff --git a/frontend/src/app/core/path-helper/path-helper.service.ts b/frontend/src/app/core/path-helper/path-helper.service.ts
index 5e80a59998c..31148c81783 100644
--- a/frontend/src/app/core/path-helper/path-helper.service.ts
+++ b/frontend/src/app/core/path-helper/path-helper.service.ts
@@ -221,6 +221,10 @@ export class PathHelperService {
return `${this.projectPath(projectIdentifier)}/dashboards`;
}
+ public projectWidgetPath(projectIdentifier:string, widgetName:string) {
+ return `${this.projectPath(projectIdentifier)}/widgets/${widgetName}`;
+ }
+
public timeEntriesPath(workPackageId:string|number) {
const suffix = '/time_entries';
diff --git a/frontend/src/app/shared/components/grids/openproject-grids.module.ts b/frontend/src/app/shared/components/grids/openproject-grids.module.ts
index aa4072eeb99..75f8a1fd7d2 100644
--- a/frontend/src/app/shared/components/grids/openproject-grids.module.ts
+++ b/frontend/src/app/shared/components/grids/openproject-grids.module.ts
@@ -26,7 +26,7 @@
// See COPYRIGHT and LICENSE files for more details.
//++
-import { Injector, NgModule } from '@angular/core';
+import { CUSTOM_ELEMENTS_SCHEMA, Injector, NgModule } from '@angular/core';
import { DynamicModule } from 'ng-dynamic-component';
import { HookService } from 'core-app/features/plugins/hook-service';
import { OpSharedModule } from 'core-app/shared/shared.module';
@@ -73,6 +73,9 @@ import { WidgetMembersComponent } from 'core-app/shared/components/grids/widgets
import {
WidgetProjectStatusComponent,
} from 'core-app/shared/components/grids/widgets/project-status/project-status.component';
+import {
+ WidgetProjectStatusBetaComponent,
+} from 'core-app/shared/components/grids/widgets/project-status-beta/project-status-beta.component';
import { OpenprojectTimeEntriesModule } from 'core-app/shared/components/time_entries/openproject-time-entries.module';
import {
WidgetTimeEntriesCurrentUserMenuComponent,
@@ -127,6 +130,7 @@ import { OpenprojectEnterpriseModule } from 'core-app/features/enterprise/openpr
WidgetWpGraphComponent,
WidgetProjectDescriptionComponent,
WidgetProjectStatusComponent,
+ WidgetProjectStatusBetaComponent,
WidgetSubprojectsComponent,
WidgetProjectFavoritesComponent,
WidgetTimeEntriesCurrentUserComponent,
@@ -146,6 +150,7 @@ import { OpenprojectEnterpriseModule } from 'core-app/features/enterprise/openpr
exports: [
GridComponent,
],
+ schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class OpenprojectGridsModule {
constructor(injector:Injector) {
@@ -333,6 +338,14 @@ export function registerWidgets(injector:Injector) {
name: i18n.t('js.grid.widgets.project_status.title'),
},
},
+ {
+ identifier: 'project_status_beta',
+ component: WidgetProjectStatusBetaComponent,
+ title: i18n.t('js.grid.widgets.project_status_beta.title'),
+ properties: {
+ name: i18n.t('js.grid.widgets.project_status_beta.title'),
+ },
+ },
{
identifier: 'subprojects',
component: WidgetSubprojectsComponent,
diff --git a/frontend/src/app/shared/components/grids/widgets/project-status-beta/project-status-beta.component.html b/frontend/src/app/shared/components/grids/widgets/project-status-beta/project-status-beta.component.html
new file mode 100644
index 00000000000..919407b37a7
--- /dev/null
+++ b/frontend/src/app/shared/components/grids/widgets/project-status-beta/project-status-beta.component.html
@@ -0,0 +1,17 @@
+<widget-header
+ [name]="widgetName"
+ [editable]="isEditable">
+
+ <attribute-help-text slot="prepend"
+ attribute="status"
+ [attributeScope]="'Project'"></attribute-help-text>
+
+ <widget-menu
+ slot="menu"
+ [resource]="resource">
+ </widget-menu>
+</widget-header>
+
+<div class="op-widget-box--body -allow-inner-overflow">
+ <turbo-frame [id]="frameId" [src]="src"></turbo-frame>
+</div>
diff --git a/frontend/src/app/shared/components/grids/widgets/project-status-beta/project-status-beta.component.ts b/frontend/src/app/shared/components/grids/widgets/project-status-beta/project-status-beta.component.ts
new file mode 100644
index 00000000000..6cf936ea19a
--- /dev/null
+++ b/frontend/src/app/shared/components/grids/widgets/project-status-beta/project-status-beta.component.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 { ChangeDetectionStrategy, Component, inject } from '@angular/core';
+import { AbstractWidgetComponent } from 'core-app/shared/components/grids/widgets/abstract-widget.component';
+import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
+import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
+
+const WIDGET_FRAME_ID = 'overviews-widgets-project-status-component';
+const WIDGET_NAME = 'project_status';
+
+@Component({
+ templateUrl: './project-status-beta.component.html',
+ changeDetection: ChangeDetectionStrategy.OnPush,
+ standalone: false,
+})
+export class WidgetProjectStatusBetaComponent extends AbstractWidgetComponent {
+ protected readonly currentProject = inject(CurrentProjectService);
+ protected readonly pathHelper = inject(PathHelperService);
+
+ frameId = WIDGET_FRAME_ID;
+
+ get src():string|null {
+ if (!this.currentProject.identifier) return null;
+ return this.pathHelper.projectWidgetPath(this.currentProject.identifier, WIDGET_NAME);
+ }
+
+ public override get isEditable():boolean {
+ return false;
+ }
+}
diff --git a/modules/grids/config/locales/js-en.yml b/modules/grids/config/locales/js-en.yml
index 4d1a5838e3c..94699e78c1e 100644
--- a/modules/grids/config/locales/js-en.yml
+++ b/modules/grids/config/locales/js-en.yml
@@ -33,6 +33,8 @@ en:
not_set: 'Not set'
finished: 'Finished'
discontinued: 'Discontinued'
+ project_status_beta:
+ title: 'Project status (BETA)'
subprojects:
title: 'Subprojects'
no_results: 'No subprojects.'
diff --git a/modules/grids/lib/grids/configuration/in_project_base_registration.rb b/modules/grids/lib/grids/configuration/in_project_base_registration.rb
index d57d685d218..6f652a1f937 100644
--- a/modules/grids/lib/grids/configuration/in_project_base_registration.rb
+++ b/modules/grids/lib/grids/configuration/in_project_base_registration.rb
@@ -4,6 +4,7 @@ module Grids::Configuration
"work_packages_graph",
"project_description",
"project_status",
+ "project_status_beta",
"subprojects",
"work_packages_calendar",
"work_packages_overview",
diff --git a/modules/overviews/app/components/overviews/widgets/project_status_component.html.erb b/modules/overviews/app/components/overviews/widgets/project_status_component.html.erb
new file mode 100644
index 00000000000..1969403e234
--- /dev/null
+++ b/modules/overviews/app/components/overviews/widgets/project_status_component.html.erb
@@ -0,0 +1,47 @@
+<%#-- 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.
+
+++#%>
+
+<%=
+ component_wrapper tag: :"turbo-frame" do
+ settings_primer_form_with(
+ model: project,
+ url: project_widgets_project_status_path(project),
+ method: :patch,
+ data: { turbo: true }
+ ) do |f|
+ render(
+ Primer::Forms::FormList.new(
+ Projects::StatusButtonComponent.new(project:, user: current_user),
+ Projects::Settings::StatusForm.new(f),
+ Projects::Settings::Submit.new(f, label: I18n.t("projects.settings.button_update_status_description"))
+ )
+ )
+ end
+ end
+%>
diff --git a/modules/overviews/app/components/overviews/widgets/project_status_component.rb b/modules/overviews/app/components/overviews/widgets/project_status_component.rb
new file mode 100644
index 00000000000..82fa058a4c6
--- /dev/null
+++ b/modules/overviews/app/components/overviews/widgets/project_status_component.rb
@@ -0,0 +1,48 @@
+# 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 Overviews
+ module Widgets
+ class ProjectStatusComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ attr_reader :project, :current_user
+
+ def initialize(project:, current_user:)
+ super()
+
+ @project = project
+ @current_user = current_user
+ end
+ end
+ end
+end
diff --git a/modules/overviews/app/controllers/overviews/widget_controller.rb b/modules/overviews/app/controllers/overviews/widget_controller.rb
new file mode 100644
index 00000000000..7c5c3ece6c8
--- /dev/null
+++ b/modules/overviews/app/controllers/overviews/widget_controller.rb
@@ -0,0 +1,36 @@
+# 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.
+#++
+
+class Overviews::WidgetController < Grids::BaseInProjectController
+ include OpTurbo::ComponentStream
+ include OpTurbo::FlashStreamHelper
+
+ layout -> { "turbo_rails/frame" }
+end
diff --git a/modules/overviews/app/controllers/overviews/widgets/project_statuses_controller.rb b/modules/overviews/app/controllers/overviews/widgets/project_statuses_controller.rb
new file mode 100644
index 00000000000..9019ffbd0d9
--- /dev/null
+++ b/modules/overviews/app/controllers/overviews/widgets/project_statuses_controller.rb
@@ -0,0 +1,46 @@
+# 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.
+#++
+
+class Overviews::Widgets::ProjectStatusesController < Overviews::WidgetController
+ def update
+ call = Projects::UpdateService
+ .new(model: @project, user: current_user)
+ .call(permitted_params.project_status)
+
+ if call.success?
+ @project = call.result
+ update_via_turbo_stream(component: Overviews::Widgets::ProjectStatusComponent.new(project: @project, current_user:))
+ render_success_flash_message_via_turbo_stream(message: t(:notice_successful_update))
+ respond_with_turbo_streams
+ else
+ respond_with_flash_error(message: t(:notice_unsuccessful_update_with_reason, reason: call.message))
+ end
+ end
+end
diff --git a/modules/overviews/app/views/overviews/widgets/project_statuses/show.html.erb b/modules/overviews/app/views/overviews/widgets/project_statuses/show.html.erb
new file mode 100644
index 00000000000..a90a69bf247
--- /dev/null
+++ b/modules/overviews/app/views/overviews/widgets/project_statuses/show.html.erb
@@ -0,0 +1,30 @@
+<%#-- 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 Overviews::Widgets::ProjectStatusComponent.new(project: @project, current_user:) %>
diff --git a/modules/overviews/config/routes.rb b/modules/overviews/config/routes.rb
index 7a73a367275..0c8651b37db 100644
--- a/modules/overviews/config/routes.rb
+++ b/modules/overviews/config/routes.rb
@@ -14,6 +14,14 @@ Rails.application.routes.draw do
get "projects/:project_id/project_life_cycle_sidebar",
to: "overviews/overviews#project_life_cycle_sidebar", as: :project_life_cycle_sidebar
+
+ scope "projects/:project_id", as: "project" do
+ scope module: "overviews" do
+ namespace :widgets do
+ resource :project_status, only: %i[show update]
+ end
+ end
+ end
end
resources :project_phases, controller: "overviews/project_phases", only: %i[edit update] do
diff --git a/modules/overviews/lib/overviews/engine.rb b/modules/overviews/lib/overviews/engine.rb
index a2400154879..d36f35d8e37 100644
--- a/modules/overviews/lib/overviews/engine.rb
+++ b/modules/overviews/lib/overviews/engine.rb
@@ -47,7 +47,14 @@ module Overviews
OpenProject::AccessControl.permission(:view_project)
.controller_actions
.push(
- "overviews/overviews/show"
+ "overviews/overviews/show",
+ "overviews/widgets/project_statuses/show"
+ )
+
+ OpenProject::AccessControl.permission(:edit_project)
+ .controller_actions
+ .push(
+ "overviews/widgets/project_statuses/update"
)
OpenProject::AccessControl.permission(:view_project_attributes)
diff --git a/modules/overviews/spec/components/overviews/widgets/project_status_component_spec.rb b/modules/overviews/spec/components/overviews/widgets/project_status_component_spec.rb
new file mode 100644
index 00000000000..7867d5bcb51
--- /dev/null
+++ b/modules/overviews/spec/components/overviews/widgets/project_status_component_spec.rb
@@ -0,0 +1,70 @@
+# 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 "rails_helper"
+
+RSpec.describe Overviews::Widgets::ProjectStatusComponent, type: :component do
+ include Rails.application.routes.url_helpers
+
+ def render_component(...)
+ render_inline(described_class.new(...))
+ end
+
+ let(:project) { build_stubbed(:project) }
+ let(:user) { build_stubbed(:user) }
+
+ current_user { user }
+
+ subject(:rendered_component) do
+ render_component(project:, current_user:)
+ end
+
+ it "renders turbo-frame component wrapper" do
+ expect(rendered_component).to have_element :"turbo-frame"
+ end
+
+ it "renders form" do
+ expect(rendered_component).to have_element :form, method: :post,
+ action: project_widgets_project_status_path(project)
+ end
+
+ it "renders hidden method field" do
+ expect(rendered_component).to have_field "_method", type: :hidden, with: "patch"
+ end
+
+ it "renders Projects Status Button component" do
+ expect(rendered_component).to have_element id: "projects-status-button-component"
+ end
+
+ it "renders text area field" do
+ expect(rendered_component).to have_element "opce-ckeditor-augmented-textarea",
+ "data-test-selector": "augmented-text-area-status_explanation"
+ end
+end
diff --git a/modules/overviews/spec/controllers/overviews/widgets/project_statuses_controller_spec.rb b/modules/overviews/spec/controllers/overviews/widgets/project_statuses_controller_spec.rb
new file mode 100644
index 00000000000..e15f24247b8
--- /dev/null
+++ b/modules/overviews/spec/controllers/overviews/widgets/project_statuses_controller_spec.rb
@@ -0,0 +1,105 @@
+# 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 "rails_helper"
+
+RSpec.describe Overviews::Widgets::ProjectStatusesController do
+ shared_let(:user) { create(:admin) }
+ current_user { user }
+
+ let(:project) { build_stubbed(:project) }
+ let(:service_result) { ServiceResult.failure }
+
+ before do
+ allow(Project)
+ .to receive(:find)
+ .with(project.identifier)
+ .and_return(project)
+
+ update_service = instance_double(Projects::UpdateService, call: service_result)
+
+ allow(Projects::UpdateService)
+ .to receive(:new)
+ .with(user:, model: project)
+ .and_return(update_service)
+ end
+
+ describe "GET #show" do
+ before do
+ get :show, params: { project_id: project }
+ end
+
+ it "renders show template", :aggregate_failures do
+ expect(response).to be_successful
+ expect(response).to render_template "show"
+ end
+ end
+
+ describe "PUT #update" do
+ before do
+ put :update, params: { project_id: project, project: { **project_params } }, format: :turbo_stream
+ end
+
+ context "with valid status_explanation param" do
+ let(:project_params) { { status_explanation: "Long explanation" } }
+
+ context "when service call succeeds" do
+ let(:service_result) { ServiceResult.success(result: project) }
+
+ it "renders turbo streams updating Overviews::Widgets::ProjectStatusComponent and flash action", :aggregate_failures do
+ expect(response).to be_successful
+ expect(assigns(:project)).to eq project
+ expect(response).to have_turbo_stream action: "update", target: "overviews-widgets-project-status-component"
+ expect(response).to have_turbo_stream action: "flash", target: "op-primer-flash-component"
+ end
+ end
+
+ context "when service call fails" do
+ let(:service_result) { ServiceResult.failure(result: project, message: "") }
+
+ it "renders turbo stream flash action", :aggregate_failures do
+ expect(response).not_to be_successful
+ expect(response).to have_http_status :unprocessable_entity
+ expect(assigns(:project)).to eq project
+ expect(response).to have_turbo_stream action: "flash", target: "op-primer-flash-component"
+ end
+ end
+ end
+
+ context "with invalid params" do
+ let(:project_params) { { not_status_code: "something" } }
+
+ it "responds with 400 Bad Request status", :aggregate_failures do
+ expect(response).not_to be_successful
+ expect(response).to have_http_status :bad_request
+ end
+ end
+ end
+end
diff --git a/modules/overviews/spec/permissions/widgets_project_statuses_spec.rb b/modules/overviews/spec/permissions/widgets_project_statuses_spec.rb
new file mode 100644
index 00000000000..66787b9737a
--- /dev/null
+++ b/modules/overviews/spec/permissions/widgets_project_statuses_spec.rb
@@ -0,0 +1,39 @@
+# 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"
+require "support/permission_specs"
+
+RSpec.describe Overviews::Widgets::ProjectStatusesController, "permissions", type: :controller do # rubocop:disable RSpec/EmptyExampleGroup,RSpec/SpecFilePathFormat
+ include PermissionSpecs
+
+ check_permission_required_for("overviews/widgets/project_statuses#show", :view_project)
+ check_permission_required_for("overviews/widgets/project_statuses#update", :edit_project)
+end
diff --git a/modules/overviews/spec/routing/widget_routing_spec.rb b/modules/overviews/spec/routing/widget_routing_spec.rb
new file mode 100644
index 00000000000..e25a6a6e6da
--- /dev/null
+++ b/modules/overviews/spec/routing/widget_routing_spec.rb
@@ -0,0 +1,87 @@
+# 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 "rails_helper"
+
+RSpec.describe Overviews::WidgetController do
+ describe "project_status routing" do
+ describe "GET #show" do
+ it do
+ expect(get("/projects/my-project/widgets/project_status"))
+ .to route_to(
+ controller: "overviews/widgets/project_statuses", action: "show", project_id: "my-project"
+ )
+ end
+ end
+
+ describe "PUT/PATCH #update" do
+ it do
+ expect(put("/projects/my-project/widgets/project_status"))
+ .to route_to(
+ controller: "overviews/widgets/project_statuses", action: "update", project_id: "my-project"
+ )
+ end
+
+ it do
+ expect(patch("/projects/my-project/widgets/project_status"))
+ .to route_to(
+ controller: "overviews/widgets/project_statuses", action: "update", project_id: "my-project"
+ )
+ end
+ end
+ end
+
+ describe "project_status named routing" do
+ describe "GET #show" do
+ it do
+ expect(get(project_widgets_project_status_path("my-project")))
+ .to route_to(
+ controller: "overviews/widgets/project_statuses", action: "show", project_id: "my-project"
+ )
+ end
+ end
+
+ describe "PUT/PATCH #update" do
+ it do
+ expect(put(project_widgets_project_status_path("my-project")))
+ .to route_to(
+ controller: "overviews/widgets/project_statuses", action: "update", project_id: "my-project"
+ )
+ end
+
+ it do
+ expect(patch(project_widgets_project_status_path("my-project")))
+ .to route_to(
+ controller: "overviews/widgets/project_statuses", action: "update", project_id: "my-project"
+ )
+ end
+ end
+ end
+end
diff --git a/spec/models/permitted_params_spec.rb b/spec/models/permitted_params_spec.rb
index 683c989a4dd..0bc7ea4fe01 100644
--- a/spec/models/permitted_params_spec.rb
+++ b/spec/models/permitted_params_spec.rb
@@ -256,6 +256,31 @@ RSpec.describe PermittedParams do
it_behaves_like "allows params"
end
+ describe "#project" do
+ let(:attribute) { :project }
+
+ describe "status_code" do
+ context "with valid status_code" do
+ let(:hash) { { "status_code" => "not_started" } }
+
+ it_behaves_like "allows params"
+ end
+
+ context "with empty status_code" do
+ let(:hash) { { "status_code" => "" } }
+ let(:expected_allowed_params) { { "status_code" => nil } }
+
+ it_behaves_like "allows params"
+ end
+ end
+
+ describe "status_explanation" do
+ let(:hash) { { "status_explanation" => "Blah..." } }
+
+ it_behaves_like "allows params"
+ end
+ end
+
describe "#new_project" do
let(:attribute) { :new_project }
let(:hash_key) { "project" }
@@ -309,6 +334,32 @@ RSpec.describe PermittedParams do
end
end
+ describe "#project_status" do
+ let(:attribute) { :project_status }
+ let(:hash_key) { "project" }
+
+ describe "status_code" do
+ context "with valid status_code" do
+ let(:hash) { { "status_code" => "not_started" } }
+
+ it_behaves_like "allows params"
+ end
+
+ context "with empty status_code" do
+ let(:hash) { { "status_code" => "" } }
+ let(:expected_allowed_params) { { "status_code" => nil } }
+
+ it_behaves_like "allows params"
+ end
+ end
+
+ describe "status_explanation" do
+ let(:hash) { { "status_explanation" => "Blah..." } }
+
+ it_behaves_like "allows params"
+ end
+ end
+
describe "#projects_type_ids" do
let(:attribute) { :projects_type_ids }
let(:hash_key) { "project" }