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

Skip to content

feat: condition Audit log on licensing #3685

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 21 commits into from
Aug 25, 2022
Merged

Conversation

presleyp
Copy link
Contributor

@presleyp presleyp commented Aug 24, 2022

Closes #3219

  • Add RequirePermissions wrapper component to make AppRouter more readable (currently doing the XState stuff in AppRouter instead of the wrapper, either way is workable though)
  • Condition Audit Log link and page visibility on license in addition to RBAC and dev mode
  • upgrade xstate-react because a recent patch fixes a testing issue

In the past, we've punted on some component tests thinking that e2e tests would work better for cases that need to include the whole component tree. But e2e tests are difficult - they require setup instead of mocks and can be flaky. So I tried doing a component test while rendering App. I think it's a good way forward for such cases.

Click SHOW_MOCK_BANNER and HIDE_MOCK_BANNER in the XState inspector to see/hide the Audit link in the navbar - they change the stored license data to trigger both the warning banner and enabling the Audit Log.

Remaining issue:
A test that passes in my workspace fails on CI, I'm investigating.

@presleyp presleyp marked this pull request as ready for review August 25, 2022 18:46
@presleyp presleyp requested a review from a team as a code owner August 25, 2022 18:46
@presleyp presleyp requested review from jsjoeio and removed request for a team August 25, 2022 18:46
@@ -33,7 +33,7 @@
"@material-ui/lab": "4.0.0-alpha.42",
"@testing-library/react-hooks": "8.0.1",
"@xstate/inspect": "0.6.5",
"@xstate/react": "3.0.0",
"@xstate/react": "3.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the testing issue this fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getSnapshot warning/crash and the shallowEqual util for avoiding it. https://newreleases.io/project/github/statelyai/xstate/release/@xstate%[email protected]

@@ -14,3 +14,9 @@ export interface ReconnectingPTYRequest {
export type WorkspaceBuildTransition = "start" | "stop" | "delete"

export type Message = { message: string }

// Keep up to date with coder/codersdk/features.go
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this something that can be autogenerated?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is there's some reason why we can't get enums in our generated types.

})
})

it("does not show Audit Log link when not entitled", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading this code, how does one know Audit Log link is not entitled? Is it due to the lack of the mocked request or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the default handler in handlers.ts returns empty license data, as if you're an OSS user.

})
})

it("does not show Audit Log link when not permitted via role", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with this test. How does one know that a member is not permitted? I see MockMemberPermissions but hard to tell from code what role is being given or why they don't have permission.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Member role does not have auditing permissions.

import { Navigate } from "react-router"

export interface RequirePermissionProps {
children: JSX.Element
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would PropsWithChildren help here? reference

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried using it here and got a TS error, not sure why!

@@ -51,6 +51,10 @@ export function assignableRole(role: TypesGen.Role, assignable: boolean): TypesG
}
}

export const MockMemberPermissions = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be helpful to convey permissions in name i.e. MockMemberWithoutAuditLogPermissions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added comments, does that help?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it does! Thank you!

Copy link
Contributor

@jsjoeio jsjoeio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

@presleyp presleyp merged commit 623fc5b into main Aug 25, 2022
@presleyp presleyp deleted the license-audit/presleyp/3219 branch August 25, 2022 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Show Audit Log if licensed
2 participants