summaryrefslogtreecommitdiff
path: root/lib/api/projects.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-03 19:49:04 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2013-06-03 19:49:04 +0300
commit50e8d6c0c03b11cc539cca37aea782538ee77262 (patch)
treed2eb9faf5cefff2bf3bf1a2951afd2c28fa0a104 /lib/api/projects.rb
parent0447c731ba392641145ac53cb8c50fab5392cda7 (diff)
downloadgitlab-ce-50e8d6c0c03b11cc539cca37aea782538ee77262.tar.gz
Add api to collect owned user projects. Api deploy_key.create: Enable deploy key if it exist in other owned project
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r--lib/api/projects.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index ddc403c12db..13aa42b755d 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -22,6 +22,15 @@ module API
present @projects, with: Entities::Project
end
+ # Get an owned projects list for authenticated user
+ #
+ # Example Request:
+ # GET /projects/owned
+ get '/owned' do
+ @projects = paginate current_user.owned_projects
+ present @projects, with: Entities::Project
+ end
+
# Get a single project
#
# Parameters:
@@ -408,6 +417,8 @@ module API
end
# Add new ssh key to currently authenticated user
+ # If deploy key already exists - it will be joined to project
+ # but only if original one was owned by same user
#
# Parameters:
# key (required) - New SSH Key
@@ -416,7 +427,26 @@ module API
# POST /projects/:id/keys
post ":id/keys" do
attrs = attributes_for_keys [:title, :key]
+
+ attrs[:key].strip!
+
+ # check if key already exist in project
+ key = user_project.deploy_keys.find_by_key(attrs[:key])
+ if key
+ present key, with: Entities::SSHKey
+ return
+ end
+
+ # Check for available deploy keys in other projects
+ key = current_user.owned_deploy_keys.find_by_key(attrs[:key])
+ if key
+ user_project.deploy_keys << key
+ present key, with: Entities::SSHKey
+ return
+ end
+
key = DeployKey.new attrs
+
if key.valid? && user_project.deploy_keys << key
present key, with: Entities::SSHKey
else