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
Tatuya Kamada
gitlab-ce
Commits
ebd2a5d0
Commit
ebd2a5d0
authored
Sep 09, 2012
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1387 from miks/project_users_api
Project users api
parents
911c06c1
ba584c7d
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
187 additions
and
0 deletions
+187
-0
app/models/users_project.rb
app/models/users_project.rb
+17
-0
app/roles/team.rb
app/roles/team.rb
+13
-0
doc/api/projects.md
doc/api/projects.md
+60
-0
lib/api/entities.rb
lib/api/entities.rb
+5
-0
lib/api/projects.rb
lib/api/projects.rb
+49
-0
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+43
-0
No files found.
app/models/users_project.rb
View file @
ebd2a5d0
...
@@ -20,6 +20,23 @@ class UsersProject < ActiveRecord::Base
...
@@ -20,6 +20,23 @@ class UsersProject < ActiveRecord::Base
delegate
:name
,
:email
,
to: :user
,
prefix:
true
delegate
:name
,
:email
,
to: :user
,
prefix:
true
def
self
.
bulk_delete
(
project
,
user_ids
)
UsersProject
.
transaction
do
UsersProject
.
where
(
:user_id
=>
user_ids
,
:project_id
=>
project
.
id
).
each
do
|
users_project
|
users_project
.
delete
end
end
end
def
self
.
bulk_update
(
project
,
user_ids
,
project_access
)
UsersProject
.
transaction
do
UsersProject
.
where
(
:user_id
=>
user_ids
,
:project_id
=>
project
.
id
).
each
do
|
users_project
|
users_project
.
project_access
=
project_access
users_project
.
save
end
end
end
def
self
.
bulk_import
(
project
,
user_ids
,
project_access
)
def
self
.
bulk_import
(
project
,
user_ids
,
project_access
)
UsersProject
.
transaction
do
UsersProject
.
transaction
do
user_ids
.
each
do
|
user_id
|
user_ids
.
each
do
|
user_id
|
...
...
app/roles/team.rb
View file @
ebd2a5d0
...
@@ -36,4 +36,17 @@ module Team
...
@@ -36,4 +36,17 @@ module Team
UsersProject
.
bulk_import
(
self
,
users_ids
,
access_role
)
UsersProject
.
bulk_import
(
self
,
users_ids
,
access_role
)
self
.
update_repository
self
.
update_repository
end
end
# Update multiple project users
# to same access role by user ids
def
update_users_ids_to_role
(
users_ids
,
access_role
)
UsersProject
.
bulk_update
(
self
,
users_ids
,
access_role
)
self
.
update_repository
end
# Delete multiple users from project by user ids
def
delete_users_ids_from_team
(
users_ids
)
UsersProject
.
bulk_delete
(
self
,
users_ids
)
self
.
update_repository
end
end
end
doc/api/projects.md
View file @
ebd2a5d0
...
@@ -112,6 +112,66 @@ Parameters:
...
@@ -112,6 +112,66 @@ 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 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
```
POST /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 `
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
## Project repository branches
...
...
lib/api/entities.rb
View file @
ebd2a5d0
...
@@ -16,6 +16,11 @@ module Gitlab
...
@@ -16,6 +16,11 @@ 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
expose
:user
,
using:
Entities
::
UserBasic
expose
:project_access
end
class
RepoObject
<
Grape
::
Entity
class
RepoObject
<
Grape
::
Entity
expose
:name
,
:commit
expose
:name
,
:commit
end
end
...
...
lib/api/projects.rb
View file @
ebd2a5d0
...
@@ -54,6 +54,55 @@ module Gitlab
...
@@ -54,6 +54,55 @@ module Gitlab
end
end
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:
# 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
# Example Request:
# POST /projects/:id/users
post
":id/users"
do
user_project
.
add_users_ids_to_team
(
params
[
:user_ids
].
values
,
params
[
:project_access
])
nil
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
])
nil
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
)
nil
end
# Get a project repository branches
# Get a project repository branches
#
#
# Parameters:
# Parameters:
...
...
spec/requests/api/projects_spec.rb
View file @
ebd2a5d0
...
@@ -4,8 +4,12 @@ describe Gitlab::API do
...
@@ -4,8 +4,12 @@ describe Gitlab::API do
include
ApiHelpers
include
ApiHelpers
let
(
:user
)
{
Factory
:user
}
let
(
:user
)
{
Factory
:user
}
let
(
:user2
)
{
Factory
.
create
(
:user
)
}
let
(
:user3
)
{
Factory
.
create
(
:user
)
}
let!
(
:project
)
{
Factory
:project
,
owner:
user
}
let!
(
:project
)
{
Factory
:project
,
owner:
user
}
let!
(
:snippet
)
{
Factory
:snippet
,
author:
user
,
project:
project
,
title:
'example'
}
let!
(
:snippet
)
{
Factory
:snippet
,
author:
user
,
project:
project
,
title:
'example'
}
let!
(
:users_project
)
{
Factory
:users_project
,
user:
user
,
project:
project
,
project_access:
UsersProject
::
MASTER
}
let!
(
:users_project2
)
{
Factory
:users_project
,
user:
user3
,
project:
project
,
project_access:
UsersProject
::
DEVELOPER
}
before
{
project
.
add_access
(
user
,
:read
)
}
before
{
project
.
add_access
(
user
,
:read
)
}
describe
"GET /projects"
do
describe
"GET /projects"
do
...
@@ -104,6 +108,45 @@ describe Gitlab::API do
...
@@ -104,6 +108,45 @@ describe Gitlab::API do
end
end
end
end
describe
"GET /projects/:id/users"
do
it
"should return project users"
do
get
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
count
.
should
==
2
json_response
.
first
[
'user'
][
'id'
].
should
==
user
.
id
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
)
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"
=>
user3
.
id
},
project_access:
UsersProject
::
MASTER
}.
to
change
{
project
.
users_projects
.
where
(
:project_access
=>
UsersProject
::
MASTER
).
count
}.
by
(
1
)
end
end
describe
"DELETE /projects/:id/users"
do
it
"should delete users from project"
do
expect
{
delete
api
(
"/projects/
#{
project
.
code
}
/users"
,
user
),
user_ids:
{
"0"
=>
user3
.
id
}
}.
to
change
{
project
.
users_projects
.
count
}.
by
(
-
1
)
end
end
describe
"GET /projects/:id/repository/tags"
do
describe
"GET /projects/:id/repository/tags"
do
it
"should return an array of project tags"
do
it
"should return an array of project tags"
do
get
api
(
"/projects/
#{
project
.
code
}
/repository/tags"
,
user
)
get
api
(
"/projects/
#{
project
.
code
}
/repository/tags"
,
user
)
...
...
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