-
Notifications
You must be signed in to change notification settings - Fork 974
feat: Auditing group members as part of group resource #5730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6c73cf3
added AuditableGroup type
Kira-Pilot 40842b9
added json tags
Kira-Pilot f4e5801
Anonymizing gGroup struct
Kira-Pilot c478e9a
adding support on the FE for nested group diffs
Kira-Pilot ed17aa8
Merge remote-tracking branch 'origin/main' into audit-group-and-membe…
Kira-Pilot 25bbb3a
added type for GroupMember
Kira-Pilot 6b5f134
Update coderd/database/modelmethods.go
Kira-Pilot d33b330
Update coderd/database/modelmethods.go
Kira-Pilot 240c004
fetching group members in group.delete
Kira-Pilot 921107c
Merge branch 'audit-group-and-members/kira-pilot' of github.com:coder…
Kira-Pilot 2ffcab8
passing through right error
Kira-Pilot 66acf51
broke out into util function and added tests
Kira-Pilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ import userAgentParser from "ua-parser-js" | |
import { AuditLogDiff } from "./AuditLogDiff" | ||
import i18next from "i18next" | ||
import { AuditLogDescription } from "./AuditLogDescription" | ||
import { determineGroupDiff } from "./auditUtils" | ||
|
||
const httpStatusColor = (httpStatus: number): PaletteIndex => { | ||
if (httpStatus >= 300 && httpStatus < 500) { | ||
|
@@ -49,6 +50,13 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({ | |
? `${browser.name} ${browser.version}` | ||
: t("auditLog:table.logRow.notAvailable") | ||
|
||
let auditDiff = auditLog.diff | ||
|
||
// groups have nested diffs (group members) | ||
if (auditLog.resource_type === "group") { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you pull this out into a util function, maybe with a unit test? |
||
auditDiff = determineGroupDiff(auditLog.diff) | ||
} | ||
|
||
const toggle = () => { | ||
if (shouldDisplayDiff) { | ||
setIsDiffOpen((v) => !v) | ||
|
@@ -153,7 +161,7 @@ export const AuditLogRow: React.FC<AuditLogRowProps> = ({ | |
|
||
{shouldDisplayDiff && ( | ||
<Collapse in={isDiffOpen}> | ||
<AuditLogDiff diff={auditLog.diff} /> | ||
<AuditLogDiff diff={auditDiff} /> | ||
</Collapse> | ||
)} | ||
</TableCell> | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import { determineGroupDiff } from "./auditUtils" | ||
|
||
const auditDiffForNewGroup = { | ||
id: { | ||
old: "", | ||
new: "e22e0eb9-625a-468b-b962-269b19473789", | ||
secret: false, | ||
}, | ||
members: { | ||
new: [], | ||
secret: false, | ||
}, | ||
name: { | ||
old: "", | ||
new: "another-test-group", | ||
secret: false, | ||
}, | ||
} | ||
|
||
const auditDiffForAddedGroupMember = { | ||
members: { | ||
old: [], | ||
new: [ | ||
{ | ||
group_id: "e22e0eb9-625a-468b-b962-269b19473789", | ||
user_id: "cea4c2b0-6373-4858-b26a-df3cbfce8845", | ||
}, | ||
], | ||
secret: false, | ||
}, | ||
} | ||
|
||
const auditDiffForRemovedGroupMember = { | ||
members: { | ||
old: [ | ||
{ | ||
group_id: "25793395-b093-4a3c-a473-9ecf9b243478", | ||
user_id: "84d1cd5a-17e1-4022-898c-52e64256e737", | ||
}, | ||
{ | ||
group_id: "25793395-b093-4a3c-a473-9ecf9b243478", | ||
user_id: "cea4c2b0-6373-4858-b26a-df3cbfce8845", | ||
}, | ||
], | ||
new: [ | ||
{ | ||
group_id: "25793395-b093-4a3c-a473-9ecf9b243478", | ||
user_id: "84d1cd5a-17e1-4022-898c-52e64256e737", | ||
}, | ||
], | ||
secret: false, | ||
}, | ||
} | ||
|
||
const AuditDiffForDeletedGroup = { | ||
id: { | ||
old: "25793395-b093-4a3c-a473-9ecf9b243478", | ||
new: "", | ||
secret: false, | ||
}, | ||
members: { | ||
old: [ | ||
{ | ||
group_id: "25793395-b093-4a3c-a473-9ecf9b243478", | ||
user_id: "84d1cd5a-17e1-4022-898c-52e64256e737", | ||
}, | ||
], | ||
secret: false, | ||
}, | ||
name: { | ||
old: "test-group", | ||
new: "", | ||
secret: false, | ||
}, | ||
} | ||
|
||
describe("determineAuditDiff", () => { | ||
it("auditDiffForNewGroup", () => { | ||
// there should be no change as members are not added when a group is created | ||
expect(determineGroupDiff(auditDiffForNewGroup)).toEqual( | ||
auditDiffForNewGroup, | ||
) | ||
}) | ||
|
||
it("auditDiffForAddedGroupMember", () => { | ||
const result = { | ||
members: { | ||
...auditDiffForAddedGroupMember.members, | ||
new: ["cea4c2b0-6373-4858-b26a-df3cbfce8845"], | ||
}, | ||
} | ||
|
||
expect(determineGroupDiff(auditDiffForAddedGroupMember)).toEqual(result) | ||
}) | ||
|
||
it("auditDiffForRemovedGroupMember", () => { | ||
const result = { | ||
members: { | ||
...auditDiffForRemovedGroupMember.members, | ||
old: [ | ||
"84d1cd5a-17e1-4022-898c-52e64256e737", | ||
"cea4c2b0-6373-4858-b26a-df3cbfce8845", | ||
], | ||
new: ["84d1cd5a-17e1-4022-898c-52e64256e737"], | ||
}, | ||
} | ||
|
||
expect(determineGroupDiff(auditDiffForRemovedGroupMember)).toEqual(result) | ||
}) | ||
|
||
it("AuditDiffForDeletedGroup", () => { | ||
const result = { | ||
...AuditDiffForDeletedGroup, | ||
members: { | ||
...AuditDiffForDeletedGroup.members, | ||
old: ["84d1cd5a-17e1-4022-898c-52e64256e737"], | ||
}, | ||
} | ||
|
||
expect(determineGroupDiff(AuditDiffForDeletedGroup)).toEqual(result) | ||
}) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.