From c7f8b59cd68cd2b0abe0b55f233d329dbb0543dc Mon Sep 17 00:00:00 2001 From: Eduardo Martinez Echevarria Date: Wed, 27 Nov 2024 17:00:04 +0100 Subject: [PATCH] Ignore context if allow_attachments_in_comments is disable for the organization --- .../comments/comment_cell_attachments.rb | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/cells/concerns/decidim/decidim_awesome/comments/comment_cell_attachments.rb b/app/cells/concerns/decidim/decidim_awesome/comments/comment_cell_attachments.rb index 1d60927b..6ca46c83 100644 --- a/app/cells/concerns/decidim/decidim_awesome/comments/comment_cell_attachments.rb +++ b/app/cells/concerns/decidim/decidim_awesome/comments/comment_cell_attachments.rb @@ -17,17 +17,21 @@ def cache_hash end def attachments_allowed? - @attachments_allowed ||= begin - if model.respond_to?(:component) - awesome_config_instance.context_from_component(model.component) - elsif model.is_a?(Decidim::Participable) - awesome_config_instance.context_from_participatory_space(model) - else - awesome_config_instance.context_from_request(request) - end - - awesome_config_instance.enabled_in_context?(:allow_attachments_in_comments) + @attachments_allowed ||= attachments_config_from_context + end + + def attachments_config_from_context + return false unless Decidim::DecidimAwesome::AwesomeConfig.find_by(var: :allow_attachments_in_comments, organization: current_organization)&.value + + if model.respond_to?(:component) + awesome_config_instance.context_from_component(model.component) + elsif model.is_a?(Decidim::Participable) + awesome_config_instance.context_from_participatory_space(model) + else + awesome_config_instance.context_from_request(request) end + + awesome_config_instance.enabled_in_context?(:allow_attachments_in_comments) end end end