FIX: Unactivated users should not be automatically added into groups as well.

This commit is contained in:
Guo Xiang Tan 2016-12-21 18:15:01 +08:00
parent 7228081820
commit 076a08d8e1
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)
.activated
.where(staged: false)
.find_each do |user|

View File

@ -11,6 +11,7 @@ describe Jobs::AutomaticGroupMembership do
user1 = Fabricate(:user, email: "foo@wat.com")
user2 = Fabricate(:user, email: "foo@bar.com")
user3 = Fabricate(:user, email: "bar@wat.com", staged: true)
user4 = Fabricate(:user, email: "abc@wat.com", active: false)
group = Fabricate(:group, automatic_membership_email_domains: "wat.com", automatic_membership_retroactive: true)
Jobs::AutomaticGroupMembership.new.execute(group_id: group.id)
@ -19,6 +20,7 @@ describe Jobs::AutomaticGroupMembership do
expect(group.users.include?(user1)).to eq(true)
expect(group.users.include?(user2)).to eq(false)
expect(group.users.include?(user3)).to eq(false)
expect(group.users.include?(user4)).to eq(false)
end
end