Commit 306ea84e85fe4821dd124163eef8ca5a7f041cbb
Exists in
master
and in
4 other branches
Merge pull request #3251 from AlexDenisov/api_additional_user_fields
Abilities added to /user and /sign_in requests
Showing
7 changed files
with
33 additions
and
6 deletions
Show diff stats
doc/api/session.md
| @@ -17,7 +17,17 @@ Parameters: | @@ -17,7 +17,17 @@ Parameters: | ||
| 17 | "email": "john@example.com", | 17 | "email": "john@example.com", |
| 18 | "name": "John Smith", | 18 | "name": "John Smith", |
| 19 | "private_token": "dd34asd13as", | 19 | "private_token": "dd34asd13as", |
| 20 | + "blocked": false, | ||
| 20 | "created_at": "2012-05-23T08:00:58Z", | 21 | "created_at": "2012-05-23T08:00:58Z", |
| 21 | - "blocked": true | 22 | + "bio": null, |
| 23 | + "skype": "", | ||
| 24 | + "linkedin": "", | ||
| 25 | + "twitter": "", | ||
| 26 | + "dark_scheme": false, | ||
| 27 | + "theme_id": 1 | ||
| 28 | + "is_admin": false, | ||
| 29 | + "can_create_group" : true, | ||
| 30 | + "can_create_team" : true, | ||
| 31 | + "can_create_project" : true | ||
| 22 | } | 32 | } |
| 23 | ``` | 33 | ``` |
doc/api/users.md
| @@ -154,6 +154,7 @@ GET /user | @@ -154,6 +154,7 @@ GET /user | ||
| 154 | "username": "john_smith", | 154 | "username": "john_smith", |
| 155 | "email": "john@example.com", | 155 | "email": "john@example.com", |
| 156 | "name": "John Smith", | 156 | "name": "John Smith", |
| 157 | + "private_token": "dd34asd13as", | ||
| 157 | "blocked": false, | 158 | "blocked": false, |
| 158 | "created_at": "2012-05-23T08:00:58Z", | 159 | "created_at": "2012-05-23T08:00:58Z", |
| 159 | "bio": null, | 160 | "bio": null, |
| @@ -162,6 +163,10 @@ GET /user | @@ -162,6 +163,10 @@ GET /user | ||
| 162 | "twitter": "", | 163 | "twitter": "", |
| 163 | "dark_scheme": false, | 164 | "dark_scheme": false, |
| 164 | "theme_id": 1 | 165 | "theme_id": 1 |
| 166 | + "is_admin": false, | ||
| 167 | + "can_create_group" : true, | ||
| 168 | + "can_create_team" : true, | ||
| 169 | + "can_create_project" : true | ||
| 165 | } | 170 | } |
| 166 | ``` | 171 | ``` |
| 167 | 172 |
lib/api/entities.rb
| @@ -13,8 +13,12 @@ module Gitlab | @@ -13,8 +13,12 @@ module Gitlab | ||
| 13 | expose :id, :username, :email, :name, :state, :created_at | 13 | expose :id, :username, :email, :name, :state, :created_at |
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | - class UserLogin < UserBasic | 16 | + class UserLogin < User |
| 17 | expose :private_token | 17 | expose :private_token |
| 18 | + expose :is_admin?, as: :is_admin | ||
| 19 | + expose :can_create_group?, as: :can_create_group | ||
| 20 | + expose :can_create_project?, as: :can_create_project | ||
| 21 | + expose :can_create_team?, as: :can_create_team | ||
| 18 | end | 22 | end |
| 19 | 23 | ||
| 20 | class Hook < Grape::Entity | 24 | class Hook < Grape::Entity |
| @@ -31,7 +35,7 @@ module Gitlab | @@ -31,7 +35,7 @@ module Gitlab | ||
| 31 | end | 35 | end |
| 32 | 36 | ||
| 33 | class ProjectMember < UserBasic | 37 | class ProjectMember < UserBasic |
| 34 | - expose :project_access, :as => :access_level do |user, options| | 38 | + expose :project_access, as: :access_level do |user, options| |
| 35 | options[:project].users_projects.find_by_user_id(user.id).project_access | 39 | options[:project].users_projects.find_by_user_id(user.id).project_access |
| 36 | end | 40 | end |
| 37 | end | 41 | end |
lib/api/projects.rb
| @@ -191,7 +191,7 @@ module Gitlab | @@ -191,7 +191,7 @@ module Gitlab | ||
| 191 | unless team_member.nil? | 191 | unless team_member.nil? |
| 192 | team_member.destroy | 192 | team_member.destroy |
| 193 | else | 193 | else |
| 194 | - {:message => "Access revoked", :id => params[:user_id].to_i} | 194 | + {message: "Access revoked", id: params[:user_id].to_i} |
| 195 | end | 195 | end |
| 196 | end | 196 | end |
| 197 | 197 | ||
| @@ -322,7 +322,7 @@ module Gitlab | @@ -322,7 +322,7 @@ module Gitlab | ||
| 322 | protected = user_project.protected_branches.find_by_name(@branch.name) | 322 | protected = user_project.protected_branches.find_by_name(@branch.name) |
| 323 | 323 | ||
| 324 | unless protected | 324 | unless protected |
| 325 | - user_project.protected_branches.create(:name => @branch.name) | 325 | + user_project.protected_branches.create(name: @branch.name) |
| 326 | end | 326 | end |
| 327 | 327 | ||
| 328 | present @branch, with: Entities::RepoObject, project: user_project | 328 | present @branch, with: Entities::RepoObject, project: user_project |
lib/api/users.rb
| @@ -124,7 +124,7 @@ module Gitlab | @@ -124,7 +124,7 @@ module Gitlab | ||
| 124 | # Example Request: | 124 | # Example Request: |
| 125 | # GET /user | 125 | # GET /user |
| 126 | get do | 126 | get do |
| 127 | - present @current_user, with: Entities::User | 127 | + present @current_user, with: Entities::UserLogin |
| 128 | end | 128 | end |
| 129 | 129 | ||
| 130 | # Get currently authenticated user's keys | 130 | # Get currently authenticated user's keys |
spec/requests/api/session_spec.rb
| @@ -13,6 +13,10 @@ describe Gitlab::API do | @@ -13,6 +13,10 @@ describe Gitlab::API do | ||
| 13 | 13 | ||
| 14 | json_response['email'].should == user.email | 14 | json_response['email'].should == user.email |
| 15 | json_response['private_token'].should == user.private_token | 15 | json_response['private_token'].should == user.private_token |
| 16 | + json_response['is_admin'].should == user.is_admin? | ||
| 17 | + json_response['can_create_team'].should == user.can_create_team? | ||
| 18 | + json_response['can_create_project'].should == user.can_create_project? | ||
| 19 | + json_response['can_create_group'].should == user.can_create_group? | ||
| 16 | end | 20 | end |
| 17 | end | 21 | end |
| 18 | 22 |
spec/requests/api/users_spec.rb
| @@ -214,6 +214,10 @@ describe Gitlab::API do | @@ -214,6 +214,10 @@ describe Gitlab::API do | ||
| 214 | get api("/user", user) | 214 | get api("/user", user) |
| 215 | response.status.should == 200 | 215 | response.status.should == 200 |
| 216 | json_response['email'].should == user.email | 216 | json_response['email'].should == user.email |
| 217 | + json_response['is_admin'].should == user.is_admin? | ||
| 218 | + json_response['can_create_team'].should == user.can_create_team? | ||
| 219 | + json_response['can_create_project'].should == user.can_create_project? | ||
| 220 | + json_response['can_create_group'].should == user.can_create_group? | ||
| 217 | end | 221 | end |
| 218 | 222 | ||
| 219 | it "should return 401 error if user is unauthenticated" do | 223 | it "should return 401 error if user is unauthenticated" do |