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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/organization.rb')
-rw-r--r--app/models/organization.rb24
1 files changed, 22 insertions, 2 deletions
diff --git a/app/models/organization.rb b/app/models/organization.rb
index 73a7e84305f..cfbbbf1183e 100644
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -1,6 +1,26 @@
# frozen_string_literal: true
-# rubocop: disable Gitlab/NamespacedClass
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
-# rubocop: enable Gitlab/NamespacedClass