summaryrefslogtreecommitdiff
path: root/app/models/group.rb
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <zegerjan@gitlab.com>2016-03-18 13:28:16 +0100
committerFelipe Artur <felipefac@gmail.com>2016-03-18 16:58:04 -0300
commitb959ae553b1243e081d557b1e545d30830931e5b (patch)
treece6c7410a97d93645fce4eb4ae77f1e8a1f9879b /app/models/group.rb
parent0a7f7161198feaa9a4cae7c16669a0e6187aed33 (diff)
downloadgitlab-ce-b959ae553b1243e081d557b1e545d30830931e5b.tar.gz
Improve group visibility level feature
Diffstat (limited to 'app/models/group.rb')
-rw-r--r--app/models/group.rb22
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