Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /lib/api/milestone_responses.rb
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'lib/api/milestone_responses.rb')
-rw-r--r--lib/api/milestone_responses.rb48
1 files changed, 44 insertions, 4 deletions
diff --git a/lib/api/milestone_responses.rb b/lib/api/milestone_responses.rb
index 8ff885983bc..b337b992841 100644
--- a/lib/api/milestone_responses.rb
+++ b/lib/api/milestone_responses.rb
@@ -14,10 +14,12 @@ module API
params :list_params do
optional :state, type: String, values: %w[active closed all], default: 'all',
- desc: 'Return "active", "closed", or "all" milestones'
+ desc: 'Return "active", "closed", or "all" milestones'
optional :iids, type: Array[Integer], coerce_with: ::API::Validations::Types::CommaSeparatedToIntegerArray.coerce, desc: 'The IIDs of the milestones'
optional :title, type: String, desc: 'The title of the milestones'
optional :search, type: String, desc: 'The search criteria for the title or description of the milestone'
+ optional :include_parent_milestones, type: Grape::API::Boolean, default: false,
+ desc: 'Include group milestones from parent and its ancestors'
use :pagination
end
@@ -25,15 +27,18 @@ module API
requires :milestone_id, type: Integer, desc: 'The milestone ID number'
optional :title, type: String, desc: 'The title of the milestone'
optional :state_event, type: String, values: %w[close activate],
- desc: 'The state event of the milestone '
+ desc: 'The state event of the milestone '
use :optional_params
at_least_one_of :title, :description, :start_date, :due_date, :state_event
end
def list_milestones_for(parent)
- milestones = parent.milestones.order_id_desc
+ milestones = init_milestones_collection(parent)
milestones = Milestone.filter_by_state(milestones, params[:state])
- milestones = filter_by_iid(milestones, params[:iids]) if params[:iids].present?
+ if params[:iids].present? && !params[:include_parent_milestones]
+ milestones = filter_by_iid(milestones, params[:iids])
+ end
+
milestones = filter_by_title(milestones, params[:title]) if params[:title]
milestones = filter_by_search(milestones, params[:search]) if params[:search]
@@ -96,6 +101,41 @@ module API
[MergeRequestsFinder, Entities::MergeRequestBasic]
end
end
+
+ def init_milestones_collection(parent)
+ milestones = if params[:include_parent_milestones].present?
+ parent_and_ancestors_milestones(parent)
+ else
+ parent.milestones
+ end
+
+ milestones.order_id_desc
+ end
+
+ def parent_and_ancestors_milestones(parent)
+ project_id, group_ids = if parent.is_a?(Project)
+ [parent.id, project_group_ids(parent)]
+ else
+ [nil, parent_group_ids(parent)]
+ end
+
+ Milestone.for_projects_and_groups(project_id, group_ids)
+ end
+
+ def project_group_ids(parent)
+ group = parent.group
+ return unless group.present?
+
+ group.self_and_ancestors.select(:id)
+ end
+
+ def parent_group_ids(group)
+ return unless group.present?
+
+ group.self_and_ancestors
+ .public_or_visible_to_user(current_user)
+ .select(:id)
+ end
end
end
end