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

Migrate Members widget from Angular to rails based implementation

Henriette Darge78f310789de9
diff --git a/frontend/src/app/shared/components/grids/widgets/members/members.component.html b/frontend/src/app/shared/components/grids/widgets/members/members.component.html
index d750e4695d2..edb6a8474fd 100644
--- a/frontend/src/app/shared/components/grids/widgets/members/members.component.html
+++ b/frontend/src/app/shared/components/grids/widgets/members/members.component.html
@@ -10,54 +10,4 @@
[resource]="resource" />
</widget-header>
-<div class="op-widget-box--body">
- @if (noMembers) {
- <op-no-results [title]="text.noResults" />
- }
- <div class="op-members-widget--attributes-map -minimal-keys">
- @for (usersByRole of usersByRole; track usersByRole) {
- <div class="attributes-map--key">
- {{usersByRole.role.name}}
- </div>
- <div class="attributes-map--value">
- @for (principal of usersByRole.users; track principal; let last = $last) {
- <op-principal [principal]="principal"
- size="mini"
- />
- @if (!last) {
- ,
- }
- }
- </div>
- }
- </div>
- @if (moreMembers) {
- <div
- class="op-members-widget--notification">
- {{moreMembersText}}
- </div>
- }
- <div class="op-members-widget--grid--widget-footer">
- @if (membersAddable$ | async) {
- <a
- [href]="projectMembershipsPath + '?show_add_members=true'"
- class="button -primary">
- <i class="button--icon icon-add" aria-hidden="true"></i>
- <span class="button--text"
- [textContent]="text.add">
- </span>
- </a>
- }
-
- @if (!noMembers) {
- <a
- [href]="projectMembershipsPath"
- class="button -highlight-inverted">
- <i class="button--icon icon-group" aria-hidden="true"></i>
- <span class="button--text"
- [textContent]="text.viewAll">
- </span>
- </a>
- }
- </div>
-</div>
+<turbo-frame [id]="frameId" [src]="src" loading="lazy" />
diff --git a/frontend/src/app/shared/components/grids/widgets/members/members.component.sass b/frontend/src/app/shared/components/grids/widgets/members/members.component.sass
deleted file mode 100644
index 3801299056d..00000000000
--- a/frontend/src/app/shared/components/grids/widgets/members/members.component.sass
+++ /dev/null
@@ -1,17 +0,0 @@
-.op-members-widget
- &--notification
- font-style: italic
- margin-top: 0.5rem
-
- &--grid--widget-footer
- margin-top: 0.5rem
-
- .button
- margin-bottom: 0
-
- &--attributes-map
- padding-bottom: 0.875rem
- line-height: 1.5rem
-
- .attributes-map--value:not(:last-of-type)
- margin-bottom: 0.5rem
\ No newline at end of file
diff --git a/frontend/src/app/shared/components/grids/widgets/members/members.component.ts b/frontend/src/app/shared/components/grids/widgets/members/members.component.ts
index 187caa7d853..4a757165d7d 100644
--- a/frontend/src/app/shared/components/grids/widgets/members/members.component.ts
+++ b/frontend/src/app/shared/components/grids/widgets/members/members.component.ts
@@ -1,144 +1,15 @@
-import { AbstractWidgetComponent } from 'core-app/shared/components/grids/widgets/abstract-widget.component';
import {
ChangeDetectionStrategy,
- ChangeDetectorRef,
Component,
- Injector,
- OnInit,
} from '@angular/core';
-import { I18nService } from 'core-app/core/i18n/i18n.service';
-import { PathHelperService } from 'core-app/core/path-helper/path-helper.service';
-import { CurrentProjectService } from 'core-app/core/current-project/current-project.service';
-import { MembershipResource } from 'core-app/features/hal/resources/membership-resource';
-import { RoleResource } from 'core-app/features/hal/resources/role-resource';
-import { ApiV3Service } from 'core-app/core/apiv3/api-v3.service';
-import { ApiV3ListParameters } from 'core-app/core/apiv3/paths/apiv3-list-resource.interface';
-import { HalResource } from 'core-app/features/hal/resources/hal-resource';
-import { map } from 'rxjs/operators';
-import { Observable } from 'rxjs';
-
-const DISPLAYED_MEMBERS_LIMIT = 100;
+import { AbstractTurboWidgetComponent } from 'core-app/shared/components/grids/widgets/abstract-turbo-widget.component';
@Component({
templateUrl: './members.component.html',
changeDetection: ChangeDetectionStrategy.OnPush,
- styleUrls: ['./members.component.sass'],
standalone: false,
})
-export class WidgetMembersComponent extends AbstractWidgetComponent implements OnInit {
- public text = {
- add: this.i18n.t('js.grid.widgets.members.add'),
- noResults: this.i18n.t('js.grid.widgets.members.no_results'),
- viewAll: this.i18n.t('js.grid.widgets.members.view_all_members'),
- };
-
- public totalMembers:number;
-
- public entriesByRoles:{ [roleId:string]:{ role:RoleResource, users:HalResource[] } } = {};
-
- private entriesLoaded = false;
-
- public membersAddable$:Observable<boolean>;
-
- constructor(
- readonly pathHelper:PathHelperService,
- readonly apiV3Service:ApiV3Service,
- readonly i18n:I18nService,
- protected readonly injector:Injector,
- readonly currentProject:CurrentProjectService,
- readonly cdr:ChangeDetectorRef,
- ) {
- super(i18n, injector);
- }
-
- ngOnInit() {
- this
- .apiV3Service
- .memberships
- .list(this.listMembersParams)
- .subscribe((collection) => {
- this.partitionEntriesByRole(collection.elements);
- this.sortUsersByName();
- this.totalMembers = collection.total;
-
- this.entriesLoaded = true;
- this.cdr.detectChanges();
- });
-
- this.membersAddable$ = this
- .apiV3Service
- .memberships
- .available_projects
- .list(this.listAvailableProjectsParams)
- .pipe(
- map((collection) => collection.total > 0),
- );
- }
-
- public get isEditable() {
- return false;
- }
-
- public get noMembers() {
- return this.entriesLoaded && !Object.keys(this.entriesByRoles).length;
- }
-
- public get moreMembers() {
- return this.entriesLoaded && this.totalMembers > DISPLAYED_MEMBERS_LIMIT;
- }
-
- public get moreMembersText() {
- return I18n.t(
- 'js.grid.widgets.members.too_many',
- { count: DISPLAYED_MEMBERS_LIMIT, total: this.totalMembers },
- );
- }
-
- public get projectMembershipsPath() {
- return this.pathHelper.projectMembershipsPath(this.currentProject.identifier!);
- }
-
- public get usersByRole() {
- return Object.values(this.entriesByRoles);
- }
-
- private partitionEntriesByRole(memberships:MembershipResource[]) {
- memberships.forEach((membership) => {
- membership.roles.forEach((role) => {
- if (!this.entriesByRoles[role.id!]) {
- this.entriesByRoles[role.id!] = { role, users: [] };
- }
-
- this.entriesByRoles[role.id!].users.push(membership.principal);
- });
- });
- }
-
- private sortUsersByName() {
- Object.values(this.entriesByRoles).forEach((entry) => {
- entry.users.sort((a, b) => a.name.localeCompare(b.name));
- });
- }
-
- private get listMembersParams() {
- const params:ApiV3ListParameters = { sortBy: [['created_at', 'desc']], pageSize: DISPLAYED_MEMBERS_LIMIT };
-
- if (this.currentProject.id) {
- params.filters = [['project_id', '=', [this.currentProject.id]]];
- }
-
- return params;
- }
-
- private get listAvailableProjectsParams() {
- // It would make sense to set the pageSize but the backend for projects
- // returns an upaginated list which does not support that.
- const params:ApiV3ListParameters = {};
-
- if (this.currentProject.id) {
- params.filters = [['id', '=', [this.currentProject.id]]];
- }
-
- return params;
- }
+export class WidgetMembersComponent extends AbstractTurboWidgetComponent {
+ override frameId = 'overviews-widgets-members-component';
+ override name = 'members';
}
diff --git a/modules/overviews/app/controllers/overviews/widgets/members_controller.rb b/modules/overviews/app/controllers/overviews/widgets/members_controller.rb
new file mode 100644
index 00000000000..69c4f2b61a5
--- /dev/null
+++ b/modules/overviews/app/controllers/overviews/widgets/members_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::MembersController < Overviews::WidgetController
+end
diff --git a/modules/overviews/app/views/overviews/widgets/members/show.html.erb b/modules/overviews/app/views/overviews/widgets/members/show.html.erb
new file mode 100644
index 00000000000..c1270195712
--- /dev/null
+++ b/modules/overviews/app/views/overviews/widgets/members/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::MembersComponent.new(@project) %>
diff --git a/modules/overviews/config/routes.rb b/modules/overviews/config/routes.rb
index f110b217a83..c8dd1ad0195 100644
--- a/modules/overviews/config/routes.rb
+++ b/modules/overviews/config/routes.rb
@@ -21,6 +21,7 @@ Rails.application.routes.draw do
resource :project_status, only: %i[show update]
resource :news, only: %i[show]
resource :subitems, only: %i[show]
+ resource :members, only: %i[show]
end
end
end
diff --git a/modules/overviews/lib/overviews/engine.rb b/modules/overviews/lib/overviews/engine.rb
index c3562da3247..f468322d00d 100644
--- a/modules/overviews/lib/overviews/engine.rb
+++ b/modules/overviews/lib/overviews/engine.rb
@@ -110,6 +110,11 @@ module Overviews
.push(
"overviews/widgets/news/show"
)
+ OpenProject::AccessControl.permission(:view_members)
+ .controller_actions
+ .push(
+ "overviews/widgets/members/show"
+ )
end
end
diff --git a/modules/overviews/spec/controllers/overviews/widgets/members_controller_spec.rb b/modules/overviews/spec/controllers/overviews/widgets/members_controller_spec.rb
new file mode 100644
index 00000000000..9047d3fb32e
--- /dev/null
+++ b/modules/overviews/spec/controllers/overviews/widgets/members_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::Members do
+ shared_let(:project) { create(:project) }
+ shared_let(:user) { create(:user, member_with_permissions: { project => %i[view_member] }) }
+ 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
+end
diff --git a/modules/overviews/spec/permissions/widgets/members_spec.rb b/modules/overviews/spec/permissions/widgets/members_spec.rb
new file mode 100644
index 00000000000..e201bfae510
--- /dev/null
+++ b/modules/overviews/spec/permissions/widgets/members_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::MembersController, "permissions", type: :controller do # rubocop:disable RSpec/EmptyExampleGroup,RSpec/SpecFilePathFormat
+ include PermissionSpecs
+
+ check_permission_required_for("overviews/widgets/members#show", :view_member)
+end
diff --git a/modules/overviews/spec/routing/widget_routing_spec.rb b/modules/overviews/spec/routing/widget_routing_spec.rb
index a4d861920c9..c5684577fe3 100644
--- a/modules/overviews/spec/routing/widget_routing_spec.rb
+++ b/modules/overviews/spec/routing/widget_routing_spec.rb
@@ -138,4 +138,22 @@ RSpec.describe Overviews::WidgetController do
end
end
end
+
+ describe "members routing" do
+ describe "GET #show" do
+ it do
+ expect(get("/projects/my-project/widgets/members"))
+ .to route_to(controller: "overviews/widgets/members", action: "show", project_id: "my-project")
+ end
+ end
+ end
+
+ describe "members named routing" do
+ describe "GET #show" do
+ it do
+ expect(get(project_widgets_members_path("my-project")))
+ .to route_to(controller: "overviews/widgets/members", action: "show", project_id: "my-project")
+ end
+ end
+ end
end