debian-mirror-gitlab/lib/api/resource_label_events.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

58 lines
2.3 KiB
Ruby
Raw Permalink Normal View History

2018-11-20 20:47:30 +05:30
# frozen_string_literal: true
module API
2021-01-03 14:25:43 +05:30
class ResourceLabelEvents < ::API::Base
2018-11-20 20:47:30 +05:30
include PaginationParams
helpers ::API::Helpers::NotesHelpers
before { authenticate! }
2022-10-11 01:57:18 +05:30
Helpers::ResourceEventsHelpers.eventable_types.each do |eventable_type, details|
2018-11-20 20:47:30 +05:30
parent_type = eventable_type.parent_class.to_s.underscore
eventables_str = eventable_type.to_s.underscore.pluralize
2022-10-11 01:57:18 +05:30
human_eventable_str = eventable_type.to_s.underscore.humanize.downcase
feature_category = details[:feature_category]
2018-11-20 20:47:30 +05:30
params do
requires :id, type: String, desc: "The ID of a #{parent_type}"
end
2019-02-15 15:39:39 +05:30
resource parent_type.pluralize.to_sym, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
2022-10-11 01:57:18 +05:30
desc "Get a list of #{human_eventable_str} resource label events" do
2018-11-20 20:47:30 +05:30
success Entities::ResourceLabelEvent
detail 'This feature was introduced in 11.3'
end
params do
2022-10-11 01:57:18 +05:30
requires :eventable_id, types: [Integer, String], desc: "The #{details[:id_field]} of the #{human_eventable_str}"
2018-11-20 20:47:30 +05:30
use :pagination
end
2018-12-05 23:21:45 +05:30
2022-01-26 12:08:38 +05:30
get ":id/#{eventables_str}/:eventable_id/resource_label_events", feature_category: feature_category, urgency: :low do
2020-03-13 15:44:24 +05:30
eventable = find_noteable(eventable_type, params[:eventable_id])
2019-09-30 23:59:55 +05:30
2020-06-23 00:09:42 +05:30
events = eventable.resource_label_events.inc_relations
2018-11-20 20:47:30 +05:30
2020-06-23 00:09:42 +05:30
present ResourceLabelEvent.visible_to_user?(current_user, paginate(events)), with: Entities::ResourceLabelEvent
2018-11-20 20:47:30 +05:30
end
2022-10-11 01:57:18 +05:30
desc "Get a single #{human_eventable_str} resource label event" do
2018-11-20 20:47:30 +05:30
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'
2022-10-11 01:57:18 +05:30
requires :eventable_id, types: [Integer, String], desc: "The #{details[:id_field]} of the #{human_eventable_str}"
2018-11-20 20:47:30 +05:30
end
2021-01-29 00:20:46 +05:30
get ":id/#{eventables_str}/:eventable_id/resource_label_events/:event_id", feature_category: feature_category do
2020-03-13 15:44:24 +05:30
eventable = find_noteable(eventable_type, params[:eventable_id])
2018-11-20 20:47:30 +05:30
event = eventable.resource_label_events.find(params[:event_id])
2019-09-30 23:59:55 +05:30
not_found!('ResourceLabelEvent') unless can?(current_user, :read_resource_label_event, event)
2018-11-20 20:47:30 +05:30
present event, with: Entities::ResourceLabelEvent
end
end
end
end
end