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
Move sub description of each share into the strategy
Klaus Zanders8ed942945080
diff --git a/app/components/shares/share_row_component.html.erb b/app/components/shares/share_row_component.html.erbindex 8663e29e3b8..bd39ae962c2 100644--- a/app/components/shares/share_row_component.html.erb+++ b/app/components/shares/share_row_component.html.erb@@ -17,13 +17,13 @@enduser_row_grid.with_area(:user_details, tag: :div, classes: 'ellipsis') do- render(Shares::UserDetailsComponent.new(share:, manager_mode: share_editable?))+ render(Shares::UserDetailsComponent.new(share:, strategy:))enduser_row_grid.with_area(:button, tag: :div, color: :subtle) dorender(Shares::PermissionButtonComponent.new(share:,- strategy: strategy,- data: { 'test-selector': 'op-share-dialog-update-role' }))+ strategy: strategy,+ data: { 'test-selector': 'op-share-dialog-update-role' }))endif share_editable?diff --git a/app/components/shares/user_details_component.html.erb b/app/components/shares/user_details_component.html.erbindex 2af0f5a1929..da387ac45bd 100644--- a/app/components/shares/user_details_component.html.erb+++ b/app/components/shares/user_details_component.html.erb@@ -1,67 +1,38 @@-<%=- component_wrapper do- flex_layout do |flex|- flex.with_row do- render(Primer::Beta::Link.new(font_weight: :semibold, href: principal_show_path)) { user.name }- end+<%= component_wrapper do+ 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(classes: 'ellipsis') do- if manager_mode?- if user_is_a_group?- if project_group?- render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.project_group")}- else- render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("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("sharing.user_details.locked") })- elsif user.invited?- if invite_resent?- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.invite_resent") })- else- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t('sharing.user_details.invited') })- concat(- form_with(url: resend_invite_path, method: :post) do- render(Primer::Beta::Button.new(type: :submit, px: 0, scheme: :link)) { I18n.t('sharing.user_details.resend_invite') }- end- )- end- end+ flex.with_row(classes: "ellipsis") do+ if strategy.manageable?+ 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("sharing.user_details.locked") })+ elsif user.invited?+ if invite_resent?+ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.invite_resent") })else- if part_of_a_group?- if part_of_a_shared_group?- if project_member?- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.additional_privileges_project_or_group") })- else- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.additional_privileges_group") })- end- else- if inherited_project_member?- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.additional_privileges_project_or_group") })- elsif project_member?- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.additional_privileges_project") })- else- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.not_project_member") })- end- end- else- if project_member?- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.additional_privileges_project") })- else- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.not_project_member") })- end- end++ concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.invited") })+ concat(+ form_with(url: resend_invite_path, method: :post) do+ render(Primer::Beta::Button.new(type: :submit, px: 0, scheme: :link)) { I18n.t("sharing.user_details.resend_invite") }+ end)endendelse- if user.invited?- concat(render(Primer::Beta::Text.new(color: :subtle)) { I18n.t("sharing.user_details.invited")})- end+ concat(render(Primer::Beta::Text.new(color: :subtle)) { strategy.share_description(share) })end+ else+ concat(render(Primer::Beta::Text.new(color: :subtle)) { strategy.share_description(share) })endendend-%>+end %>diff --git a/app/components/shares/user_details_component.rb b/app/components/shares/user_details_component.rbindex 8f189f2b6db..8e809efe887 100644--- a/app/components/shares/user_details_component.rb+++ b/app/components/shares/user_details_component.rb@@ -33,22 +33,18 @@ module Sharesinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(share:,- manager_mode:,- invite_resent: false)+ def initialize(share:, strategy:, invite_resent: false)super@share = share@user = share.principal- @manager_mode = manager_mode+ @strategy = strategy@invite_resent = invite_resentendprivate- attr_reader :user, :share-- def manager_mode? = @manager_mode+ attr_reader :user, :share, :strategydef invite_resent? = @invite_resent@@ -56,12 +52,6 @@ module Sharesshare.idend- def authoritative_work_package_role_name- @authoritative_work_package_role_name = options.find do |option|- option[:value] == share.roles.first.id- end[:label]- end-def principal_show_pathcase userwhen User@@ -77,50 +67,8 @@ module Sharesurl_for([:resend_invite, share.entity, share])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-- # Is a user member of a project no matter whether inherited or directly assigned- def project_member?- Member.exists?(project: share.project,- principal: user,- entity: nil)- end-- # Explicitly check whether the project membership was inherited by a group- def inherited_project_member?- Member.includes(:roles)- .references(:member_roles)- .where(project: share.project, principal: user, entity: nil) # membership in the project- .merge(MemberRole.only_inherited) # that was inherited- .any?- 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 part_of_a_group?- GroupUser.where(user_id: user.id).any?- end-- def project_role_name- Member.where(project: share.project,- principal: user,- entity: nil)- .first- .roles- .first- .name- endendenddiff --git a/app/models/sharing_strategies/base_strategy.rb b/app/models/sharing_strategies/base_strategy.rbindex 445ebd18a08..56ac9de26f5 100644--- a/app/models/sharing_strategies/base_strategy.rb+++ b/app/models/sharing_strategies/base_strategy.rb@@ -62,6 +62,10 @@ module SharingStrategiesraise NotImplementedError, "Override in a subclass and return the contract class for deleting a share"end+ def share_description(share)+ raise NotImplementedError, "Override in a subclass and return a description for the shared user"+ end+def custom_body_components?!additional_body_components.empty?enddiff --git a/app/models/sharing_strategies/project_query_strategy.rb b/app/models/sharing_strategies/project_query_strategy.rbindex 19d7ec62348..d8ac94abc16 100644--- a/app/models/sharing_strategies/project_query_strategy.rb+++ b/app/models/sharing_strategies/project_query_strategy.rb@@ -88,6 +88,21 @@ module SharingStrategiesendend+ def share_description(share) # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity+ return I18n.t("sharing.user_details.invited") if !manageable? && share.principal.invited?+ return "" if !manageable?++ if share.principal == entity.user+ I18n.t("sharing.project_queries.user_details.owner")+ elsif entity.public?+ if share.principal.is_a?(User) && share.principal.allowed_globally?(:manage_public_project_queries)+ I18n.t("sharing.project_queries.user_details.can_manage_public_lists")+ elsif share.roles.any? { |role| role.builtin == Role::BUILTIN_PROJECT_QUERY_VIEW }+ I18n.t("sharing.project_queries.user_details.can_view_because_public")+ end+ end+ end+privatedef virtual_owner_sharediff --git a/app/models/sharing_strategies/work_package_strategy.rb b/app/models/sharing_strategies/work_package_strategy.rbindex 3d24ef89a81..0c10e018390 100644--- a/app/models/sharing_strategies/work_package_strategy.rb+++ b/app/models/sharing_strategies/work_package_strategy.rb@@ -53,6 +53,38 @@ module SharingStrategiesuser.allowed_in_project?(:view_shared_work_packages, @entity.project)end+ def share_description(share) # rubocop:disable Metrics/PerceivedComplexity,Metrics/AbcSize+ return I18n.t("sharing.user_details.invited") if !manageable? && share.principal.invited?+ return "" if !manageable?++ if share.principal.is_a?(Group)+ if project_member?(share)+ I18n.t("sharing.user_details.project_group")+ else+ I18n.t("sharing.user_details.not_project_group")+ end++ elsif group_member?(share)+ if has_roles_via_group_membership?(share)+ if project_member?(share)+ I18n.t("sharing.user_details.additional_privileges_project_or_group")+ else+ I18n.t("sharing.user_details.additional_privileges_group")+ end+ elsif inherited_project_member?(share)+ I18n.t("sharing.user_details.additional_privileges_project_or_group")+ elsif project_member?(share)+ I18n.t("sharing.user_details.additional_privileges_project")+ else+ I18n.t("sharing.user_details.not_project_member")+ end+ elsif project_member?(share)+ I18n.t("sharing.user_details.additional_privileges_project")+ else+ I18n.t("sharing.user_details.not_project_member")+ end+ end+def create_contract_classShares::WorkPackages::CreateContractend@@ -64,5 +96,27 @@ module SharingStrategiesdef delete_contract_classShares::WorkPackages::DeleteContractend++ private++ def project_member?(share)+ Member.exists?(project: share.entity.project, principal: share.principal, entity: nil)+ end++ def group_member?(share)+ GroupUser.where(user_id: share.principal.id).any?+ end++ def has_roles_via_group_membership?(share)+ share.member_roles.where.not(inherited_from: nil).any?+ end++ def inherited_project_member?(share)+ Member.includes(:roles)+ .references(:member_roles)+ .where(project: share.project, principal: share.principal, entity: nil)+ .merge(MemberRole.only_inherited)+ .any?+ endendenddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 8f7ded21eb7..d8be3a8635d 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3700,6 +3700,10 @@ en:project_queries:publishing_denied: "You do not have permission to make project lists public."access_warning: "Users will only see the projects they have access to. Sharing project lists does not impact individual project permissions."+ user_details:+ owner: "List owner"+ can_view_because_public: "Can already view because list is shared with everyone"+ can_manage_public_lists: "Can edit due to global permissions"public_flag:label: "Share with everyone at %{instance_name}"caption: "Everyone can view this project list. Those with global edit permissions can modify it."