2018-09-07 13:39:20 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
2020-04-28 03:09:53 +00:00
|
|
|
class ResourceLabelEvents < Grape::API
|
2018-09-07 13:39:20 +00:00
|
|
|
include PaginationParams
|
|
|
|
helpers ::API::Helpers::NotesHelpers
|
|
|
|
|
|
|
|
before { authenticate! }
|
|
|
|
|
2019-02-26 16:07:32 +00:00
|
|
|
Helpers::ResourceLabelEventsHelpers.eventable_types.each do |eventable_type|
|
2018-09-07 13:39:20 +00: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
|
2018-11-08 12:18:17 +00:00
|
|
|
resource parent_type.pluralize.to_sym, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2018-09-07 13:39:20 +00:00
|
|
|
desc "Get a list of #{eventable_type.to_s.downcase} resource label events" do
|
|
|
|
success Entities::ResourceLabelEvent
|
|
|
|
detail 'This feature was introduced in 11.3'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :eventable_id, types: [Integer, String], desc: 'The ID of the eventable'
|
|
|
|
use :pagination
|
|
|
|
end
|
2018-08-27 15:31:01 +00:00
|
|
|
|
2018-09-07 13:39:20 +00:00
|
|
|
get ":id/#{eventables_str}/:eventable_id/resource_label_events" do
|
2020-01-24 21:09:09 +00:00
|
|
|
eventable = find_noteable(eventable_type, params[:eventable_id])
|
2019-09-17 12:38:09 +00:00
|
|
|
|
|
|
|
opts = { page: params[:page], per_page: params[:per_page] }
|
|
|
|
events = ResourceLabelEventFinder.new(current_user, eventable, opts).execute
|
2018-09-07 13:39:20 +00:00
|
|
|
|
|
|
|
present paginate(events), with: Entities::ResourceLabelEvent
|
|
|
|
end
|
|
|
|
|
|
|
|
desc "Get a single #{eventable_type.to_s.downcase} resource label event" do
|
|
|
|
success Entities::ResourceLabelEvent
|
|
|
|
detail 'This feature was introduced in 11.3'
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :event_id, type: String, desc: 'The ID of a resource label event'
|
|
|
|
requires :eventable_id, types: [Integer, String], desc: 'The ID of the eventable'
|
|
|
|
end
|
|
|
|
get ":id/#{eventables_str}/:eventable_id/resource_label_events/:event_id" do
|
2020-01-24 21:09:09 +00:00
|
|
|
eventable = find_noteable(eventable_type, params[:eventable_id])
|
|
|
|
|
2018-09-07 13:39:20 +00:00
|
|
|
event = eventable.resource_label_events.find(params[:event_id])
|
|
|
|
|
2019-09-17 12:38:09 +00:00
|
|
|
not_found!('ResourceLabelEvent') unless can?(current_user, :read_resource_label_event, event)
|
|
|
|
|
2018-09-07 13:39:20 +00:00
|
|
|
present event, with: Entities::ResourceLabelEvent
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|