mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 15: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
|
# Gestiona acciones de moderación
|
||||||
class ActivityPubsController < ApplicationController
|
class ActivityPubsController < ApplicationController
|
||||||
|
include ModerationConcern
|
||||||
|
|
||||||
ActivityPub.events.each do |event|
|
ActivityPub.events.each do |event|
|
||||||
define_method(event) do
|
define_method(event) do
|
||||||
|
authorize activity_pub
|
||||||
|
|
||||||
activity_pub.public_send(:"#{event}!") if activity_pub.public_send(:"may_#{event}?")
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
def action_on_several
|
def action_on_several
|
||||||
|
redirect_to_moderation_queue!
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
# Gestiona la cola de moderación de actores
|
# Gestiona la cola de moderación de actores
|
||||||
class ActorModerationsController < ApplicationController
|
class ActorModerationsController < ApplicationController
|
||||||
|
include ModerationConcern
|
||||||
|
|
||||||
ActorModeration.events.each do |actor_event|
|
ActorModeration.events.each do |actor_event|
|
||||||
define_method(actor_event) do
|
define_method(actor_event) do
|
||||||
authorize actor_moderation
|
authorize actor_moderation
|
||||||
|
@ -11,7 +13,7 @@ class ActorModerationsController < ApplicationController
|
||||||
|
|
||||||
actor_moderation.public_send(:"#{actor_event}!") if actor_moderation.public_send(:"may_#{actor_event}?")
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -29,6 +31,8 @@ class ActorModerationsController < ApplicationController
|
||||||
method = :"#{action}!"
|
method = :"#{action}!"
|
||||||
may = :"may_#{action}?"
|
may = :"may_#{action}?"
|
||||||
|
|
||||||
|
redirect_to_moderation_queue!
|
||||||
|
|
||||||
return unless ActorModeration.events.include? action
|
return unless ActorModeration.events.include? action
|
||||||
|
|
||||||
ActorModeration.transaction do
|
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
|
# Actualiza la relación entre un sitio y una instancia
|
||||||
class InstanceModerationsController < ApplicationController
|
class InstanceModerationsController < ApplicationController
|
||||||
before_action :authorize_policy, except: %i[action_on_several]
|
include ModerationConcern
|
||||||
around_action :redirect_to_moderation_queue!
|
|
||||||
|
|
||||||
def pause
|
InstanceModeration.events.each do |event|
|
||||||
instance_moderation.pause! if instance_moderation.may_pause?
|
define_method(event) do
|
||||||
end
|
authorize instance_moderation
|
||||||
|
|
||||||
def allow
|
instance_moderation.public_send(:"#{event}!") if instance_moderation.public_send(:"may_#{event}?")
|
||||||
instance_moderation.allow! if instance_moderation.may_allow?
|
|
||||||
end
|
|
||||||
|
|
||||||
def block
|
redirect_to_moderation_queue!
|
||||||
instance_moderation.block! if instance_moderation.may_block?
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def action_on_several
|
def action_on_several
|
||||||
|
@ -25,9 +22,10 @@ class InstanceModerationsController < ApplicationController
|
||||||
action = params[:instance_moderation_action].to_sym
|
action = params[:instance_moderation_action].to_sym
|
||||||
method = :"#{action}!"
|
method = :"#{action}!"
|
||||||
may = :"may_#{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
|
InstanceModeration.transaction do
|
||||||
instance_moderations.find_each do |instance_moderation|
|
instance_moderations.find_each do |instance_moderation|
|
||||||
|
@ -38,18 +36,8 @@ class InstanceModerationsController < ApplicationController
|
||||||
|
|
||||||
private
|
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]
|
# @return [InstanceModeration]
|
||||||
def instance_moderation
|
def instance_moderation
|
||||||
@instance_moderation ||= site.instance_moderations.find(params[:instance_moderation_id])
|
@instance_moderation ||= site.instance_moderations.find(params[:instance_moderation_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def authorize_policy
|
|
||||||
authorize instance_moderation
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,7 @@ class ModerationQueueController < ApplicationController
|
||||||
def index
|
def index
|
||||||
dummy_data
|
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
|
# @todo cambiar el estado por query
|
||||||
@activity_pubs = site.activity_pubs
|
@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
|
# Solo les usuaries pueden moderar instancias
|
||||||
InstanceModerationPolicy = Struct.new(:usuarie, :instance_moderation) do
|
InstanceModerationPolicy = Struct.new(:usuarie, :instance_moderation) do
|
||||||
def pause?
|
InstanceModeration.events.each do |event|
|
||||||
instance_moderation.site.usuarie? usuarie
|
define_method(:"#{event}?") do
|
||||||
end
|
instance_moderation.site.usuarie? usuarie
|
||||||
|
end
|
||||||
def allow?
|
|
||||||
pause?
|
|
||||||
end
|
|
||||||
|
|
||||||
def block?
|
|
||||||
pause?
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# En este paso tenemos varias instancias por moderar pero todas son
|
# En este paso tenemos varias instancias por moderar pero todas son
|
||||||
|
|
Loading…
Reference in a new issue