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
d5c49779
Commit
d5c49779
authored
Nov 29, 2016
by
Markus Koller
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Consistently use current_user in API entities
parent
d05dd81b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
21 deletions
+21
-21
lib/api/entities.rb
lib/api/entities.rb
+8
-8
lib/api/groups.rb
lib/api/groups.rb
+7
-7
lib/api/projects.rb
lib/api/projects.rb
+6
-6
No files found.
lib/api/entities.rb
View file @
d5c49779
...
...
@@ -78,11 +78,11 @@ module API
expose
:container_registry_enabled
# Expose old field names with the new permissions methods to keep API compatible
expose
(
:issues_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:issues
,
options
[
:user
])
}
expose
(
:merge_requests_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:merge_requests
,
options
[
:user
])
}
expose
(
:wiki_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:wiki
,
options
[
:user
])
}
expose
(
:builds_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:builds
,
options
[
:user
])
}
expose
(
:snippets_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:snippets
,
options
[
:user
])
}
expose
(
:issues_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:issues
,
options
[
:
current_
user
])
}
expose
(
:merge_requests_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:merge_requests
,
options
[
:
current_
user
])
}
expose
(
:wiki_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:wiki
,
options
[
:
current_
user
])
}
expose
(
:builds_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:builds
,
options
[
:
current_
user
])
}
expose
(
:snippets_enabled
)
{
|
project
,
options
|
project
.
feature_available?
(
:snippets
,
options
[
:
current_
user
])
}
expose
:created_at
,
:last_activity_at
expose
:shared_runners_enabled
...
...
@@ -92,7 +92,7 @@ module API
expose
:forked_from_project
,
using:
Entities
::
BasicProjectDetails
,
if:
lambda
{
|
project
,
options
|
project
.
forked?
}
expose
:avatar_url
expose
:star_count
,
:forks_count
expose
:open_issues_count
,
if:
lambda
{
|
project
,
options
|
project
.
feature_available?
(
:issues
,
options
[
:user
])
&&
project
.
default_issues_tracker?
}
expose
:open_issues_count
,
if:
lambda
{
|
project
,
options
|
project
.
feature_available?
(
:issues
,
options
[
:
current_
user
])
&&
project
.
default_issues_tracker?
}
expose
:runners_token
,
if:
lambda
{
|
_project
,
options
|
options
[
:user_can_admin_project
]
}
expose
:public_builds
expose
:shared_with_groups
do
|
project
,
options
|
...
...
@@ -440,12 +440,12 @@ module API
class
ProjectWithAccess
<
Project
expose
:permissions
do
expose
:project_access
,
using:
Entities
::
ProjectAccess
do
|
project
,
options
|
project
.
project_members
.
find_by
(
user_id:
options
[
:user
].
id
)
project
.
project_members
.
find_by
(
user_id:
options
[
:
current_
user
].
id
)
end
expose
:group_access
,
using:
Entities
::
GroupAccess
do
|
project
,
options
|
if
project
.
group
project
.
group
.
group_members
.
find_by
(
user_id:
options
[
:user
].
id
)
project
.
group
.
group_members
.
find_by
(
user_id:
options
[
:
current_
user
].
id
)
end
end
end
...
...
lib/api/groups.rb
View file @
d5c49779
...
...
@@ -38,7 +38,7 @@ module API
groups
=
groups
.
where
.
not
(
id:
params
[
:skip_groups
])
if
params
[
:skip_groups
].
present?
groups
=
groups
.
reorder
(
params
[
:order_by
]
=>
params
[
:sort
])
present
paginate
(
groups
),
with:
Entities
::
Group
present
paginate
(
groups
),
with:
Entities
::
Group
,
current_user:
current_user
end
desc
'Get list of owned groups for authenticated user'
do
...
...
@@ -49,7 +49,7 @@ module API
end
get
'/owned'
do
groups
=
current_user
.
owned_groups
present
paginate
(
groups
),
with:
Entities
::
Group
,
user:
current_user
present
paginate
(
groups
),
with:
Entities
::
Group
,
current_
user:
current_user
end
desc
'Create a group. Available only for users who can create groups.'
do
...
...
@@ -66,7 +66,7 @@ module API
group
=
::
Groups
::
CreateService
.
new
(
current_user
,
declared_params
(
include_missing:
false
)).
execute
if
group
.
persisted?
present
group
,
with:
Entities
::
Group
present
group
,
with:
Entities
::
Group
,
current_user:
current_user
else
render_api_error!
(
"Failed to save group
#{
group
.
errors
.
messages
}
"
,
400
)
end
...
...
@@ -92,7 +92,7 @@ module API
authorize!
:admin_group
,
group
if
::
Groups
::
UpdateService
.
new
(
group
,
current_user
,
declared_params
(
include_missing:
false
)).
execute
present
group
,
with:
Entities
::
GroupDetail
present
group
,
with:
Entities
::
GroupDetail
,
current_user:
current_user
else
render_validation_error!
(
group
)
end
...
...
@@ -103,7 +103,7 @@ module API
end
get
":id"
do
group
=
find_group!
(
params
[
:id
])
present
group
,
with:
Entities
::
GroupDetail
present
group
,
with:
Entities
::
GroupDetail
,
current_user:
current_user
end
desc
'Remove a group.'
...
...
@@ -134,7 +134,7 @@ module API
projects
=
GroupProjectsFinder
.
new
(
group
).
execute
(
current_user
)
projects
=
filter_projects
(
projects
)
entity
=
params
[
:simple
]
?
Entities
::
BasicProjectDetails
:
Entities
::
Project
present
paginate
(
projects
),
with:
entity
,
user:
current_user
present
paginate
(
projects
),
with:
entity
,
current_
user:
current_user
end
desc
'Transfer a project to the group namespace. Available only for admin.'
do
...
...
@@ -150,7 +150,7 @@ module API
result
=
::
Projects
::
TransferService
.
new
(
project
,
current_user
).
execute
(
group
)
if
result
present
group
,
with:
Entities
::
GroupDetail
present
group
,
with:
Entities
::
GroupDetail
,
current_user:
current_user
else
render_api_error!
(
"Failed to transfer project
#{
project
.
errors
.
messages
}
"
,
400
)
end
...
...
lib/api/projects.rb
View file @
d5c49779
...
...
@@ -75,7 +75,7 @@ module API
projects
=
filter_projects
(
projects
)
entity
=
params
[
:simple
]
||
!
current_user
?
Entities
::
BasicProjectDetails
:
Entities
::
ProjectWithAccess
present
paginate
(
projects
),
with:
entity
,
user:
current_user
present
paginate
(
projects
),
with:
entity
,
current_
user:
current_user
end
desc
'Get a projects list for authenticated user'
do
...
...
@@ -94,7 +94,7 @@ module API
projects
=
filter_projects
(
projects
)
entity
=
params
[
:simple
]
?
Entities
::
BasicProjectDetails
:
Entities
::
ProjectWithAccess
present
paginate
(
projects
),
with:
entity
,
user:
current_user
present
paginate
(
projects
),
with:
entity
,
current_
user:
current_user
end
desc
'Get an owned projects list for authenticated user'
do
...
...
@@ -110,7 +110,7 @@ module API
projects
=
current_user
.
owned_projects
projects
=
filter_projects
(
projects
)
present
paginate
(
projects
),
with:
Entities
::
ProjectWithAccess
,
user:
current_user
present
paginate
(
projects
),
with:
Entities
::
ProjectWithAccess
,
current_
user:
current_user
end
desc
'Gets starred project for the authenticated user'
do
...
...
@@ -126,7 +126,7 @@ module API
projects
=
current_user
.
viewable_starred_projects
projects
=
filter_projects
(
projects
)
present
paginate
(
projects
),
with:
Entities
::
Project
,
user:
current_user
present
paginate
(
projects
),
with:
Entities
::
Project
,
current_
user:
current_user
end
desc
'Get all projects for admin user'
do
...
...
@@ -142,7 +142,7 @@ module API
projects
=
Project
.
all
projects
=
filter_projects
(
projects
)
present
paginate
(
projects
),
with:
Entities
::
ProjectWithAccess
,
user:
current_user
present
paginate
(
projects
),
with:
Entities
::
ProjectWithAccess
,
current_
user:
current_user
end
desc
'Search for projects the current user has access to'
do
...
...
@@ -221,7 +221,7 @@ module API
end
get
":id"
do
entity
=
current_user
?
Entities
::
ProjectWithAccess
:
Entities
::
BasicProjectDetails
present
user_project
,
with:
entity
,
user:
current_user
,
present
user_project
,
with:
entity
,
current_
user:
current_user
,
user_can_admin_project:
can?
(
current_user
,
:admin_project
,
user_project
)
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