diff --git a/frontend/actions/user.ts b/frontend/actions/user.ts index 119f86409..d76fe40fe 100644 --- a/frontend/actions/user.ts +++ b/frontend/actions/user.ts @@ -1,6 +1,6 @@ import qs from 'querystring' import useSWR from 'swr' -import { EntityObject } from 'types/v2/types' +import { EntityObject, ModelInterface, TokenActionsKeys, TokenInterface, TokenScopeKeys, User } from 'types/v2/types' import { ErrorInfo, fetcher } from '../utils/fetcher' @@ -28,13 +28,11 @@ export function useListUsers(q: string) { } interface UserResponse { - user: { - dn: string - } + user: User } export function useGetCurrentUser() { - const { data, error, mutate } = useSWR(`/api/v2/entities/me`, fetcher) + const { data, error, mutate } = useSWR('/api/v2/entities/me', fetcher) return { mutateCurrentUser: mutate, @@ -43,3 +41,37 @@ export function useGetCurrentUser() { isCurrentUserError: error, } } + +interface GetUserTokensResponse { + tokens: TokenInterface[] +} + +export function useGetUserTokens() { + const { data, error, mutate } = useSWR('/api/v2/user/tokens', fetcher) + + return { + mutateTokens: mutate, + tokens: data?.tokens || [], + isTokensLoading: !error && !data, + isTokensError: error, + } +} + +export function postUserToken( + description: string, + scope: TokenScopeKeys, + modelIds: ModelInterface['id'][], + actions: TokenActionsKeys[], +) { + return fetch('/api/v2/user/tokens', { + method: 'post', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ description, scope, modelIds, actions }), + }) +} + +export function deleteUserToken(accessKey: TokenInterface['accessKey']) { + return fetch(`/api/v2/user/token/${accessKey}`, { + method: 'delete', + }) +} diff --git a/frontend/cypress/e2e/beta/push-image-registry.cy.ts b/frontend/cypress/e2e/beta/push-image-registry.cy.ts index 1d05832ac..7520ab6ed 100644 --- a/frontend/cypress/e2e/beta/push-image-registry.cy.ts +++ b/frontend/cypress/e2e/beta/push-image-registry.cy.ts @@ -39,7 +39,7 @@ describe('Make and approve an access request', () => { cy.contains('Pushing an Image for this Model') cy.log('Fetching the docker login password and running all the docker commands to push an image') - cy.get('[data-test=showTokenButton]').click() + cy.get('[data-test=regenerateTokenButton]').click() cy.get('[data-test=dockerPassword]').should('not.contain.text', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx') cy.get('[data-test=dockerPassword]') .invoke('text') diff --git a/frontend/pages/beta/schemas/new.tsx b/frontend/pages/beta/schemas/new.tsx index 602a0bc6e..33c794a21 100644 --- a/frontend/pages/beta/schemas/new.tsx +++ b/frontend/pages/beta/schemas/new.tsx @@ -2,6 +2,7 @@ import { ArrowBack, Schema } from '@mui/icons-material' import { LoadingButton } from '@mui/lab' import { Box, Button, Container, MenuItem, Paper, Select, Stack, TextField, Typography } from '@mui/material' import { styled } from '@mui/material/styles' +import { useTheme } from '@mui/material/styles' import { postSchema, SchemaKind } from 'actions/schema' import { useRouter } from 'next/router' import { ChangeEvent, FormEvent, useState } from 'react' @@ -34,6 +35,7 @@ export default function NewSchema() { const [loading, setLoading] = useState(false) const router = useRouter() + const theme = useTheme() const handleUploadChange = (event: ChangeEvent) => { const fileReader = new FileReader() @@ -106,7 +108,7 @@ export default function NewSchema() { - Id * + Id * - Name * + Name * - Description * + Description * - Schema Type * + Schema Type *