Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capability for admins to answer to close comments #75

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
85bce8f
Fix showing announcement when comments are disabled
andreslucena Mar 4, 2024
fdcc1eb
Wait for the comment thread loading before checking for the form
andreslucena Mar 4, 2024
8f6e123
Add a check for the verification announcement
andreslucena Mar 4, 2024
112e9d9
Extract comments blocked to a shared example
andreslucena Mar 5, 2024
dd184f8
Add missing spec for blogs module
andreslucena Mar 5, 2024
2930d3d
Fix specs
andreslucena Mar 6, 2024
2b56387
Fix rubocop offenses
andreslucena May 23, 2024
bbf0cf4
Fix spec
andreslucena May 23, 2024
6d27979
Add Attachments with a Link (#12917)
mllocs Jun 14, 2024
9e284cd
Do not allow registering to a meeting if it started (#12995)
andreslucena Jun 16, 2024
f390ba5
Add checks in system for the secret key and the ActiveJob queue (#12846)
andreslucena Jun 16, 2024
928272d
Change default proposal sorting word to automatic (#12984)
andreslucena Jun 16, 2024
761ae2c
Extend polls feature in meetings (#12957)
entantoencuanto Jun 17, 2024
c144a2b
Standardise `current_user` call within Commands tasks (Meetings part …
greenwoodt Jun 17, 2024
53502ed
Merge branch 'fix/comments-disabled-announcement' into feature/admin_…
ElviaBth Jun 17, 2024
70ae27e
modify warning message for blocked comments
ElviaBth Jun 19, 2024
4df034c
enable admin to post comments
ElviaBth Jun 19, 2024
5e93e5f
add missing argument to user_has_any_role? methods
ElviaBth Jun 19, 2024
d89aeaf
add a new condition to user_has_any_role? method
ElviaBth Jun 19, 2024
2335e68
enable admin to reply close comments
ElviaBth Jun 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .erb-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ linters:
- is-accordion-submenu
- is-accordion-submenu-parent
- is-accordion-submenu-parent[aria-expanded=true]
- is-admin
- is-anchored
- is-at-bottom
- is-at-top
Expand Down
1 change: 1 addition & 0 deletions config/i18n-tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ ignore_unused:
- layouts.decidim.assemblies.promoted_assembly.take_part
- versions.dropdown.option_*
- decidim.meetings.meetings.filters.*
- decidim.meetings.polls.questions.index_admin.statuses.{closed,published,unpublished}
- decidim.meetings.directory.meetings.index.space_type
- decidim.authorization_modals.content.*
- time.buttons.*
Expand Down
7 changes: 7 additions & 0 deletions decidim-accountability/spec/system/comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
let(:resource_path) { resource_locator(commentable).path }

include_examples "comments"

context "with comments blocked" do
let!(:component) { create(:component, manifest_name: :accountability, participatory_space:, organization:) }
let(:participatory_space) { create(:participatory_process, :with_steps, organization:) }

include_examples "comments blocked"
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def build_attachment
weight: form.weight,
attachment_collection: form.attachment_collection,
file: form.file, # Define attached_to before this
content_type: blob(form.file).content_type
content_type: form.file && blob(form.file).content_type,
link: form.file ? nil : form.link
)
end

Expand Down
11 changes: 7 additions & 4 deletions decidim-admin/app/commands/decidim/admin/update_attachment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ def attributes
{
title: form.title,
file: form.file,
link: form.link,
description: form.description,
weight: form.weight,
attachment_collection: form.attachment_collection
weight: form.weight
}.merge(
attachment_attributes(:file)
).reject do |attribute, value|
value.blank? && attribute != :attachment_collection
).compact_blank.merge(
attachment_collection: form.attachment_collection
).tap do |attrs|
attrs[:file] = nil if form.link.present? && form.file.blank?
attrs[:link] = nil if form.file.present? && form.link.blank?
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module NeedsAdminTosAccepted
extend ActiveSupport::Concern

included do
include UserRoleChecker
before_action :tos_accepted_by_admin
end

Expand All @@ -15,7 +16,7 @@ module NeedsAdminTosAccepted
def tos_accepted_by_admin
return unless request.format.html?
return unless current_user
return unless user_has_any_role?
return unless user_has_any_role?(current_user)
return if current_user.admin_terms_accepted?
return if permitted_paths?

Expand All @@ -38,34 +39,6 @@ def permitted_paths
def admin_tos_path
decidim_admin.admin_terms_show_path
end

def user_has_any_role?
return true if current_user.admin
return true if current_user.roles.any?
return true if participatory_process_user_role?
return true if assembly_user_role?
return true if conference_user_role?

false
end

def participatory_process_user_role?
return false unless Decidim.module_installed?(:participatory_processes)

true if Decidim::ParticipatoryProcessUserRole.exists?(user: current_user)
end

def assembly_user_role?
return false unless Decidim.module_installed?(:assemblies)

true if Decidim::AssemblyUserRole.exists?(user: current_user)
end

def conference_user_role?
return false unless Decidim.module_installed?(:conferences)

true if Decidim::ConferenceUserRole.exists?(user: current_user)
end
end
end
end
8 changes: 7 additions & 1 deletion decidim-admin/app/forms/decidim/admin/attachment_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ class AttachmentForm < Form
translatable_attribute :description, String
attribute :weight, Integer, default: 0
attribute :attachment_collection_id, Integer
attribute :link, String

mimic :attachment

validates :file, presence: true, unless: :persisted?
validates :file, presence: true, unless: :persisted_or_link?
validates :link, url: true
validates :file, passthru: { to: Decidim::Attachment }
validates :title, :description, translatable_presence: true
validates :attachment_collection, presence: true, if: ->(form) { form.attachment_collection_id.present? }
Expand All @@ -25,6 +27,10 @@ class AttachmentForm < Form

alias organization current_organization

def persisted_or_link?
persisted? || link.present?
end

def attachment_collections
@attachment_collections ||= attached_to.attachment_collections
end
Expand Down
23 changes: 21 additions & 2 deletions decidim-admin/app/views/decidim/admin/attachments/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,27 @@
<%= form.select :attachment_collection_id, @form.attachment_collections.map { |c| [translated_attribute(c.name), c.id] }, include_blank: true %>
</div>

<div class="row column">
<%= form.upload :file, button_class: "button button__sm button__transparent-secondary" %>
<div class="p-6" data-file-or-link-tabs-controller>
<%= cell "decidim/tab_panels", [
{
enabled: true,
id: "file",
text: "Upload file",
icon: "file-upload-line",
method: :cell,
selected: form.object.file.present?,
args: ["/decidim/attachments_file_tab", form]
},
{
enabled: true,
id: "link",
text: "Link",
icon: "link",
method: :cell,
selected: form.object.link.present?,
args: ["/decidim/attachments_link_tab", form]
}
] %>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<%= attachment.file_type %>
</td>
<td>
<%= number_to_human_size(attachment.file_size) %>
<%= attachment.file? ? number_to_human_size(attachment.file_size) : "-" %>
</td>
<td class="table-list__actions">
<% if allowed_to? :update, :attachment, attachment: attachment %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,42 @@
end
end

it "can add attachments with a link to a process" do
click_on "New attachment"

within ".new_attachment" do
fill_in_i18n(
:attachment_title,
"#attachment-title-tabs",
en: "Very Important Document",
es: "Documento Muy Importante",
ca: "Document Molt Important"
)

fill_in_i18n(
:attachment_description,
"#attachment-description-tabs",
en: "This document contains important information",
es: "Este documento contiene información importante",
ca: "Aquest document conté informació important"
)
end

within ".new_attachment" do
find_by_id("trigger-link").click

fill_in "attachment[link]", with: "https://example.com/docs.pdf"

find("*[type=submit]").click
end

expect(page).to have_admin_callout("successfully")

within "#attachments table" do
expect(page).to have_text("Very Important Document")
end
end

it "can add attachments within a collection to a process" do
click_on "New attachment"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ module Decidim::Admin
es: "Una ciudad"
},
file:,
link:,
attachment_collection: nil,
weight: 2
)
end
let(:file) { upload_test_file(Decidim::Dev.test_file("city.jpeg", "image/jpeg")) }
let(:link) { "" }

describe "when valid" do
before do
Expand Down
19 changes: 19 additions & 0 deletions decidim-blogs/spec/system/comments_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require "spec_helper"

describe "Comments", perform_enqueued: true do
let!(:component) { create(:post_component, organization:) }
let!(:commentable) { create(:post, component:) }

let(:resource_path) { resource_locator(commentable).path }

include_examples "comments"

context "with comments blocked" do
let!(:component) { create(:post_component, participatory_space:, organization:) }
let(:participatory_space) { create(:participatory_process, :with_steps, organization:) }

include_examples "comments blocked"
end
end
7 changes: 7 additions & 0 deletions decidim-budgets/spec/system/comments_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@

include_examples "comments"

context "with comments blocked" do
let!(:component) { create(:budgets_component, participatory_space:, organization:) }
let(:participatory_space) { create(:participatory_process, :with_steps, organization:) }

include_examples "comments blocked"
end

context "when requesting the comments index with a non-XHR request" do
it "redirects the user to the correct commentable path" do
visit decidim_comments.comments_path(commentable_gid: commentable.to_signed_global_id.to_s)
Expand Down
3 changes: 3 additions & 0 deletions decidim-comments/app/cells/decidim/comments/comment_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module Comments
# A cell to display a single comment.
class CommentCell < Decidim::ViewModel
include Decidim::ResourceHelper
include Decidim::UserRoleChecker
include Cell::ViewModel::Partial

delegate :current_user, :user_signed_in?, to: :controller
Expand Down Expand Up @@ -95,6 +96,8 @@ def context_menu_id
end

def can_reply?
return true if user_has_any_role?(current_user)

user_signed_in? && accepts_new_comments? &&
root_commentable.user_allowed_to_comment?(current_user)
end
Expand Down
19 changes: 13 additions & 6 deletions decidim-comments/app/cells/decidim/comments/comments_cell.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@ module Decidim
module Comments
# A cell to display a comments section for a commentable object.
class CommentsCell < Decidim::ViewModel
include UserRoleChecker
delegate :user_signed_in?, to: :controller
def add_comment
return if single_comment?
return if comments_blocked?
return if user_comments_blocked?

render :add_comment
def add_comment
render :add_comment if show_comments?
end

def single_comment_warning
Expand All @@ -27,7 +25,7 @@ def comments_loading

def blocked_comments_warning
return unless comments_blocked?
return unless user_comments_blocked?
return if user_comments_blocked?

render :blocked_comments_warning
end
Expand All @@ -41,6 +39,15 @@ def user_comments_blocked_warning

private

def show_comments?
return true if user_has_any_role?(current_user)
return if single_comment?
return if comments_blocked?
return if user_comments_blocked?

true
end

def decidim_comments
Decidim::Comments::Engine.routes.url_helpers
end
Expand Down
13 changes: 13 additions & 0 deletions decidim-comments/app/forms/decidim/comments/comment_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ module Comments
# A form object used to create comments from the graphql api.
#
class CommentForm < Form
include Decidim::UserRoleChecker

attribute :body, Decidim::Attributes::CleanString
attribute :alignment, Integer
attribute :user_group_id, Integer
Expand All @@ -17,6 +19,7 @@ class CommentForm < Form
validates :alignment, inclusion: { in: [0, 1, -1] }, if: ->(form) { form.alignment.present? }

validate :max_depth
validate :commentable_can_have_comments

def max_length
if current_component.try(:settings).respond_to?(:comments_max_length)
Expand All @@ -33,6 +36,16 @@ def max_depth

errors.add(:base, :invalid) if commentable.depth >= Comment::MAX_DEPTH
end

private

# Private: Check if commentable can have comments and if not adds
# a validation error to the model
def commentable_can_have_comments
return if user_has_any_role?(current_user)

errors.add(:commentable, :cannot_have_comments) unless commentable.accepts_new_comments?
end
end
end
end
7 changes: 0 additions & 7 deletions decidim-comments/app/models/decidim/comments/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class Comment < ApplicationRecord
validates :depth, numericality: { only_integer: true, greater_than_or_equal_to: 0, less_than_or_equal_to: MAX_DEPTH }
validates :alignment, inclusion: { in: [0, 1, -1] }
validate :body_length
validate :commentable_can_have_comments

scope :not_deleted, -> { where(deleted_at: nil) }

Expand Down Expand Up @@ -228,12 +227,6 @@ def component_settings_comments_max_length?
component.settings.comments_max_length.positive?
end

# Private: Check if commentable can have comments and if not adds
# a validation error to the model
def commentable_can_have_comments
errors.add(:commentable, :cannot_have_comments) unless root_commentable.accepts_new_comments?
end

# Private: Compute comment depth inside the current comment tree
def compute_depth
self.depth = commentable.depth + 1 if commentable.respond_to?(:depth)
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ en:
comments:
blocked_comments_for_unauthorized_user_warning: You need to be verified to comment at this moment, but you can read the previous ones.
blocked_comments_for_user_warning: You are not able to comment at this moment, but you can read the previous ones.
blocked_comments_warning: Comments are disabled at this time, but you can read the previous ones.
blocked_comments_warning: Comments are currently disabled, only administrators can reply or post new ones.
comment_details_title: Comment details
loading: Loading comments ...
single_comment_warning: <a href="%{url}">View all comments</a>
Expand Down
Loading
Loading