Welcome to mirror list, hosted at ThFree Co, Russian Federation.

organization.rb « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cfbbbf1183ef57e94d0f55f7fe21ebf1cb93f753 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

class Organization < ApplicationRecord
  DEFAULT_ORGANIZATION_ID = 1

  scope :without_default, -> { where.not(id: DEFAULT_ORGANIZATION_ID) }

  before_destroy :check_if_default_organization

  validates :name,
    presence: true,
    length: { maximum: 255 },
    uniqueness: { case_sensitive: false }

  def default?
    id == DEFAULT_ORGANIZATION_ID
  end

  private

  def check_if_default_organization
    return unless default?

    raise ActiveRecord::RecordNotDestroyed, _('Cannot delete the default organization')
  end
end