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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
adbc3780
Commit
adbc3780
authored
Dec 09, 2016
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor duplicate code into a by_scope method
parent
eaf92daa
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
35 deletions
+19
-35
app/finders/snippets_finder.rb
app/finders/snippets_finder.rb
+19
-35
No files found.
app/finders/snippets_finder.rb
View file @
adbc3780
...
...
@@ -29,21 +29,11 @@ class SnippetsFinder
def
by_user
(
current_user
,
user
,
scope
)
snippets
=
user
.
snippets
.
fresh
return
snippets
.
are_public
unless
current_user
if
user
==
current_user
case
scope
when
'are_internal'
then
snippets
.
are_internal
when
'are_private'
then
snippets
.
are_private
when
'are_public'
then
snippets
.
are_public
else
snippets
end
if
current_user
include_private
=
user
==
current_user
by_scope
(
snippets
,
scope
,
include_private
)
else
snippets
.
public_and_internal
snippets
.
are_public
end
end
...
...
@@ -51,29 +41,23 @@ class SnippetsFinder
snippets
=
project
.
snippets
.
fresh
if
current_user
if
project
.
team
.
member?
(
current_user
)
||
current_user
.
admin?
case
scope
when
'are_internal'
then
snippets
.
are_internal
when
'are_private'
then
snippets
.
are_private
when
'are_public'
then
snippets
.
are_public
else
snippets
end
else
case
scope
when
'are_internal'
then
snippets
.
are_internal
when
'are_public'
then
snippets
.
are_public
else
snippets
.
public_and_internal
end
end
include_private
=
project
.
team
.
member?
(
current_user
)
||
current_user
.
admin?
by_scope
(
snippets
,
scope
,
include_private
)
else
snippets
.
are_public
end
end
def
by_scope
(
snippets
,
scope
=
nil
,
include_private
=
false
)
case
scope
.
to_s
when
'are_private'
include_private
?
snippets
.
are_private
:
nil
when
'are_internal'
snippets
.
are_internal
when
'are_public'
snippets
.
are_public
else
include_private
?
snippets
:
snippets
.
public_and_internal
end
end
end
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