2018-09-29 18:34:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-25 19:34:01 -04:00
|
|
|
module API
|
2020-10-14 20:08:42 -04:00
|
|
|
class BroadcastMessages < ::API::Base
|
2016-11-21 14:15:46 -05:00
|
|
|
include PaginationParams
|
|
|
|
|
2020-10-29 08:08:50 -04:00
|
|
|
feature_category :navigation
|
2022-05-20 17:08:53 -04:00
|
|
|
urgency :low
|
2020-10-29 08:08:50 -04:00
|
|
|
|
2016-08-25 19:34:01 -04:00
|
|
|
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
|
2016-11-21 14:15:46 -05:00
|
|
|
use :pagination
|
2016-08-25 19:34:01 -04:00
|
|
|
end
|
|
|
|
get do
|
2017-08-15 06:27:37 -04:00
|
|
|
messages = BroadcastMessage.all.order_id_desc
|
2016-08-25 19:34:01 -04:00
|
|
|
|
|
|
|
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
|
2019-12-11 22:07:34 -05:00
|
|
|
requires :message, type: String, desc: 'Message to display'
|
2016-08-25 19:34:01 -04:00
|
|
|
optional :starts_at, type: DateTime, desc: 'Starting time', default: -> { Time.zone.now }
|
2019-12-11 22:07:34 -05:00
|
|
|
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-03-10 07:07:07 -05:00
|
|
|
optional :target_access_levels, type: Array[Integer], coerce_with: Validations::Types::CommaSeparatedToIntegerArray.coerce,
|
|
|
|
values: BroadcastMessage::ALLOWED_TARGET_ACCESS_LEVELS, desc: 'Target user roles'
|
2019-12-11 22:07:34 -05:00
|
|
|
optional :target_path, type: String, desc: 'Target path'
|
2020-01-30 16:08:47 -05:00
|
|
|
optional :broadcast_type, type: String, values: BroadcastMessage.broadcast_types.keys, desc: 'Broadcast type. Defaults to banner', default: -> { 'banner' }
|
2020-03-04 19:07:49 -05:00
|
|
|
optional :dismissable, type: Boolean, desc: 'Is dismissable'
|
2016-08-25 19:34:01 -04:00
|
|
|
end
|
|
|
|
post do
|
2020-01-24 13:09:00 -05:00
|
|
|
authenticated_as_admin!
|
|
|
|
|
2016-11-14 08:44:27 -05:00
|
|
|
message = BroadcastMessage.create(declared_params(include_missing: false))
|
2016-08-25 19:34:01 -04:00
|
|
|
|
|
|
|
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
|
2019-12-11 22:07:34 -05:00
|
|
|
requires :id, type: Integer, desc: 'Broadcast message ID'
|
|
|
|
optional :message, type: String, desc: 'Message to display'
|
2016-08-25 19:34:01 -04:00
|
|
|
optional :starts_at, type: DateTime, desc: 'Starting time'
|
2019-12-11 22:07:34 -05:00
|
|
|
optional :ends_at, type: DateTime, desc: 'Ending time'
|
|
|
|
optional :color, type: String, desc: 'Background color'
|
|
|
|
optional :font, type: String, desc: 'Foreground color'
|
2022-03-10 07:07:07 -05:00
|
|
|
optional :target_access_levels, type: Array[Integer], coerce_with: Validations::Types::CommaSeparatedToIntegerArray.coerce,
|
|
|
|
values: BroadcastMessage::ALLOWED_TARGET_ACCESS_LEVELS, desc: 'Target user roles'
|
2019-12-11 22:07:34 -05:00
|
|
|
optional :target_path, type: String, desc: 'Target path'
|
2020-01-30 16:08:47 -05:00
|
|
|
optional :broadcast_type, type: String, values: BroadcastMessage.broadcast_types.keys, desc: 'Broadcast Type'
|
2020-03-04 19:07:49 -05:00
|
|
|
optional :dismissable, type: Boolean, desc: 'Is dismissable'
|
2016-08-25 19:34:01 -04:00
|
|
|
end
|
|
|
|
put ':id' do
|
2020-01-24 13:09:00 -05:00
|
|
|
authenticated_as_admin!
|
|
|
|
|
2016-08-25 19:34:01 -04:00
|
|
|
message = find_message
|
|
|
|
|
2016-11-14 08:44:27 -05:00
|
|
|
if message.update(declared_params(include_missing: false))
|
2016-08-25 19:34:01 -04:00
|
|
|
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-01-24 13:09:00 -05:00
|
|
|
authenticated_as_admin!
|
|
|
|
|
2016-08-25 19:34:01 -04:00
|
|
|
message = find_message
|
|
|
|
|
2017-03-02 07:14:13 -05:00
|
|
|
destroy_conditionally!(message)
|
2016-08-25 19:34:01 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|