Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
69d578bd6952
Commit
69d578bd
authored
Feb 13, 2018
by
Andreas Brandl
Browse files
Shortcut when all levels visible.
parent
0bd5751b3b07
Changes
3
Hide whitespace changes
Inline
Side-by-side
app/models/project.rb
View file @
69d578bd
...
...
@@ -325,6 +325,12 @@
levels
=
Gitlab
::
VisibilityLevel
.
levels_for_user
(
user
)
if
Gitlab
::
VisibilityLevel
.
all_levels?
(
levels
)
# If the user is allowed to see all projects,
# we can shortcut and just return.
return
all
end
authorized_projects
=
where
(
'EXISTS (?)'
,
authorized
).
select
(
:id
)
visible_projects
=
where
(
'visibility_level IN (?)'
,
levels
).
select
(
:id
)
...
...
lib/gitlab/visibility_level.rb
View file @
69d578bd
...
...
@@ -20,6 +20,7 @@
PRIVATE
=
0
unless
const_defined?
(
:PRIVATE
)
INTERNAL
=
10
unless
const_defined?
(
:INTERNAL
)
PUBLIC
=
20
unless
const_defined?
(
:PUBLIC
)
ALL_LEVELS
=
[
PRIVATE
,
INTERNAL
,
PUBLIC
].
freeze
unless
const_defined?
(
:ALL_LEVELS
)
class
<<
self
delegate
:values
,
to: :options
...
...
@@ -28,7 +29,7 @@
return
[
PUBLIC
]
unless
user
if
user
.
full_private_access?
[
PRIVATE
,
INTERNAL
,
PUBLIC
]
ALL_LEVELS
elsif
user
.
external?
[
PUBLIC
]
else
...
...
@@ -36,6 +37,10 @@
end
end
def
all_levels?
(
levels
=
[])
levels
&
.
sort
==
ALL_LEVELS
end
def
string_values
string_options
.
keys
end
...
...
spec/lib/gitlab/visibility_level_spec.rb
View file @
69d578bd
...
...
@@ -50,6 +50,28 @@
end
end
describe
'.all_levels?'
do
let
(
:levels
)
do
[
Gitlab
::
VisibilityLevel
::
PUBLIC
,
Gitlab
::
VisibilityLevel
::
INTERNAL
,
Gitlab
::
VisibilityLevel
::
PRIVATE
].
shuffle
end
it
'returns true only when given all levels defined at once'
do
expect
(
described_class
.
all_levels?
(
levels
)).
to
be_truthy
end
it
'returns true for ALL_LEVELS'
do
expect
(
described_class
.
all_levels?
(
Gitlab
::
VisibilityLevel
::
ALL_LEVELS
)).
to
be_truthy
end
it
'returns false if any one level is missing'
do
expect
(
described_class
.
all_levels?
(
levels
[
0
..-
2
])).
to
be_falsey
end
end
describe
'.allowed_levels'
do
it
'only includes the levels that arent restricted'
do
stub_application_setting
(
restricted_visibility_levels:
[
Gitlab
::
VisibilityLevel
::
INTERNAL
])
...
...
Write
Preview
Supports
Markdown
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