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
Prepend newest created row to the top of shares list
Aaron Contreras399e6710391b
diff --git a/app/components/work_packages/share/modal_body_component.html.erb b/app/components/work_packages/share/modal_body_component.html.erbindex f7b46c5e0ae..f7e1c8a850f 100644--- a/app/components/work_packages/share/modal_body_component.html.erb+++ b/app/components/work_packages/share/modal_body_component.html.erb@@ -25,18 +25,16 @@endelsemodal_content.with_row(mt: 3, data: { 'test-selector': 'op-share-wp-active-list'}) do- render(Primer::Beta::BorderBox.new) do |invited_user_list|- invited_user_list.with_header(color: :subtle, data: { 'test-selector': 'op-share-wp-active-count' }) do+ invited_user_list do |border_box|+ border_box.with_header(color: :subtle, data: { 'test-selector': 'op-share-wp-active-count' }) dorender(WorkPackages::Share::ShareCounterComponent.new(count: shared_users.count))endshared_users.each do |user|share = user.work_package_shares.where(entity: @work_package).first- render(WorkPackages::Share::ShareRowComponent.new(user:,- share:,- container: invited_user_list,- render_controls: share_editable?(share)))+ render(WorkPackages::Share::ShareRowComponent.new(share:,+ container: border_box))endendenddiff --git a/app/components/work_packages/share/modal_body_component.rb b/app/components/work_packages/share/modal_body_component.rbindex 2b0905c315e..1e1ef9cda86 100644--- a/app/components/work_packages/share/modal_body_component.rb+++ b/app/components/work_packages/share/modal_body_component.rb@@ -33,11 +33,11 @@ module WorkPackagesinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(work_package:, shared_users: nil)+ def initialize(work_package:)super@work_package = work_package- @shared_users = shared_users || find_shared_users+ @shared_users = find_shared_usersenddef self.wrapper_key@@ -48,21 +48,38 @@ module WorkPackagesattr_reader :shared_users+ def insert_target_modified?+ true+ end++ # There is currently no available system argument for setting an id on the+ # rendered <ul> tag that houses the row slots on Primer::Beta::BorderBox components.+ def invited_user_list(&)+ border_box = Primer::Beta::BorderBox.new++ set_id_on_list_element(border_box)++ render(border_box, &)+ end++ def set_id_on_list_element(list_container)+ new_list_arguments = list_container.instance_variable_get(:@list_arguments)+ .merge(id: insert_target_modifier_id)++ list_container.instance_variable_set(:@list_arguments, new_list_arguments)+ end+def find_shared_users- User- .having_entity_membership(@work_package)- .includes(work_package_shares: :roles)- .where(work_package_shares: { entity: @work_package })- .order('work_package_shares.created_at DESC')+ @shared_users = User+ .having_entity_membership(@work_package)+ .includes(work_package_shares: :roles)+ .where(work_package_shares: { entity: @work_package })+ .order('work_package_shares.created_at DESC')enddef sharing_manageable?User.current.allowed_to?(:share_work_packages, @work_package.project)end-- def share_editable?(share)- User.current != share.principal && sharing_manageable?- endendendenddiff --git a/app/components/work_packages/share/share_row_component.html.erb b/app/components/work_packages/share/share_row_component.html.erbindex e4f1e45c8b2..c6c01cc3a81 100644--- a/app/components/work_packages/share/share_row_component.html.erb+++ b/app/components/work_packages/share/share_row_component.html.erb@@ -1,12 +1,12 @@<%=component_wrapper do- container.with_row(id: wrapper_key, data: { 'test-selector': "op-share-wp-active-user-#{user.id}" }) do+ border_box_row dogrid_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') dorender(Users::AvatarComponent.new(user: user, size: :medium))end- if render_controls?+ if share_editable?user_row_grid.with_area(:button, tag: :div, color: :subtle) dorender(WorkPackages::Share::PermissionButtonComponent.new(share:,data: { 'test-selector': 'op-share-wp-update-role' }))diff --git a/app/components/work_packages/share/share_row_component.rb b/app/components/work_packages/share/share_row_component.rbindex 8b2ff3d4159..8726a7974c3 100644--- a/app/components/work_packages/share/share_row_component.rb+++ b/app/components/work_packages/share/share_row_component.rb@@ -36,14 +36,12 @@ module WorkPackagesinclude OpPrimer::ComponentHelpersdef initialize(share:,- user: share.principal,- render_controls: false,container: nil)super@share = share- @user = user- @render_controls = render_controls+ @work_package = share.entity+ @user = share.principal@container = containerend@@ -51,12 +49,31 @@ module WorkPackagesshare.idend+ def border_box_row(&)+ if container+ container.with_row(**row_system_arguments, &)+ else+ container = Primer::Beta::BorderBox.new+ row = container.registered_slots[:rows][:renderable_function]+ .bind_call(container, **row_system_arguments)+ render(row, &)+ end+ end++ def row_system_arguments+ { id: wrapper_key, data: { 'test-selector': "op-share-wp-active-user-#{user.id}" } }+ end+privateattr_reader :user, :share, :container- def render_controls?- !!@render_controls+ def share_editable?+ @share_editable ||= User.current != share.principal && sharing_manageable?+ end++ def sharing_manageable?+ User.current.allowed_to?(:share_work_packages, @work_package.project)endendenddiff --git a/app/controllers/work_packages/shares_controller.rb b/app/controllers/work_packages/shares_controller.rbindex 34268518199..285a8496018 100644--- a/app/controllers/work_packages/shares_controller.rb+++ b/app/controllers/work_packages/shares_controller.rb@@ -39,13 +39,20 @@ class WorkPackages::SharesController < ApplicationControllerenddef create- WorkPackageMembers::CreateOrUpdateService+ any_currently_shared_users = find_shared_users.any?++ @share = WorkPackageMembers::CreateOrUpdateService.new(user: current_user).call(entity: @work_package,user_id: params[:member][:user_id],- role_ids: find_role_ids(params[:member][:role_id]))+ role_ids: find_role_ids(params[:member][:role_id])).result+- respond_with_update_modal+ if any_currently_shared_users+ respond_with_prepend_share+ else+ respond_with_replace_modal+ endenddef update@@ -61,10 +68,8 @@ class WorkPackages::SharesController < ApplicationController.new(user: current_user, model: @share).call- find_shared_users-- if @shared_users.none?- respond_with_update_modal+ if find_shared_users.none?+ respond_with_replace_modalelserespond_with_remove_shareend@@ -72,7 +77,7 @@ class WorkPackages::SharesController < ApplicationControllerprivate- def respond_with_update_modal+ def respond_with_replace_modalreplace_via_turbo_stream(component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package))@@ -80,6 +85,19 @@ class WorkPackages::SharesController < ApplicationControllerrespond_with_turbo_streamsend+ def respond_with_prepend_share+ prepend_via_turbo_stream(+ component: WorkPackages::Share::ShareRowComponent.new(share: @share),+ target_component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package)+ )++ update_via_turbo_stream(+ component: WorkPackages::Share::ShareCounterComponent.new(count: @shared_users.size)+ )++ respond_with_turbo_streams+ end+def respond_with_remove_shareremove_via_turbo_stream(component: WorkPackages::Share::ShareRowComponent.new(share: @share)