Skip to content

Commit

Permalink
ui: alter role events render correctly
Browse files Browse the repository at this point in the history
Previously, ALTER ROLE events without role options would render with
an "undefined" option in the event log on the DB Console. This change
amends the rendering logic to correctly render events without any
options.

Resolves cockroachdb#124871
Epic: None

Release note (bug fix,ui change): ALTER ROLE events in the DB Console
event log now render correctly when the event does not contain any
role options.
  • Loading branch information
dhartunian committed Jun 27, 2024
1 parent 4fa534b commit 84cf77d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
41 changes: 40 additions & 1 deletion pkg/ui/workspaces/db-console/src/util/events.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
// by the Apache License, Version 2.0, included in the file
// licenses/APL.txt.

import { EventInfo, getDroppedObjectsText } from "src/util/events";
import { api as clusterUiApi } from "@cockroachlabs/cluster-ui";

import {EventInfo, getDroppedObjectsText, getEventDescription} from "src/util/events";

describe("getDroppedObjectsText", function () {
// The key indicating which objects were dropped in a DROP_DATABASE event has been
Expand Down Expand Up @@ -42,3 +44,40 @@ describe("getDroppedObjectsText", function () {
});
});
});

describe("getEventDescription", function () {
it("ignores the options field when empty for role changes", function () {
interface TestCase {
event: Partial<clusterUiApi.EventColumns>;
expected: string;
}
const tcs: TestCase[] = [
{
event: {
eventType: "alter_role",
info: '{"User": "abc", "RoleName": "123"}',
},
expected: "Role Altered: User abc altered role 123",
},
{
event: {
eventType: "alter_role",
info: '{"User": "abc", "RoleName": "123", "Options": []}',
},
expected: "Role Altered: User abc altered role 123",
},
{
event: {
eventType: "alter_role",
info: '{"User": "abc", "RoleName": "123", "Options": ["o1", "o2"]}',
},
expected: "Role Altered: User abc altered role 123 with options o1,o2",
},
];
tcs.forEach(tc => {
expect(getEventDescription(tc.event as clusterUiApi.EventColumns)).toEqual(
tc.expected,
);
});
});
});
6 changes: 5 additions & 1 deletion pkg/ui/workspaces/db-console/src/util/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ export function getEventDescription(e: clusterUiApi.EventColumns): string {
case eventTypes.DROP_ROLE:
return `Role Dropped: User ${info.User} dropped role ${info.RoleName}`;
case eventTypes.ALTER_ROLE:
return `Role Altered: User ${info.User} altered role ${info.RoleName} with options ${info.Options}`;
if (info.Options && info.Options.length > 0) {
return `Role Altered: User ${info.User} altered role ${info.RoleName} with options ${info.Options}`;
} else {
return `Role Altered: User ${info.User} altered role ${info.RoleName}`;
}
case eventTypes.IMPORT:
return `Import Job: User ${info.User} has a job ${info.JobID} running with status ${info.Status}`;
case eventTypes.RESTORE:
Expand Down

0 comments on commit 84cf77d

Please sign in to comment.