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

Fix: Ammend stream actions to enable functional responsiveness behavior

Aaron Contreras1c478e3a5a81
diff --git a/app/components/work_packages/share/modal_body_component.html.erb b/app/components/work_packages/share/modal_body_component.html.erb
index 7a854d61943..d004ee4c338 100644
--- a/app/components/work_packages/share/modal_body_component.html.erb
+++ b/app/components/work_packages/share/modal_body_component.html.erb
@@ -5,7 +5,7 @@
render(WorkPackages::Share::InviteUserFormComponent.new(work_package: @work_package))
end
- if @shares.none?
+ if @shares.blank?
modal_content.with_row(mt: 3) do
render(Primer::Beta::Blankslate.new(border: true)) do |component|
component.with_visual_icon(icon: :people, size: :medium)
@@ -98,8 +98,8 @@
end
end
- @shares.each do |principal|
- render(WorkPackages::Share::ShareRowComponent.new(share: principal, container: border_box))
+ @shares.each do |share|
+ render(WorkPackages::Share::ShareRowComponent.new(share: share, container: border_box))
end
end
end
diff --git a/app/controllers/work_packages/shares/bulk_controller.rb b/app/controllers/work_packages/shares/bulk_controller.rb
index bbb20dcdc5b..ea553b7657f 100644
--- a/app/controllers/work_packages/shares/bulk_controller.rb
+++ b/app/controllers/work_packages/shares/bulk_controller.rb
@@ -33,13 +33,13 @@ class WorkPackages::Shares::BulkController < ApplicationController
include MemberHelper
before_action :find_work_package
- before_action :find_shares
+ before_action :find_selected_shares
before_action :find_role_ids_from_params, only: :update
before_action :find_project
before_action :authorize
def update
- @shares.each do |share|
+ @selected_shares.each do |share|
WorkPackageMembers::CreateOrUpdateService
.new(user: current_user)
.call(entity: @work_package,
@@ -51,7 +51,7 @@ class WorkPackages::Shares::BulkController < ApplicationController
end
def destroy
- @shares.each do |share|
+ @selected_shares.each do |share|
WorkPackageMembers::DeleteService
.new(user: current_user, model: share)
.call
@@ -67,7 +67,7 @@ class WorkPackages::Shares::BulkController < ApplicationController
private
def respond_with_update_permission_buttons
- @shares.each do |share|
+ @selected_shares.each do |share|
replace_via_turbo_stream(
component: WorkPackages::Share::PermissionButtonComponent.new(share:,
data: { 'test-selector': 'op-share-wp-update-role' })
@@ -79,14 +79,14 @@ class WorkPackages::Shares::BulkController < ApplicationController
def respond_with_replace_modal
replace_via_turbo_stream(
- component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package, shares: @shares)
+ component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package, shares: find_shares)
)
respond_with_turbo_streams
end
def respond_with_remove_shares
- @shares.each do |share|
+ @selected_shares.each do |share|
remove_via_turbo_stream(
component: WorkPackages::Share::ShareRowComponent.new(share:)
)
@@ -108,9 +108,16 @@ class WorkPackages::Shares::BulkController < ApplicationController
end
def find_shares
- @shares = Member.includes(:principal)
+ @shares = Member.includes(:principal, :member_roles)
+ .references(:member_roles)
.of_work_package(@work_package)
- .where(id: params[:share_ids])
+ .merge(MemberRole.only_non_inherited)
+ end
+
+ def find_selected_shares
+ @selected_shares = Member.includes(:principal)
+ .of_work_package(@work_package)
+ .where(id: params[:share_ids])
end
def find_role_ids_from_params
diff --git a/app/controllers/work_packages/shares_controller.rb b/app/controllers/work_packages/shares_controller.rb
index 7d7e342b11b..9b54db9928d 100644
--- a/app/controllers/work_packages/shares_controller.rb
+++ b/app/controllers/work_packages/shares_controller.rb
@@ -57,17 +57,15 @@ class WorkPackages::SharesController < ApplicationController
user_id: member_params[:user_id],
role_ids: find_role_ids(params[:member][:role_id]))
- @share = service_call.result
-
overall_result.push(service_call)
end
- @shares = overall_result.map(&:result).reverse
+ @new_shares = overall_result.map(&:result).reverse
if overall_result.present?
# In case the number of newly added shares is equal to the whole number of shares,
# we have to render the whole modal again to get rid of the blankslate
- if current_visible_member_count > 1 && @shares.size < current_visible_member_count
+ if current_visible_member_count > 1 && @new_shares.size < current_visible_member_count
respond_with_prepend_shares
else
respond_with_replace_modal
@@ -99,7 +97,7 @@ class WorkPackages::SharesController < ApplicationController
def respond_with_replace_modal
replace_via_turbo_stream(
- component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package, shares: @shares)
+ component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package, shares: @new_shares || find_shares)
)
respond_with_turbo_streams
@@ -114,10 +112,10 @@ class WorkPackages::SharesController < ApplicationController
component: WorkPackages::Share::CounterComponent.new(work_package: @work_package, count: current_visible_member_count)
)
- @shares.each do |share|
+ @new_shares.each do |share|
prepend_via_turbo_stream(
component: WorkPackages::Share::ShareRowComponent.new(share:),
- target_component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package, shares: @shares)
+ target_component: WorkPackages::Share::ModalBodyComponent.new(work_package: @work_package, shares: find_shares)
)
end
@@ -154,6 +152,13 @@ class WorkPackages::SharesController < ApplicationController
@work_package = @share.entity
end
+ def find_shares
+ @shares = Member.includes(:roles)
+ .references(:member_roles)
+ .of_work_package(@work_package)
+ .merge(MemberRole.only_non_inherited)
+ end
+
def find_project
@project = @work_package.project
end