Add `AnonymousBlockController`
This commit is contained in:
parent
ddded27757
commit
d000ddaae4
|
@ -0,0 +1,43 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AnonymousBlockController < ApplicationController
|
||||||
|
before_action :authenticate_user!
|
||||||
|
|
||||||
|
def create
|
||||||
|
params.require :question
|
||||||
|
|
||||||
|
question = Question.find(params[:question])
|
||||||
|
|
||||||
|
authorize AnonymousBlock, :create_global? if params[:global]
|
||||||
|
|
||||||
|
AnonymousBlock.create!(
|
||||||
|
user: params[:global] ? nil : current_user,
|
||||||
|
identifier: question.author_identifier,
|
||||||
|
question:
|
||||||
|
)
|
||||||
|
|
||||||
|
inbox_id = question.inboxes.first.id
|
||||||
|
question.inboxes.first&.destroy
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.turbo_stream do
|
||||||
|
render turbo_stream: turbo_stream.remove("inbox_#{inbox_id}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
params.require :id
|
||||||
|
|
||||||
|
block = AnonymousBlock.find(params[:id])
|
||||||
|
authorize block
|
||||||
|
|
||||||
|
block.destroy!
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.turbo_stream do
|
||||||
|
render turbo_stream: turbo_stream.remove("block_#{params[:id]}")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,18 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AnonymousBlockPolicy
|
||||||
|
attr_reader :user, :anonymous_block
|
||||||
|
|
||||||
|
def initialize(user, anonymous_block)
|
||||||
|
@user = user
|
||||||
|
@anonymous_block = anonymous_block
|
||||||
|
end
|
||||||
|
|
||||||
|
def create_global?
|
||||||
|
user.mod?
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy?
|
||||||
|
user == anonymous_block.user || user.mod?
|
||||||
|
end
|
||||||
|
end
|
|
@ -134,6 +134,8 @@ Rails.application.routes.draw do
|
||||||
post "/unsubscribe", to: "subscription#unsubscribe", as: :unsubscribe_answer
|
post "/unsubscribe", to: "subscription#unsubscribe", as: :unsubscribe_answer
|
||||||
end
|
end
|
||||||
|
|
||||||
|
resource :anonymous_block, controller: :anonymous_block, only: %i[create destroy]
|
||||||
|
|
||||||
get "/discover", to: "discover#index", as: :discover
|
get "/discover", to: "discover#index", as: :discover
|
||||||
match "/public", to: "timeline#public", via: [:get, :post], as: :public_timeline if APP_CONFIG.dig(:features, :public, :enabled)
|
match "/public", to: "timeline#public", via: [:get, :post], as: :public_timeline if APP_CONFIG.dig(:features, :public, :enabled)
|
||||||
match "/list/:list_name", to: "timeline#list", via: [:get, :post], as: :list_timeline
|
match "/list/:list_name", to: "timeline#list", via: [:get, :post], as: :list_timeline
|
||||||
|
|
Loading…
Reference in New Issue