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

Add primerized members widget

Henriette Darge7a2fb9aa3e1e
diff --git a/app/models/member.rb b/app/models/member.rb
index 8808fce05cc..92e1228d446 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -125,6 +125,10 @@ class Member < ApplicationRecord
ALLOWED_ENTITIES.include?(checked_class)
end
+ def self.newest_first
+ order "#{table_name}.created_at DESC"
+ end
+
protected
attr_accessor :prune_watchers_on_destruction
diff --git a/modules/overviews/app/components/overviews/overview_grid_component.html.erb b/modules/overviews/app/components/overviews/overview_grid_component.html.erb
index ec33d11af0a..005bed456fc 100644
--- a/modules/overviews/app/components/overviews/overview_grid_component.html.erb
+++ b/modules/overviews/app/components/overviews/overview_grid_component.html.erb
@@ -32,6 +32,7 @@ See COPYRIGHT and LICENSE files for more details.
grid.with_widget(Overviews::Widgets::DescriptionComponent, @project)
grid.with_widget(Overviews::Widgets::ProjectStatusComponent, @project)
grid.with_widget(Overviews::Widgets::SubitemsComponent, @project)
+ grid.with_widget(Overviews::Widgets::MembersComponent, @project)
grid.with_widget(Overviews::Widgets::NewsComponent, @project)
end
%>
diff --git a/modules/overviews/app/components/overviews/widgets/members_component.html.erb b/modules/overviews/app/components/overviews/widgets/members_component.html.erb
new file mode 100644
index 00000000000..e19ca7b58d2
--- /dev/null
+++ b/modules/overviews/app/components/overviews/widgets/members_component.html.erb
@@ -0,0 +1,45 @@
+<%#-- 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.
+
+++#%>
+
+<%=
+ widget_wrapper do
+ flex_layout do |flex|
+ @newest_members.each do |item|
+ flex.with_row(mb: 3) do
+ render Users::AvatarComponent.new(user: item.principal, size: :mini, link: false, show_name: true)
+ end
+ end
+ flex.with_row do
+ render Primer::Beta::Link.new(href: project_members_path(@project)) do
+ I18n.t(:"overviews.widgets.members.view_all_members")
+ end
+ end
+ end
+ end
+%>
diff --git a/modules/overviews/app/components/overviews/widgets/members_component.rb b/modules/overviews/app/components/overviews/widgets/members_component.rb
new file mode 100644
index 00000000000..9b41bfaa1d6
--- /dev/null
+++ b/modules/overviews/app/components/overviews/widgets/members_component.rb
@@ -0,0 +1,60 @@
+# 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 MembersComponent < Grids::WidgetComponent
+ MEMBERS_LIMIT = 5
+
+ attr_reader :project, :current_user
+
+ def initialize(project)
+ super()
+
+ @project = project
+ @current_user = current_user
+ @members =
+ if project
+ project.members.visible(current_user).newest_first
+ end
+
+ @newest_members = @members.limit(MEMBERS_LIMIT).to_a
+ end
+
+ def title
+ t(:"overviews.widgets.members.title")
+ end
+
+ def render?
+ current_user.allowed_in_project?(:view_members, project) && @newest_members.present?
+ end
+ end
+ end
+end
diff --git a/modules/overviews/app/components/overviews/widgets/subitems_component.rb b/modules/overviews/app/components/overviews/widgets/subitems_component.rb
index d1f6d046e36..fc6cc8315cb 100644
--- a/modules/overviews/app/components/overviews/widgets/subitems_component.rb
+++ b/modules/overviews/app/components/overviews/widgets/subitems_component.rb
@@ -44,6 +44,10 @@ module Overviews
def children
@children ||= project.children.visible
end
+
+ def wrapper_arguments
+ { full_width: true }
+ end
end
end
end
diff --git a/modules/overviews/config/locales/en.yml b/modules/overviews/config/locales/en.yml
index 158daf33827..5585d9f1bff 100644
--- a/modules/overviews/config/locales/en.yml
+++ b/modules/overviews/config/locales/en.yml
@@ -10,4 +10,7 @@ en:
in_this_program: "In this program"
in_this_project: "In this project"
no_visible_children: "There are no visible children."
+ members:
+ title: "Latest members"
+ view_all_members: "View all members"
permission_manage_overview: 'Manage overview page'
diff --git a/modules/overviews/spec/components/overviews/widgets/members_component_spec.rb b/modules/overviews/spec/components/overviews/widgets/members_component_spec.rb
new file mode 100644
index 00000000000..34905ad9469
--- /dev/null
+++ b/modules/overviews/spec/components/overviews/widgets/members_component_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::Widgets::MembersComponent, type: :component do
+ include Rails.application.routes.url_helpers
+
+ def render_component(...)
+ render_inline(described_class.new(...))
+ end
+
+ let(:project) { nil }
+ let(:user) { nil }
+
+ current_user { user }
+
+ subject(:rendered_component) do
+ render_component(project)
+ end
+
+ context "with permissions" do
+ let(:project) { create(:project) }
+ let(:user) { create(:admin) }
+
+ context "with no members" do
+ it "does not render" do
+ expect(rendered_component).not_to have_element "#overviews-widgets-members-component-box"
+ end
+ end
+
+ context "with members" do
+ let(:member) { create(:user, member_with_permissions: { project => %i[view_members] }) }
+
+ before do
+ member
+ end
+
+ it "renders turbo-frame component wrapper" do
+ expect(rendered_component).to have_element :"turbo-frame"
+ end
+
+ it "renders members items", :aggregate_failures do
+ expect(rendered_component).to have_element class: "op-widget-box--body" do |body|
+ expect(body).to have_link href: project_members_path(project)
+ expect(body).to have_element :"opce-principal"
+ end
+ end
+ end
+ end
+
+ context "without permissions" do
+ let(:project) { create(:project) }
+ let(:user) { create(:anonymous) }
+
+ it "does not render" do
+ expect(rendered_component).not_to have_element "#overviews-widgets-members-component-box"
+ end
+ end
+end