Skip to content

Commit

Permalink
Backport "Don't display blocked users in mentions" to v0.26 (#8770)
Browse files Browse the repository at this point in the history
Co-authored-by: Armand Fardeau <armandfardeau@users.noreply.github.com>
  • Loading branch information
andreslucena and armandfardeau committed Feb 2, 2022
1 parent cf4e767 commit b50c1f6
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 8 deletions.
6 changes: 0 additions & 6 deletions decidim-core/app/models/decidim/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ def self.all
scope :officialized, -> { where.not(officialized_at: nil) }
scope :not_officialized, -> { where(officialized_at: nil) }

scope :confirmed, -> { where.not(confirmed_at: nil) }
scope :not_confirmed, -> { where(confirmed_at: nil) }

scope :blocked, -> { where(blocked: true) }
scope :not_blocked, -> { where(blocked: false) }

scope :interested_in_scopes, lambda { |scope_ids|
actual_ids = scope_ids.select(&:presence)
if actual_ids.count.positive?
Expand Down
6 changes: 6 additions & 0 deletions decidim-core/app/models/decidim/user_base_entity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class UserBaseEntity < ApplicationRecord

validates :name, format: { with: REGEXP_NAME }

scope :confirmed, -> { where.not(confirmed_at: nil) }
scope :not_confirmed, -> { where(confirmed_at: nil) }

scope :blocked, -> { where(blocked: true) }
scope :not_blocked, -> { where(blocked: false) }

# Public: Returns a collection with all the public entities this user is following.
#
# This can't be done as with a `has_many :following, through: :following_follows`
Expand Down
3 changes: 2 additions & 1 deletion decidim-core/lib/decidim/api/functions/user_entity_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ def call(_obj, args, ctx)
filters[argument.to_sym] = v
end
Decidim::UserBaseEntity
.where.not(confirmed_at: nil)
.confirmed
.not_blocked
.find_by(filters)
end
end
Expand Down
3 changes: 2 additions & 1 deletion decidim-core/lib/decidim/api/functions/user_entity_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def initialize
def call(_obj, args, ctx)
@query = Decidim::UserBaseEntity
.where(organization: ctx[:current_organization])
.where.not(confirmed_at: nil)
.confirmed
.not_blocked
.includes(avatar_attachment: :blob)
add_filter_keys(args[:filter])
add_order_keys(args[:order].to_h)
Expand Down
66 changes: 66 additions & 0 deletions decidim-core/spec/types/user_entity_input_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ module Core
expect(users).to include({ "id" => user.id.to_s, "__typename" => "User" },
"id" => user_group.id.to_s, "__typename" => "UserGroup")
end

context "when user is blocked" do
let(:user) { create(:user, :blocked, :confirmed, organization: current_organization) }

it "doesn't returns all the types" do
users = response["users"]
expect(users).to include("id" => user_group.id.to_s, "__typename" => "UserGroup")
end
end
end

context "when user or groups are not confirmed" do
Expand All @@ -43,6 +52,15 @@ module Core
expect(users).to include("id" => user.id.to_s)
expect(users).not_to include("id" => user_group.id.to_s)
end

context "when user is blocked" do
let(:user) { create(:user, :blocked, :confirmed, organization: current_organization) }

it "doesn't returns all the types" do
users = response["users"]
expect(users).to eq([])
end
end
end

context "when filtering by type UserGroup" do
Expand Down Expand Up @@ -86,6 +104,14 @@ module Core
expect(response["users"]).to include("name" => user5.name)
expect(response["users"]).to include("name" => user6.name)
end

context "when user is blocked" do
let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) }

it "doesn't returns matching users" do
expect(response["users"]).not_to include("name" => user1.name)
end
end
end

context "when search a user by name" do
Expand All @@ -100,6 +126,14 @@ module Core
expect(response["users"]).to include("name" => user5.name)
expect(response["users"]).to include("name" => user6.name)
end

context "when user is blocked" do
let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) }

it "doesn't returns matching users" do
expect(response["users"]).not_to include("name" => user1.name)
end
end
end

context "when search a user by wildcard" do
Expand All @@ -114,6 +148,14 @@ module Core
expect(response["users"]).to include("name" => user5.name)
expect(response["users"]).to include("name" => user6.name)
end

context "when user is blocked" do
let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) }

it "doesn't returns matching users" do
expect(response["users"]).not_to include("name" => user1.name)
end
end
end

context "when search a user by wildcard but with empty exclusion list" do
Expand All @@ -129,6 +171,14 @@ module Core
expect(response["users"]).to include("name" => user5.name)
expect(response["users"]).to include("name" => user6.name)
end

context "when user is blocked" do
let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) }

it "doesn't returns matching users" do
expect(response["users"]).not_to include("name" => user1.name)
end
end
end

context "when search a user by wildcard but with exclusion list" do
Expand All @@ -144,6 +194,14 @@ module Core
expect(response["users"]).not_to include("name" => user5.name)
expect(response["users"]).to include("name" => user6.name)
end

context "when user is blocked" do
let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) }

it "doesn't returns matching users" do
expect(response["users"]).not_to include("name" => user1.name)
end
end
end

context "when search a user by wildcard but with multiple exclusion list" do
Expand All @@ -159,6 +217,14 @@ module Core
expect(response["users"]).not_to include("name" => user5.name)
expect(response["users"]).not_to include("name" => user6.name)
end

context "when user is blocked" do
let!(:user1) { create(:user, :blocked, :confirmed, nickname: "_foo_user_1", name: "FooBar User 1", organization: current_organization) }

it "doesn't returns matching users" do
expect(response["users"]).not_to include("name" => user1.name)
end
end
end
end
end
Expand Down

0 comments on commit b50c1f6

Please sign in to comment.