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
Kazuhiko Shiozaki
gitlab-ce
Commits
909c8c34
Commit
909c8c34
authored
Sep 06, 2012
by
miks
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make project users API more RESTful
parent
2dc05192
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
8 deletions
+111
-8
doc/api/projects.md
doc/api/projects.md
+47
-2
lib/api/entities.rb
lib/api/entities.rb
+5
-0
lib/api/projects.rb
lib/api/projects.rb
+36
-2
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+23
-4
No files found.
doc/api/projects.md
View file @
909c8c34
...
...
@@ -106,12 +106,26 @@ Parameters:
Will return created project with status
`201 Created`
on success, or
`404 Not
found`
on fail.
## Get project users
Get users and access roles for existing project
```
GET /projects/:id/users
```
Parameters:
+
`id`
(required) - The ID or code name of a project
Will return users and their access roles with status
`200 OK`
on success, or
`404 Not found`
on fail.
## Add project users
Add users to exiting project
```
P
UT /projects/:id/add_
users
P
OST /projects/:id/
users
```
Parameters:
...
...
@@ -120,7 +134,38 @@ Parameters:
+
`user_ids`
(required) - The ID list of users to add
+
`project_access`
(required) - Project access level
Will return updated project with status
`200 OK`
on success, or
`404 Not found`
on fail.
Will return status
`201 Created`
on success, or
`404 Not found`
on fail.
## Update project users access level
Update existing users to specified access level
```
PUT /projects/:id/users
```
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`user_ids`
(required) - The ID list of users to add
+
`project_access`
(required) - Project access level
Will return status
`200 OK`
on success, or
`404 Not found`
on fail.
## Delete project users
Delete users from exiting project
```
DELETE /projects/:id/users
```
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`user_ids`
(required) - The ID list of users to add
Will return status
`200 OK`
on success, or
`404 Not found`
on fail.
## Project repository branches
...
...
lib/api/entities.rb
View file @
909c8c34
...
...
@@ -16,6 +16,11 @@ module Gitlab
expose
:issues_enabled
,
:merge_requests_enabled
,
:wall_enabled
,
:wiki_enabled
,
:created_at
end
class
UsersProject
<
Grape
::
Entity
expose
:user
,
using:
Entities
::
UserBasic
expose
:project_access
end
class
RepoObject
<
Grape
::
Entity
expose
:name
,
:commit
end
...
...
lib/api/projects.rb
View file @
909c8c34
...
...
@@ -44,6 +44,17 @@ module Gitlab
end
end
# Get project users
#
# Parameters:
# id (required) - The ID or code name of a project
# Example Request:
# GET /projects/:id/users
get
":id/users"
do
@users_projects
=
paginate
user_project
.
users_projects
present
@users_projects
,
with:
Entities
::
UsersProject
end
# Add users to project with specified access level
#
# Parameters:
...
...
@@ -51,11 +62,34 @@ module Gitlab
# user_ids (required) - The ID list of users to add
# project_access (required) - Project access level
# Example Request:
# P
UT /projects/:id/add_
users
p
ut
":id/add_
users"
do
# P
OST /projects/:id/
users
p
ost
":id/
users"
do
user_project
.
add_users_ids_to_team
(
params
[
:user_ids
].
values
,
params
[
:project_access
])
end
# Update users to specified access level
#
# Parameters:
# id (required) - The ID or code name of a project
# user_ids (required) - The ID list of users to add
# project_access (required) - New project access level to
# Example Request:
# PUT /projects/:id/add_users
put
":id/users"
do
user_project
.
update_users_ids_to_role
(
params
[
:user_ids
].
values
,
params
[
:project_access
])
end
# Delete project users
#
# Parameters:
# id (required) - The ID or code name of a project
# user_ids (required) - The ID list of users to delete
# Example Request:
# DELETE /projects/:id/users
delete
":id/users"
do
user_project
.
delete_users_ids_from_team
(
params
[
:user_ids
].
values
)
end
# Get a project repository branches
#
# Parameters:
...
...
spec/requests/api/projects_spec.rb
View file @
909c8c34
...
...
@@ -8,6 +8,7 @@ describe Gitlab::API do
let
(
:user3
)
{
Factory
.
create
(
:user
)
}
let!
(
:project
)
{
Factory
:project
,
owner:
user
}
let!
(
:snippet
)
{
Factory
:snippet
,
author:
user
,
project:
project
,
title:
'example'
}
let!
(
:users_project
)
{
Factory
:users_project
,
user:
user
,
project:
project
}
before
{
project
.
add_access
(
user
,
:read
)
}
describe
"GET /projects"
do
...
...
@@ -64,12 +65,30 @@ describe Gitlab::API do
end
end
describe
"P
UT /projects/:id/add_
users"
do
it
"should add users to
existing
project"
do
describe
"P
OST /projects/:id/
users"
do
it
"should add users to project"
do
expect
{
p
ut
api
(
"/projects/
#{
project
.
code
}
/add_
users"
,
user
),
p
ost
api
(
"/projects/
#{
project
.
code
}
/
users"
,
user
),
user_ids:
{
"0"
=>
user2
.
id
,
"1"
=>
user3
.
id
},
project_access:
UsersProject
::
DEVELOPER
}.
to
change
{
Project
.
last
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
DEVELOPER
).
count
}.
by
(
2
)
}.
to
change
{
project
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
DEVELOPER
).
count
}.
by
(
2
)
end
end
describe
"PUT /projects/:id/users"
do
it
"should update users to new access role"
do
expect
{
put
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
),
user_ids:
{
"0"
=>
user
},
project_access:
UsersProject
::
DEVELOPER
}.
to
change
{
project
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
DEVELOPER
).
count
}.
by
(
1
)
end
end
describe
"DELETE /projects/:id/users"
do
it
"should delete users from project"
do
expect
{
delete
api
(
"/projects/
#{
project
.
code
}
/delete"
,
user
),
user_ids:
{
"0"
=>
users_project
.
id
}
}.
to
change
{
project
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
DEVELOPER
).
count
}.
by
(
-
1
)
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