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
[#67291] Primerized News (BETA) widget in projects
Oliver Güntherd0c18aec6d13
diff --git a/frontend/src/app/shared/components/grids/openproject-grids.module.ts b/frontend/src/app/shared/components/grids/openproject-grids.module.tsindex 75f8a1fd7d2..e7325513c16 100644--- a/frontend/src/app/shared/components/grids/openproject-grids.module.ts+++ b/frontend/src/app/shared/components/grids/openproject-grids.module.ts@@ -44,6 +44,7 @@ import { GridComponent } from 'core-app/shared/components/grids/grid/grid.componimport { AddGridWidgetModalComponent } from 'core-app/shared/components/grids/widgets/add/add.modal';import { WidgetDocumentsComponent } from 'core-app/shared/components/grids/widgets/documents/documents.component';import { WidgetNewsComponent } from 'core-app/shared/components/grids/widgets/news/news.component';+import { WidgetNewsBetaComponent } from 'core-app/shared/components/grids/widgets/news-beta/news-beta.component';import { WidgetWpTableComponent } from 'core-app/shared/components/grids/widgets/wp-table/wp-table.component';import { WidgetMenuComponent } from 'core-app/shared/components/grids/widgets/menu/widget-menu.component';import { WidgetWpTableMenuComponent } from 'core-app/shared/components/grids/widgets/wp-table/wp-table-menu.component';@@ -123,6 +124,7 @@ import { OpenprojectEnterpriseModule } from 'core-app/features/enterprise/openprWidgetDocumentsComponent,WidgetMembersComponent,WidgetNewsComponent,+ WidgetNewsBetaComponent,WidgetWpCalendarComponent,WidgetWpOverviewComponent,WidgetWpTableComponent,@@ -311,6 +313,14 @@ export function registerWidgets(injector:Injector) {name: i18n.t('js.grid.widgets.news.title'),},},+ {+ identifier: 'news_beta',+ component: WidgetNewsBetaComponent,+ title: i18n.t('js.grid.widgets.news_beta.title'),+ properties: {+ name: i18n.t('js.grid.widgets.news_beta.title'),+ },+ },{identifier: 'project_description',component: WidgetProjectDescriptionComponent,diff --git a/frontend/src/app/shared/components/grids/widgets/news-beta/news-beta.component.html b/frontend/src/app/shared/components/grids/widgets/news-beta/news-beta.component.htmlnew file mode 100644index 00000000000..f33e04ec97b--- /dev/null+++ b/frontend/src/app/shared/components/grids/widgets/news-beta/news-beta.component.html@@ -0,0 +1,13 @@+<widget-header+ [name]="widgetName"+ [editable]="isEditable">++ <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/news-beta/news-beta.component.ts b/frontend/src/app/shared/components/grids/widgets/news-beta/news-beta.component.tsnew file mode 100644index 00000000000..294ba9d5218--- /dev/null+++ b/frontend/src/app/shared/components/grids/widgets/news-beta/news-beta.component.ts@@ -0,0 +1,40 @@+//-- 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 } from '@angular/core';+import { AbstractTurboWidgetComponent } from 'core-app/shared/components/grids/widgets/abstract-turbo-widget.component';++@Component({+ templateUrl: './news-beta.component.html',+ changeDetection: ChangeDetectionStrategy.OnPush,+ standalone: false,+})+export class WidgetNewsBetaComponent extends AbstractTurboWidgetComponent {+ override frameId = 'overviews-widgets-news-component';+ override name = 'news';+}diff --git a/modules/grids/config/locales/js-en.yml b/modules/grids/config/locales/js-en.ymlindex 94699e78c1e..779caaaabc1 100644--- a/modules/grids/config/locales/js-en.yml+++ b/modules/grids/config/locales/js-en.yml@@ -21,6 +21,8 @@ en:title: 'News'at: 'at'no_results: 'Nothing new to report.'+ news_beta:+ title: 'News (BETA)'project_description:title: 'Project description'no_results: "No description has been written yet. One can be provided in the 'Project settings'."diff --git a/modules/grids/lib/grids/configuration/in_project_base_registration.rb b/modules/grids/lib/grids/configuration/in_project_base_registration.rbindex 675d3abdcdb..b4a1a631775 100644--- a/modules/grids/lib/grids/configuration/in_project_base_registration.rb+++ b/modules/grids/lib/grids/configuration/in_project_base_registration.rb@@ -11,6 +11,7 @@ module Grids::Configuration"time_entries_list","members","news",+ "news_beta","documents","custom_text"@@ -71,6 +72,10 @@ module Grids::Configurationallowed ->(user, project) { user.allowed_in_project?(:view_news, project) }end+ widget_strategy "news_beta" do+ allowed ->(user, project) { view_beta_widgets.(user, project) && user.allowed_in_project?(:view_news, project) }+ end+widget_strategy "documents" doallowed ->(user, project) { user.allowed_in_project?(:view_documents, project) }enddiff --git a/modules/overviews/app/components/overviews/widgets/news_component.html.erb b/modules/overviews/app/components/overviews/widgets/news_component.html.erbnew file mode 100644index 00000000000..69d2810f903--- /dev/null+++ b/modules/overviews/app/components/overviews/widgets/news_component.html.erb@@ -0,0 +1,50 @@+<%#-- 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+ box_collection do |box|+ @newest.each_with_index do |news, i|+ box.with_box(mt: 2, pb: 2, border: i == @newest.count - 1 ? false : :bottom) do+ component_collection do |body|+ body.with_component(+ render(Primer::Beta::Link.new(font_weight: :bold, underline: true, href: news_path(news))) { news.title }+ )+ body.with_component(+ render(Primer::Beta::Text.new(tag: :p, color: :subtle)) { helpers.authoring_at(format_time(news.created_at), news.author) }+ )+ body.with_component(+ render(Primer::Beta::Text.new) { news.summary }+ )+ end+ end+ end+ end+ end+%>diff --git a/modules/overviews/app/components/overviews/widgets/news_component.rb b/modules/overviews/app/components/overviews/widgets/news_component.rbnew file mode 100644index 00000000000..3cf517c8b12--- /dev/null+++ b/modules/overviews/app/components/overviews/widgets/news_component.rb@@ -0,0 +1,52 @@+# 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 NewsComponent < ApplicationComponent+ NEWS_LIMIT = 5++ 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+ @news = project.news.visible.newest_first+ @newest = @news.limit(NEWS_LIMIT).to_a+ end+ end+ end+enddiff --git a/modules/overviews/app/controllers/overviews/widgets/news_controller.rb b/modules/overviews/app/controllers/overviews/widgets/news_controller.rbnew file mode 100644index 00000000000..d64f9cfe9f7--- /dev/null+++ b/modules/overviews/app/controllers/overviews/widgets/news_controller.rb@@ -0,0 +1,32 @@+# 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::NewsController < Overviews::WidgetController+enddiff --git a/modules/overviews/app/views/overviews/widgets/news/show.html.erb b/modules/overviews/app/views/overviews/widgets/news/show.html.erbnew file mode 100644index 00000000000..5896eba57f8--- /dev/null+++ b/modules/overviews/app/views/overviews/widgets/news/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::NewsComponent.new(project: @project, current_user:) %>diff --git a/modules/overviews/config/routes.rb b/modules/overviews/config/routes.rbindex a519839a7e8..84786065bd2 100644--- a/modules/overviews/config/routes.rb+++ b/modules/overviews/config/routes.rb@@ -17,6 +17,7 @@ Rails.application.routes.draw donamespace :widgets doresource :project_status, only: %i[show update]+ resource :news, only: %i[show]endendenddiff --git a/modules/overviews/lib/overviews/engine.rb b/modules/overviews/lib/overviews/engine.rbindex 6d40231fc56..b2f283869eb 100644--- a/modules/overviews/lib/overviews/engine.rb+++ b/modules/overviews/lib/overviews/engine.rb@@ -48,7 +48,8 @@ module Overviews.controller_actions.push("overviews/overviews/show",- "overviews/widgets/project_statuses/show"+ "overviews/widgets/project_statuses/show",+ "overviews/widgets/news/show")OpenProject::AccessControl.permission(:edit_project)diff --git a/modules/overviews/spec/components/overviews/widgets/news_component_spec.rb b/modules/overviews/spec/components/overviews/widgets/news_component_spec.rbnew file mode 100644index 00000000000..99c0590eea2--- /dev/null+++ b/modules/overviews/spec/components/overviews/widgets/news_component_spec.rb@@ -0,0 +1,50 @@+# 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::NewsComponent, type: :component do+ 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+enddiff --git a/modules/overviews/spec/controllers/overviews/widgets/news_controller_spec.rb b/modules/overviews/spec/controllers/overviews/widgets/news_controller_spec.rbnew file mode 100644index 00000000000..051d3363571--- /dev/null+++ b/modules/overviews/spec/controllers/overviews/widgets/news_controller_spec.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.+#++++require "rails_helper"++RSpec.describe Overviews::Widgets::NewsController do+ shared_let(:project) { create(:project) }+ shared_let(:user) { create(:user, member_with_permissions: { project => %i[view_news] }) }+ current_user { user }++ 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+enddiff --git a/modules/overviews/spec/permissions/widgets/news_spec.rb b/modules/overviews/spec/permissions/widgets/news_spec.rbnew file mode 100644index 00000000000..353f71486ad--- /dev/null+++ b/modules/overviews/spec/permissions/widgets/news_spec.rb@@ -0,0 +1,38 @@+# 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::NewsController, "permissions", type: :controller do # rubocop:disable RSpec/EmptyExampleGroup,RSpec/SpecFilePathFormat+ include PermissionSpecs++ check_permission_required_for("overviews/widgets/news#show", :view_project)+enddiff --git a/modules/overviews/spec/permissions/widgets_project_statuses_spec.rb b/modules/overviews/spec/permissions/widgets/project_statuses_spec.rbsimilarity index 100%rename from modules/overviews/spec/permissions/widgets_project_statuses_spec.rbrename to modules/overviews/spec/permissions/widgets/project_statuses_spec.rbdiff --git a/modules/overviews/spec/routing/widget_routing_spec.rb b/modules/overviews/spec/routing/widget_routing_spec.rbindex e25a6a6e6da..795bfc0d97a 100644--- a/modules/overviews/spec/routing/widget_routing_spec.rb+++ b/modules/overviews/spec/routing/widget_routing_spec.rb@@ -58,6 +58,17 @@ RSpec.describe Overviews::WidgetController doendend+ describe "news routing" do+ describe "GET #show" do+ it do+ expect(get("/projects/my-project/widgets/news"))+ .to route_to(+ controller: "overviews/widgets/news", action: "show", project_id: "my-project"+ )+ end+ end+ end+describe "project_status named routing" dodescribe "GET #show" doit do@@ -84,4 +95,15 @@ RSpec.describe Overviews::WidgetController doendendend++ describe "news named routing" do+ describe "GET #show" do+ it do+ expect(get(project_widgets_news_path("my-project")))+ .to route_to(+ controller: "overviews/widgets/news", action: "show", project_id: "my-project"+ )+ end+ end+ endend