blob: 0661082dcedc48421d4427fd68efd1a9cac0fc8d (
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
27
|
# frozen_string_literal: true
class MemberRole < ApplicationRecord # rubocop:disable Gitlab/NamespacedClass
has_many :members
belongs_to :namespace
validates :namespace, presence: true
validates :base_access_level, presence: true
validate :belongs_to_top_level_namespace
validate :validate_namespace_locked, on: :update
validates_associated :members
private
def belongs_to_top_level_namespace
return if !namespace || namespace.root?
errors.add(:namespace, s_("MemberRole|must be top-level namespace"))
end
def validate_namespace_locked
return unless namespace_id_changed?
errors.add(:namespace, s_("MemberRole|can't be changed"))
end
end
|