5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-02 13:24:17 +00:00
panel/app/controllers/api/v1/posts_controller.rb
2020-09-29 18:22:28 -03:00

45 lines
1.2 KiB
Ruby

# frozen_string_literal: true
module Api
module V1
# Recibe artículos desde colaboraciones anónimas
class PostsController < ProtectedController
# Crea un artículo solo si el sitio admite invitades
def create
# No procesar nada más si ya se aplicaron todos los filtros
return if performed?
usuarie = GitAuthor.new name: 'Anon', email: "anon@#{site.hostname}"
service = PostService.new(params: params,
site: site,
usuarie: usuarie)
site.touch if service.create_anonymous.persisted?
# Redirigir a la URL de agradecimiento
redirect_to params[:redirect_to] || origin.to_s
end
private
def gave_consent?
return if params[:consent].present?
@reason = 'no_consent'
render plain: Rails.env.production? ? nil : @reason, status: :precondition_required
end
def destination_exists?
return if post? && site.layout?(params[:layout])
@reason = 'layout_doesnt_exist'
render plain: Rails.env.production? ? nil : @reason, status: :precondition_required
end
def from_is_address?
true
end
end
end
end