diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /app/models/customer_relations | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'app/models/customer_relations')
-rw-r--r-- | app/models/customer_relations/contact.rb | 3 | ||||
-rw-r--r-- | app/models/customer_relations/issue_contact.rb | 20 |
2 files changed, 22 insertions, 1 deletions
diff --git a/app/models/customer_relations/contact.rb b/app/models/customer_relations/contact.rb index c632f8e2efa..5898bc3412f 100644 --- a/app/models/customer_relations/contact.rb +++ b/app/models/customer_relations/contact.rb @@ -7,7 +7,8 @@ class CustomerRelations::Contact < ApplicationRecord belongs_to :group, -> { where(type: Group.sti_name) }, foreign_key: 'group_id' belongs_to :organization, optional: true - has_and_belongs_to_many :issues, join_table: :issue_customer_relations_contacts # rubocop: disable Rails/HasAndBelongsToMany + has_many :issue_contacts, inverse_of: :contact + has_many :issues, through: :issue_contacts, inverse_of: :customer_relations_contacts strip_attributes! :phone, :first_name, :last_name diff --git a/app/models/customer_relations/issue_contact.rb b/app/models/customer_relations/issue_contact.rb new file mode 100644 index 00000000000..98faf8d6644 --- /dev/null +++ b/app/models/customer_relations/issue_contact.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +class CustomerRelations::IssueContact < ApplicationRecord + self.table_name = "issue_customer_relations_contacts" + + belongs_to :issue, optional: false, inverse_of: :customer_relations_contacts + belongs_to :contact, optional: false, inverse_of: :issue_contacts + + validate :contact_belongs_to_issue_group + + private + + def contact_belongs_to_issue_group + return unless contact&.group_id + return unless issue&.project&.namespace_id + return if contact.group_id == issue.project.namespace_id + + errors.add(:base, _('The contact does not belong to the same group as the issue')) + end +end |