From 9ef25521eb77c43319129f00ba7c739d27346962 Mon Sep 17 00:00:00 2001 From: f Date: Thu, 5 Sep 2024 16:40:19 -0300 Subject: [PATCH 01/10] =?UTF-8?q?feat:=20mostrar=20error=20al=20no=20tener?= =?UTF-8?q?=20autorizaci=C3=B3n=20para=20editar=20un=20art=C3=ADculo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/exception_handler.rb | 26 +++++++++++++++---- config/locales/en.yml | 2 ++ config/locales/es.yml | 2 ++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/app/controllers/concerns/exception_handler.rb b/app/controllers/concerns/exception_handler.rb index 7c1cd540..a47278db 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) + 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) + + 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/config/locales/en.yml b/config/locales/en.yml index ec5b34a9..39054b6f 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 61c645a0..deb193c2 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: From c9bb3defff8f1ed7d77dc15812fa64743eeb533a Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Sep 2024 13:31:54 -0300 Subject: [PATCH 02/10] =?UTF-8?q?fix:=20permitir=20eliminar=20a=20le=20?= =?UTF-8?q?=C3=BAltime=20invitade?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/usuaries_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From d3e09a2776884fe9378320641839a49517c62406 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Sep 2024 13:32:13 -0300 Subject: [PATCH 03/10] =?UTF-8?q?fix:=20evitar=20generar=20error=20de=20tr?= =?UTF-8?q?aducci=C3=B3n=20al=20perder=20acceso=20a=20un=20sitio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/posts_controller.rb | 2 ++ 1 file changed, 2 insertions(+) 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 From cbe2f66a94902b1b2ba6a2aafc1dcf7af489034b Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Sep 2024 14:11:49 -0300 Subject: [PATCH 04/10] fix: les invitades siempre crean borradores #17343 --- app/services/post_service.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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| From 78f757d429d3ec336ccbe36060d87769386a8bea Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Sep 2024 16:01:52 -0300 Subject: [PATCH 05/10] feat: poder establecer una lista de esquemas para invitades #17343 --- app/models/site/layout_ordering.rb | 8 ++++++-- app/views/posts/index.haml | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) 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/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 From fc39a780ffdb9a651675c21031272212bf8a245c Mon Sep 17 00:00:00 2001 From: f Date: Fri, 6 Sep 2024 16:11:20 -0300 Subject: [PATCH 06/10] feat: no mostrar el campo borrador a les invitades #17343 --- app/views/posts/attributes/_boolean.haml | 26 ++++++++++++++---------- 1 file changed, 15 insertions(+), 11 deletions(-) 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 From 65ed03e0eb6cbfc8bf4fe8a01859bfc0ac155137 Mon Sep 17 00:00:00 2001 From: f Date: Mon, 14 Oct 2024 15:18:51 -0300 Subject: [PATCH 07/10] fix: informar usuarie que no pudo acceder para debug closes #17571 --- app/controllers/concerns/exception_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/exception_handler.rb b/app/controllers/concerns/exception_handler.rb index a47278db..fa6415a8 100644 --- a/app/controllers/concerns/exception_handler.rb +++ b/app/controllers/concerns/exception_handler.rb @@ -32,7 +32,7 @@ module ExceptionHandler flash[:error] = I18n.t('errors.page_unauthorized') - ExceptionNotifier.notify_exception(exception) + ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie.id }) redirect_to site_path(site) end From 7acc79d5ff63d2d308a318cfddbeccf79f245a32 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 16 Oct 2024 12:18:23 -0300 Subject: [PATCH 08/10] =?UTF-8?q?fix:=20saber=20cu=C3=A1l=20ruta=20fall?= =?UTF-8?q?=C3=B3=20#17384?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/concerns/exception_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/exception_handler.rb b/app/controllers/concerns/exception_handler.rb index fa6415a8..42b7932b 100644 --- a/app/controllers/concerns/exception_handler.rb +++ b/app/controllers/concerns/exception_handler.rb @@ -32,7 +32,7 @@ module ExceptionHandler flash[:error] = I18n.t('errors.page_unauthorized') - ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie.id }) + ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie.id, path: request.fullpath }) redirect_to site_path(site) end From 414133ce5b4d7b9d1030dcfaba38c91aa17dce8f Mon Sep 17 00:00:00 2001 From: f Date: Wed, 18 Dec 2024 15:13:55 -0300 Subject: [PATCH 09/10] fix: informar la ruta #17335 --- app/controllers/concerns/exception_handler.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/concerns/exception_handler.rb b/app/controllers/concerns/exception_handler.rb index 42b7932b..852d7d5f 100644 --- a/app/controllers/concerns/exception_handler.rb +++ b/app/controllers/concerns/exception_handler.rb @@ -22,7 +22,7 @@ module ExceptionHandler flash[:error] = I18n.t('errors.site_not_found') - ExceptionNotifier.notify_exception(exception) + ExceptionNotifier.notify_exception(exception, data: { path: request.fullpath }) redirect_to sites_path end From 7cc0573926ea7f6f97e7664dd26cab80a26fa955 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 18 Dec 2024 15:14:12 -0300 Subject: [PATCH 10/10] fix: informar le usuarie --- app/controllers/concerns/exception_handler.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/exception_handler.rb b/app/controllers/concerns/exception_handler.rb index 852d7d5f..3925f42c 100644 --- a/app/controllers/concerns/exception_handler.rb +++ b/app/controllers/concerns/exception_handler.rb @@ -22,7 +22,7 @@ module ExceptionHandler flash[:error] = I18n.t('errors.site_not_found') - ExceptionNotifier.notify_exception(exception, data: { path: request.fullpath }) + ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie&.id, path: request.fullpath }) redirect_to sites_path end @@ -32,7 +32,7 @@ module ExceptionHandler flash[:error] = I18n.t('errors.page_unauthorized') - ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie.id, path: request.fullpath }) + ExceptionNotifier.notify_exception(exception, data: { usuarie: current_usuarie&.id, path: request.fullpath }) redirect_to site_path(site) end