Welcome to mirror list, hosted at ThFree Co, Russian Federation.

broadcast_messages_controller.rb « admin « controllers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ef843a84e6ccbbb023406056be0424c566c2abbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# frozen_string_literal: true

class Admin::BroadcastMessagesController < Admin::ApplicationController
  include BroadcastMessagesHelper

  before_action :finder, only: [:edit, :update, :destroy]

  feature_category :navigation

  # rubocop: disable CodeReuse/ActiveRecord
  def index
    @broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page])
    @broadcast_message  = BroadcastMessage.new
  end
  # rubocop: enable CodeReuse/ActiveRecord

  def edit
  end

  def create
    @broadcast_message = BroadcastMessage.new(broadcast_message_params)

    if @broadcast_message.save
      redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully created.')
    else
      render :index
    end
  end

  def update
    if @broadcast_message.update(broadcast_message_params)
      redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully updated.')
    else
      render :edit
    end
  end

  def destroy
    @broadcast_message.destroy

    respond_to do |format|
      format.html { redirect_back_or_default(default: { action: 'index' }) }
      format.js { head :ok }
    end
  end

  def preview
    broadcast_message = BroadcastMessage.new(broadcast_message_params)
    render json: { message: render_broadcast_message(broadcast_message) }
  end

  protected

  def finder
    @broadcast_message = BroadcastMessage.find(params[:id])
  end

  def broadcast_message_params
    params.require(:broadcast_message).permit(%i(
      color
      ends_at
      font
      message
      starts_at
      target_path
      broadcast_type
      dismissable
    ), target_access_levels: []).reverse_merge!(target_access_levels: [])
  end
end