-
Notifications
You must be signed in to change notification settings - Fork 14
Add SCIM UI #2926
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
Add SCIM UI #2926
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
c3cbe1d
Add SCIM tab to UI
charliepark 781338f
Add tests
charliepark 2e9fd5d
Tweak truncation
charliepark 711e286
Use 90 day default for expiration time in mock data
charliepark 9a5b622
revert UI copy change
charliepark 5d0ec9d
TODOs update
charliepark ddc38a0
Remove Delete All from UI and set handler to NotImplemented
charliepark bcaede8
Merge branch 'main' into scim-ui
charliepark 72b0478
npm i
charliepark 1f9d238
update npm and re-run npm i
charliepark f8da78a
merge main and resolve conflicts
charliepark 9c180b5
Remove todo list
charliepark 5ccfbd5
Update import and className ordering
charliepark 732151c
Update path snapshots
charliepark 366107f
tweak height of token pseudo input; order tokens by created_at
charliepark 47e43af
Remove EXPIRES column and content from confirmation modal
charliepark 6769f2f
Simplify mock handler
charliepark 69283da
Revert "Remove EXPIRES column and content from confirmation modal"
charliepark e50b8dd
Set mock token data to have null expiration datetime
charliepark cbe165e
Hide 'Learn about SCIM Auth' text until we have documentation up that…
charliepark 31dbaae
Remove unnecessary test
charliepark fe07125
For desktops, give a min-width to the Expires column so it doesn't fe…
charliepark 8b04094
merge main
david-crespo d7a7f28
SCIM UI tweaks
benjaminleonard 373cf62
Fix funky modal (unrelated to SCIM)
benjaminleonard bb1b6ef
Message spacing tweak
benjaminleonard 0ffff24
Unify input label with others
benjaminleonard cf84e81
merge main
david-crespo 3177244
tweak copy, add saml_scim option in silo create
david-crespo af34dfa
put oxide-scim- back in. see https://github.com/oxidecomputer/omicron…
david-crespo 95063f1
fix e2e failure and bug around admin group name
david-crespo 80bcd3a
merge main, resolve conflicts
david-crespo eb82796
take out the docs link so we can merge
david-crespo 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,264 @@ | ||
| /* | ||
| * This Source Code Form is subject to the terms of the Mozilla Public | ||
| * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| * file, you can obtain one at https://mozilla.org/MPL/2.0/. | ||
| * | ||
| * Copyright Oxide Computer Company | ||
| */ | ||
|
|
||
| import { createColumnHelper, getCoreRowModel, useReactTable } from '@tanstack/react-table' | ||
| import { useCallback, useMemo, useState } from 'react' | ||
| import { type LoaderFunctionArgs } from 'react-router' | ||
|
|
||
| import { AccessToken24Icon } from '@oxide/design-system/icons/react' | ||
| import { Badge } from '@oxide/design-system/ui' | ||
|
|
||
| import { | ||
| apiQueryClient, | ||
| useApiMutation, | ||
| usePrefetchedApiQuery, | ||
| type ScimClientBearerToken, | ||
| } from '~/api' | ||
| import { getSiloSelector, useSiloSelector } from '~/hooks/use-params' | ||
| import { confirmDelete } from '~/stores/confirm-delete' | ||
| import { addToast } from '~/stores/toast' | ||
| import { useColsWithActions, type MenuAction } from '~/table/columns/action-col' | ||
| import { Columns } from '~/table/columns/common' | ||
| import { Table } from '~/table/Table' | ||
| import { CardBlock } from '~/ui/lib/CardBlock' | ||
| import { CopyToClipboard } from '~/ui/lib/CopyToClipboard' | ||
| import { CreateButton } from '~/ui/lib/CreateButton' | ||
| import { DateTime } from '~/ui/lib/DateTime' | ||
| import { EmptyMessage } from '~/ui/lib/EmptyMessage' | ||
| import { Message } from '~/ui/lib/Message' | ||
| import { Modal } from '~/ui/lib/Modal' | ||
| import { TableEmptyBox } from '~/ui/lib/Table' | ||
| import { Truncate } from '~/ui/lib/Truncate' | ||
|
|
||
| const colHelper = createColumnHelper<ScimClientBearerToken>() | ||
|
|
||
| const EmptyState = () => ( | ||
| <TableEmptyBox border={false}> | ||
| <EmptyMessage | ||
| icon={<AccessToken24Icon />} | ||
| title="No SCIM tokens" | ||
| body="Create a token to see it here" | ||
| /> | ||
| </TableEmptyBox> | ||
| ) | ||
|
|
||
| export async function clientLoader({ params }: LoaderFunctionArgs) { | ||
| const { silo } = getSiloSelector(params) | ||
| await apiQueryClient.prefetchQuery('scimTokenList', { query: { silo } }) | ||
| return null | ||
| } | ||
|
|
||
| export default function SiloScimTab() { | ||
| const siloSelector = useSiloSelector() | ||
| const { data } = usePrefetchedApiQuery('scimTokenList', { | ||
| query: { silo: siloSelector.silo }, | ||
| }) | ||
|
|
||
| // Order tokens by creation date, oldest first | ||
| const tokens = useMemo( | ||
| () => [...data].sort((a, b) => a.timeCreated.getTime() - b.timeCreated.getTime()), | ||
| [data] | ||
| ) | ||
|
|
||
| const [showCreateModal, setShowCreateModal] = useState(false) | ||
| const [createdToken, setCreatedToken] = useState<{ | ||
| id: string | ||
| bearerToken: string | ||
| timeCreated: Date | ||
| timeExpires?: Date | null | ||
| } | null>(null) | ||
|
|
||
| const deleteToken = useApiMutation('scimTokenDelete', { | ||
| onSuccess() { | ||
| apiQueryClient.invalidateQueries('scimTokenList') | ||
| }, | ||
| }) | ||
|
|
||
| const makeActions = useCallback( | ||
| (token: ScimClientBearerToken): MenuAction[] => [ | ||
| { | ||
| label: 'Delete', | ||
| onActivate: confirmDelete({ | ||
| doDelete: () => | ||
| deleteToken.mutateAsync({ | ||
| path: { tokenId: token.id }, | ||
| query: { silo: siloSelector.silo }, | ||
| }), | ||
| label: token.id, | ||
| }), | ||
| }, | ||
| ], | ||
| [deleteToken, siloSelector.silo] | ||
| ) | ||
|
|
||
| const staticColumns = useMemo( | ||
| () => [ | ||
| colHelper.accessor('id', { | ||
| header: 'ID', | ||
| cell: (info) => ( | ||
| <Truncate text={info.getValue()} position="middle" maxLength={18} /> | ||
| ), | ||
| }), | ||
| colHelper.accessor('timeCreated', Columns.timeCreated), | ||
| colHelper.accessor('timeExpires', { | ||
| header: 'Expires', | ||
| cell: (info) => { | ||
| const expires = info.getValue() | ||
| return expires ? ( | ||
| <DateTime date={expires} /> | ||
| ) : ( | ||
| <Badge color="neutral">Never</Badge> | ||
| ) | ||
| }, | ||
| meta: { thClassName: 'lg:w-1/4' }, | ||
| }), | ||
| ], | ||
| [] | ||
| ) | ||
|
|
||
| const columns = useColsWithActions(staticColumns, makeActions, 'Copy token ID') | ||
|
|
||
| const table = useReactTable({ | ||
| data: tokens, | ||
| columns, | ||
| getCoreRowModel: getCoreRowModel(), | ||
| }) | ||
| // const { href, linkText } = docLinks.scim | ||
| return ( | ||
| <> | ||
| <CardBlock> | ||
| <CardBlock.Header | ||
| title="SCIM Tokens" | ||
| titleId="scim-tokens-label" | ||
| description="Tokens for authenticating requests to SCIM endpoints" | ||
| > | ||
| <CreateButton onClick={() => setShowCreateModal(true)}>Create token</CreateButton> | ||
| </CardBlock.Header> | ||
| <CardBlock.Body> | ||
| {tokens.length === 0 ? ( | ||
| <EmptyState /> | ||
| ) : ( | ||
| <Table | ||
| aria-labelledby="scim-tokens-label" | ||
| table={table} | ||
| className="table-inline" | ||
| /> | ||
| )} | ||
| </CardBlock.Body> | ||
| {/* TODO: put this back! | ||
| <CardBlock.Footer> | ||
| <LearnMore href={links.scimDocs} text="SCIM" /> | ||
| </CardBlock.Footer> */} | ||
| </CardBlock> | ||
|
|
||
| {showCreateModal && ( | ||
| <CreateTokenModal | ||
| siloSelector={siloSelector} | ||
| onDismiss={() => setShowCreateModal(false)} | ||
| onSuccess={(token) => { | ||
| setShowCreateModal(false) | ||
| setCreatedToken(token) | ||
| }} | ||
| /> | ||
| )} | ||
|
|
||
| {createdToken && ( | ||
| <TokenCreatedModal token={createdToken} onDismiss={() => setCreatedToken(null)} /> | ||
| )} | ||
| </> | ||
| ) | ||
| } | ||
|
|
||
| function CreateTokenModal({ | ||
| siloSelector, | ||
| onDismiss, | ||
| onSuccess, | ||
| }: { | ||
| siloSelector: { silo: string } | ||
| onDismiss: () => void | ||
| onSuccess: (token: { | ||
| id: string | ||
| bearerToken: string | ||
| timeCreated: Date | ||
| timeExpires?: Date | null | ||
| }) => void | ||
| }) { | ||
| const createToken = useApiMutation('scimTokenCreate', { | ||
| onSuccess(token) { | ||
| apiQueryClient.invalidateQueries('scimTokenList') | ||
| onSuccess(token) | ||
| }, | ||
| onError(err) { | ||
| addToast({ variant: 'error', title: 'Failed to create token', content: err.message }) | ||
| }, | ||
| }) | ||
|
|
||
| return ( | ||
| <Modal isOpen onDismiss={onDismiss} title="Create SCIM token"> | ||
| <Modal.Section> | ||
| Anyone with this token can manage users and groups in this silo via SCIM. Since | ||
| group membership grants roles, this token can be used to give a user admin | ||
| privileges. Store it securely and never share it publicly. | ||
| </Modal.Section> | ||
|
|
||
| <Modal.Footer | ||
| onDismiss={onDismiss} | ||
| onAction={() => { | ||
| createToken.mutate({ query: { silo: siloSelector.silo } }) | ||
| }} | ||
| actionText="Create" | ||
| actionLoading={createToken.isPending} | ||
| /> | ||
| </Modal> | ||
| ) | ||
| } | ||
|
|
||
| function TokenCreatedModal({ | ||
| token, | ||
| onDismiss, | ||
| }: { | ||
| token: { | ||
| id: string | ||
| bearerToken: string | ||
| timeCreated: Date | ||
| timeExpires?: Date | null | ||
| } | ||
| onDismiss: () => void | ||
| }) { | ||
| return ( | ||
| <Modal isOpen onDismiss={onDismiss} title="SCIM token created"> | ||
| <Modal.Section> | ||
| <Message | ||
| variant="notice" | ||
| content=<> | ||
| This is the only time you’ll see this token. Copy it now and store it securely. | ||
| </> | ||
| /> | ||
|
|
||
| <div className="mt-4"> | ||
| <div className="text-sans-md text-raise mb-2">Bearer Token</div> | ||
| <div className="text-sans-md text-raise bg-default border-default flex items-stretch rounded border"> | ||
| <div className="flex-1 overflow-hidden px-3 py-2.75 text-ellipsis"> | ||
| {token.bearerToken} | ||
| </div> | ||
| <div className="border-default flex w-8 items-center justify-center border-l"> | ||
| <CopyToClipboard text={token.bearerToken} /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </Modal.Section> | ||
|
|
||
| <Modal.Footer | ||
| onDismiss={onDismiss} | ||
| actionText="Done" | ||
| onAction={onDismiss} | ||
| showCancel={false} | ||
| /> | ||
| </Modal> | ||
| ) | ||
| } | ||
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we need design polish from @benjaminleonard. I'd put the yellow bit at the top, for one. Maybe put the expiration at the bottom and display it in one line. Could do without the pseudo form field styling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
heh just kidding. it's a lot closer to the design than I expected. The pseudo-input it too tall though.