BigW Consortium Gitlab

Commit 909c8c34 by miks

Make project users API more RESTful

parent 2dc05192
......@@ -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
```
PUT /projects/:id/add_users
POST /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
......
......@@ -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
......
......@@ -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:
# PUT /projects/:id/add_users
put ":id/add_users" do
# POST /projects/:id/users
post ":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:
......
......@@ -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 "PUT /projects/:id/add_users" do
it "should add users to existing project" do
describe "POST /projects/:id/users" do
it "should add users to project" do
expect {
put api("/projects/#{project.code}/add_users", user),
post 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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment