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
Allow custom-rendered `component_wrapper`
Aaron Contreras7afed612edd1
diff --git a/app/components/concerns/op_turbo/streamable.rb b/app/components/concerns/op_turbo/streamable.rbindex 23fe8d9c926..5d8030f6789 100644--- a/app/components/concerns/op_turbo/streamable.rb+++ b/app/components/concerns/op_turbo/streamable.rb@@ -86,15 +86,17 @@ module OpTurbo).render_in(view_context)end- def component_wrapper(tag: "div", class: nil, data: nil, style: nil, &block)+ def component_wrapper(method = nil, tag: "div", class: nil, data: nil, style: nil, &block)@wrapped = true+ wrapper_arguments = { id: wrapper_key, class:, data:, style: }+if inner_html_only?capture(&block)elsif wrapper_only?- content_tag(tag, id: wrapper_key, class:, data:, style:)+ method ? send(method, wrapper_arguments) : content_tag(tag, wrapper_arguments)else- content_tag(tag, id: wrapper_key, class:, data:, style:, &block)+ method ? send(method, wrapper_arguments, &block) : content_tag(tag, wrapper_arguments, &block)endenddiff --git a/app/components/work_packages/share/concerns/authorization.rb b/app/components/work_packages/share/concerns/authorization.rbnew file mode 100644index 00000000000..3cf2adddc8e--- /dev/null+++ b/app/components/work_packages/share/concerns/authorization.rb@@ -0,0 +1,45 @@+# 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+ module Concerns+ module Authorization+ extend ActiveSupport::Concern++ included do+ def sharing_manageable?+ User.current.allowed_to?(:share_work_packages, @work_package.project)+ end+ end+ end+ end+ end+enddiff --git a/app/components/work_packages/share/modal_body_component.rb b/app/components/work_packages/share/modal_body_component.rbindex 1e1ef9cda86..c4e4d7051da 100644--- a/app/components/work_packages/share/modal_body_component.rb+++ b/app/components/work_packages/share/modal_body_component.rb@@ -32,6 +32,7 @@ module WorkPackagesinclude ApplicationHelperinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers+ include WorkPackages::Share::Concerns::Authorizationdef initialize(work_package:)super@@ -76,10 +77,6 @@ module WorkPackages.where(work_package_shares: { entity: @work_package }).order('work_package_shares.created_at DESC')end-- def sharing_manageable?- User.current.allowed_to?(:share_work_packages, @work_package.project)- endendendenddiff --git a/app/components/work_packages/share/share_row_component.html.erb b/app/components/work_packages/share/share_row_component.html.erbindex c6c01cc3a81..c8ebbae2a58 100644--- a/app/components/work_packages/share/share_row_component.html.erb+++ b/app/components/work_packages/share/share_row_component.html.erb@@ -1,21 +1,20 @@<%=- component_wrapper do- border_box_row do- grid_layout('op-share-wp-modal-body--user-row', tag: :div, align_items: :center, classes: 'ellipsis') do |user_row_grid|- user_row_grid.with_area(:user, tag: :div, classes: 'ellipsis') do- render(Users::AvatarComponent.new(user: user, size: :medium))- end+ component_wrapper(:border_box_row, data: { 'test-selector': "op-share-wp-active-user-#{user.id}" }) do+ grid_layout('op-share-wp-modal-body--user-row', tag: :div, align_items: :center, classes: 'ellipsis') do |user_row_grid|+ user_row_grid.with_area(:user, tag: :div, classes: ' ellipsis') do+ render(Users::AvatarComponent.new(user: user, size: :medium))+ end- if share_editable?- user_row_grid.with_area(:button, tag: :div, color: :subtle) do- render(WorkPackages::Share::PermissionButtonComponent.new(share:,- data: { 'test-selector': 'op-share-wp-update-role' }))- end- user_row_grid.with_area(:remove, tag: :div) do- form_with url: work_packages_share_path(share), method: :delete do- render(Primer::Beta::Button.new(type: :submit, scheme: :invisible)) { I18n.t('work_package.sharing.remove') }- end+ if share_editable?+ user_row_grid.with_area(:button, tag: :div, color: :subtle) do+ render(WorkPackages::Share::PermissionButtonComponent.new(share:,+ data: { 'test-selector': 'op-share-wp-update-role' }))+ end++ user_row_grid.with_area(:remove, tag: :div) do+ form_with url: work_packages_share_path(share), method: :delete do+ render(Primer::Beta::Button.new(type: :submit, scheme: :invisible)) { I18n.t('work_package.sharing.remove') }endendenddiff --git a/app/components/work_packages/share/share_row_component.rb b/app/components/work_packages/share/share_row_component.rbindex 8726a7974c3..e9e8774d16b 100644--- a/app/components/work_packages/share/share_row_component.rb+++ b/app/components/work_packages/share/share_row_component.rb@@ -34,6 +34,7 @@ module WorkPackagesinclude ApplicationHelperinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers+ include WorkPackages::Share::Concerns::Authorizationdef initialize(share:,container: nil)@@ -49,32 +50,25 @@ module WorkPackagesshare.idend- def border_box_row(&)+ def border_box_row(wrapper_arguments, &)if container- container.with_row(**row_system_arguments, &)+ container.with_row(**wrapper_arguments, &)elsecontainer = Primer::Beta::BorderBox.newrow = container.registered_slots[:rows][:renderable_function]- .bind_call(container, **row_system_arguments)+ .bind_call(container, **wrapper_arguments)+render(row, &)endend- def row_system_arguments- { id: wrapper_key, data: { 'test-selector': "op-share-wp-active-user-#{user.id}" } }- end-private- attr_reader :user, :share, :container+ attr_reader :share, :work_package, :user, :containerdef share_editable?@share_editable ||= User.current != share.principal && sharing_manageable?end-- def sharing_manageable?- User.current.allowed_to?(:share_work_packages, @work_package.project)- endendendend