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

Update `destroy` action to granularly send turbo stream responses

Aaron Contreras847fa17427d3
diff --git a/app/controllers/work_packages/shares_controller.rb b/app/controllers/work_packages/shares_controller.rb
index 20873d2ef99..6325844d0af 100644
--- a/app/controllers/work_packages/shares_controller.rb
+++ b/app/controllers/work_packages/shares_controller.rb
@@ -61,7 +61,13 @@ class WorkPackages::SharesController < ApplicationController
.new(user: current_user, model: @share)
.call
- respond_with_update_modal
+ find_shared_users
+
+ if @shared_users.none?
+ respond_with_update_modal
+ else
+ respond_with_remove_share
+ end
end
private
@@ -74,6 +80,18 @@ class WorkPackages::SharesController < ApplicationController
respond_with_turbo_streams
end
+ def respond_with_remove_share
+ remove_via_turbo_stream(
+ component: WorkPackages::Share::ShareRowComponent.new(share: @share)
+ )
+
+ update_via_turbo_stream(
+ component: WorkPackages::Share::ShareCounterComponent.new(count: @shared_users.size)
+ )
+
+ respond_with_turbo_streams
+ end
+
def find_work_package
@work_package = WorkPackage.find(params[:work_package_id])
end
@@ -92,4 +110,12 @@ class WorkPackages::SharesController < ApplicationController
# is why we unscope.
WorkPackageRole.unscoped.where(builtin: builtin_value).pluck(:id)
end
+
+ def find_shared_users
+ @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')
+ end
end