Skip to content

feat: condition Audit log on licensing - #3685

Merged
presleyp merged 21 commits into
mainfrom
license-audit/presleyp/3219
Aug 25, 2022
Merged

presleyp merged 21 commits into
mainfrom
license-audit/presleyp/3219

Conversation

@presleyp

@presleyp presleyp commented Aug 24, 2022 •

Copy link
Copy Markdown
Contributor

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
Comment thread site/package.json
"@testing-library/react-hooks": "8.0.1",
"@xstate/inspect": "0.6.5",
"@xstate/react": "3.0.0",
"@xstate/react": "3.0.1",

Copy link
Copy Markdown
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
Copy Markdown
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%2Freact@3.0.1

Comment thread site/src/api/types.ts

export type Message = { message: string }

// Keep up to date with coder/codersdk/features.go

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

Copy link
Copy Markdown
Contributor

}
}

export const MockMemberPermissions = {

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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!

@jsjoeio jsjoeio left a comment

Copy link
Copy Markdown
Contributor

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