mirror of
https://0xacab.org/sutty/sutty
synced 2025-03-14 20:08:19 +00:00
Merge branch 'issue-17343' into 'issue-15068'
Issue #17343 See merge request sutty/sutty!279
This commit is contained in:
commit
8d0f465bd9
9 changed files with 52 additions and 21 deletions
|
@ -10,25 +10,41 @@ module ExceptionHandler
|
||||||
included do
|
included do
|
||||||
rescue_from SiteNotFound, with: :site_not_found
|
rescue_from SiteNotFound, with: :site_not_found
|
||||||
rescue_from PageNotFound, with: :page_not_found
|
rescue_from PageNotFound, with: :page_not_found
|
||||||
rescue_from ActionController::RoutingError, with: :page_not_found
|
rescue_from Pundit::Error, with: :page_not_found
|
||||||
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
rescue_from Pundit::NotAuthorizedError, with: :page_unauthorized
|
||||||
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
rescue_from Pundit::NilPolicyError, with: :page_not_found
|
||||||
rescue_from ActionController::RoutingError, with: :page_not_found
|
rescue_from ActionController::RoutingError, with: :page_not_found
|
||||||
rescue_from ActionController::ParameterMissing, with: :page_not_found
|
rescue_from ActionController::ParameterMissing, with: :page_not_found
|
||||||
end
|
end
|
||||||
|
|
||||||
def site_not_found
|
def site_not_found(exception)
|
||||||
reset_response!
|
reset_response!
|
||||||
|
|
||||||
flash[:error] = I18n.t('errors.site_not_found')
|
flash[:error] = I18n.t('errors.site_not_found')
|
||||||
|
|
||||||
|
ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie&.id, path: request.fullpath })
|
||||||
|
|
||||||
redirect_to sites_path
|
redirect_to sites_path
|
||||||
end
|
end
|
||||||
|
|
||||||
def page_not_found
|
def page_unauthorized(exception)
|
||||||
reset_response!
|
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
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
@ -15,6 +15,8 @@ class PostsController < ApplicationController
|
||||||
# Las URLs siempre llevan el idioma actual o el de le usuarie
|
# Las URLs siempre llevan el idioma actual o el de le usuarie
|
||||||
def default_url_options
|
def default_url_options
|
||||||
{ locale: locale }
|
{ locale: locale }
|
||||||
|
rescue SiteNotFound
|
||||||
|
{}
|
||||||
end
|
end
|
||||||
|
|
||||||
# @todo Mover a tu propio scope
|
# @todo Mover a tu propio scope
|
||||||
|
|
|
@ -29,7 +29,7 @@ class UsuariesController < ApplicationController
|
||||||
|
|
||||||
@usuarie = Usuarie.find(params[:id])
|
@usuarie = Usuarie.find(params[:id])
|
||||||
|
|
||||||
if @site.usuaries.count > 1
|
if @site.invitade?(@usuarie) || @site.usuaries.count > 1
|
||||||
# Mágicamente elimina el rol
|
# Mágicamente elimina el rol
|
||||||
@usuarie.sites.delete(@site)
|
@usuarie.sites.delete(@site)
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,11 +13,15 @@ class Site
|
||||||
# Por defecto, si el sitio no lo soporta, se obtienen los layouts
|
# Por defecto, si el sitio no lo soporta, se obtienen los layouts
|
||||||
# ordenados alfabéticamente por traducción.
|
# ordenados alfabéticamente por traducción.
|
||||||
#
|
#
|
||||||
|
# @param [Usuarie,nil]
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def schema_organization
|
def schema_organization(usuarie = nil)
|
||||||
@schema_organization ||=
|
@schema_organization ||=
|
||||||
begin
|
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&.symbolize_keys!
|
||||||
schema_organization&.transform_values! do |ary|
|
schema_organization&.transform_values! do |ary|
|
||||||
ary.map(&:to_sym)
|
ary.map(&:to_sym)
|
||||||
|
|
|
@ -26,8 +26,9 @@ PostService = Struct.new(:site, :usuarie, :post, :params, keyword_init: true) do
|
||||||
# @return Post
|
# @return Post
|
||||||
def create
|
def create
|
||||||
self.post ||= site.posts(lang: locale).build(layout: layout)
|
self.post ||= site.posts(lang: locale).build(layout: layout)
|
||||||
|
params[base][:draft] = true if site.invitade? usuarie
|
||||||
|
|
||||||
post.usuaries << usuarie
|
post.usuaries << usuarie
|
||||||
post.draft.value = true if post.attribute?(:draft) && site.invitade?(usuarie)
|
|
||||||
post.assign_attributes(post_params)
|
post.assign_attributes(post_params)
|
||||||
|
|
||||||
params.require(base).permit(:slug).tap do |p|
|
params.require(base).permit(:slug).tap do |p|
|
||||||
|
|
|
@ -1,3 +1,7 @@
|
||||||
|
-# TODO: convertir los atributos draft a un tipo
|
||||||
|
- if attribute == :draft && site.invitade?(current_usuarie)
|
||||||
|
-# Nada
|
||||||
|
- else
|
||||||
.form-check
|
.form-check
|
||||||
= hidden_field_tag "#{base}[#{attribute}]", '0', id: nil
|
= hidden_field_tag "#{base}[#{attribute}]", '0', id: nil
|
||||||
.custom-control.custom-switch
|
.custom-control.custom-switch
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
%h3= t('posts.new')
|
%h3= t('posts.new')
|
||||||
%table.table.table-sm.mb-3
|
%table.table.table-sm.mb-3
|
||||||
%tbody
|
%tbody
|
||||||
- @site.schema_organization.each do |schema, _|
|
- @site.schema_organization(current_usuarie).each do |schema, _|
|
||||||
- schema = @site.layouts[schema]
|
- schema = @site.layouts[schema]
|
||||||
- next if schema.hidden?
|
- next if schema.hidden?
|
||||||
= render 'schemas/row', site: @site, schema: schema, filter: @filter_params
|
= render 'schemas/row', site: @site, schema: schema, filter: @filter_params
|
||||||
|
|
|
@ -397,6 +397,8 @@ en:
|
||||||
not_available: "This language is not yet available, would you help us by translating Sutty into it?"
|
not_available: "This language is not yet available, would you help us by translating Sutty into it?"
|
||||||
errors:
|
errors:
|
||||||
site_not_found: "Site not found, or maybe you don't have access to it."
|
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}'
|
argument_error: 'Argument `%{argument}` must be an instance of %{class}'
|
||||||
unknown_locale: 'Unknown %{locale} locale'
|
unknown_locale: 'Unknown %{locale} locale'
|
||||||
posts:
|
posts:
|
||||||
|
|
|
@ -396,6 +396,8 @@ es:
|
||||||
not_available: "Este idioma todavía no está disponible, ¿nos ayudas a agregarlo y mantenerlo?"
|
not_available: "Este idioma todavía no está disponible, ¿nos ayudas a agregarlo y mantenerlo?"
|
||||||
errors:
|
errors:
|
||||||
site_not_found: "No encontramos ese sitio o quizás no tengas acceso."
|
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}'
|
argument_error: 'El argumento `%{argument}` debe ser una instancia de %{class}'
|
||||||
unknown_locale: 'El idioma %{locale} es desconocido'
|
unknown_locale: 'El idioma %{locale} es desconocido'
|
||||||
posts:
|
posts:
|
||||||
|
|
Loading…
Reference in a new issue