5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-24 15:56:20 +00:00
panel/app/controllers/api/v1/posts_controller.rb

45 lines
1.2 KiB
Ruby
Raw Permalink Normal View History

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