Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
af6968a1
Commit
af6968a1
authored
Aug 24, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
separate visibility_level_allowed logic from model validators
parent
b2b9d63f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
15 deletions
+17
-15
app/models/group.rb
app/models/group.rb
+17
-15
No files found.
app/models/group.rb
View file @
af6968a1
...
@@ -105,33 +105,35 @@ class Group < Namespace
...
@@ -105,33 +105,35 @@ class Group < Namespace
end
end
def
visibility_level_allowed_by_parent
def
visibility_level_allowed_by_parent
return
if
parent_id
.
blank
?
return
if
visibility_level_allowed_by_parent
?
if
parent
&&
(
visibility_level
>
parent
.
visibility_level
)
errors
.
add
(
:visibility_level
,
"
#{
visibility
}
is not allowed since the parent group has a
#{
parent
.
visibility
}
visibility."
)
errors
.
add
(
:visibility_level
,
"
#{
visibility
}
is not allowed since the parent group has a
#{
parent
.
visibility
}
visibility."
)
end
end
end
def
visibility_level_allowed_by_projects
def
visibility_level_allowed_by_projects
check_visibility_level_for
(
:projects
)
return
if
visibility_level_allowed_by_projects?
errors
.
add
(
:visibility_level
,
"
#{
visibility
}
is not allowed since this group contains projects with higher visibility."
)
end
end
def
visibility_level_allowed_by_sub_groups
def
visibility_level_allowed_by_sub_groups
check_visibility_level_for
(
:children
)
return
if
visibility_level_allowed_by_sub_groups?
errors
.
add
(
:visibility_level
,
"
#{
visibility
}
is not allowed since there are sub-groups with higher visibility."
)
end
end
def
check_visibility_level_for
(
children_type
)
def
visibility_level_allowed_by_parent?
(
level
=
self
.
visibility_level
)
base_query
=
public_send
(
children_type
)
return
true
unless
parent_id
.
present?
||
parent
children_have_higher_visibility
=
base_query
.
where
(
'visibility_level > ?'
,
visibility_level
).
exists?
if
children_have_higher_visibility
level
<=
parent
.
visibility_level
children_label
=
children_type
==
:projects
?
'projects'
:
'sub groups'
end
level_name
=
Gitlab
::
VisibilityLevel
.
level_name
(
visibility_level
).
downcase
self
.
errors
.
add
(
:visibility_level
,
"
#{
level_name
}
is not allowed since there are
#{
children_label
}
with higher visibility."
)
def
visibility_level_allowed_by_projects?
(
level
=
self
.
visibility_level
)
projects
.
where
(
'visibility_level > ?'
,
level
).
none?
end
end
children_have_higher_visibility
def
visibility_level_allowed_by_sub_groups?
(
level
=
self
.
visibility_level
)
children
.
where
(
'visibility_level > ?'
,
level
).
none?
end
end
def
avatar_url
(
**
args
)
def
avatar_url
(
**
args
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment