refactor: name null users in audit logs (#16890)

A few audit logs can have the user as null which means the user is not
authenticated when executing the action. To make it more explicit we
named than as "Unauthenticated user" in the log description instead of
"undefined user".
This commit is contained in:
Bruno Quaresma
2025-03-12 11:36:38 -03:00
committed by GitHub
parent 5285c12b9e
commit 78df7869d5
3 changed files with 15 additions and 2 deletions

View File

@ -105,3 +105,12 @@ export const SCIMUpdateUser: Story = {
},
},
};
export const UnauthenticatedUser: Story = {
args: {
auditLog: {
...MockAuditLog,
user: null,
},
},
};

View File

@ -19,7 +19,9 @@ export const AuditLogDescription: FC<AuditLogDescriptionProps> = ({
}
let target = auditLog.resource_target.trim();
let user = auditLog.user?.username.trim();
let user = auditLog.user
? auditLog.user.username.trim()
: "Unauthenticated user";
// SSH key entries have no links
if (auditLog.resource_type === "git_ssh_key") {

View File

@ -16,7 +16,9 @@ export const BuildAuditDescription: FC<BuildAuditDescriptionProps> = ({
auditLog.additional_fields?.build_reason &&
auditLog.additional_fields?.build_reason !== "initiator"
? "Coder automatically"
: auditLog.user?.username.trim();
: auditLog.user
? auditLog.user.username.trim()
: "Unauthenticated user";
const action = useMemo(() => {
switch (auditLog.action) {