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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
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
Hide 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:
...
@@ -112,66 +112,89 @@ Parameters:
Will return created project with status
`201 Created`
on success, or
`404 Not
Will return created project with status
`201 Created`
on success, or
`404 Not
found`
on fail.
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:
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`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:
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`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 user
to add
+
`
project_access
`
(required) - Project access level
+
`
access_level
`
(required) - Project access level
Will return status
`201 Created`
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
##
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:
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`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
+
`
project_access
`
(required) - Project access level
+
`
access_level
`
(required) - Project access level
Will return status
`200 OK`
on success, or
`404 Not found`
on fail.
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:
Parameters:
+
`id`
(required) - The ID or code name of a project
+
`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
## Get project hooks
...
@@ -344,7 +367,7 @@ Parameters:
...
@@ -344,7 +367,7 @@ Parameters:
+
`id`
(required) - The ID or code name of a project
+
`id`
(required) - The ID or code name of a project
+
`sha`
(required) - The commit or branch name
+
`sha`
(required) - The commit or branch name
+
`filepath`
(required) - The path the file
+
`filepath`
(required) - The path the file
Will return the raw file contents.
Will return the raw file contents.
lib/api/entities.rb
View file @
25b74527
...
@@ -24,9 +24,10 @@ module Gitlab
...
@@ -24,9 +24,10 @@ module Gitlab
expose
:issues_enabled
,
:merge_requests_enabled
,
:wall_enabled
,
:wiki_enabled
,
:created_at
expose
:issues_enabled
,
:merge_requests_enabled
,
:wall_enabled
,
:wiki_enabled
,
:created_at
end
end
class
UsersProject
<
Grape
::
Entity
class
ProjectMember
<
UserBasic
expose
:user
,
using:
Entities
::
UserBasic
expose
:project_access
,
:as
=>
:access_level
do
|
user
,
options
|
expose
:project_access
options
[
:project
].
users_projects
.
find_by_user_id
(
user
.
id
).
project_access
end
end
end
class
RepoObject
<
Grape
::
Entity
class
RepoObject
<
Grape
::
Entity
...
...
lib/api/projects.rb
View file @
25b74527
...
@@ -40,14 +40,14 @@ module Gitlab
...
@@ -40,14 +40,14 @@ module Gitlab
post
do
post
do
params
[
:code
]
||=
params
[
:name
]
params
[
:code
]
||=
params
[
:name
]
params
[
:path
]
||=
params
[
:name
]
params
[
:path
]
||=
params
[
:name
]
attrs
=
attributes_for_keys
[
:code
,
attrs
=
attributes_for_keys
[
:code
,
:path
,
:path
,
:name
,
:name
,
:description
,
:description
,
:default_branch
,
:default_branch
,
:issues_enabled
,
:issues_enabled
,
:wall_enabled
,
:wall_enabled
,
:merge_requests_enabled
,
:merge_requests_enabled
,
:wiki_enabled
]
:wiki_enabled
]
@project
=
Project
.
create_by_user
(
attrs
,
current_user
)
@project
=
Project
.
create_by_user
(
attrs
,
current_user
)
if
@project
.
saved?
if
@project
.
saved?
...
@@ -57,56 +57,83 @@ module Gitlab
...
@@ -57,56 +57,83 @@ module Gitlab
end
end
end
end
# Get
project us
ers
# Get
a project team memb
ers
#
#
# Parameters:
# Parameters:
# id (required) - The ID or code name of a project
# id (required) - The ID or code name of a project
# Example Request:
# Example Request:
# GET /projects/:id/
us
ers
# GET /projects/:id/
memb
ers
get
":id/
us
ers"
do
get
":id/
memb
ers"
do
@
users_projects
=
paginate
user_project
.
users_project
s
@
members
=
paginate
user_project
.
user
s
present
@
users_projects
,
with:
Entities
::
UsersP
roject
present
@
members
,
with:
Entities
::
ProjectMember
,
project:
user_p
roject
end
end
#
Add users to project with specified access level
#
Get a project team members
#
#
# Parameters:
# Parameters:
# id (required) - The ID or code name of a project
# id (required) - The ID or code name of a project
# user_ids (required) - The ID list of users to add
# user_id (required) - The ID of a user
# project_access (required) - Project access level
# Example Request:
# Example Request:
# POST /projects/:id/users
# GET /projects/:id/members/:user_id
post
":id/users"
do
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
authorize!
:admin_project
,
user_project
user_project
.
add_users_ids_to_team
(
params
[
:user_ids
].
values
,
params
[
:project_access
])
users_project
=
user_project
.
users_projects
.
new
(
nil
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
end
# Update
users to specified access level
# Update
project team member
#
#
# Parameters:
# Parameters:
# id (required) - The ID or code name of a project
# 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
#
project_access (required) - New project access level to
#
access_level (required) - Project access level
# Example Request:
# Example Request:
# PUT /projects/:id/
add_users
# PUT /projects/:id/
members/:user_id
put
":id/
users
"
do
put
":id/
members/:user_id
"
do
authorize!
:admin_project
,
user_project
authorize!
:admin_project
,
user_project
user_project
.
update_users_ids_to_role
(
params
[
:user_ids
].
values
,
params
[
:project_access
])
users_project
=
user_project
.
users_projects
.
find_by_user_id
params
[
:user_id
]
nil
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
end
#
Delete project users
#
Remove a team member from project
#
#
# Parameters:
# Parameters:
# id (required) - The ID or code name of a project
# 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:
# Example Request:
# DELETE /projects/:id/
users
# DELETE /projects/:id/
members/:user_id
delete
":id/
users
"
do
delete
":id/
members/:user_id
"
do
authorize!
:admin_project
,
user_project
authorize!
:admin_project
,
user_project
user
_project
.
delete_users_ids_from_team
(
params
[
:user_ids
].
values
)
user
s_project
=
user_project
.
users_projects
.
find_by_user_id
params
[
:user_id
]
nil
users_project
.
destroy
end
end
# Get project hooks
# Get project hooks
...
...
spec/requests/api/projects_spec.rb
View file @
25b74527
...
@@ -111,42 +111,52 @@ describe Gitlab::API do
...
@@ -111,42 +111,52 @@ describe Gitlab::API do
end
end
end
end
describe
"GET /projects/:id/users"
do
describe
"GET /projects/:id/members"
do
it
"should return project users"
do
it
"should return project team members"
do
get
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
)
get
api
(
"/projects/
#{
project
.
code
}
/members"
,
user
)
response
.
status
.
should
==
200
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
should
be_an
Array
json_response
.
count
.
should
==
2
json_response
.
count
.
should
==
2
json_response
.
first
[
'
user'
][
'id'
].
should
==
user
.
id
json_response
.
first
[
'
email'
].
should
==
user
.
email
end
end
end
end
describe
"
POST /projects/:id/users
"
do
describe
"
GET /projects/:id/members/:user_id
"
do
it
"should
add users to project
"
do
it
"should
return project team member
"
do
expect
{
get
api
(
"/projects/
#{
project
.
code
}
/members/
#{
user
.
id
}
"
,
user
)
post
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
),
response
.
status
.
should
==
200
user_ids:
{
"0"
=>
user2
.
id
},
project_access:
UsersProject
::
DEVELOPER
json_response
[
'email'
].
should
==
user
.
email
}.
to
change
{
project
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
DEVELOPER
).
count
}.
by
(
1
)
json_response
[
'access_level'
].
should
==
UsersProject
::
MASTER
end
end
end
end
describe
"P
UT /projects/:id/us
ers"
do
describe
"P
OST /projects/:id/memb
ers"
do
it
"should
update users to new access role
"
do
it
"should
add user to project team
"
do
expect
{
expect
{
put
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
),
post
api
(
"/projects/
#{
project
.
code
}
/members"
,
user
),
user_id:
user2
.
id
,
user_ids:
{
"0"
=>
user3
.
id
},
project_access:
UsersProject
::
MASTER
access_level:
UsersProject
::
DEVELOPER
}.
to
change
{
project
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
MASTER
).
count
}.
by
(
1
)
}.
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
end
end
describe
"DELETE /projects/:id/
users
"
do
describe
"DELETE /projects/:id/
members/:user_id
"
do
it
"should
delete users from project
"
do
it
"should
remove user from project team
"
do
expect
{
expect
{
delete
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
),
delete
api
(
"/projects/
#{
project
.
code
}
/members/
#{
user3
.
id
}
"
,
user
)
user_ids:
{
"0"
=>
user3
.
id
}
}.
to
change
{
UsersProject
.
count
}.
by
(
-
1
)
}.
to
change
{
project
.
users_projects
.
count
}.
by
(
-
1
)
end
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