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}} {{/if}}
</td> </td>
<td class="d-admin-row__detail key-created"> <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 <div class="d-admin-row__mobile-label">{{i18n
"admin.api.created" "admin.api.created"
}}</div> }}</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") @discourseComputed("description")
shortDescription(description) { shortDescription(description) {
if (!description || description.length < 40) { if (!description || description.length < 40) {

View File

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

View File

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

View File

@ -11,6 +11,7 @@ class ApiKeySerializer < ApplicationSerializer
:revoked_at :revoked_at
has_one :user, serializer: BasicUserSerializer, embed: :objects has_one :user, serializer: BasicUserSerializer, embed: :objects
has_one :created_by, serializer: BasicUserSerializer, embed: :objects
has_many :api_key_scopes, serializer: ApiKeyScopeSerializer, embed: :objects has_many :api_key_scopes, serializer: ApiKeyScopeSerializer, embed: :objects
def include_user_id? 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 attributes :id, :truncated_key, :description, :created_at, :last_used_at, :revoked_at
has_one :user, serializer: BasicUserSerializer, embed: :objects has_one :user, serializer: BasicUserSerializer, embed: :objects
has_one :created_by, serializer: BasicUserSerializer, embed: :objects
end end

View File

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