0
0
Fork 1
Spiegel von https://github.com/paviliondev/discourse-custom-wizard.git synchronisiert 2024-12-02 05:21:10 +01:00
discourse-custom-wizard/app/controllers/custom_wizard/admin/notice.rb

69 Zeilen
1,7 KiB
Ruby

2021-09-24 11:58:42 +02:00
# frozen_string_literal: true
class CustomWizard::AdminNoticeController < CustomWizard::AdminController
2021-11-01 14:52:29 +01:00
before_action :find_notice, only: [:dismiss, :hide]
2021-09-24 11:58:42 +02:00
def index
2021-11-01 14:52:29 +01:00
type = params[:type]
archetype = params[:archtype]
page = params[:page].to_i
include_all = ActiveRecord::Type::Boolean.new.cast(params[:include_all])
visible = ActiveRecord::Type::Boolean.new.cast(params[:visible])
if type
if type.is_a?(Array)
2021-11-17 13:48:11 +01:00
type = type.map { |t| CustomWizard::Notice.types[t.to_sym] }
2021-11-01 14:52:29 +01:00
else
type = CustomWizard::Notice.types[type.to_sym]
end
end
if archetype
if archetype.is_a?(Array)
2021-11-17 13:48:11 +01:00
archetype = archetype.map { |t| CustomWizard::Notice.archetypes[archetype.to_sym] }
2021-11-01 14:52:29 +01:00
else
archetype = CustomWizard::Notice.archetypes[archetype.to_sym]
end
end
notices = CustomWizard::Notice.list(
include_all: include_all,
page: page,
type: type,
archetype: archetype,
visible: visible
)
render_serialized(notices, CustomWizard::NoticeSerializer, root: :notices)
2021-09-24 11:58:42 +02:00
end
def dismiss
2021-11-01 14:52:29 +01:00
if @notice.dismissable? && @notice.dismiss!
2021-09-24 11:58:42 +02:00
render json: success_json.merge(dismissed_at: @notice.dismissed_at)
else
render json: failed_json
end
end
2021-11-01 14:52:29 +01:00
def hide
if @notice.can_hide? && @notice.hide!
render json: success_json.merge(hidden_at: @notice.hidden_at)
else
render json: failed_json
end
end
def dismiss_all
if CustomWizard::Notice.dismiss_all
render json: success_json
else
render json: failed_json
end
end
2021-09-24 11:58:42 +02:00
def find_notice
@notice = CustomWizard::Notice.find(params[:notice_id])
raise Discourse::InvalidParameters.new(:notice_id) unless @notice
end
2021-10-05 14:54:06 +02:00
end