-
Notifications
You must be signed in to change notification settings - Fork 13k
chore: ABAC Attributes room info view #37484
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
16 commits
Select commit
Hold shift + click to select a range
b554a33
chore: ABAC Attributes room info view
MartinSchoeler 0f20549
chore: snapshot
MartinSchoeler d738f36
snapshot
MartinSchoeler 9158479
review: Fix reviews
MartinSchoeler 8bf14ff
review: fix condition
MartinSchoeler 7ef6305
chore: oh snap(shot)!
MartinSchoeler be7a0b8
review: ul li
MartinSchoeler 41cbd35
review: bunnyman review
MartinSchoeler fb6b37c
fix: ts
MartinSchoeler 222a52b
ts
MartinSchoeler de53087
ts: ts
MartinSchoeler 0cb3df3
Merge branch 'develop' into chore/abac-room-info
kodiakhq[bot] 0960dbf
Merge branch 'develop' into chore/abac-room-info
kodiakhq[bot] f4c50f9
Merge branch 'develop' into chore/abac-room-info
tassoevan b3b8f2f
Merge branch 'develop' into chore/abac-room-info
kodiakhq[bot] b56f763
Merge branch 'develop' into chore/abac-room-info
MartinSchoeler 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
79 changes: 79 additions & 0 deletions
79
apps/meteor/client/views/room/contextualBar/Info/RoomInfo/ABAC/RoomInfoABACSection.spec.tsx
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,79 @@ | ||
| import type { IRoom } from '@rocket.chat/core-typings'; | ||
| import { mockAppRoot } from '@rocket.chat/mock-providers'; | ||
| import { render, screen } from '@testing-library/react'; | ||
| import { axe } from 'jest-axe'; | ||
|
|
||
| import RoomInfoABACSection from './RoomInfoABACSection'; | ||
| import { createFakeRoom } from '../../../../../../../tests/mocks/data'; | ||
|
|
||
| type RoomWithABAC = IRoom & { | ||
| abacAttributes?: { | ||
| key: string; | ||
| values: string[]; | ||
| }[]; | ||
| }; | ||
|
|
||
| describe('RoomInfoABACSection', () => { | ||
| const createRoomWithABAC = (attributes: { key: string; values: string[] }[]): RoomWithABAC => { | ||
| const room = createFakeRoom(); | ||
| return { | ||
| ...room, | ||
| abacAttributes: attributes, | ||
| } as RoomWithABAC; | ||
| }; | ||
|
|
||
| const appRootWithABACEnabled = mockAppRoot().withSetting('ABAC_Enabled', true).withSetting('ABAC_ShowAttributesInRooms', true).build(); | ||
|
|
||
| describe('Conditional rendering', () => { | ||
| it('should return null when ABAC_Enabled is false', () => { | ||
| const room = createRoomWithABAC([{ key: 'Test', values: ['Value1'] }]); | ||
| const appRoot = mockAppRoot().withSetting('ABAC_Enabled', false).withSetting('ABAC_ShowAttributesInRooms', true).build(); | ||
|
|
||
| render(<RoomInfoABACSection room={room} />, { wrapper: appRoot }); | ||
| expect(screen.queryByText('ABAC_Managed')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should return null when ABAC_ShowAttributesInRooms is false', () => { | ||
| const room = createRoomWithABAC([{ key: 'Test', values: ['Value1'] }]); | ||
| const appRoot = mockAppRoot().withSetting('ABAC_Enabled', true).withSetting('ABAC_ShowAttributesInRooms', false).build(); | ||
|
|
||
| render(<RoomInfoABACSection room={room} />, { wrapper: appRoot }); | ||
| expect(screen.queryByText('ABAC_Managed')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should return null when abacAttributes is empty', () => { | ||
| const room = createRoomWithABAC([]); | ||
| render(<RoomInfoABACSection room={room} />, { wrapper: appRootWithABACEnabled }); | ||
| expect(screen.queryByText('ABAC_Managed')).not.toBeInTheDocument(); | ||
| }); | ||
|
|
||
| it('should render when all conditions are met', () => { | ||
| const room = createRoomWithABAC([{ key: 'Test', values: ['Value1'] }]); | ||
| render(<RoomInfoABACSection room={room} />, { wrapper: appRootWithABACEnabled }); | ||
| expect(screen.getByText('ABAC_Managed')).toBeInTheDocument(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('Accessibility', () => { | ||
| it('should have no accessibility violations', async () => { | ||
| const room = createRoomWithABAC([ | ||
| { key: 'Chat-sensitivity', values: ['Classified', 'Top-Secret'] }, | ||
| { key: 'Country', values: ['US-only'] }, | ||
| ]); | ||
| const { container } = render(<RoomInfoABACSection room={room} />, { wrapper: appRootWithABACEnabled }); | ||
|
|
||
| const results = await axe(container); | ||
| expect(results).toHaveNoViolations(); | ||
| }); | ||
| }); | ||
| describe('Snapshot', () => { | ||
| it('should match the snapshot', () => { | ||
| const room = createRoomWithABAC([ | ||
| { key: 'Chat-sensitivity', values: ['Classified', 'Top-Secret'] }, | ||
| { key: 'Country', values: ['US-only'] }, | ||
| ]); | ||
| const { baseElement } = render(<RoomInfoABACSection room={room} />, { wrapper: appRootWithABACEnabled }); | ||
| expect(baseElement).toMatchSnapshot(); | ||
| }); | ||
| }); | ||
| }); |
66 changes: 66 additions & 0 deletions
66
apps/meteor/client/views/room/contextualBar/Info/RoomInfo/ABAC/RoomInfoABACSection.tsx
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,66 @@ | ||
| import type { IRoom } from '@rocket.chat/core-typings'; | ||
| import { Box, Divider, Tag } from '@rocket.chat/fuselage'; | ||
| import { useSetting } from '@rocket.chat/ui-contexts'; | ||
| import { useTranslation } from 'react-i18next'; | ||
|
|
||
| import { InfoPanelField, InfoPanelLabel } from '../../../../../../components/InfoPanel'; | ||
| import { RoomIcon } from '../../../../../../components/RoomIcon'; | ||
|
|
||
| // TODO: Remove type union when ABAC is implemented | ||
| type RoomInfoABACSectionProps = { | ||
| room: IRoom & { | ||
| abacAttributes?: { | ||
| key: string; | ||
| values: string[]; | ||
| }[]; | ||
| }; | ||
| }; | ||
|
|
||
| const RoomInfoABACSection = ({ room }: RoomInfoABACSectionProps) => { | ||
| const { t } = useTranslation(); | ||
|
|
||
| const abacEnabled = useSetting('ABAC_Enabled'); | ||
| const showAttributesInRoom = useSetting('ABAC_ShowAttributesInRooms'); | ||
|
|
||
| if (!abacEnabled || !showAttributesInRoom || !room.abacAttributes?.length) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <> | ||
| <Divider mb={32} width='full' /> | ||
| <InfoPanelField> | ||
| <Box display='flex' mbe={16}> | ||
| <Tag medium> | ||
| <Box display='flex' alignItems='center'> | ||
| <RoomIcon room={room} /> | ||
| <Box mis={2}>{t('ABAC_Managed')}</Box> | ||
| </Box> | ||
| </Tag> | ||
| </Box> | ||
|
|
||
| {t('ABAC_Managed_description')} | ||
|
|
||
| <InfoPanelLabel id='room-attributes-list-label'>{t('ABAC_Room_Attributes')}</InfoPanelLabel> | ||
| <Box is='ul' aria-labelledby='room-attributes-list-label'> | ||
| {room.abacAttributes.map((attribute) => ( | ||
| <Box is='li' key={attribute.key} mb={16}> | ||
| <Box is='span' id={`room-attribute-${attribute.key}-label`}> | ||
| {attribute.key} | ||
| </Box> | ||
| <Box is='ul' display='flex' mbs={8} alignItems='center' aria-labelledby={`room-attribute-${attribute.key}-label`}> | ||
| {attribute.values.map((value) => ( | ||
| <Box is='li' mie={4} key={value}> | ||
| <Tag medium>{value}</Tag> | ||
| </Box> | ||
| ))} | ||
| </Box> | ||
| </Box> | ||
| ))} | ||
| </Box> | ||
| </InfoPanelField> | ||
| </> | ||
| ); | ||
| }; | ||
|
|
||
| export default RoomInfoABACSection; | ||
123 changes: 123 additions & 0 deletions
123
...ews/room/contextualBar/Info/RoomInfo/ABAC/__snapshots__/RoomInfoABACSection.spec.tsx.snap
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,123 @@ | ||
| // Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing | ||
|
|
||
| exports[`RoomInfoABACSection Snapshot should match the snapshot 1`] = ` | ||
| <body> | ||
| <div> | ||
| <hr | ||
| class="rcx-box rcx-box--full rcx-divider rcx-css-1972bnv" | ||
| /> | ||
| <div | ||
| class="rcx-box rcx-box--full rcx-css-1jagyun" | ||
| > | ||
| <div | ||
| class="rcx-box rcx-box--full rcx-css-ukxwz6" | ||
| > | ||
| <span | ||
| class="rcx-box rcx-box--full rcx-tag rcx-tag--medium" | ||
| > | ||
| <span | ||
| class="rcx-tag__inner" | ||
| > | ||
| <div | ||
| class="rcx-box rcx-box--full rcx-css-127j9mz" | ||
| > | ||
| <i | ||
| aria-hidden="true" | ||
| class="rcx-box rcx-box--full rcx-icon--name-hash-shield rcx-icon rcx-css-1g87xs3" | ||
| > | ||
| | ||
| </i> | ||
| <div | ||
| class="rcx-box rcx-box--full rcx-css-1hq8wl6" | ||
| > | ||
| ABAC_Managed | ||
| </div> | ||
| </div> | ||
| </span> | ||
| </span> | ||
| </div> | ||
| ABAC_Managed_description | ||
| <div | ||
| class="rcx-box rcx-box--full rcx-css-f0ql1y" | ||
| id="room-attributes-list-label" | ||
| > | ||
| ABAC_Room_Attributes | ||
| </div> | ||
| <ul | ||
| aria-labelledby="room-attributes-list-label" | ||
| class="rcx-box rcx-box--full" | ||
| > | ||
| <li | ||
| class="rcx-box rcx-box--full rcx-css-1jagyun" | ||
| > | ||
| <span | ||
| class="rcx-box rcx-box--full" | ||
| id="room-attribute-Chat-sensitivity-label" | ||
| > | ||
| Chat-sensitivity | ||
| </span> | ||
| <ul | ||
| aria-labelledby="room-attribute-Chat-sensitivity-label" | ||
| class="rcx-box rcx-box--full rcx-css-q18nro" | ||
| > | ||
| <li | ||
| class="rcx-box rcx-box--full rcx-css-sdt442" | ||
| > | ||
| <span | ||
| class="rcx-box rcx-box--full rcx-tag rcx-tag--medium" | ||
| > | ||
| <span | ||
| class="rcx-tag__inner" | ||
| > | ||
| Classified | ||
| </span> | ||
| </span> | ||
| </li> | ||
| <li | ||
| class="rcx-box rcx-box--full rcx-css-sdt442" | ||
| > | ||
| <span | ||
| class="rcx-box rcx-box--full rcx-tag rcx-tag--medium" | ||
| > | ||
| <span | ||
| class="rcx-tag__inner" | ||
| > | ||
| Top-Secret | ||
| </span> | ||
| </span> | ||
| </li> | ||
| </ul> | ||
| </li> | ||
| <li | ||
| class="rcx-box rcx-box--full rcx-css-1jagyun" | ||
| > | ||
| <span | ||
| class="rcx-box rcx-box--full" | ||
| id="room-attribute-Country-label" | ||
| > | ||
| Country | ||
| </span> | ||
| <ul | ||
| aria-labelledby="room-attribute-Country-label" | ||
| class="rcx-box rcx-box--full rcx-css-q18nro" | ||
| > | ||
| <li | ||
| class="rcx-box rcx-box--full rcx-css-sdt442" | ||
| > | ||
| <span | ||
| class="rcx-box rcx-box--full rcx-tag rcx-tag--medium" | ||
| > | ||
| <span | ||
| class="rcx-tag__inner" | ||
| > | ||
| US-only | ||
| </span> | ||
| </span> | ||
| </li> | ||
| </ul> | ||
| </li> | ||
| </ul> | ||
| </div> | ||
| </div> | ||
| </body> | ||
| `; |
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
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.