Merge pull request #3251 from AlexDenisov/api_additional_user_fields
Abilities added to /user and /sign_in requests
This commit is contained in:
commit
306ea84e85
7 changed files with 33 additions and 6 deletions
|
@ -17,7 +17,17 @@ Parameters:
|
||||||
"email": "john@example.com",
|
"email": "john@example.com",
|
||||||
"name": "John Smith",
|
"name": "John Smith",
|
||||||
"private_token": "dd34asd13as",
|
"private_token": "dd34asd13as",
|
||||||
|
"blocked": false,
|
||||||
"created_at": "2012-05-23T08:00:58Z",
|
"created_at": "2012-05-23T08:00:58Z",
|
||||||
"blocked": true
|
"bio": null,
|
||||||
|
"skype": "",
|
||||||
|
"linkedin": "",
|
||||||
|
"twitter": "",
|
||||||
|
"dark_scheme": false,
|
||||||
|
"theme_id": 1
|
||||||
|
"is_admin": false,
|
||||||
|
"can_create_group" : true,
|
||||||
|
"can_create_team" : true,
|
||||||
|
"can_create_project" : true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
|
@ -154,6 +154,7 @@ GET /user
|
||||||
"username": "john_smith",
|
"username": "john_smith",
|
||||||
"email": "john@example.com",
|
"email": "john@example.com",
|
||||||
"name": "John Smith",
|
"name": "John Smith",
|
||||||
|
"private_token": "dd34asd13as",
|
||||||
"blocked": false,
|
"blocked": false,
|
||||||
"created_at": "2012-05-23T08:00:58Z",
|
"created_at": "2012-05-23T08:00:58Z",
|
||||||
"bio": null,
|
"bio": null,
|
||||||
|
@ -162,6 +163,10 @@ GET /user
|
||||||
"twitter": "",
|
"twitter": "",
|
||||||
"dark_scheme": false,
|
"dark_scheme": false,
|
||||||
"theme_id": 1
|
"theme_id": 1
|
||||||
|
"is_admin": false,
|
||||||
|
"can_create_group" : true,
|
||||||
|
"can_create_team" : true,
|
||||||
|
"can_create_project" : true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,12 @@ module Gitlab
|
||||||
expose :id, :username, :email, :name, :state, :created_at
|
expose :id, :username, :email, :name, :state, :created_at
|
||||||
end
|
end
|
||||||
|
|
||||||
class UserLogin < UserBasic
|
class UserLogin < User
|
||||||
expose :private_token
|
expose :private_token
|
||||||
|
expose :is_admin?, as: :is_admin
|
||||||
|
expose :can_create_group?, as: :can_create_group
|
||||||
|
expose :can_create_project?, as: :can_create_project
|
||||||
|
expose :can_create_team?, as: :can_create_team
|
||||||
end
|
end
|
||||||
|
|
||||||
class Hook < Grape::Entity
|
class Hook < Grape::Entity
|
||||||
|
@ -31,7 +35,7 @@ module Gitlab
|
||||||
end
|
end
|
||||||
|
|
||||||
class ProjectMember < UserBasic
|
class ProjectMember < UserBasic
|
||||||
expose :project_access, :as => :access_level do |user, options|
|
expose :project_access, as: :access_level do |user, options|
|
||||||
options[:project].users_projects.find_by_user_id(user.id).project_access
|
options[:project].users_projects.find_by_user_id(user.id).project_access
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -191,7 +191,7 @@ module Gitlab
|
||||||
unless team_member.nil?
|
unless team_member.nil?
|
||||||
team_member.destroy
|
team_member.destroy
|
||||||
else
|
else
|
||||||
{:message => "Access revoked", :id => params[:user_id].to_i}
|
{message: "Access revoked", id: params[:user_id].to_i}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -322,7 +322,7 @@ module Gitlab
|
||||||
protected = user_project.protected_branches.find_by_name(@branch.name)
|
protected = user_project.protected_branches.find_by_name(@branch.name)
|
||||||
|
|
||||||
unless protected
|
unless protected
|
||||||
user_project.protected_branches.create(:name => @branch.name)
|
user_project.protected_branches.create(name: @branch.name)
|
||||||
end
|
end
|
||||||
|
|
||||||
present @branch, with: Entities::RepoObject, project: user_project
|
present @branch, with: Entities::RepoObject, project: user_project
|
||||||
|
|
|
@ -124,7 +124,7 @@ module Gitlab
|
||||||
# Example Request:
|
# Example Request:
|
||||||
# GET /user
|
# GET /user
|
||||||
get do
|
get do
|
||||||
present @current_user, with: Entities::User
|
present @current_user, with: Entities::UserLogin
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get currently authenticated user's keys
|
# Get currently authenticated user's keys
|
||||||
|
|
|
@ -13,6 +13,10 @@ describe Gitlab::API do
|
||||||
|
|
||||||
json_response['email'].should == user.email
|
json_response['email'].should == user.email
|
||||||
json_response['private_token'].should == user.private_token
|
json_response['private_token'].should == user.private_token
|
||||||
|
json_response['is_admin'].should == user.is_admin?
|
||||||
|
json_response['can_create_team'].should == user.can_create_team?
|
||||||
|
json_response['can_create_project'].should == user.can_create_project?
|
||||||
|
json_response['can_create_group'].should == user.can_create_group?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -214,6 +214,10 @@ describe Gitlab::API do
|
||||||
get api("/user", user)
|
get api("/user", user)
|
||||||
response.status.should == 200
|
response.status.should == 200
|
||||||
json_response['email'].should == user.email
|
json_response['email'].should == user.email
|
||||||
|
json_response['is_admin'].should == user.is_admin?
|
||||||
|
json_response['can_create_team'].should == user.can_create_team?
|
||||||
|
json_response['can_create_project'].should == user.can_create_project?
|
||||||
|
json_response['can_create_group'].should == user.can_create_group?
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should return 401 error if user is unauthenticated" do
|
it "should return 401 error if user is unauthenticated" do
|
||||||
|
|
Loading…
Reference in a new issue