From 28e7d1a8bf3ef172331125cf56d92af85ea5e8b2 Mon Sep 17 00:00:00 2001 From: Alex Denisov <1101.debian@gmail.com> Date: Mon, 18 Mar 2013 20:11:28 +0000 Subject: [PATCH] Abilities added to /user and /sign_in requests --- lib/api/entities.rb | 6 +++++- lib/api/projects.rb | 4 ++-- lib/api/users.rb | 2 +- spec/requests/api/session_spec.rb | 4 ++++ spec/requests/api/users_spec.rb | 4 ++++ 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 5479765a..92191e4b 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -15,6 +15,10 @@ module Gitlab class UserLogin < UserBasic 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 class Hook < Grape::Entity @@ -31,7 +35,7 @@ module Gitlab end 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 end end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index e82cfeca..d4f50fda 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -191,7 +191,7 @@ module Gitlab unless team_member.nil? team_member.destroy else - {:message => "Access revoked", :id => params[:user_id].to_i} + {message: "Access revoked", id: params[:user_id].to_i} end end @@ -322,7 +322,7 @@ module Gitlab protected = user_project.protected_branches.find_by_name(@branch.name) unless protected - user_project.protected_branches.create(:name => @branch.name) + user_project.protected_branches.create(name: @branch.name) end present @branch, with: Entities::RepoObject, project: user_project diff --git a/lib/api/users.rb b/lib/api/users.rb index e9cf16fa..567750df 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -124,7 +124,7 @@ module Gitlab # Example Request: # GET /user get do - present @current_user, with: Entities::User + present @current_user, with: Entities::UserLogin end # Get currently authenticated user's keys diff --git a/spec/requests/api/session_spec.rb b/spec/requests/api/session_spec.rb index 2cdb0d7e..4a37312b 100644 --- a/spec/requests/api/session_spec.rb +++ b/spec/requests/api/session_spec.rb @@ -13,6 +13,10 @@ describe Gitlab::API do json_response['email'].should == user.email 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 diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb index 749769d4..b4688dd2 100644 --- a/spec/requests/api/users_spec.rb +++ b/spec/requests/api/users_spec.rb @@ -214,6 +214,10 @@ describe Gitlab::API do get api("/user", user) response.status.should == 200 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 it "should return 401 error if user is unauthenticated" do