diff options
Diffstat (limited to 'app/models/group.rb')
-rw-r--r-- | app/models/group.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/app/models/group.rb b/app/models/group.rb index b094a65e3d6..17c69af4d1b 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -29,6 +29,8 @@ class Group < Namespace has_many :shared_projects, through: :project_group_links, source: :project validate :avatar_type, if: ->(user) { user.avatar.present? && user.avatar_changed? } + validate :visibility_level_allowed_by_projects + validates :avatar, file_size: { maximum: 200.kilobytes.to_i } mount_uploader :avatar, AvatarUploader @@ -80,6 +82,26 @@ class Group < Namespace visibility_level end + def visibility_level_allowed_by_projects + unless visibility_level_allowed? + level_name = Gitlab::VisibilityLevel.level_name(visibility_level).downcase + self.errors.add(:visibility_level, "#{level_name} is not allowed since there are projects with higher visibility.") + end + end + + def visibility_level_allowed? + projects_visibility = self.projects.pluck(:visibility_level) + + allowed_by_projects = projects_visibility.none? { |project_visibility| self.visibility_level < project_visibility } + + unless allowed_by_projects + level_name = Gitlab::VisibilityLevel.level_name(visibility_level).downcase + self.errors.add(:visibility_level, "#{level_name} is not allowed since there are projects with higher visibility.") + end + + allowed_by_projects + end + def avatar_url(size = nil) if avatar.present? [gitlab_config.url, avatar.url].join |