stop adding users to a group if they are already in the group
This commit is contained in:
parent
e82f892c2d
commit
f743bc6e74
1 changed files with 3 additions and 1 deletions
|
@ -13,7 +13,9 @@ module Jobs
|
||||||
|
|
||||||
domains = group.automatic_membership_email_domains.gsub('.', '\.')
|
domains = group.automatic_membership_email_domains.gsub('.', '\.')
|
||||||
|
|
||||||
User.where("email ~* '@(#{domains})$'").find_each do |user|
|
User.where("email ~* '@(#{domains})$' and users.id not in (
|
||||||
|
select user_id from group_users where group_users.group_id = ?
|
||||||
|
)", group_id).find_each do |user|
|
||||||
begin
|
begin
|
||||||
group.add(user)
|
group.add(user)
|
||||||
rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
|
rescue ActiveRecord::RecordNotUnique, PG::UniqueViolation
|
||||||
|
|
Reference in a new issue