5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2025-03-14 17:08:21 +00:00

Merge branch 'issue-17343' into 'issue-15068'

Issue #17343

See merge request sutty/sutty!279
This commit is contained in:
fauno 2024-12-19 02:32:45 +00:00
commit 8d0f465bd9
9 changed files with 52 additions and 21 deletions

View file

@ -10,25 +10,41 @@ module ExceptionHandler
included do
rescue_from SiteNotFound, with: :site_not_found
rescue_from PageNotFound, with: :page_not_found
rescue_from ActionController::RoutingError, with: :page_not_found
rescue_from Pundit::NilPolicyError, with: :page_not_found
rescue_from Pundit::Error, with: :page_not_found
rescue_from Pundit::NotAuthorizedError, with: :page_unauthorized
rescue_from Pundit::NilPolicyError, with: :page_not_found
rescue_from ActionController::RoutingError, with: :page_not_found
rescue_from ActionController::ParameterMissing, with: :page_not_found
end
def site_not_found
def site_not_found(exception)
reset_response!
flash[:error] = I18n.t('errors.site_not_found')
ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie&.id, path: request.fullpath })
redirect_to sites_path
end
def page_not_found
def page_unauthorized(exception)
reset_response!
render 'application/page_not_found', status: :not_found
flash[:error] = I18n.t('errors.page_unauthorized')
ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie&.id, path: request.fullpath })
redirect_to site_path(site)
end
def page_not_found(exception)
reset_response!
flash[:error] = I18n.t('errors.page_not_found')
ExceptionNotifier.notify_exception(exception)
redirect_to site_path(site)
end
private

View file

@ -15,6 +15,8 @@ class PostsController < ApplicationController
# Las URLs siempre llevan el idioma actual o el de le usuarie
def default_url_options
{ locale: locale }
rescue SiteNotFound
{}
end
# @todo Mover a tu propio scope

View file

@ -29,7 +29,7 @@ class UsuariesController < ApplicationController
@usuarie = Usuarie.find(params[:id])
if @site.usuaries.count > 1
if @site.invitade?(@usuarie) || @site.usuaries.count > 1
# Mágicamente elimina el rol
@usuarie.sites.delete(@site)
else

View file

@ -13,11 +13,15 @@ class Site
# Por defecto, si el sitio no lo soporta, se obtienen los layouts
# ordenados alfabéticamente por traducción.
#
# @param [Usuarie,nil]
# @return [Hash]
def schema_organization
def schema_organization(usuarie = nil)
@schema_organization ||=
begin
schema_organization = data.dig('schema', 'organization')
# XXX: retrocompatibilidad
key = (usuarie.blank? || usuarie?(usuarie)) ? 'organization' : 'organization_guest'
schema_organization = data.dig('schema', key)
schema_organization ||= data.dig('schema', 'organization')
schema_organization&.symbolize_keys!
schema_organization&.transform_values! do |ary|
ary.map(&:to_sym)

View file

@ -26,8 +26,9 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
# @return Post
def create
self.post ||= site.posts(lang: locale).build(layout: layout)
params[base][:draft] = true if site.invitade? usuarie
post.usuaries << usuarie
post.draft.value = true if post.attribute?(:draft) && site.invitade?(usuarie)
post.assign_attributes(post_params)
params.require(base).permit(:slug).tap do |p|

View file

@ -1,12 +1,16 @@
.form-check
= hidden_field_tag "#{base}[#{attribute}]", '0', id: nil
.custom-control.custom-switch
= check_box_tag "#{base}[#{attribute}]", '1', metadata.value,
class: "custom-control-input #{invalid(post, attribute)}",
aria: { describedby: id_for_help(attribute) },
autofocus: autofocus
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post),
class: 'custom-control-label'
-# TODO: convertir los atributos draft a un tipo
- if attribute == :draft && site.invitade?(current_usuarie)
-# Nada
- else
.form-check
= hidden_field_tag "#{base}[#{attribute}]", '0', id: nil
.custom-control.custom-switch
= check_box_tag "#{base}[#{attribute}]", '1', metadata.value,
class: "custom-control-input #{invalid(post, attribute)}",
aria: { describedby: id_for_help(attribute) },
autofocus: autofocus
= label_tag "#{base}_#{attribute}", post_label_t(attribute, post: post),
class: 'custom-control-label'
= render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata
= render 'posts/attribute_feedback',
post: post, attribute: attribute, metadata: metadata

View file

@ -16,7 +16,7 @@
%h3= t('posts.new')
%table.table.table-sm.mb-3
%tbody
- @site.schema_organization.each do |schema, _|
- @site.schema_organization(current_usuarie).each do |schema, _|
- schema = @site.layouts[schema]
- next if schema.hidden?
= render 'schemas/row', site: @site, schema: schema, filter: @filter_params

View file

@ -397,6 +397,8 @@ en:
not_available: "This language is not yet available, would you help us by translating Sutty into it?"
errors:
site_not_found: "Site not found, or maybe you don't have access to it."
page_not_found: "Page not found."
page_unauthorized: "You don't have access to this page, please contact the operators of this site."
argument_error: 'Argument `%{argument}` must be an instance of %{class}'
unknown_locale: 'Unknown %{locale} locale'
posts:

View file

@ -396,6 +396,8 @@ es:
not_available: "Este idioma todavía no está disponible, ¿nos ayudas a agregarlo y mantenerlo?"
errors:
site_not_found: "No encontramos ese sitio o quizás no tengas acceso."
page_not_found: "No encontramos esa página."
page_unauthorized: "No tenés acceso a página, para solicitarla, ponete en contacto con les gestores del sitio."
argument_error: 'El argumento `%{argument}` debe ser una instancia de %{class}'
unknown_locale: 'El idioma %{locale} es desconocido'
posts: