Commit 50e8d6c0 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add api to collect owned user projects. Api deploy_key.create: Enable deploy...

Add api to collect owned user projects. Api deploy_key.create: Enable deploy key if it exist in other owned project
parent 0447c731
......@@ -54,6 +54,6 @@ class DeployKeysController < ProjectResourceController
protected
def available_keys
@available_keys ||= DeployKey.in_projects(current_user.owned_projects).uniq
@available_keys ||= current_user.owned_deploy_keys
end
end
......@@ -352,4 +352,8 @@ class User < ActiveRecord::Base
def ldap_user?
extern_uid && provider == 'ldap'
end
def owned_deploy_keys
DeployKey.in_projects(self.owned_projects).uniq
end
end
......@@ -26,9 +26,9 @@ module API
end
class Project < Grape::Entity
expose :id, :name, :description, :default_branch
expose :id, :description, :default_branch, :public, :ssh_url_to_repo, :http_url_to_repo, :web_url
expose :owner, using: Entities::UserBasic
expose :public
expose :name, :name_with_namespace
expose :path, :path_with_namespace
expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at
expose :namespace
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment