-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Delete a user's public key via admin api (closes #3014) #3059
Delete a user's public key via admin api (closes #3014) #3059
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3059 +/- ##
==========================================
+ Coverage 33.63% 34.07% +0.44%
==========================================
Files 273 273
Lines 39954 39998 +44
==========================================
+ Hits 13437 13629 +192
+ Misses 24610 24429 -181
- Partials 1907 1940 +33
Continue to review full report at Codecov.
|
f3bea44
to
7d646ed
Compare
Can you also add test that adds and later deletes that key? |
@lafriks done! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly looks good, just a few comments
routers/api/v1/admin/user.go
Outdated
// - name: id | ||
// in: path | ||
// description: key's id to delete | ||
// type: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type: integer
routers/api/v1/admin/user.go
Outdated
// required: true | ||
// - name: id | ||
// in: path | ||
// description: key's id to delete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "id of the key to delete"
routers/api/v1/admin/user.go
Outdated
func DeleteUserPublicKey(ctx *context.APIContext) { | ||
// swagger:operation DELETE /admin/users/{username}/keys/{id} admin adminDeleteUserPublicKey | ||
// --- | ||
// summary: Delete a user's public key on behalf of a user |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "Delete a user's public key". Don't need to repeat "user" twice.
routers/api/v1/admin/user.go
Outdated
return | ||
} | ||
|
||
if _, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id")); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice if we didn't have to call GetPublicKeyByID
before calling DeletePublicKey
, since DeletePublicKey
already calls GetPublicKeyByID
. Perhaps it's worthwhile to have DeletePublicKey
return a ErrKeyNotExist
when you try to delete a non-existent key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeap, I wanted to do that, but my concern was that right now DeletePublicKey
returns nil
if it encounters an ErrKeyNotExist
error and maybe, somewhere in the code, somebody is relying on that. (even though is not a sane behavior)
Is it safe to return ErrKeyNotExist
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That function is used only in one file, so additional checks for that could be added for that error
integrations/api_admin_test.go
Outdated
// user1 is an admin user | ||
session := loginUser(t, "user1") | ||
|
||
req := NewRequestf(t, "DELETE", "/api/v1/admin/users/user1/keys/99999") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: please use models.NonexistentID
instead of 99999
565c4b7
to
0e3388f
Compare
0e3388f
to
65871ea
Compare
@ethantkoenig done |
@@ -36,6 +36,7 @@ | |||
], | |||
"summary": "Create a user", | |||
"operationId": "adminCreateUser", | |||
"security": null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've run swagger generate spec
and this was the output. I didn't want to manually change it since it's easier to maintain this way.
LGTM |
LGTM |
Let admin delete a user's key via API