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
5566c021
Commit
5566c021
authored
Dec 03, 2019
by
Andreas Brandl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor load/prepare/present pattern
parent
5b27e0e0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
7 deletions
+17
-7
lib/api/projects.rb
lib/api/projects.rb
+17
-7
No files found.
lib/api/projects.rb
View file @
5566c021
...
@@ -75,15 +75,18 @@ module API
...
@@ -75,15 +75,18 @@ module API
mutually_exclusive
:import_url
,
:template_name
,
:template_project_id
mutually_exclusive
:import_url
,
:template_name
,
:template_project_id
end
end
def
loa
d_projects
def
fin
d_projects
ProjectsFinder
.
new
(
current_user:
current_user
,
params:
project_finder_params
).
execute
ProjectsFinder
.
new
(
current_user:
current_user
,
params:
project_finder_params
).
execute
end
end
def
present_projects
(
projects
,
options
=
{})
# Prepare the full projects query
# None if this is supposed to actually execute any database query
def
prepare_query
(
projects
)
projects
=
reorder_projects
(
projects
)
projects
=
reorder_projects
(
projects
)
projects
=
apply_filters
(
projects
)
projects
=
apply_filters
(
projects
)
projects
=
paginate
(
projects
)
projects
=
paginate
(
projects
)
projects
,
options
=
with_custom_attributes
(
projects
,
options
)
projects
,
options
=
with_custom_attributes
(
projects
)
options
=
options
.
reverse_merge
(
options
=
options
.
reverse_merge
(
with:
current_user
?
Entities
::
ProjectWithAccess
:
Entities
::
BasicProjectDetails
,
with:
current_user
?
Entities
::
ProjectWithAccess
:
Entities
::
BasicProjectDetails
,
...
@@ -91,10 +94,17 @@ module API
...
@@ -91,10 +94,17 @@ module API
current_user:
current_user
,
current_user:
current_user
,
license:
false
license:
false
)
)
options
[
:with
]
=
Entities
::
BasicProjectDetails
if
params
[
:simple
]
options
[
:with
]
=
Entities
::
BasicProjectDetails
if
params
[
:simple
]
projects
=
options
[
:with
].
prepare_relation
(
projects
,
options
)
projects
=
options
[
:with
].
prepare_relation
(
projects
,
options
)
[
projects
,
options
]
end
def
prepare_and_present
(
project_relation
)
projects
,
options
=
prepare_query
(
project_relation
)
# Refresh count caches
# Refresh count caches
options
[
:with
].
execute_batch_counting
(
projects
)
options
[
:with
].
execute_batch_counting
(
projects
)
...
@@ -123,7 +133,7 @@ module API
...
@@ -123,7 +133,7 @@ module API
params
[
:user
]
=
user
params
[
:user
]
=
user
pre
sent_projects
loa
d_projects
pre
pare_and_present
fin
d_projects
end
end
desc
'Get projects starred by a user'
do
desc
'Get projects starred by a user'
do
...
@@ -139,7 +149,7 @@ module API
...
@@ -139,7 +149,7 @@ module API
not_found!
(
'User'
)
unless
user
not_found!
(
'User'
)
unless
user
starred_projects
=
StarredProjectsFinder
.
new
(
user
,
params:
project_finder_params
,
current_user:
current_user
).
execute
starred_projects
=
StarredProjectsFinder
.
new
(
user
,
params:
project_finder_params
,
current_user:
current_user
).
execute
pre
sent_projects
starred_projects
pre
pare_and_present
starred_projects
end
end
end
end
...
@@ -155,7 +165,7 @@ module API
...
@@ -155,7 +165,7 @@ module API
use
:with_custom_attributes
use
:with_custom_attributes
end
end
get
do
get
do
pre
sent_projects
loa
d_projects
pre
pare_and_present
fin
d_projects
end
end
desc
'Create new project'
do
desc
'Create new project'
do
...
@@ -292,7 +302,7 @@ module API
...
@@ -292,7 +302,7 @@ module API
get
':id/forks'
do
get
':id/forks'
do
forks
=
ForkProjectsFinder
.
new
(
user_project
,
params:
project_finder_params
,
current_user:
current_user
).
execute
forks
=
ForkProjectsFinder
.
new
(
user_project
,
params:
project_finder_params
,
current_user:
current_user
).
execute
pre
sent_projects
forks
pre
pare_and_present
forks
end
end
desc
'Check pages access of this project'
desc
'Check pages access of this project'
...
...
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