Exclude inactive users
The system user should never be a subsriber but we should not serve it if it is
This commit is contained in:
@@ -21,10 +21,13 @@ module Card::Watchable
|
||||
end
|
||||
|
||||
def watchers_and_subscribers(include_only_watching: false)
|
||||
involvements = include_only_watching ? [ :watching ] : []
|
||||
subscribers = collection.users.where(accesses: { involvement: involvements })
|
||||
|
||||
User.where(id: subscribers.pluck(:id) +
|
||||
User.active.where(id: subscribers(include_only_watching:).pluck(:id) +
|
||||
watches.watching.pluck(:user_id) - watches.not_watching.pluck(:user_id))
|
||||
end
|
||||
|
||||
private
|
||||
def subscribers(include_only_watching: false)
|
||||
involvements = include_only_watching ? [ :watching ] : []
|
||||
collection.users.where(accesses: { involvement: involvements })
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,7 +7,7 @@ module User::Accessor
|
||||
has_many :accessible_cards, through: :collections, source: :cards
|
||||
has_many :accessible_comments, through: :accessible_cards, source: :comments
|
||||
|
||||
after_create_commit :grant_access_to_collections
|
||||
after_create_commit :grant_access_to_collections, unless: :system?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -39,5 +39,9 @@ class Card::WatchableTest < ActiveSupport::TestCase
|
||||
cards(:logo).watch_by users(:david)
|
||||
|
||||
assert_equal [ users(:kevin), users(:david) ].sort, cards(:logo).watchers_and_subscribers.sort
|
||||
|
||||
# Only active users
|
||||
users(:david).system!
|
||||
assert_equal [ users(:kevin) ].sort, cards(:logo).watchers_and_subscribers.sort
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
require "test_helper"
|
||||
|
||||
class User::AccessorTest < ActiveSupport::TestCase
|
||||
test "new users get added to all_access collections on creation" do
|
||||
regular_user = User.create!(name: "Jorge", email_address: "testregular@example.com", password: "secret123456")
|
||||
|
||||
assert_includes regular_user.collections, collections(:writebook)
|
||||
assert_equal Collection.all_access.count, regular_user.collections.count
|
||||
end
|
||||
|
||||
test "system user does not get added to collections on creation" do
|
||||
system_user = User.create!(role: "system", name: "Test System User")
|
||||
assert_empty system_user.collections
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user