Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tatuya Kamada
gitlab-ce
Commits
4528fa98
Commit
4528fa98
authored
May 06, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
modify api to work with new deploy keys
parent
1882baa1
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
52 deletions
+54
-52
lib/api/internal.rb
lib/api/internal.rb
+2
-2
lib/api/projects.rb
lib/api/projects.rb
+3
-4
lib/api/users.rb
lib/api/users.rb
+1
-1
spec/models/project_spec.rb
spec/models/project_spec.rb
+2
-1
spec/requests/api/projects_spec.rb
spec/requests/api/projects_spec.rb
+46
-44
No files found.
lib/api/internal.rb
View file @
4528fa98
...
@@ -25,8 +25,8 @@ module Gitlab
...
@@ -25,8 +25,8 @@ module Gitlab
return
false
unless
project
return
false
unless
project
if
key
.
is_
deploy_k
ey
if
key
.
is_
a?
DeployK
ey
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
...
...
lib/api/projects.rb
View file @
4528fa98
...
@@ -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
.
de
lete
key
.
de
stroy
end
end
end
end
end
end
end
end
lib/api/users.rb
View file @
4528fa98
...
@@ -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
.
de
lete
key
.
de
stroy
rescue
rescue
end
end
end
end
...
...
spec/models/project_spec.rb
View file @
4528fa98
...
@@ -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
)
}
...
...
spec/requests/api/projects_spec.rb
View file @
4528fa98
...
@@ -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,58 +635,61 @@ describe Gitlab::API do
...
@@ -636,58 +635,61 @@ describe Gitlab::API do
end
end
end
end
describe
"GET /projects/:id/keys"
do
describe
:deploy_keys
do
it
"should return array of ssh keys"
do
let
(
:deploy_keys_project
)
{
create
(
:deploy_keys_project
,
project:
project
)
}
project
.
deploy_keys
<<
key
let
(
:deploy_key
)
{
deploy_keys_project
.
deploy_key
}
project
.
save
get
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
)
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
key
.
title
end
end
describe
"GET /projects/:id/keys/:key_id"
do
describe
"GET /projects/:id/keys"
do
it
"should return a single key"
do
before
{
deploy_key
}
project
.
deploy_keys
<<
key
project
.
save
get
api
(
"/projects/
#{
project
.
id
}
/keys/
#{
key
.
id
}
"
,
user
)
response
.
status
.
should
==
200
json_response
[
'title'
].
should
==
key
.
title
end
it
"should return 404 Not Found with invalid ID"
do
it
"should return array of ssh keys"
do
get
api
(
"/projects/
#{
project
.
id
}
/keys/404"
,
user
)
get
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
)
response
.
status
.
should
==
404
response
.
status
.
should
==
200
json_response
.
should
be_an
Array
json_response
.
first
[
'title'
].
should
==
deploy_key
.
title
end
end
end
end
describe
"POST /projects/:id/keys"
do
describe
"GET /projects/:id/keys/:key_id"
do
it
"should not create an invalid ssh key"
do
it
"should return a single key"
do
post
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
),
{
title:
"invalid key"
}
get
api
(
"/projects/
#{
project
.
id
}
/keys/
#{
deploy_key
.
id
}
"
,
user
)
response
.
status
.
should
==
404
response
.
status
.
should
==
200
end
json_response
[
'title'
].
should
==
deploy_key
.
title
end
it
"should create new ssh key"
do
it
"should return 404 Not Found with invalid ID"
do
key_attrs
=
attributes_for
:key
get
api
(
"/projects/
#{
project
.
id
}
/keys/404"
,
user
)
expect
{
response
.
status
.
should
==
404
post
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
),
key_attrs
end
}.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
1
)
end
end
end
describe
"DELETE /projects/:id/keys/:key_id"
do
describe
"POST /projects/:id/keys"
do
it
"should delete existing key"
do
it
"should not create an invalid ssh key"
do
project
.
deploy_keys
<<
key
post
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
),
{
title:
"invalid key"
}
project
.
save
response
.
status
.
should
==
404
expect
{
end
delete
api
(
"/projects/
#{
project
.
id
}
/keys/
#{
key
.
id
}
"
,
user
)
}.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
-
1
)
it
"should create new ssh key"
do
key_attrs
=
attributes_for
:key
expect
{
post
api
(
"/projects/
#{
project
.
id
}
/keys"
,
user
),
key_attrs
}.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
1
)
end
end
end
it
"should return 404 Not Found with invalid ID"
do
describe
"DELETE /projects/:id/keys/:key_id"
do
delete
api
(
"/projects/
#{
project
.
id
}
/keys/404"
,
user
)
before
{
deploy_key
}
response
.
status
.
should
==
404
it
"should delete existing key"
do
expect
{
delete
api
(
"/projects/
#{
project
.
id
}
/keys/
#{
deploy_key
.
id
}
"
,
user
)
}.
to
change
{
project
.
deploy_keys
.
count
}.
by
(
-
1
)
end
it
"should return 404 Not Found with invalid ID"
do
delete
api
(
"/projects/
#{
project
.
id
}
/keys/404"
,
user
)
response
.
status
.
should
==
404
end
end
end
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment