diff --git a/app/jobs/regular/automatic_group_membership.rb b/app/jobs/regular/automatic_group_membership.rb index a6220db4277..963b3f4bc80 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) + .where(staged: false) .find_each do |user| group.add(user) diff --git a/spec/jobs/automatic_group_membership_spec.rb b/spec/jobs/automatic_group_membership_spec.rb index e6d59993085..c0bdc8c1b74 100644 --- a/spec/jobs/automatic_group_membership_spec.rb +++ b/spec/jobs/automatic_group_membership_spec.rb @@ -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