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

Move loading of shares into the strategy

Klaus Zanders15e3f69af6e5
diff --git a/app/controllers/shares_controller.rb b/app/controllers/shares_controller.rb
index 5eebc6cef77..0c517b9ec1b 100644
--- a/app/controllers/shares_controller.rb
+++ b/app/controllers/shares_controller.rb
@@ -326,22 +326,7 @@ class SharesController < ApplicationController
end
def load_query
- return @query if defined?(@query)
-
- @query = ParamsToQueryService
- .new(Member, current_user, query_class: Queries::Members::NonInheritedMemberQuery)
- .call(params)
-
- # Set default filter on the entity
- @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]
-
- @query
+ @query = sharing_strategy.shares_query(params)
end
def load_shares
diff --git a/app/models/sharing_strategies/base_strategy.rb b/app/models/sharing_strategies/base_strategy.rb
index e28dbf2e55a..ce2b186799b 100644
--- a/app/models/sharing_strategies/base_strategy.rb
+++ b/app/models/sharing_strategies/base_strategy.rb
@@ -79,5 +79,24 @@ module SharingStrategies
def empty_state_component
nil
end
+
+ def shares_query(params) # rubocop:disable Metrics/AbcSize
+ return @query if defined?(@query)
+
+ @query = ParamsToQueryService
+ .new(Member, user, query_class: Queries::Members::NonInheritedMemberQuery)
+ .call(params)
+
+ # Set default filter on the entity
+ @query.where("entity_id", "=", entity.id)
+ @query.where("entity_type", "=", entity.class.name)
+ if entity.respond_to?(:project)
+ @query.where("project_id", "=", entity.project.id)
+ end
+
+ @query.order(name: :asc) unless params[:sortBy]
+
+ @query
+ end
end
end