2020-05-26 11:08:17 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class ResourceMilestoneEvents < ::API::Base
|
2020-05-26 11:08:17 -04:00
|
|
|
include PaginationParams
|
|
|
|
helpers ::API::Helpers::NotesHelpers
|
|
|
|
|
|
|
|
before { authenticate! }
|
|
|
|
|
2020-10-30 11:08:59 -04:00
|
|
|
{
|
2021-10-27 11:13:41 -04:00
|
|
|
Issue => :team_planning,
|
2020-10-30 11:08:59 -04:00
|
|
|
MergeRequest => :code_review
|
|
|
|
}.each do |eventable_type, feature_category|
|
2020-05-26 11:08:17 -04:00
|
|
|
parent_type = eventable_type.parent_class.to_s.underscore
|
|
|
|
eventables_str = eventable_type.to_s.underscore.pluralize
|
|
|
|
|
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: "The ID of a #{parent_type}"
|
|
|
|
end
|
|
|
|
resource parent_type.pluralize.to_sym, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
|
|
|
desc "Get a list of #{eventable_type.to_s.downcase} resource milestone events" do
|
|
|
|
success Entities::ResourceMilestoneEvent
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :eventable_id, types: [Integer, String], desc: 'The ID of the eventable'
|
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
|
2021-12-08 07:13:04 -05:00
|
|
|
get ":id/#{eventables_str}/:eventable_id/resource_milestone_events", feature_category: feature_category, urgency: :low do
|
2020-05-26 11:08:17 -04:00
|
|
|
eventable = find_noteable(eventable_type, params[:eventable_id])
|
|
|
|
|
2020-06-23 11:08:41 -04:00
|
|
|
events = ResourceMilestoneEventFinder.new(current_user, eventable).execute
|
2020-05-26 11:08:17 -04:00
|
|
|
|
|
|
|
present paginate(events), with: Entities::ResourceMilestoneEvent
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Get a single #{eventable_type.to_s.downcase} resource milestone event" do
|
|
|
|
success Entities::ResourceMilestoneEvent
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :event_id, type: String, desc: 'The ID of a resource milestone event'
|
|
|
|
requires :eventable_id, types: [Integer, String], desc: 'The ID of the eventable'
|
|
|
|
end
|
2020-10-30 11:08:59 -04:00
|
|
|
get ":id/#{eventables_str}/:eventable_id/resource_milestone_events/:event_id", feature_category: feature_category do
|
2020-05-26 11:08:17 -04:00
|
|
|
eventable = find_noteable(eventable_type, params[:eventable_id])
|
|
|
|
|
|
|
|
event = eventable.resource_milestone_events.find(params[:event_id])
|
|
|
|
|
|
|
|
not_found!('ResourceMilestoneEvent') unless can?(current_user, :read_milestone, event.milestone_parent)
|
|
|
|
|
|
|
|
present event, with: Entities::ResourceMilestoneEvent
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|