summaryrefslogtreecommitdiff
path: root/app/models/customer_relations/issue_contact.rb
blob: 98faf8d664450fb584e34601d3cbcc754bcdf7b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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