debian-mirror-gitlab/app/controllers/admin/broadcast_messages_controller.rb

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

106 lines
2.8 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2023-03-04 22:38:38 +05:30
module Admin
class BroadcastMessagesController < ApplicationController
include BroadcastMessagesHelper
2018-03-17 18:26:18 +05:30
2023-03-04 22:38:38 +05:30
before_action :find_broadcast_message, only: [:edit, :update, :destroy]
before_action :find_broadcast_messages, only: [:index, :create]
before_action :push_features, only: [:index, :edit]
2014-09-02 18:07:02 +05:30
2023-03-04 22:38:38 +05:30
feature_category :onboarding
urgency :low
2021-01-03 14:25:43 +05:30
2023-03-04 22:38:38 +05:30
def index
@broadcast_message = BroadcastMessage.new
end
2014-09-02 18:07:02 +05:30
2023-03-04 22:38:38 +05:30
def edit
end
2014-09-02 18:07:02 +05:30
2023-03-04 22:38:38 +05:30
def create
@broadcast_message = BroadcastMessage.new(broadcast_message_params)
success = @broadcast_message.save
respond_to do |format|
format.json do
if success
render json: @broadcast_message, status: :ok
else
render json: { errors: @broadcast_message.errors.full_messages }, status: :bad_request
end
2023-01-13 00:05:48 +05:30
end
2023-03-04 22:38:38 +05:30
format.html do
if success
redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully created.')
else
render :index
end
2023-01-13 00:05:48 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
2023-03-04 22:38:38 +05:30
def update
success = @broadcast_message.update(broadcast_message_params)
2023-01-13 00:05:48 +05:30
2023-03-04 22:38:38 +05:30
respond_to do |format|
format.json do
if success
render json: @broadcast_message, status: :ok
else
render json: { errors: @broadcast_message.errors.full_messages }, status: :bad_request
end
2023-01-13 00:05:48 +05:30
end
2023-03-04 22:38:38 +05:30
format.html do
if success
redirect_to admin_broadcast_messages_path, notice: _('Broadcast Message was successfully updated.')
else
render :edit
end
2023-01-13 00:05:48 +05:30
end
end
end
2023-03-04 22:38:38 +05:30
def destroy
@broadcast_message.destroy
2014-09-02 18:07:02 +05:30
2023-03-04 22:38:38 +05:30
respond_to do |format|
format.html { redirect_back_or_default(default: { action: 'index' }) }
format.js { head :ok }
end
2014-09-02 18:07:02 +05:30
end
2023-03-04 22:38:38 +05:30
def preview
@broadcast_message = BroadcastMessage.new(broadcast_message_params)
2023-05-27 22:25:52 +05:30
render plain: render_broadcast_message(@broadcast_message), status: :ok
2023-03-04 22:38:38 +05:30
end
2016-04-02 18:10:28 +05:30
2023-03-04 22:38:38 +05:30
protected
2014-09-02 18:07:02 +05:30
2023-03-04 22:38:38 +05:30
def find_broadcast_message
@broadcast_message = BroadcastMessage.find(params[:id])
end
2014-09-02 18:07:02 +05:30
2023-03-04 22:38:38 +05:30
def find_broadcast_messages
@broadcast_messages = BroadcastMessage.order(ends_at: :desc).page(params[:page]) # rubocop: disable CodeReuse/ActiveRecord
end
2023-01-13 00:05:48 +05:30
2023-03-04 22:38:38 +05:30
def broadcast_message_params
params.require(:broadcast_message)
.permit(%i[
theme
ends_at
message
starts_at
target_path
broadcast_type
dismissable
], target_access_levels: []).reverse_merge!(target_access_levels: [])
end
2023-01-13 00:05:48 +05:30
2023-03-04 22:38:38 +05:30
def push_features
push_frontend_feature_flag(:role_targeted_broadcast_messages, current_user)
end
2023-01-13 00:05:48 +05:30
end
2014-09-02 18:07:02 +05:30
end