diff options
author | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-02-08 10:32:42 +0100 |
---|---|---|
committer | Sebastian Ziebell <sebastian.ziebell@asquera.de> | 2013-02-08 10:32:42 +0100 |
commit | 8045a81bcf5822f1992442750e1484a93c368229 (patch) | |
tree | 94ce2b257f3ba002ac1a0fde70b69b622304810d /lib/api | |
parent | 5d8a99f10429168e6471fdd1843f5045a10a84b3 (diff) | |
parent | 2f0a75ab77af430f682d67aa9bb865007d832795 (diff) | |
download | gitlab-ce-8045a81bcf5822f1992442750e1484a93c368229.tar.gz |
Merge branch 'master' into fixes/api
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 17 | ||||
-rw-r--r-- | lib/api/groups.rb | 56 | ||||
-rw-r--r-- | lib/api/internal.rb | 49 | ||||
-rw-r--r-- | lib/api/notes.rb | 2 | ||||
-rw-r--r-- | lib/api/projects.rb | 40 | ||||
-rw-r--r-- | lib/api/users.rb | 47 |
6 files changed, 206 insertions, 5 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 80e2954a344..c1873d87b55 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -2,7 +2,7 @@ module Gitlab module Entities class User < Grape::Entity expose :id, :username, :email, :name, :bio, :skype, :linkedin, :twitter, - :dark_scheme, :theme_id, :blocked, :created_at + :dark_scheme, :theme_id, :blocked, :created_at, :extern_uid, :provider end class UserBasic < Grape::Entity @@ -21,6 +21,7 @@ module Gitlab expose :id, :name, :description, :default_branch expose :owner, using: Entities::UserBasic expose :private_flag, as: :private + expose :path, :path_with_namespace expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at expose :namespace end @@ -31,8 +32,22 @@ module Gitlab end end + class Group < Grape::Entity + expose :id, :name, :path, :owner_id + end + + class GroupDetail < Group + expose :projects, using: Entities::Project + end + + class RepoObject < Grape::Entity expose :name, :commit + expose :protected do |repo, options| + if options[:project] + options[:project].protected_branch? repo.name + end + end end class RepoCommit < Grape::Entity diff --git a/lib/api/groups.rb b/lib/api/groups.rb new file mode 100644 index 00000000000..a67caef0bc5 --- /dev/null +++ b/lib/api/groups.rb @@ -0,0 +1,56 @@ +module Gitlab + # groups API + class Groups < Grape::API + before { authenticate! } + + resource :groups do + # Get a groups list + # + # Example Request: + # GET /groups + get do + if current_user.admin + @groups = paginate Group + else + @groups = paginate current_user.groups + end + present @groups, with: Entities::Group + end + + # Create group. Available only for admin + # + # Parameters: + # name (required) - Name + # path (required) - Path + # Example Request: + # POST /groups + post do + authenticated_as_admin! + attrs = attributes_for_keys [:name, :path] + @group = Group.new(attrs) + @group.owner = current_user + + if @group.save + present @group, with: Entities::Group + else + not_found! + end + end + + # Get a single group, with containing projects + # + # Parameters: + # id (required) - The ID of a group + # Example Request: + # GET /groups/:id + get ":id" do + @group = Group.find(params[:id]) + if current_user.admin or current_user.groups.include? @group + present @group, with: Entities::GroupDetail + else + not_found! + end + end + end + end +end diff --git a/lib/api/internal.rb b/lib/api/internal.rb new file mode 100644 index 00000000000..3e5e3a478ba --- /dev/null +++ b/lib/api/internal.rb @@ -0,0 +1,49 @@ +module Gitlab + # Internal access API + class Internal < Grape::API + namespace 'internal' do + # + # Check if ssh key has access to project code + # + get "/allowed" do + key = Key.find(params[:key_id]) + project = Project.find_with_namespace(params[:project]) + git_cmd = params[:action] + + if key.is_deploy_key + project == key.project && git_cmd == 'git-upload-pack' + else + user = key.user + action = case git_cmd + when 'git-upload-pack' + then :download_code + when 'git-receive-pack' + then + if project.protected_branch?(params[:ref]) + :push_code_to_protected_branches + else + :push_code + end + end + + user.can?(action, project) + end + end + + # + # Discover user by ssh key + # + get "/discover" do + key = Key.find(params[:key_id]) + present key.user, with: Entities::User + end + + get "/check" do + { + api_version: '3' + } + end + end + end +end + diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 75ea238fe23..47dead9dfae 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -3,7 +3,7 @@ module Gitlab class Notes < Grape::API before { authenticate! } - NOTEABLE_TYPES = [Issue, Snippet] + NOTEABLE_TYPES = [Issue, MergeRequest, Snippet] resource :projects do # Get a list of project wall notes diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 5444ba6a205..47ab4e1aab0 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -222,7 +222,7 @@ module Gitlab # Example Request: # GET /projects/:id/repository/branches get ":id/repository/branches" do - present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject + present user_project.repo.heads.sort_by(&:name), with: Entities::RepoObject, project: user_project end # Get a single branch @@ -234,7 +234,43 @@ module Gitlab # GET /projects/:id/repository/branches/:branch get ":id/repository/branches/:branch" do @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } - present @branch, with: Entities::RepoObject + present @branch, with: Entities::RepoObject, project: user_project + end + + # Protect a single branch + # + # Parameters: + # id (required) - The ID of a project + # branch (required) - The name of the branch + # Example Request: + # PUT /projects/:id/repository/branches/:branch/protect + put ":id/repository/branches/:branch/protect" do + @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } + protected = user_project.protected_branches.find_by_name(@branch.name) + + unless protected + user_project.protected_branches.create(:name => @branch.name) + end + + present @branch, with: Entities::RepoObject, project: user_project + end + + # Unprotect a single branch + # + # Parameters: + # id (required) - The ID of a project + # branch (required) - The name of the branch + # Example Request: + # PUT /projects/:id/repository/branches/:branch/unprotect + put ":id/repository/branches/:branch/unprotect" do + @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } + protected = user_project.protected_branches.find_by_name(@branch.name) + + if protected + protected.destroy + end + + present @branch, with: Entities::RepoObject, project: user_project end # Get a project repository tags diff --git a/lib/api/users.rb b/lib/api/users.rb index 140c20f6bd2..7ea90c75e9e 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -34,11 +34,14 @@ module Gitlab # linkedin - Linkedin # twitter - Twitter account # projects_limit - Number of projects user can create + # extern_uid - External authentication provider UID + # provider - External provider + # bio - Bio # Example Request: # POST /users post do authenticated_as_admin! - attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username] + attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio] user = User.new attrs, as: :admin if user.save present user, with: Entities::User @@ -46,6 +49,48 @@ module Gitlab not_found! end end + + # Update user. Available only for admin + # + # Parameters: + # email - Email + # name - Name + # password - Password + # skype - Skype ID + # linkedin - Linkedin + # twitter - Twitter account + # projects_limit - Limit projects wich user can create + # extern_uid - External authentication provider UID + # provider - External provider + # bio - Bio + # Example Request: + # PUT /users/:id + put ":id" do + authenticated_as_admin! + attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio] + user = User.find_by_id(params[:id]) + + if user && user.update_attributes(attrs) + present user, with: Entities::User + else + not_found! + end + end + + # Delete user. Available only for admin + # + # Example Request: + # DELETE /users/:id + delete ":id" do + authenticated_as_admin! + user = User.find_by_id(params[:id]) + + if user + user.destroy + else + not_found! + end + end end resource :user do |