Conversation
latest changes from upstream
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
4c1f4b2 to
8e5aabd
Compare
|
hmm is it possible for me to get a @greptileai review |
8e5aabd to
f588a2e
Compare
Greptile SummaryThis PR extends the internal revocation endpoint to support revoking regular user
Confidence Score: 4/5
Sequence DiagramsequenceDiagram
participant Revoker as Revoker Service
participant RC as RevocationsController
participant DB as Database
Revoker->>RC: POST /api/internal/revoke (Bearer auth)
RC->>RC: authenticate! via secure_compare
alt Matches ADMIN_KEY_REGEX
RC->>DB: AdminApiKey.active.find_by(key)
DB-->>RC: admin_key or nil
RC->>DB: admin_key.revoke! sets revoked_at and renames
DB-->>RC: ok or raises
else Matches REGULAR_KEY_REGEX
RC->>DB: ApiKey.find_by(key)
DB-->>RC: api_key or nil
RC->>DB: api_key.update rolls uuid and renames
DB-->>RC: true or false
else No regex match
RC-->>Revoker: success false
end
alt Not found or failed
RC-->>Revoker: success false
else Succeeded
RC-->>Revoker: success true plus owner_email and key_name
end
Last reviewed commit: 2fb2aff |
|
@greptileai re-review pls? |
| render json: { | ||
| success: true, | ||
| owner_email: user.email_addresses.first&.email, | ||
| key_name: admin_api_key.name | ||
| key_name: key.name | ||
| }.compact_blank |
There was a problem hiding this comment.
key_name reflects post-mutation name
After revoke_key! runs, key is already updated in memory — for regular ApiKeys the name becomes "Desktop_revoked_abc12345", and for AdminApiKeys the same applies via revoke!. So the key_name field in the success response always carries the mangled, post-revocation name rather than the human-readable original.
This behaviour was already present for the admin-key path before this PR, so it's consistent, but any downstream consumer (e.g. the revoker service notification) will see "Desktop_revoked_abc12345" instead of "Desktop". If the revoker uses key_name to build a user-facing message, consider capturing the original name before calling revoke_key!:
original_key_name = key.name
return render json: { success: false } unless revoke_key!(key)
render json: {
success: true,
owner_email: user.email_addresses.first&.email,
key_name: original_key_name
}.compact_blankPrompt To Fix With AI
This is a comment left during a code review.
Path: app/controllers/api/internal/revocations_controller.rb
Line: 17-21
Comment:
`key_name` reflects post-mutation name
After `revoke_key!` runs, `key` is already updated in memory — for regular `ApiKey`s the name becomes `"Desktop_revoked_abc12345"`, and for `AdminApiKey`s the same applies via `revoke!`. So the `key_name` field in the success response always carries the mangled, post-revocation name rather than the human-readable original.
This behaviour was already present for the admin-key path before this PR, so it's consistent, but any downstream consumer (e.g. the revoker service notification) will see `"Desktop_revoked_abc12345"` instead of `"Desktop"`. If the revoker uses `key_name` to build a user-facing message, consider capturing the original name before calling `revoke_key!`:
```ruby
original_key_name = key.name
return render json: { success: false } unless revoke_key!(key)
render json: {
success: true,
owner_email: user.email_addresses.first&.email,
key_name: original_key_name
}.compact_blank
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
@skyfallwastaken what do you think the best behavior would be in regards to this?
This PR will be landed prior to but alongside a corresponding one for the revoker.
This PR adds: