diff --git a/app/controllers/concerns/exception_handler.rb b/app/controllers/concerns/exception_handler.rb index 7c1cd540..3925f42c 100644 --- a/app/controllers/concerns/exception_handler.rb +++ b/app/controllers/concerns/exception_handler.rb @@ -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 diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 4aa2c8d0..7974d317 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -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 diff --git a/app/controllers/usuaries_controller.rb b/app/controllers/usuaries_controller.rb index 6924c860..cba349c5 100644 --- a/app/controllers/usuaries_controller.rb +++ b/app/controllers/usuaries_controller.rb @@ -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 diff --git a/app/models/site/layout_ordering.rb b/app/models/site/layout_ordering.rb index 9fecbf21..79e53c75 100644 --- a/app/models/site/layout_ordering.rb +++ b/app/models/site/layout_ordering.rb @@ -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) diff --git a/app/services/post_service.rb b/app/services/post_service.rb index 920c912e..a0b891a2 100644 --- a/app/services/post_service.rb +++ b/app/services/post_service.rb @@ -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| diff --git a/app/views/posts/attributes/_boolean.haml b/app/views/posts/attributes/_boolean.haml index 6928ebd7..050ede70 100644 --- a/app/views/posts/attributes/_boolean.haml +++ b/app/views/posts/attributes/_boolean.haml @@ -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 diff --git a/app/views/posts/index.haml b/app/views/posts/index.haml index 5d180518..0ff30799 100644 --- a/app/views/posts/index.haml +++ b/app/views/posts/index.haml @@ -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 diff --git a/config/locales/en.yml b/config/locales/en.yml index c348d73b..da76ba74 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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: diff --git a/config/locales/es.yml b/config/locales/es.yml index e9a52019..97569022 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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: