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

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

123 lines
4.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2016-09-29 09:46:39 +05:30
module API
2021-01-03 14:25:43 +05:30
class BroadcastMessages < ::API::Base
2017-08-17 22:00:37 +05:30
include PaginationParams
2022-08-13 15:12:31 +05:30
feature_category :onboarding
2022-07-23 23:45:48 +05:30
urgency :low
2021-01-29 00:20:46 +05:30
2016-09-29 09:46:39 +05:30
resource :broadcast_messages do
helpers do
def find_message
BroadcastMessage.find(params[:id])
end
end
desc 'Get all broadcast messages' do
detail 'This feature was introduced in GitLab 8.12.'
success Entities::BroadcastMessage
end
params do
2017-08-17 22:00:37 +05:30
use :pagination
2016-09-29 09:46:39 +05:30
end
get do
2018-03-17 18:26:18 +05:30
messages = BroadcastMessage.all.order_id_desc
2016-09-29 09:46:39 +05:30
present paginate(messages), with: Entities::BroadcastMessage
end
desc 'Create a broadcast message' do
detail 'This feature was introduced in GitLab 8.12.'
success Entities::BroadcastMessage
end
params do
2020-01-01 13:55:28 +05:30
requires :message, type: String, desc: 'Message to display'
2016-09-29 09:46:39 +05:30
optional :starts_at, type: DateTime, desc: 'Starting time', default: -> { Time.zone.now }
2020-01-01 13:55:28 +05:30
optional :ends_at, type: DateTime, desc: 'Ending time', default: -> { 1.hour.from_now }
optional :color, type: String, desc: 'Background color'
optional :font, type: String, desc: 'Foreground color'
2022-08-27 11:52:29 +05:30
optional :target_access_levels,
type: Array[Integer],
coerce_with: Validations::Types::CommaSeparatedToIntegerArray.coerce,
values: BroadcastMessage::ALLOWED_TARGET_ACCESS_LEVELS,
desc: 'Target user roles'
2020-01-01 13:55:28 +05:30
optional :target_path, type: String, desc: 'Target path'
2020-03-13 15:44:24 +05:30
optional :broadcast_type, type: String, values: BroadcastMessage.broadcast_types.keys, desc: 'Broadcast type. Defaults to banner', default: -> { 'banner' }
2020-04-08 14:13:33 +05:30
optional :dismissable, type: Boolean, desc: 'Is dismissable'
2016-09-29 09:46:39 +05:30
end
post do
2020-03-13 15:44:24 +05:30
authenticated_as_admin!
2017-08-17 22:00:37 +05:30
message = BroadcastMessage.create(declared_params(include_missing: false))
2016-09-29 09:46:39 +05:30
if message.persisted?
present message, with: Entities::BroadcastMessage
else
render_validation_error!(message)
end
end
desc 'Get a specific broadcast message' do
detail 'This feature was introduced in GitLab 8.12.'
success Entities::BroadcastMessage
end
params do
requires :id, type: Integer, desc: 'Broadcast message ID'
end
get ':id' do
message = find_message
present message, with: Entities::BroadcastMessage
end
desc 'Update a broadcast message' do
detail 'This feature was introduced in GitLab 8.12.'
success Entities::BroadcastMessage
end
params do
2020-01-01 13:55:28 +05:30
requires :id, type: Integer, desc: 'Broadcast message ID'
optional :message, type: String, desc: 'Message to display'
2016-09-29 09:46:39 +05:30
optional :starts_at, type: DateTime, desc: 'Starting time'
2020-01-01 13:55:28 +05:30
optional :ends_at, type: DateTime, desc: 'Ending time'
optional :color, type: String, desc: 'Background color'
optional :font, type: String, desc: 'Foreground color'
2022-08-27 11:52:29 +05:30
optional :target_access_levels,
type: Array[Integer],
coerce_with: Validations::Types::CommaSeparatedToIntegerArray.coerce,
values: BroadcastMessage::ALLOWED_TARGET_ACCESS_LEVELS,
desc: 'Target user roles'
2020-01-01 13:55:28 +05:30
optional :target_path, type: String, desc: 'Target path'
2020-03-13 15:44:24 +05:30
optional :broadcast_type, type: String, values: BroadcastMessage.broadcast_types.keys, desc: 'Broadcast Type'
2020-04-08 14:13:33 +05:30
optional :dismissable, type: Boolean, desc: 'Is dismissable'
2016-09-29 09:46:39 +05:30
end
put ':id' do
2020-03-13 15:44:24 +05:30
authenticated_as_admin!
2016-09-29 09:46:39 +05:30
message = find_message
2017-08-17 22:00:37 +05:30
if message.update(declared_params(include_missing: false))
2016-09-29 09:46:39 +05:30
present message, with: Entities::BroadcastMessage
else
render_validation_error!(message)
end
end
desc 'Delete a broadcast message' do
detail 'This feature was introduced in GitLab 8.12.'
success Entities::BroadcastMessage
end
params do
requires :id, type: Integer, desc: 'Broadcast message ID'
end
delete ':id' do
2020-03-13 15:44:24 +05:30
authenticated_as_admin!
2016-09-29 09:46:39 +05:30
message = find_message
2018-03-17 18:26:18 +05:30
destroy_conditionally!(message)
2016-09-29 09:46:39 +05:30
end
end
end
end