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
Remove work package specific loading in SharesController and use entity
Klaus Zanders95910211c920
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rbindex 9fb8cf22d34..5459d374bdd 100644--- a/app/controllers/shares_controller.rb+++ b/app/controllers/shares_controller.rb@@ -30,22 +30,18 @@ class SharesController < ApplicationControllerinclude OpTurbo::ComponentStreaminclude MemberHelper- before_action :find_work_package, only: %i[index create destroy update resend_invite]- before_action :find_share, only: %i[destroy update resend_invite]- before_action :find_project+ before_action :load_entity+ before_action :load_shares, only: %i[index]+ before_action :load_share, only: %i[destroy update resend_invite]before_action :authorizebefore_action :enterprise_check, only: %i[index]def index- query = load_query-- unless query.valid?+ unless @query.valid?flash.now[:error] = query.errors.full_messagesend- @shares = load_shares query-- render Shares::ModalBodyComponent.new(work_package: @work_package, shares: @shares, errors: @errors), layout: nil+ render Shares::ModalBodyComponent.new(work_package: @entity, shares: @shares, errors: @errors), layout: nilenddef create@@ -59,7 +55,7 @@ class SharesController < ApplicationControllerelseservice_call = WorkPackageMembers::CreateOrUpdateService.new(user: current_user)- .call(entity: @work_package,+ .call(entity: @entity,user_id: member_params[:user_id],role_ids: find_role_ids(params[:member][:role_id]))@@ -87,7 +83,7 @@ class SharesController < ApplicationController.new(user: current_user, model: @share).call(role_ids: find_role_ids(params[:role_ids]))- find_shares+ load_sharesif @shares.empty?respond_with_replace_modal@@ -128,9 +124,9 @@ class SharesController < ApplicationControllerdef respond_with_replace_modalreplace_via_turbo_stream(- component: Shares::ModalBodyComponent.new(work_package: @work_package,- shares: @new_shares || find_shares,- errors: @errors)+ component: Shares::ModalBodyComponent.new(work_package: @entity,+ shares: @new_shares || load_shares,+ errors: @errors))respond_with_turbo_streams@@ -138,19 +134,19 @@ class SharesController < ApplicationControllerdef respond_with_prepend_sharesreplace_via_turbo_stream(- component: Shares::InviteUserFormComponent.new(work_package: @work_package, errors: @errors)+ component: Shares::InviteUserFormComponent.new(work_package: @entity, errors: @errors))update_via_turbo_stream(- component: Shares::CounterComponent.new(work_package: @work_package, count: current_visible_member_count)+ component: Shares::CounterComponent.new(work_package: @entity, count: current_visible_member_count))@new_shares.each do |share|prepend_via_turbo_stream(component: Shares::ShareRowComponent.new(share:),- target_component: Shares::ModalBodyComponent.new(work_package: @work_package,- shares: find_shares,- errors: @errors)+ target_component: Shares::ModalBodyComponent.new(work_package: @entity,+ shares: load_shares,+ errors: @errors))end@@ -158,81 +154,78 @@ class SharesController < ApplicationControllerenddef respond_with_new_invite_form- replace_via_turbo_stream(- component: Shares::InviteUserFormComponent.new(work_package: @work_package, errors: @errors)- )+ replace_via_turbo_stream(component: Shares::InviteUserFormComponent.new(work_package: @entity, errors: @errors))respond_with_turbo_streamsenddef respond_with_update_permission_button- replace_via_turbo_stream(- component: Shares::PermissionButtonComponent.new(share: @share,- data: { "test-selector": "op-share-wp-update-role" })- )+ replace_via_turbo_stream(component: Shares::PermissionButtonComponent.new(share: @share,+ data: { "test-selector": "op-share-wp-update-role" }))respond_with_turbo_streamsenddef respond_with_remove_share- remove_via_turbo_stream(- component: Shares::ShareRowComponent.new(share: @share)- )-- update_via_turbo_stream(- component: Shares::CounterComponent.new(work_package: @work_package, count: current_visible_member_count)- )+ remove_via_turbo_stream(component: Shares::ShareRowComponent.new(share: @share))+ update_via_turbo_stream(component: Shares::CounterComponent.new(work_package: @entity, count: current_visible_member_count))respond_with_turbo_streamsenddef respond_with_update_user_details- update_via_turbo_stream(- component: Shares::UserDetailsComponent.new(share: @share,- invite_resent: true)- )+ update_via_turbo_stream(component: Shares::UserDetailsComponent.new(share: @share, invite_resent: true))respond_with_turbo_streamsend- def find_work_package- @work_package = WorkPackage.find(params[:work_package_id])- end-- def find_share- @share = @work_package.members.find(params[:id])- end-- def find_shares- @shares = load_shares(load_query)+ def load_entity+ puts "*" * 100, "Loading Entity", params.to_unsafe_h, "*" * 100+ @entity = if params["work_package_id"]+ WorkPackage.visible.find(params["work_package_id"])+ # TODO: Add support for other entities+ else+ raise ArgumentError, <<~ERROR+ Nested the SharesController under an entity controller that is not yet configured to support sharing.+ Edit the SharesController#load_entity method to load the entity from the correct parent.+ ERROR+ end++ puts "**** Entity: #{@entity} ****"+ if @entity.respond_to?(:project)+ @project = @entity.project+ endend- def find_project- @project = @work_package.project+ def load_share+ @share = @entity.members.find(params[:id])enddef current_visible_member_count- @current_visible_member_count ||= load_shares(load_query).size+ @current_visible_member_count ||= load_shares.sizeenddef load_query+ return @query if defined?(@query)+@query = ParamsToQueryService.new(Member,current_user,query_class: Queries::Members::EntityMemberQuery).call(params)# Set default filter on the entity- @query.where("entity_id", "=", @work_package.id)- @query.where("entity_type", "=", WorkPackage.name)- @query.where("project_id", "=", @project.id)+ @query.where("entity_id", "=", @entity.id)+ @query.where("entity_type", "=", @entity.class.name)+ if @project+ @query.where("project_id", "=", @project.id)+ end@query.order(name: :asc) unless params[:sortBy]@queryend- def load_shares(query)- query- .results+ def load_shares+ @shares = load_query.resultsendend