Commit 4528fa98 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

modify api to work with new deploy keys

parent 1882baa1
...@@ -25,8 +25,8 @@ module Gitlab ...@@ -25,8 +25,8 @@ module Gitlab
return false unless project return false unless project
if key.is_deploy_key if key.is_a? DeployKey
project == key.project && git_cmd == 'git-upload-pack' key.projects.include?(project) && git_cmd == 'git-upload-pack'
else else
user = key.user user = key.user
......
...@@ -531,8 +531,8 @@ module Gitlab ...@@ -531,8 +531,8 @@ module Gitlab
# POST /projects/:id/keys # POST /projects/:id/keys
post ":id/keys" do post ":id/keys" do
attrs = attributes_for_keys [:title, :key] attrs = attributes_for_keys [:title, :key]
key = user_project.deploy_keys.new attrs key = DeployKey.new attrs
if key.save if key.valid? && user_project.deploy_keys << key
present key, with: Entities::SSHKey present key, with: Entities::SSHKey
else else
not_found! not_found!
...@@ -545,9 +545,8 @@ module Gitlab ...@@ -545,9 +545,8 @@ module Gitlab
# DELETE /projects/:id/keys/:id # DELETE /projects/:id/keys/:id
delete ":id/keys/:key_id" do delete ":id/keys/:key_id" do
key = user_project.deploy_keys.find params[:key_id] key = user_project.deploy_keys.find params[:key_id]
key.delete key.destroy
end end
end end
end end
end end
...@@ -174,7 +174,7 @@ module Gitlab ...@@ -174,7 +174,7 @@ module Gitlab
delete "keys/:id" do delete "keys/:id" do
begin begin
key = current_user.keys.find params[:id] key = current_user.keys.find params[:id]
key.delete key.destroy
rescue rescue
end end
end end
......
...@@ -37,7 +37,8 @@ describe Project do ...@@ -37,7 +37,8 @@ describe Project do
it { should have_many(:users_projects).dependent(:destroy) } it { should have_many(:users_projects).dependent(:destroy) }
it { should have_many(:notes).dependent(:destroy) } it { should have_many(:notes).dependent(:destroy) }
it { should have_many(:snippets).dependent(:destroy) } it { should have_many(:snippets).dependent(:destroy) }
it { should have_many(:deploy_keys).dependent(:destroy) } it { should have_many(:deploy_keys_projects).dependent(:destroy) }
it { should have_many(:deploy_keys) }
it { should have_many(:hooks).dependent(:destroy) } it { should have_many(:hooks).dependent(:destroy) }
it { should have_many(:protected_branches).dependent(:destroy) } it { should have_many(:protected_branches).dependent(:destroy) }
it { should have_one(:forked_project_link).dependent(:destroy) } it { should have_one(:forked_project_link).dependent(:destroy) }
......
...@@ -13,7 +13,6 @@ describe Gitlab::API do ...@@ -13,7 +13,6 @@ describe Gitlab::API do
let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') } let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') }
let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
let(:key) { create(:key, project: project) }
before { project.team << [user, :reporter] } before { project.team << [user, :reporter] }
...@@ -636,24 +635,26 @@ describe Gitlab::API do ...@@ -636,24 +635,26 @@ describe Gitlab::API do
end end
end end
describe :deploy_keys do
let(:deploy_keys_project) { create(:deploy_keys_project, project: project) }
let(:deploy_key) { deploy_keys_project.deploy_key }
describe "GET /projects/:id/keys" do describe "GET /projects/:id/keys" do
before { deploy_key }
it "should return array of ssh keys" do it "should return array of ssh keys" do
project.deploy_keys << key
project.save
get api("/projects/#{project.id}/keys", user) get api("/projects/#{project.id}/keys", user)
response.status.should == 200 response.status.should == 200
json_response.should be_an Array json_response.should be_an Array
json_response.first['title'].should == key.title json_response.first['title'].should == deploy_key.title
end end
end end
describe "GET /projects/:id/keys/:key_id" do describe "GET /projects/:id/keys/:key_id" do
it "should return a single key" do it "should return a single key" do
project.deploy_keys << key get api("/projects/#{project.id}/keys/#{deploy_key.id}", user)
project.save
get api("/projects/#{project.id}/keys/#{key.id}", user)
response.status.should == 200 response.status.should == 200
json_response['title'].should == key.title json_response['title'].should == deploy_key.title
end end
it "should return 404 Not Found with invalid ID" do it "should return 404 Not Found with invalid ID" do
...@@ -677,11 +678,11 @@ describe Gitlab::API do ...@@ -677,11 +678,11 @@ describe Gitlab::API do
end end
describe "DELETE /projects/:id/keys/:key_id" do describe "DELETE /projects/:id/keys/:key_id" do
before { deploy_key }
it "should delete existing key" do it "should delete existing key" do
project.deploy_keys << key
project.save
expect { expect {
delete api("/projects/#{project.id}/keys/#{key.id}", user) delete api("/projects/#{project.id}/keys/#{deploy_key.id}", user)
}.to change{ project.deploy_keys.count }.by(-1) }.to change{ project.deploy_keys.count }.by(-1)
end end
...@@ -690,4 +691,5 @@ describe Gitlab::API do ...@@ -690,4 +691,5 @@ describe Gitlab::API do
response.status.should == 404 response.status.should == 404
end end
end end
end
end end
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