DEV: Include user who created API key in listing

This commit is contained in:
Ted Johansson 2024-12-23 14:08:51 +08:00
parent bc0a170341
commit 3759d9cf26
No known key found for this signature in database
GPG Key ID: 2E801F82D9A4C6E9
7 changed files with 30 additions and 10 deletions

View File

@ -73,6 +73,9 @@ export default class ApiKeysList extends Component {
{{/if}}
</td>
<td class="d-admin-row__detail key-created">
<LinkTo @route="adminUser" @model={{this.apiKey.createdBy}}>
{{avatar this.apiKey.createdBy imageSize="small"}}
</LinkTo>
<div class="d-admin-row__mobile-label">{{i18n
"admin.api.created"
}}</div>

View File

@ -21,6 +21,19 @@ export default class ApiKey extends RestModel {
}
}
@computed("_created_by")
get createdBy() {
return this._created_by;
}
set created_by(value) {
if (value && !(value instanceof AdminUser)) {
this.set("_created_by", AdminUser.create(value));
} else {
this.set("_created_by", value);
}
}
@discourseComputed("description")
shortDescription(description) {
if (!description || description.length < 40) {

View File

@ -94,13 +94,14 @@
color: var(--primary-high);
font-size: var(--font-down-1);
}
&__badge {
background-color: var(--primary-low);
border-radius: var(--d-border-radius);
font-size: var(--font-down-1);
margin-left: var(--space-1);
padding: var(--space-2);
}
}
&__badge {
background-color: var(--primary-low);
border-radius: var(--d-border-radius);
font-size: var(--font-down-1);
margin-left: var(--space-1);
padding: var(--space-2);
}
// Success badge

View File

@ -14,6 +14,7 @@ class Admin::ApiController < Admin::AdminController
ApiKey
.where(hidden: false)
.includes(:user)
.includes(:created_by)
.order("revoked_at DESC NULLS FIRST, created_at DESC")
.offset(offset)
.limit(limit)

View File

@ -11,6 +11,7 @@ class ApiKeySerializer < ApplicationSerializer
:revoked_at
has_one :user, serializer: BasicUserSerializer, embed: :objects
has_one :created_by, serializer: BasicUserSerializer, embed: :objects
has_many :api_key_scopes, serializer: ApiKeyScopeSerializer, embed: :objects
def include_user_id?

View File

@ -4,4 +4,5 @@ class BasicApiKeySerializer < ApplicationSerializer
attributes :id, :truncated_key, :description, :created_at, :last_used_at, :revoked_at
has_one :user, serializer: BasicUserSerializer, embed: :objects
has_one :created_by, serializer: BasicUserSerializer, embed: :objects
end

View File

@ -5346,10 +5346,10 @@ en:
title: "API"
key: "Key"
keys: "Keys"
created: Created
created: Created by
updated: Updated
last_used: Last Used
never_used: (never)
last_used: Last used
never_used: Never
generate: "Generate"
undo_revoke: "Undo revoke"
revoke: "Revoke"