Skip to content
Snippets Groups Projects
Select Git revision
  • move-gl-dropdown
  • improve-table-pagination-spec
  • move-markdown-preview
  • winh-fix-merge-request-spec
  • master default
  • index-namespaces-lower-name
  • winh-single-karma-test
  • 10-3-stable
  • 36782-replace-team-user-role-with-add_role-user-in-specs
  • winh-modal-internal-state
  • tz-ide-file-icons
  • 38869-milestone-select
  • update-autodevops-template
  • jivl-activate-repo-cookie-preferences
  • qa-add-deploy-key
  • docs-move-article-ldap
  • 40780-choose-file
  • 22643-manual-job-page
  • refactor-cluster-show-page-conservative
  • dm-sidekiq-versioning
  • v10.4.0.pre
  • v10.3.0
  • v10.3.0-rc5
  • v10.3.0-rc4
  • v10.3.0-rc3
  • v10.3.0-rc2
  • v10.2.5
  • v10.3.0-rc1
  • v10.0.7
  • v10.1.5
  • v10.2.4
  • v10.2.3
  • v10.2.2
  • v10.2.1
  • v10.3.0.pre
  • v10.2.0
  • v10.2.0-rc4
  • v10.2.0-rc3
  • v10.1.4
  • v10.2.0-rc2
40 results

broadcast_messages.rb

Forked from GitLab.org / GitLab FOSS
2 commits behind, 4186 commits ahead of the upstream repository.
broadcast_messages.rb 3.03 KiB
module API
  class BroadcastMessages < Grape::API
    include PaginationParams

    before { authenticate! }
    before { authenticated_as_admin! }

    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
        use :pagination
      end
      get do
        messages = BroadcastMessage.all

        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
        requires :message,   type: String,   desc: 'Message to display'
        optional :starts_at, type: DateTime, desc: 'Starting time', default: -> { Time.zone.now }
        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'
      end
      post do
        message = BroadcastMessage.create(declared_params(include_missing: false))

        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
        requires :id,        type: Integer,  desc: 'Broadcast message ID'
        optional :message,   type: String,   desc: 'Message to display'
        optional :starts_at, type: DateTime, desc: 'Starting time'
        optional :ends_at,   type: DateTime, desc: 'Ending time'
        optional :color,     type: String,   desc: 'Background color'
        optional :font,      type: String,   desc: 'Foreground color'
      end
      put ':id' do
        message = find_message

        if message.update(declared_params(include_missing: false))
          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
        message = find_message

        status 204
        message.destroy
      end
    end
  end
end