Skip to content

Commit

Permalink
Fix report moderation for all the spaces (decidim#8813)
Browse files Browse the repository at this point in the history
# Conflicts:
#	decidim-comments/app/models/decidim/comments/comment.rb
  • Loading branch information
microstudi committed Feb 21, 2022
1 parent 55fa532 commit a532a7e
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def permissions
public_list_assemblies_action?
public_read_assembly_action?
public_list_members_action?
public_report_content_action?
return permission_action
end

Expand Down Expand Up @@ -125,13 +124,6 @@ def public_list_members_action?
allow!
end

def public_report_content_action?
return unless permission_action.action == :create &&
permission_action.subject == :moderation

allow!
end

# All users with a relation to a assembly and organization admins can enter
# the space area. The sapce area is considered to be the assemblies zone,
# not the assembly groups one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,6 @@
it { is_expected.to eq true }
end

context "when reporting a resource" do
let(:action) do
{ scope: :public, action: :create, subject: :moderation }
end

it { is_expected.to eq true }
end

context "when any other action" do
let(:action) do
{ scope: :public, action: :foo, subject: :bar }
Expand Down
2 changes: 1 addition & 1 deletion decidim-comments/app/models/decidim/comments/comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def visible?
end

def participatory_space
return root_commentable if root_commentable.is_a?(Decidim::Participable)
return root_commentable unless root_commentable.respond_to?(:participatory_space)

root_commentable.participatory_space
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def permissions
public_list_program_action?
public_list_media_links_action?
public_list_registration_types_action?
public_report_content_action?

can_join_conference?
can_leave_conference?
Expand Down Expand Up @@ -159,13 +158,6 @@ def public_list_registration_types_action?
allow!
end

def public_report_content_action?
return unless permission_action.action == :create &&
permission_action.subject == :moderation

allow!
end

# All users with a relation to a conference and organization admins can enter
# the space area. The sapce area is considered to be the conferences zone,
# not the conference groups one.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,6 @@
it { is_expected.to eq true }
end

context "when reporting a resource" do
let(:action) do
{ scope: :public, action: :create, subject: :moderation }
end

it { is_expected.to eq true }
end

context "when any other action" do
let(:action) do
{ scope: :public, action: :foo, subject: :bar }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class Question < ApplicationRecord
delegate :start_voting_date, to: :consultation
delegate :end_voting_date, to: :consultation
delegate :results_published?, to: :consultation
delegate :moderators, to: :consultation

alias participatory_space consultation

Expand Down
9 changes: 9 additions & 0 deletions decidim-core/app/permissions/decidim/permissions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def permissions
component_public_action?
search_scope_action?

public_report_content_action?

return permission_action unless user

user_manager_permissions
Expand All @@ -28,6 +30,13 @@ def permissions

private

def public_report_content_action?
return unless permission_action.action == :create &&
permission_action.subject == :moderation

allow!
end

def read_public_pages_action?
return unless permission_action.subject == :public_page &&
permission_action.action == :read
Expand Down
8 changes: 8 additions & 0 deletions decidim-core/spec/permissions/decidim/permissions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
it { is_expected.to eq true }
end

context "when reporting a resource" do
let(:action) do
{ scope: :public, action: :create, subject: :moderation }
end

it { is_expected.to eq true }
end

context "when reading a component" do
let(:action) do
{ scope: :public, action: :read, subject: :component }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def permissions
return permission_action if permission_action.scope != :public

# Non-logged users permissions
public_report_content_action?
list_public_initiatives?
read_public_initiative?
search_initiative_types_and_scopes?
Expand Down Expand Up @@ -154,13 +153,6 @@ def initiative_attachment?
toggle_allow(initiative_type.attachments_enabled?)
end

def public_report_content_action?
return unless permission_action.action == :create &&
permission_action.subject == :moderation

allow!
end

def sign_initiative?
return unless permission_action.action == :sign_initiative &&
permission_action.subject == :initiative
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ def permissions
public_list_process_groups_action?
public_read_process_group_action?
public_read_process_action?
public_report_content_action?
return permission_action
end

Expand Down Expand Up @@ -119,13 +118,6 @@ def can_view_private_space?
user.admin || process.users.include?(user)
end

def public_report_content_action?
return unless permission_action.action == :create &&
permission_action.subject == :moderation

allow!
end

# Only organization admins can enter the process groups space area.
def user_can_enter_process_groups_space_area?
return unless permission_action.action == :enter &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,6 @@
it { is_expected.to eq true }
end

context "when reporting a resource" do
let(:action) do
{ scope: :public, action: :create, subject: :moderation }
end

it { is_expected.to eq true }
end

context "when any other action" do
let(:action) do
{ scope: :public, action: :foo, subject: :bar }
Expand Down

0 comments on commit a532a7e

Please sign in to comment.