FIX: Automatic group membership should not add staged or unactivated users.

This commit is contained in:
Guo Xiang Tan 2016-12-21 18:04:26 +08:00
parent 12407484d8
commit 7228081820
2 changed files with 3 additions and 0 deletions

View File

@ -15,6 +15,7 @@ module Jobs
User.where("email ~* '@(#{domains})$'")
.where("users.id NOT IN (SELECT user_id FROM group_users WHERE group_users.group_id = ?)", group_id)
.where(staged: false)
.find_each do |user|
group.add(user)

View File

@ -10,6 +10,7 @@ describe Jobs::AutomaticGroupMembership do
it "updates the membership" do
user1 = Fabricate(:user, email: "foo@wat.com")
user2 = Fabricate(:user, email: "foo@bar.com")
user3 = Fabricate(:user, email: "bar@wat.com", staged: true)
group = Fabricate(:group, automatic_membership_email_domains: "wat.com", automatic_membership_retroactive: true)
Jobs::AutomaticGroupMembership.new.execute(group_id: group.id)
@ -17,6 +18,7 @@ describe Jobs::AutomaticGroupMembership do
group.reload
expect(group.users.include?(user1)).to eq(true)
expect(group.users.include?(user2)).to eq(false)
expect(group.users.include?(user3)).to eq(false)
end
end