diff --git a/app/jobs/regular/automatic_group_membership.rb b/app/jobs/regular/automatic_group_membership.rb index 963b3f4bc80..dbe679889b0 100644 --- a/app/jobs/regular/automatic_group_membership.rb +++ b/app/jobs/regular/automatic_group_membership.rb @@ -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| diff --git a/spec/jobs/automatic_group_membership_spec.rb b/spec/jobs/automatic_group_membership_spec.rb index c0bdc8c1b74..5989deb4898 100644 --- a/spec/jobs/automatic_group_membership_spec.rb +++ b/spec/jobs/automatic_group_membership_spec.rb @@ -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