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
Boxiang Sun
gitlab-ce
Commits
25b74527
Commit
25b74527
authored
Sep 21, 2012
by
Nihad Abbasov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add API for project team members
parent
49fe8fed
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
139 additions
and
78 deletions
+139
-78
doc/api/projects.md
doc/api/projects.md
+43
-20
lib/api/entities.rb
lib/api/entities.rb
+4
-3
lib/api/projects.rb
lib/api/projects.rb
+60
-33
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+32
-22
No files found.
doc/api/projects.md
View file @
25b74527
...
...
@@ -112,66 +112,89 @@ Parameters:
Will return created project with status
`201 Created`
on success, or
`404 Not
found`
on fail.
##
Get project us
ers
##
List project team memb
ers
Get
users and access roles for existing project
Get
a list of project team members.
```
GET /projects/:id/
us
ers
GET /projects/:id/
memb
ers
```
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.
## Get project team member
## Add project users
Get a project team member.
Add users to exiting project
```
GET /projects/:id/members/:user_id
```
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`user_id`
(required) - The ID of a user
```
json
{
"id"
:
1
,
"email"
:
"john@example.com"
,
"name"
:
"John Smith"
,
"blocked"
:
false
,
"created_at"
:
"2012-05-23T08:00:58Z"
,
"access_level"
:
40
}
```
POST /projects/:id/users
## Add project team member
Add a user to a project team.
```
POST /projects/:id/members
```
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`user_id
s`
(required) - The ID list of users
to add
+
`
project_access
`
(required) - Project access level
+
`user_id
`
(required) - The ID of a user
to add
+
`
access_level
`
(required) - Project access level
Will return status
`201 Created`
on success, or
`404 Not found`
on fail.
##
Update project users access level
##
Edit project team member
Update
existing users to specified access level
Update
project team member to specified access level.
```
PUT /projects/:id/
users
PUT /projects/:id/
members/:user_id
```
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`user_id
s`
(required) - The ID list of users to add
+
`
project_access
`
(required) - Project access level
+
`user_id
`
(required) - The ID of a team member
+
`
access_level
`
(required) - Project access level
Will return status
`200 OK`
on success, or
`404 Not found`
on fail.
##
Delete project users
##
Remove project team member
Delete users from exiting project
Removes user from project team.
```
DELETE /projects/:id/
users
DELETE /projects/:id/
members/:user_id
```
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`user_id
s`
(required) - The ID list of users to add
+
`user_id
`
(required) - The ID of a team member
Will return status
`200 OK`
on success, or
`404 Not found`
on fail
.
Status code
`200`
will be returned on success
.
## Get project hooks
...
...
lib/api/entities.rb
View file @
25b74527
...
...
@@ -24,9 +24,10 @@ 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
class
ProjectMember
<
UserBasic
expose
:project_access
,
:as
=>
:access_level
do
|
user
,
options
|
options
[
:project
].
users_projects
.
find_by_user_id
(
user
.
id
).
project_access
end
end
class
RepoObject
<
Grape
::
Entity
...
...
lib/api/projects.rb
View file @
25b74527
...
...
@@ -57,56 +57,83 @@ module Gitlab
end
end
# Get
project us
ers
# Get
a project team memb
ers
#
# Parameters:
# id (required) - The ID or code name of a project
# Example Request:
# GET /projects/:id/
us
ers
get
":id/
us
ers"
do
@
users_projects
=
paginate
user_project
.
users_project
s
present
@
users_projects
,
with:
Entities
::
UsersP
roject
# GET /projects/:id/
memb
ers
get
":id/
memb
ers"
do
@
members
=
paginate
user_project
.
user
s
present
@
members
,
with:
Entities
::
ProjectMember
,
project:
user_p
roject
end
#
Add users to project with specified access level
#
Get a project team members
#
# 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
# user_id (required) - The ID of a user
# Example Request:
# POST /projects/:id/users
post
":id/users"
do
# GET /projects/:id/members/:user_id
get
":id/members/:user_id"
do
@member
=
user_project
.
users
.
find
params
[
:user_id
]
present
@member
,
with:
Entities
::
ProjectMember
,
project:
user_project
end
# Add a new project team member
#
# Parameters:
# id (required) - The ID or code name of a project
# user_id (required) - The ID of a user
# access_level (required) - Project access level
# Example Request:
# POST /projects/:id/members
post
":id/members"
do
authorize!
:admin_project
,
user_project
user_project
.
add_users_ids_to_team
(
params
[
:user_ids
].
values
,
params
[
:project_access
])
nil
users_project
=
user_project
.
users_projects
.
new
(
user_id:
params
[
:user_id
],
project_access:
params
[
:access_level
]
)
if
users_project
.
save
@member
=
users_project
.
user
present
@member
,
with:
Entities
::
ProjectMember
,
project:
user_project
else
not_found!
end
end
# Update
users to specified access level
# Update
project team member
#
# Parameters:
# id (required) - The ID or code name of a project
# user_id
s (required) - The ID list of users to add
#
project_access (required) - New project access level to
# user_id
(required) - The ID of a team member
#
access_level (required) - Project access level
# Example Request:
# PUT /projects/:id/
add_users
put
":id/
users
"
do
# PUT /projects/:id/
members/:user_id
put
":id/
members/:user_id
"
do
authorize!
:admin_project
,
user_project
user_project
.
update_users_ids_to_role
(
params
[
:user_ids
].
values
,
params
[
:project_access
])
nil
users_project
=
user_project
.
users_projects
.
find_by_user_id
params
[
:user_id
]
if
users_project
.
update_attributes
(
project_access:
params
[
:access_level
])
@member
=
users_project
.
user
present
@member
,
with:
Entities
::
ProjectMember
,
project:
user_project
else
not_found!
end
end
#
Delete project users
#
Remove a team member from project
#
# Parameters:
# id (required) - The ID or code name of a project
# user_id
s (required) - The ID list of users to delete
# user_id
(required) - The ID of a team member
# Example Request:
# DELETE /projects/:id/
users
delete
":id/
users
"
do
# DELETE /projects/:id/
members/:user_id
delete
":id/
members/:user_id
"
do
authorize!
:admin_project
,
user_project
user
_project
.
delete_users_ids_from_team
(
params
[
:user_ids
].
values
)
nil
user
s_project
=
user_project
.
users_projects
.
find_by_user_id
params
[
:user_id
]
users_project
.
destroy
end
# Get project hooks
...
...
spec/requests/api/projects_spec.rb
View file @
25b74527
...
...
@@ -111,42 +111,52 @@ describe Gitlab::API do
end
end
describe
"GET /projects/:id/users"
do
it
"should return project users"
do
get
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
)
describe
"GET /projects/:id/members"
do
it
"should return project team members"
do
get
api
(
"/projects/
#{
project
.
code
}
/members"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
count
.
should
==
2
json_response
.
first
[
'
user'
][
'id'
].
should
==
user
.
id
json_response
.
first
[
'
email'
].
should
==
user
.
email
end
end
describe
"
POST /projects/:id/users
"
do
it
"should
add users to project
"
do
expect
{
post
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
),
user_ids:
{
"0"
=>
user2
.
id
},
project_access:
UsersProject
::
DEVELOPER
}.
to
change
{
project
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
DEVELOPER
).
count
}.
by
(
1
)
describe
"
GET /projects/:id/members/:user_id
"
do
it
"should
return project team member
"
do
get
api
(
"/projects/
#{
project
.
code
}
/members/
#{
user
.
id
}
"
,
user
)
response
.
status
.
should
==
200
json_response
[
'email'
].
should
==
user
.
email
json_response
[
'access_level'
].
should
==
UsersProject
::
MASTER
end
end
describe
"P
UT /projects/:id/us
ers"
do
it
"should
update users to new access role
"
do
describe
"P
OST /projects/:id/memb
ers"
do
it
"should
add user to project team
"
do
expect
{
put
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
),
user_ids:
{
"0"
=>
user3
.
id
},
project_access:
UsersProject
::
MASTER
}.
to
change
{
project
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
MASTER
).
count
}.
by
(
1
)
post
api
(
"/projects/
#{
project
.
code
}
/members"
,
user
),
user_id:
user2
.
id
,
access_level:
UsersProject
::
DEVELOPER
}.
to
change
{
UsersProject
.
count
}.
by
(
1
)
response
.
status
.
should
==
201
json_response
[
'email'
].
should
==
user2
.
email
json_response
[
'access_level'
].
should
==
UsersProject
::
DEVELOPER
end
end
describe
"PUT /projects/:id/members/:user_id"
do
it
"should update project team member"
do
put
api
(
"/projects/
#{
project
.
code
}
/members/
#{
user3
.
id
}
"
,
user
),
access_level:
UsersProject
::
MASTER
response
.
status
.
should
==
200
json_response
[
'email'
].
should
==
user3
.
email
json_response
[
'access_level'
].
should
==
UsersProject
::
MASTER
end
end
describe
"DELETE /projects/:id/
users
"
do
it
"should
delete users from project
"
do
describe
"DELETE /projects/:id/
members/:user_id
"
do
it
"should
remove user from project team
"
do
expect
{
delete
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
),
user_ids:
{
"0"
=>
user3
.
id
}
}.
to
change
{
project
.
users_projects
.
count
}.
by
(
-
1
)
delete
api
(
"/projects/
#{
project
.
code
}
/members/
#{
user3
.
id
}
"
,
user
)
}.
to
change
{
UsersProject
.
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