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
Create `UserDetailsComponent`
Aaron Contreras1798e9570a38
diff --git a/app/components/work_packages/share/modal_body_component.sass b/app/components/work_packages/share/modal_body_component.sassindex d29d6c986f2..b40ec027bb5 100644--- a/app/components/work_packages/share/modal_body_component.sass+++ b/app/components/work_packages/share/modal_body_component.sass@@ -1,14 +1,14 @@.op-share-wp-modal-body&--user-rowdisplay: grid- grid-template-columns: 1fr- grid-template-areas: "user"+ grid-template-columns: auto 1fr+ grid-template-areas: "avatar user_details"grid-column-gap: 10px&_manageabledisplay: grid- grid-template-columns: 20px 1fr auto auto- grid-template-areas: "selection user button remove"+ grid-template-columns: 20px auto 1fr auto auto+ grid-template-areas: "selection avatar user_details button remove"grid-column-gap: 10px&--headerdiff --git a/app/components/work_packages/share/share_row_component.html.erb b/app/components/work_packages/share/share_row_component.html.erbindex 2d5956ab896..8491ac65169 100644--- a/app/components/work_packages/share/share_row_component.html.erb+++ b/app/components/work_packages/share/share_row_component.html.erb@@ -12,8 +12,12 @@endend- user_row_grid.with_area(:user, tag: :div, classes: 'ellipsis') do- render(Users::AvatarComponent.new(user: principal, size: :medium))+ user_row_grid.with_area(:avatar, tag: :div, classes: 'ellipsis') do+ render(Users::AvatarComponent.new(user: principal, show_name: false, size: :medium))+ end++ user_row_grid.with_area(:user_details, tag: :div) do+ render(WorkPackages::Share::UserDetailsComponent.new(user: principal, share:, manager_mode: share_editable?))endif share_editable?diff --git a/app/components/work_packages/share/user_details_component.html.erb b/app/components/work_packages/share/user_details_component.html.erbnew file mode 100644index 00000000000..c513e0bc4dd--- /dev/null+++ b/app/components/work_packages/share/user_details_component.html.erb@@ -0,0 +1,47 @@+<%=+ flex_layout do |flex|+ flex.with_row do+ render(Primer::Beta::Link.new(font_weight: :semibold, href: principal_show_path)) { user.name }+ end++ flex.with_row do+ if manager_mode?+ if user_is_a_group?+ if project_group?+ render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("work_package.sharing.user_details.project_group")}+ else+ render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("work_package.sharing.user_details.not_project_group")}+ end+ else+ if user_in_non_active_status?+ if user.locked?+ concat(render(Primer::Beta::Octicon.new(icon: :lock, color: :muted, mr: 1)))+ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("work_package.sharing.user_details.locked") })+ elsif user.invited?+ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t('work_package.sharing.user_details.invited') })+ concat(render(Primer::Beta::Link.new(href: '#')) { I18n.t('work_package.sharing.user_details.resend_invite') })+ end+ else+ if part_of_a_shared_group?+ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("work_package.sharing.user_details.part_of_a_shared_group") })+ end++ if project_member?+ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("work_package.sharing.user_details.project_member")})+ concat(render(Primer::Beta::Text.new(color: :subtle, font_weight: :semibold)) { project_role_name })+ else+ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("work_package.sharing.user_details.not_project_member")})+ end+ end+ end+ else+ if user.invited?+ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("work_package.sharing.user_details.invited")})+ end++ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("work_package.sharing.user_details.role") })+ concat(render(Primer::Beta::Text.new(color: :subtle, font_weight: :semibold)) { authoritative_work_package_role_name })+ end+ end+ end+%>diff --git a/app/components/work_packages/share/user_details_component.rb b/app/components/work_packages/share/user_details_component.rbnew file mode 100644index 00000000000..a6b44478666--- /dev/null+++ b/app/components/work_packages/share/user_details_component.rb@@ -0,0 +1,103 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2023 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 WorkPackages+ module Share+ # rubocop:disable OpenProject/AddPreviewForViewComponent+ class UserDetailsComponent < ApplicationComponent+ # rubocop:enable OpenProject/AddPreviewForViewComponent+ include OpPrimer::ComponentHelpers+ include WorkPackages::Share::Concerns::DisplayableRoles++ def initialize(user:, share:, manager_mode: false)+ super++ @user = user+ @share = share+ @manager_mode = manager_mode+ end++ private++ attr_reader :user, :share++ def manager_mode? = @manager_mode++ def authoritative_work_package_role_name+ @authoritative_work_package_role_name = options.find do |option|+ option[:value] == share.roles.first.builtin+ end[:label]+ end++ def principal_show_path+ case user+ when User+ user_path(user)+ when Group+ show_group_path(user)+ else+ placeholder_user_path(user)+ end+ end++ def user_is_a_group?+ @user_is_a_group ||= user.is_a?(Group)+ end++ def user_in_non_active_status?+ user.locked? || user.invited?+ end++ def project_member?+ Member.exists?(project: share.project,+ principal: user,+ entity: nil)+ end++ def project_group?+ user_is_a_group? && project_member?+ end++ def part_of_a_shared_group?+ share.member_roles.where.not(inherited_from: nil).any?+ end++ def project_role_name+ Member.where(project: share.project,+ principal: user,+ entity: nil)+ .first+ .roles+ .first+ .name+ end+ end+ end+enddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex f6ead939747..be3257cab75 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3273,6 +3273,16 @@ en:Adding additional users will exceed the current limit. Please contact an administrator to increase the user limit to ensure external users are able to access this work package.warning_user_limit_reached_admin: >Adding additional users will exceed the current limit. Please <a href="%{upgrade_url}">upgrade your plan</a> to be able to ensure external users are able to access this work package.+ user_details:+ locked: "Locked user"+ invited: "Pending invitation. "+ resend_invite: "Resend invite"+ project_member: "Project member: "+ not_project_member: "Not project member"+ project_group: "Project group"+ not_project_group: "Not project group"+ part_of_a_shared_group: "Part of a shared group. "+ role: "Role: "working_days:info: >diff --git a/spec/components/work_packages/share/user_details_component_spec.rb b/spec/components/work_packages/share/user_details_component_spec.rbnew file mode 100644index 00000000000..c735a0eadd1--- /dev/null+++ b/spec/components/work_packages/share/user_details_component_spec.rb@@ -0,0 +1,334 @@+# frozen_string_literal: true++# -- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2010-2023 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'++RSpec.describe WorkPackages::Share::UserDetailsComponent, type: :component do+ subject { render_inline(described_class.new(user: principal, share:, manager_mode:)) }++ shared_let(:project) { create(:project) }+ shared_let(:work_package) { create(:work_package, project:) }+ shared_let(:work_package_role) { create(:view_work_package_role) }+ shared_let(:project_role) { create(:project_role, name: 'Cool role') }++ shared_let(:user_firstname) { 'Richard' }+ shared_let(:user_lastname) { 'Hendricks' }+ shared_let(:group_name) { 'Cool group' }++ def build_inherited_share(group_share:, user_share:)+ create(:member_role,+ member: user_share,+ role: work_package_role,+ inherited_from: group_share.member_roles.first.id)+ end++ describe 'when not in manager mode' do+ let(:manager_mode) { false }++ describe 'rendering for a user in a non-active state' do+ context 'when the user is locked' do+ let!(:principal) { create(:user, firstname: user_firstname, lastname: user_lastname, status: :locked) }+ let!(:share) do+ create(:work_package_member,+ principal:,+ entity: work_package,+ roles: [work_package_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Role: View", normalize_ws: true)+ end+ end++ context 'when the user is invited' do+ let!(:principal) { create(:user, firstname: user_firstname, lastname: user_lastname, status: :invited) }+ let!(:share) do+ create(:work_package_member,+ principal:,+ entity: work_package,+ roles: [work_package_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Pending invitation. Role: View", normalize_ws: true)+ end+ end+ end++ describe 'rendering for a group' do+ shared_let(:principal) { create(:group, name: group_name) }+ shared_let(:share) do+ create(:work_package_member,+ principal:,+ entity: work_package,+ roles: [work_package_role])+ end++ context 'when it is a member in the project' do+ before do+ create(:member, project:, principal:, roles: [project_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Cool group Role: View", normalize_ws: true)+ end+ end++ context 'when it is not a member in the project' do+ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Cool group Role: View", normalize_ws: true)+ end+ end+ end++ describe 'rendering for a user' do+ shared_let(:principal) { create(:user, firstname: user_firstname, lastname: user_lastname) }+ shared_let(:share) do+ create(:work_package_member,+ principal:,+ entity: work_package,+ roles: [work_package_role])+ end++ context 'when the user is not part of a shared with group' do+ context 'and the user is not a project member' do+ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Role: View", normalize_ws: true)+ end+ end++ context 'and the user is a project member' do+ before do+ create(:member, project:, principal:, roles: [project_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Role: View", normalize_ws: true)+ end+ end+ end++ context 'when the user is part of a shared with group' do+ shared_let(:group) { create(:group, name: group_name, members: [principal]) }++ before do+ group_share = create(:work_package_member,+ principal: group,+ entity: work_package,+ roles: [work_package_role])++ build_inherited_share(group_share:, user_share: share)+ end++ context 'and the user is not a project member' do+ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Role: View", normalize_ws: true)+ end+ end++ context 'and the user is a project member' do+ before do+ create(:member, project:, principal:, roles: [project_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Role: View", normalize_ws: true)+ end+ end+ end+ end+ end++ describe 'when in manager mode' do+ let(:manager_mode) { true }++ describe 'rendering for a user in a non-active state' do+ context 'when the user is locked' do+ let!(:principal) { create(:user, firstname: user_firstname, lastname: user_lastname, status: :locked) }+ let!(:share) do+ create(:work_package_member,+ principal:,+ entity: work_package,+ roles: [work_package_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_css(".octicon-lock")+ expect(page)+ .to have_text("Richard Hendricks Locked user", normalize_ws: true)+ end+ end++ context 'when the user is invited' do+ let!(:principal) { create(:user, firstname: user_firstname, lastname: user_lastname, status: :invited) }+ let!(:share) do+ create(:work_package_member,+ principal:,+ entity: work_package,+ roles: [work_package_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Pending invitation. Resend invite", normalize_ws: true)+ end+ end+ end++ describe 'rendering for a group' do+ shared_let(:principal) { create(:group, name: group_name) }+ shared_let(:share) do+ create(:work_package_member,+ principal:,+ entity: work_package,+ roles: [work_package_role])+ end++ context 'when it is a member in the project' do+ before do+ create(:member, project:, principal:, roles: [project_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Cool group Project group", normalize_ws: true)+ end+ end++ context 'when it is not a member in the project' do+ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Cool group Not project group", normalize_ws: true)+ end+ end+ end++ describe 'rendering for a user' do+ shared_let(:principal) { create(:user, firstname: user_firstname, lastname: user_lastname) }+ shared_let(:share) do+ create(:work_package_member,+ principal:,+ entity: work_package,+ roles: [work_package_role])+ end++ context 'when the user is not part of a shared with group' do+ context 'and the user is not a project member' do+ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Not project member", normalize_ws: true)+ end+ end++ context 'and the user is a project member' do+ before do+ create(:member, project:, principal:, roles: [project_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Project member: Cool role", normalize_ws: true)+ end+ end+ end++ context 'when the user is part of a shared with group' do+ shared_let(:group) { create(:group, name: group_name, members: [principal]) }++ before do+ group_share = create(:work_package_member,+ principal: group,+ entity: work_package,+ roles: [work_package_role])++ build_inherited_share(group_share:, user_share: share)+ end++ context 'and the user is not a project member' do+ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Part of a shared group", normalize_ws: true)+ end+ end++ context 'and the user is a project member' do+ before do+ create(:member, project:, principal:, roles: [project_role])+ end++ it "", :aggregate_failures do+ subject++ expect(page)+ .to have_text("Richard Hendricks Part of a shared group. Project member: Cool role", normalize_ws: true)+ end+ end+ end+ end+ end+end