5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-22 15:36:22 +00:00

fix: sincronizar controladores

This commit is contained in:
f 2024-03-04 14:47:20 -03:00
parent 5211c9bd28
commit 8e681cdba7
No known key found for this signature in database
7 changed files with 55 additions and 36 deletions

View file

@ -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

View file

@ -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

View 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

View file

@ -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?
InstanceModeration.events.each do |event|
define_method(event) do
authorize instance_moderation
instance_moderation.public_send(:"#{event}!") if instance_moderation.public_send(:"may_#{event}?")
redirect_to_moderation_queue!
end
def allow
instance_moderation.allow! if instance_moderation.may_allow?
end
def block
instance_moderation.block! if instance_moderation.may_block?
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

View file

@ -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

View 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

View file

@ -2,16 +2,10 @@
# Solo les usuaries pueden moderar instancias
InstanceModerationPolicy = Struct.new(:usuarie, :instance_moderation) do
def pause?
InstanceModeration.events.each do |event|
define_method(:"#{event}?") do
instance_moderation.site.usuarie? usuarie
end
def allow?
pause?
end
def block?
pause?
end
# En este paso tenemos varias instancias por moderar pero todas son