summaryrefslogtreecommitdiff
path: root/app/models/customer_relations
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-11-19 18:12:50 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-11-19 18:12:50 +0000
commit78f7d2e7266a80502f91d5c3aeb5689c72f156a2 (patch)
treebd7dca46bb745b27d30ff9e0fab2c5aa92b37c69 /app/models/customer_relations
parent03a3b1a4caac4c04e81ee592fdb3b9c47dbb9623 (diff)
downloadgitlab-ce-78f7d2e7266a80502f91d5c3aeb5689c72f156a2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/customer_relations')
-rw-r--r--app/models/customer_relations/contact.rb7
-rw-r--r--app/models/customer_relations/issue_contact.rb8
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