diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-12-20 16:37:47 +0300 |
commit | aee0a117a889461ce8ced6fcf73207fe017f1d99 (patch) | |
tree | 891d9ef189227a8445d83f35c1b0fc99573f4380 /app/models/customer_relations | |
parent | 8d46af3258650d305f53b819eabf7ab18d22f59e (diff) |
Add latest changes from gitlab-org/gitlab@14-6-stable-eev14.6.0-rc42
Diffstat (limited to 'app/models/customer_relations')
-rw-r--r-- | app/models/customer_relations/contact.rb | 7 | ||||
-rw-r--r-- | app/models/customer_relations/issue_contact.rb | 8 |
2 files changed, 15 insertions, 0 deletions
diff --git a/app/models/customer_relations/contact.rb b/app/models/customer_relations/contact.rb index 5898bc3412f..d8669f1f4c2 100644 --- a/app/models/customer_relations/contact.rb +++ b/app/models/customer_relations/contact.rb @@ -25,6 +25,13 @@ class CustomerRelations::Contact < ApplicationRecord validates :description, length: { maximum: 1024 } validate :validate_email_format + def self.find_ids_by_emails(group_id, emails) + raise ArgumentError, "Cannot lookup more than #{MAX_PLUCK} emails" if emails.length > MAX_PLUCK + + where(group_id: group_id, email: emails) + .pluck(:id) + end + private def validate_email_format diff --git a/app/models/customer_relations/issue_contact.rb b/app/models/customer_relations/issue_contact.rb index 98faf8d6644..78f662b6a58 100644 --- a/app/models/customer_relations/issue_contact.rb +++ b/app/models/customer_relations/issue_contact.rb @@ -8,6 +8,14 @@ class CustomerRelations::IssueContact < ApplicationRecord validate :contact_belongs_to_issue_group + def self.find_contact_ids_by_emails(issue_id, emails) + raise ArgumentError, "Cannot lookup more than #{MAX_PLUCK} emails" if emails.length > MAX_PLUCK + + joins(:contact) + .where(issue_id: issue_id, customer_relations_contacts: { email: emails }) + .pluck(:contact_id) + end + private def contact_belongs_to_issue_group |