mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 10:36:22 +00:00
fix: sincronizar controladores
This commit is contained in:
parent
5211c9bd28
commit
8e681cdba7
7 changed files with 55 additions and 36 deletions
|
@ -2,16 +2,20 @@
|
|||
|
||||
# Gestiona acciones de moderación
|
||||
class ActivityPubsController < ApplicationController
|
||||
include ModerationConcern
|
||||
|
||||
ActivityPub.events.each do |event|
|
||||
define_method(event) do
|
||||
authorize activity_pub
|
||||
|
||||
activity_pub.public_send(:"#{event}!") if activity_pub.public_send(:"may_#{event}?")
|
||||
|
||||
redirect_back fallback_location: site_moderation_queue_path(**(session[:moderation_queue_filters] || {}))
|
||||
redirect_to_moderation_queue!
|
||||
end
|
||||
end
|
||||
|
||||
def action_on_several
|
||||
|
||||
redirect_to_moderation_queue!
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
# Gestiona la cola de moderación de actores
|
||||
class ActorModerationsController < ApplicationController
|
||||
include ModerationConcern
|
||||
|
||||
ActorModeration.events.each do |actor_event|
|
||||
define_method(actor_event) do
|
||||
authorize actor_moderation
|
||||
|
@ -11,7 +13,7 @@ class ActorModerationsController < ApplicationController
|
|||
|
||||
actor_moderation.public_send(:"#{actor_event}!") if actor_moderation.public_send(:"may_#{actor_event}?")
|
||||
|
||||
redirect_back fallback_location: site_moderation_queue_path(**(session[:moderation_queue_filters] || {}))
|
||||
redirect_to_moderation_queue!
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -29,6 +31,8 @@ class ActorModerationsController < ApplicationController
|
|||
method = :"#{action}!"
|
||||
may = :"may_#{action}?"
|
||||
|
||||
redirect_to_moderation_queue!
|
||||
|
||||
return unless ActorModeration.events.include? action
|
||||
|
||||
ActorModeration.transaction do
|
||||
|
|
13
app/controllers/concerns/moderation_concern.rb
Normal file
13
app/controllers/concerns/moderation_concern.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module ModerationConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
private
|
||||
|
||||
def redirect_to_moderation_queue!
|
||||
redirect_back fallback_location: site_moderation_queue_path(**(session[:moderation_queue_filters] || {}))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,19 +2,16 @@
|
|||
|
||||
# Actualiza la relación entre un sitio y una instancia
|
||||
class InstanceModerationsController < ApplicationController
|
||||
before_action :authorize_policy, except: %i[action_on_several]
|
||||
around_action :redirect_to_moderation_queue!
|
||||
include ModerationConcern
|
||||
|
||||
def pause
|
||||
instance_moderation.pause! if instance_moderation.may_pause?
|
||||
end
|
||||
InstanceModeration.events.each do |event|
|
||||
define_method(event) do
|
||||
authorize instance_moderation
|
||||
|
||||
def allow
|
||||
instance_moderation.allow! if instance_moderation.may_allow?
|
||||
end
|
||||
instance_moderation.public_send(:"#{event}!") if instance_moderation.public_send(:"may_#{event}?")
|
||||
|
||||
def block
|
||||
instance_moderation.block! if instance_moderation.may_block?
|
||||
redirect_to_moderation_queue!
|
||||
end
|
||||
end
|
||||
|
||||
def action_on_several
|
||||
|
@ -25,9 +22,10 @@ class InstanceModerationsController < ApplicationController
|
|||
action = params[:instance_moderation_action].to_sym
|
||||
method = :"#{action}!"
|
||||
may = :"may_#{action}?"
|
||||
events = instance_moderation.aasm.events.map(&:name)
|
||||
|
||||
return unless events.include? action
|
||||
redirect_to_moderation_queue!
|
||||
|
||||
return unless InstanceModeration.events.include? action
|
||||
|
||||
InstanceModeration.transaction do
|
||||
instance_moderations.find_each do |instance_moderation|
|
||||
|
@ -38,18 +36,8 @@ class InstanceModerationsController < ApplicationController
|
|||
|
||||
private
|
||||
|
||||
def redirect_to_moderation_queue!(&action)
|
||||
redirect_back fallback_location: site_moderation_queue_path, state: session[:moderation_queue_filtered_by_state]
|
||||
|
||||
yield
|
||||
end
|
||||
|
||||
# @return [InstanceModeration]
|
||||
def instance_moderation
|
||||
@instance_moderation ||= site.instance_moderations.find(params[:instance_moderation_id])
|
||||
end
|
||||
|
||||
def authorize_policy
|
||||
authorize instance_moderation
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ class ModerationQueueController < ApplicationController
|
|||
def index
|
||||
dummy_data
|
||||
|
||||
session[:moderation_queue_filters] = params.permit(:state, :actor_state)
|
||||
session[:moderation_queue_filters] = params.permit(:state, :actor_state, :activity_pub_state)
|
||||
|
||||
# @todo cambiar el estado por query
|
||||
@activity_pubs = site.activity_pubs
|
||||
|
|
16
app/policies/activity_pub_policy.rb
Normal file
16
app/policies/activity_pub_policy.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Solo les usuaries pueden moderar comentarios
|
||||
ActivityPubPolicy = Struct.new(:usuarie, :activity_pub) do
|
||||
ActivityPub.events.each do |event|
|
||||
define_method(:"#{event}?") do
|
||||
activity_pub.site.usuarie? usuarie
|
||||
end
|
||||
end
|
||||
|
||||
# En este paso tenemos varias instancias por moderar pero todas son
|
||||
# del mismo sitio.
|
||||
def action_on_several?
|
||||
activity_pub.first.site.usuarie? usuarie
|
||||
end
|
||||
end
|
|
@ -2,16 +2,10 @@
|
|||
|
||||
# Solo les usuaries pueden moderar instancias
|
||||
InstanceModerationPolicy = Struct.new(:usuarie, :instance_moderation) do
|
||||
def pause?
|
||||
instance_moderation.site.usuarie? usuarie
|
||||
end
|
||||
|
||||
def allow?
|
||||
pause?
|
||||
end
|
||||
|
||||
def block?
|
||||
pause?
|
||||
InstanceModeration.events.each do |event|
|
||||
define_method(:"#{event}?") do
|
||||
instance_moderation.site.usuarie? usuarie
|
||||
end
|
||||
end
|
||||
|
||||
# En este paso tenemos varias instancias por moderar pero todas son
|
||||
|
|
Loading…
Reference in a new issue