Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 78df786

Browse files
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".
1 parent 5285c12 commit 78df786

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

site/src/pages/AuditPage/AuditLogRow/AuditLogDescription/AuditLogDescription.stories.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,12 @@ export const SCIMUpdateUser: Story = {
105105
},
106106
},
107107
};
108+
109+
export const UnauthenticatedUser: Story = {
110+
args: {
111+
auditLog: {
112+
...MockAuditLog,
113+
user: null,
114+
},
115+
},
116+
};

site/src/pages/AuditPage/AuditLogRow/AuditLogDescription/AuditLogDescription.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ export const AuditLogDescription: FC<AuditLogDescriptionProps> = ({
1919
}
2020

2121
let target = auditLog.resource_target.trim();
22-
let user = auditLog.user?.username.trim();
22+
let user = auditLog.user
23+
? auditLog.user.username.trim()
24+
: "Unauthenticated user";
2325

2426
// SSH key entries have no links
2527
if (auditLog.resource_type === "git_ssh_key") {

site/src/pages/AuditPage/AuditLogRow/AuditLogDescription/BuildAuditDescription.tsx

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ export const BuildAuditDescription: FC<BuildAuditDescriptionProps> = ({
1616
auditLog.additional_fields?.build_reason &&
1717
auditLog.additional_fields?.build_reason !== "initiator"
1818
? "Coder automatically"
19-
: auditLog.user?.username.trim();
19+
: auditLog.user
20+
? auditLog.user.username.trim()
21+
: "Unauthenticated user";
2022

2123
const action = useMemo(() => {
2224
switch (auditLog.action) {

0 commit comments

Comments
 (0)