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
Move loading of shares to the strategy
Klaus Zanders4bd51fe2667d
diff --git a/app/components/shares/modal_body_component.html.erb b/app/components/shares/modal_body_component.html.erbindex aaa239c859b..fbf12195a64 100644--- a/app/components/shares/modal_body_component.html.erb+++ b/app/components/shares/modal_body_component.html.erb@@ -21,7 +21,7 @@border_box.with_header(color: :muted, data: { 'test-selector': 'op-share-dialog-header' }) dogrid_layout('op-share-dialog-modal-body--header', tag: :div, align_items: :center) do |header_grid|header_grid.with_area(:counter, tag: :div) do- render(Shares::CounterComponent.new(strategy:, count: @shares.size))+ render(Shares::CounterComponent.new(strategy:, count: strategy.shares.size))endheader_grid.with_area(:actions,@@ -99,7 +99,7 @@endend- if @shares.none?+ if strategy.shares.none?border_box.with_row doif strategy.custom_empty_state_component?render(strategy.empty_state_component.new(strategy: strategy))@@ -108,7 +108,7 @@endendelse- @shares.each do |share|+ strategy.shares.each do |share|render(Shares::ShareRowComponent.new(share:, strategy:, container: border_box))endenddiff --git a/app/components/shares/modal_body_component.rb b/app/components/shares/modal_body_component.rbindex a07102c374d..6e69008d4ef 100644--- a/app/components/shares/modal_body_component.rb+++ b/app/components/shares/modal_body_component.rb@@ -35,15 +35,13 @@ module Sharesattr_reader :strategy,:entity,- :shares,:errors- def initialize(strategy:, shares:, errors: nil)+ def initialize(strategy:, errors: nil)super@strategy = strategy@entity = strategy.entity- @shares = shares@errors = errorsenddiff --git a/app/components/shares/share_dialog_component.html.erb b/app/components/shares/share_dialog_component.html.erbindex df84ba60efd..3bfaad1719a 100644--- a/app/components/shares/share_dialog_component.html.erb+++ b/app/components/shares/share_dialog_component.html.erb@@ -2,7 +2,7 @@render(Primer::Alpha::Dialog.new(title: t(:label_share_project_list), id: 'sharing-modal', data: { 'keep-open-on-submit': true }, size: :xlarge)) do |d|d.with_header(variant: :large, mb: 3)d.with_body do- render(Shares::ModalBodyComponent.new(strategy:, shares:, errors:))+ render(Shares::ModalBodyComponent.new(strategy:, errors:))endend%>diff --git a/app/components/shares/share_dialog_component.rb b/app/components/shares/share_dialog_component.rbindex 702f5adc556..63ad3ba6f08 100644--- a/app/components/shares/share_dialog_component.rb+++ b/app/components/shares/share_dialog_component.rb@@ -34,16 +34,15 @@ module Sharesinclude OpTurbo::Streamableinclude OpPrimer::ComponentHelpers- def initialize(shares:, strategy:, errors:)+ def initialize(strategy:, errors:)super- @shares = shares@strategy = strategy@errors = errorsendprivate- attr_reader :shares, :strategy, :errors+ attr_reader :strategy, :errorsendenddiff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rbindex da10380ae58..5305f4c12df 100644--- a/app/controllers/shares_controller.rb+++ b/app/controllers/shares_controller.rb@@ -32,7 +32,6 @@ class SharesController < ApplicationControllerinclude MemberHelperbefore_action :load_entity- before_action :load_shares, only: %i[index dialog]before_action :load_selected_shares, only: %i[bulk_update bulk_destroy]before_action :load_share, only: %i[destroy update resend_invite]before_action :enterprise_check, only: %i[index]@@ -44,11 +43,11 @@ class SharesController < ApplicationControllerdef dialog; enddef index- unless @query.valid?- flash.now[:error] = query.errors.full_messages+ unless sharing_strategy.query.valid?+ flash.now[:error] = sharing_strategy.query.errors.full_messagesend- render Shares::ModalBodyComponent.new(strategy: sharing_strategy, shares: @shares, errors: @errors), layout: nil+ render Shares::ModalBodyComponent.new(strategy: sharing_strategy, errors: @errors), layout: nilenddef create # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity@@ -83,11 +82,11 @@ class SharesController < ApplicationControllerdef updatecreate_or_update_share(@share.principal.id, params[:role_ids])- load_shares+ shares = sharing_strategy.shares(reload: true)- if @shares.empty?+ if shares.empty?respond_with_replace_modal- elsif @shares.include?(@share)+ elsif shares.include?(@share)respond_with_update_permission_buttonelserespond_with_remove_share@@ -104,6 +103,7 @@ class SharesController < ApplicationControllerendend+ # TODO: This is still work package specificdef resend_inviteOpenProject::Notifications.send(OpenProject::Events::WORK_PACKAGE_SHARED,work_package_member: @share,@@ -165,10 +165,11 @@ class SharesController < ApplicationControllerenddef respond_with_replace_modal+ sharing_strategy.shares(reload: true)+replace_via_turbo_stream(component: Shares::ModalBodyComponent.new(strategy: sharing_strategy,- shares: @new_shares || load_shares,errors: @errors))@@ -199,7 +200,6 @@ class SharesController < ApplicationController),target_component: Shares::ModalBodyComponent.new(strategy: sharing_strategy,- shares: load_shares,errors: @errors))@@ -297,10 +297,10 @@ class SharesController < ApplicationControllerdef load_entity # rubocop:disable Metrics/AbcSizeif params["work_package_id"]@entity = WorkPackage.visible.find(params["work_package_id"])- @sharing_strategy = SharingStrategies::WorkPackageStrategy.new(@entity, user: current_user)+ @sharing_strategy = SharingStrategies::WorkPackageStrategy.new(@entity, user: current_user, query_params:)elsif params["project_query_id"]@entity = ProjectQuery.visible.find(params["project_query_id"])- @sharing_strategy = SharingStrategies::ProjectQueryStrategy.new(@entity, user: current_user)+ @sharing_strategy = SharingStrategies::ProjectQueryStrategy.new(@entity, user: current_user, query_params:)elseraise ArgumentError, <<~ERRORNested the SharesController under an entity controller that is not yet configured to support sharing.@@ -311,10 +311,6 @@ class SharesController < ApplicationControllerRequest Path: #{request.path}ERRORend-- if @entity.respond_to?(:project)- @project = @entity.project- endenddef load_share@@ -322,15 +318,7 @@ class SharesController < ApplicationControllerenddef current_visible_member_count- @current_visible_member_count ||= load_shares.size- end-- def load_query- @query = sharing_strategy.shares_query(params)- end-- def load_shares- @shares = load_query.results+ @current_visible_member_count ||= sharing_strategy.shares.sizeenddef load_selected_shares@@ -338,4 +326,10 @@ class SharesController < ApplicationController.of_entity(@entity).where(id: params[:share_ids])end++ def query_params+ params+ .slice(:filters, :sortBy, :groupBy)+ .permit! # ParamsToQueryService will parse the data, so we can permit everything here+ endenddiff --git a/app/models/sharing_strategies/base_strategy.rb b/app/models/sharing_strategies/base_strategy.rbindex ce2b186799b..445ebd18a08 100644--- a/app/models/sharing_strategies/base_strategy.rb+++ b/app/models/sharing_strategies/base_strategy.rb@@ -30,9 +30,10 @@ module SharingStrategiesclass BaseStrategyattr_reader :entity, :user- def initialize(entity, user: User.current)+ def initialize(entity, query_params:, user: User.current)@entity = entity@user = user+ @query_params = query_paramsenddef available_roles@@ -80,12 +81,12 @@ module SharingStrategiesnilend- def shares_query(params) # rubocop:disable Metrics/AbcSize+ def query # rubocop:disable Metrics/AbcSizereturn @query if defined?(@query)@query = ParamsToQueryService.new(Member, user, query_class: Queries::Members::NonInheritedMemberQuery)- .call(params)+ .call(@query_params)# Set default filter on the entity@query.where("entity_id", "=", entity.id)@@ -94,9 +95,14 @@ module SharingStrategies@query.where("project_id", "=", entity.project.id)end- @query.order(name: :asc) unless params[:sortBy]+ @query.order(name: :asc) unless @query_params[:sortBy]@queryend++ def shares(reload: false)+ @shares = nil if reload+ @shares ||= query.results+ endendenddiff --git a/app/views/shares/dialog.turbo_stream.erb b/app/views/shares/dialog.turbo_stream.erbindex 56f9e3b1a3a..ec19e379e13 100644--- a/app/views/shares/dialog.turbo_stream.erb+++ b/app/views/shares/dialog.turbo_stream.erb@@ -1,3 +1,3 @@<%= turbo_stream.dialog do- render(Shares::ShareDialogComponent.new(strategy: @sharing_strategy, shares: @shares, errors: @errors))+ render(Shares::ShareDialogComponent.new(strategy: @sharing_strategy, errors: @errors))end %>