diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-11 03:10:03 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-11 03:10:03 +0300 |
commit | d229251151a3bdeb80a0d8004003700ac3f95893 (patch) | |
tree | e252fc9aecf9452747413c6026139e34557564d3 /app/models/customer_relations | |
parent | caff5659c981d9b8ed2c086fb35deac9e189b865 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/customer_relations')
-rw-r--r-- | app/models/customer_relations/organization.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/app/models/customer_relations/organization.rb b/app/models/customer_relations/organization.rb new file mode 100644 index 00000000000..caf1cd68cc5 --- /dev/null +++ b/app/models/customer_relations/organization.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +class CustomerRelations::Organization < ApplicationRecord + self.table_name = "customer_relations_organizations" + + belongs_to :group, -> { where(type: 'Group') }, foreign_key: 'group_id' + + before_validation :strip_whitespace! + + enum state: { + inactive: 0, + active: 1 + } + + validates :group, presence: true + validates :name, presence: true + validates :name, uniqueness: { case_sensitive: false, scope: [:group_id] } + validates :name, length: { maximum: 255 } + validates :description, length: { maximum: 1024 } + + def self.find_by_name(group_id, name) + where(group: group_id) + .where('LOWER(name) = LOWER(?)', name) + end + + private + + def strip_whitespace! + name&.strip! + end +end |