summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/milestone_resolver.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/graphql/resolvers/milestone_resolver.rb')
-rw-r--r--app/graphql/resolvers/milestone_resolver.rb31
1 files changed, 28 insertions, 3 deletions
diff --git a/app/graphql/resolvers/milestone_resolver.rb b/app/graphql/resolvers/milestone_resolver.rb
index 2e7b6fdfd5f..6c6513e0ee4 100644
--- a/app/graphql/resolvers/milestone_resolver.rb
+++ b/app/graphql/resolvers/milestone_resolver.rb
@@ -9,6 +9,10 @@ module Resolvers
required: false,
description: 'Filter milestones by state'
+ argument :include_descendants, GraphQL::BOOLEAN_TYPE,
+ required: false,
+ description: 'Return also milestones in all subgroups and subprojects'
+
type Types::MilestoneType, null: true
def resolve(**args)
@@ -26,16 +30,16 @@ module Resolvers
state: args[:state] || 'all',
start_date: args[:start_date],
end_date: args[:end_date]
- }.merge(parent_id_parameter)
+ }.merge(parent_id_parameter(args))
end
def parent
@parent ||= object.respond_to?(:sync) ? object.sync : object
end
- def parent_id_parameter
+ def parent_id_parameter(args)
if parent.is_a?(Group)
- { group_ids: parent.id }
+ group_parameters(args)
elsif parent.is_a?(Project)
{ project_ids: parent.id }
end
@@ -46,5 +50,26 @@ module Resolvers
def authorize!
Ability.allowed?(context[:current_user], :read_milestone, parent) || raise_resource_not_available_error!
end
+
+ def group_parameters(args)
+ return { group_ids: parent.id } unless include_descendants?(args)
+
+ {
+ group_ids: parent.self_and_descendants.public_or_visible_to_user(current_user).select(:id),
+ project_ids: group_projects.with_issues_or_mrs_available_for_user(current_user)
+ }
+ end
+
+ def include_descendants?(args)
+ args[:include_descendants].present? && Feature.enabled?(:group_milestone_descendants, parent)
+ end
+
+ def group_projects
+ GroupProjectsFinder.new(
+ group: parent,
+ current_user: current_user,
+ options: { include_subgroups: true }
+ ).execute
+ end
end
end