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

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
5a47132
feat: Add ACL list support to rego objects
Emyrk Sep 13, 2022
03f69bf
Add unit tests
Emyrk Sep 13, 2022
91a358d
Rename ACL list
Emyrk Sep 13, 2022
8f837b7
Flip rego json to key by user id
Emyrk Sep 15, 2022
8378c9b
feat: add template ACL
sreya Sep 17, 2022
54a0d13
add down migration
sreya Sep 19, 2022
72ea751
remove unused file
sreya Sep 19, 2022
d533a16
undo insert templates query change
sreya Sep 19, 2022
f56fcf9
add patch endpoint tests
sreya Sep 19, 2022
f162694
Unit test use shadowed copied value
Emyrk Sep 19, 2022
ea25c08
Allow wildcards for ACL list
Emyrk Sep 19, 2022
5a081eb
fix authorize bug
sreya Sep 19, 2022
072b3e4
feat: Allow filter to accept objects of multiple types
Emyrk Sep 19, 2022
205c36c
add support for private templates
sreya Sep 19, 2022
ba32928
go.mod
sreya Sep 19, 2022
5c6344f
Merge branch 'main' into resource_acl_list
sreya Sep 19, 2022
ef15908
fix rbac merge woes
sreya Sep 19, 2022
8ab5200
update migration
sreya Sep 19, 2022
c040e8e
fix workspaces_test
sreya Sep 19, 2022
1f4ceee
remove sqlx
sreya Sep 19, 2022
7cc71e1
fix audit
sreya Sep 19, 2022
131d5ed
fix lint
sreya Sep 19, 2022
8c3ee6a
Revert "remove sqlx"
sreya Sep 19, 2022
fe2af91
add test for list templates
sreya Sep 20, 2022
0218c4e
fix error msg
sreya Sep 20, 2022
6883106
fix sqlx woes
sreya Sep 20, 2022
4fbd9be
fix lint
sreya Sep 20, 2022
c96a6ca
fix audit
sreya Sep 20, 2022
57ba8b3
make gen
sreya Sep 20, 2022
c66d247
Merge branch 'main' into resource_acl_list
sreya Sep 20, 2022
0af367a
fix merge woes
sreya Sep 20, 2022
f6c3f51
fix test template
sreya Sep 20, 2022
6e72286
fmt
sreya Sep 20, 2022
44bcbde
Add base layout
BrunoQuaresma Sep 21, 2022
0f80beb
Add table
BrunoQuaresma Sep 21, 2022
d274d62
Add search user
BrunoQuaresma Sep 21, 2022
943c76b
Add user role
BrunoQuaresma Sep 21, 2022
7f7f1d3
Add update and delete
BrunoQuaresma Sep 21, 2022
967a1a9
Fix summary view
BrunoQuaresma Sep 21, 2022
1324991
Merge branch 'resource_acl_list' of github.com:coder/coder into resou…
BrunoQuaresma Sep 21, 2022
bd34d20
Merge branch 'resource_acl_list' of github.com:coder/coder into resou…
sreya Sep 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add table
  • Loading branch information
BrunoQuaresma committed Sep 21, 2022
commit 0f80beb4a215d2f053b569fcaa2f79e577d38a2e
7 changes: 7 additions & 0 deletions site/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,3 +486,10 @@ export const getTemplateDAUs = async (
const response = await axios.get(`/api/v2/templates/${templateId}/daus`)
return response.data
}

export const getTemplateUserRoles = async (
templateId: string,
): Promise<TypesGen.TemplateUser[]> => {
const response = await axios.get(`/api/v2/templates/${templateId}/user-roles`)
return response.data
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { useMachine } from "@xstate/react"
import { FC } from "react"
import { Helmet } from "react-helmet-async"
import { useOutletContext } from "react-router-dom"
import { pageTitle } from "util/page"
import { templateUsersMachine } from "xServices/template/templateUsersXService"
import { TemplateContext } from "xServices/template/templateXService"
import { TemplateCollaboratorsPageView } from "./TemplateCollaboratorsPageView"

Expand All @@ -15,12 +17,18 @@ export const TemplateCollaboratorsPage: FC<React.PropsWithChildren<unknown>> = (
)
}

const [state] = useMachine(templateUsersMachine, { context: { templateId: template.id } })
const { templateUsers } = state.context

return (
<>
<Helmet>
<title>{pageTitle(`${template.name} · Collaborators`)}</title>
</Helmet>
<TemplateCollaboratorsPageView deleteTemplateError={deleteTemplateError} />
<TemplateCollaboratorsPageView
templateUsers={templateUsers}
deleteTemplateError={deleteTemplateError}
/>
</>
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,153 @@
import Button from "@material-ui/core/Button"
import CircularProgress from "@material-ui/core/CircularProgress"
import MenuItem from "@material-ui/core/MenuItem"
import Select from "@material-ui/core/Select"
import { makeStyles } from "@material-ui/core/styles"
import Table from "@material-ui/core/Table"
import TableBody from "@material-ui/core/TableBody"
import TableCell from "@material-ui/core/TableCell"
import TableContainer from "@material-ui/core/TableContainer"
import TableHead from "@material-ui/core/TableHead"
import TableRow from "@material-ui/core/TableRow"
import TextField from "@material-ui/core/TextField"
import PersonAdd from "@material-ui/icons/PersonAdd"
import Autocomplete from "@material-ui/lab/Autocomplete"
import { TemplateUser } from "api/typesGenerated"
import { ChooseOne, Cond } from "components/Conditionals/ChooseOne"
import { EmptyState } from "components/EmptyState/EmptyState"
import { ErrorSummary } from "components/ErrorSummary/ErrorSummary"
import { Stack } from "components/Stack/Stack"
import { FC } from "react"
import { TableLoader } from "components/TableLoader/TableLoader"
import { FC, useState } from "react"

export interface TemplateCollaboratorsPageViewProps {
deleteTemplateError: Error | unknown
templateUsers: TemplateUser[] | undefined
}

export const TemplateCollaboratorsPageView: FC<
React.PropsWithChildren<TemplateCollaboratorsPageViewProps>
> = ({ deleteTemplateError }) => {
> = ({ deleteTemplateError, templateUsers }) => {
const styles = useStyles()
const [open, setOpen] = useState(false)
const [options, setOptions] = useState([])
const isLoading = false
const deleteError = deleteTemplateError ? (
<ErrorSummary error={deleteTemplateError} dismissible />
) : null

return (
<Stack spacing={2.5}>
{deleteError}
<h2>Collaborators</h2>
<Stack direction="row" alignItems="center" spacing={1}>
<Autocomplete
id="asynchronous-demo"
style={{ width: 300 }}
open={open}
onOpen={() => {
setOpen(true)
}}
onClose={() => {
setOpen(false)
}}
getOptionSelected={(option: any, value: any) => option.name === value.name}
getOptionLabel={(option) => option.name}
options={options}
loading={isLoading}
className={styles.autocomplete}
renderInput={(params) => (
<TextField
{...params}
margin="none"
variant="outlined"
placeholder="User email or username"
InputProps={{
...params.InputProps,
endAdornment: (
<>
{isLoading ? <CircularProgress size={16} /> : null}
{params.InputProps.endAdornment}
</>
),
}}
/>
)}
/>

<Select defaultValue="read" variant="outlined" className={styles.select}>
<MenuItem key="read" value="read">
Read
</MenuItem>
<MenuItem key="write" value="write">
Write
</MenuItem>
<MenuItem key="admin" value="admin">
Admin
</MenuItem>
</Select>

<Button size="small" startIcon={<PersonAdd />}>
Add collaborator
</Button>
</Stack>

<TableContainer>
<Table>
<TableHead>
<TableRow>
<TableCell>User</TableCell>
<TableCell>Role</TableCell>
</TableRow>
</TableHead>
<TableBody>
<ChooseOne>
<Cond condition={!templateUsers}>
<TableLoader />
</Cond>
<Cond condition={Boolean(templateUsers && templateUsers.length === 0)}>
<TableRow>
<TableCell colSpan={999}>
<EmptyState
message="No collaborators yet"
description="Add a collaborator using the controls above"
/>
</TableCell>
</TableRow>
</Cond>
<Cond condition={Boolean(templateUsers && templateUsers.length > 0)}>
<TableRow>
<TableCell>Kyle</TableCell>
<TableCell>Admin</TableCell>
</TableRow>
</Cond>
</ChooseOne>
</TableBody>
</Table>
</TableContainer>
</Stack>
)
}

export const useStyles = makeStyles(() => {
return {}
export const useStyles = makeStyles((theme) => {
return {
autocomplete: {
"& .MuiInputBase-root": {
width: 300,
// Match button small height
height: 36,
},

"& input": {
fontSize: 14,
padding: `${theme.spacing(0, 0.5, 0, 0.5)} !important`,
},
},

select: {
// Match button small height
height: 36,
fontSize: 14,
width: 100,
},
}
})
46 changes: 46 additions & 0 deletions site/src/xServices/template/templateUsersXService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { getTemplateUserRoles } from "api/api"
import { TemplateUser } from "api/typesGenerated"
import { assign, createMachine } from "xstate"

export const templateUsersMachine = createMachine(
{
schema: {
context: {} as {
templateId: string
templateUsers?: TemplateUser[]
},
services: {} as {
loadTemplateUsers: {
data: TemplateUser[]
}
},
},
tsTypes: {} as import("./templateUsersXService.typegen").Typegen0,
id: "templateUserRoles",
initial: "loading",
states: {
loading: {
invoke: {
src: "loadTemplateUsers",
onDone: {
actions: ["assignTemplateUsers"],
target: "success",
},
},
},
success: {
type: "final",
},
},
},
{
services: {
loadTemplateUsers: ({ templateId }) => getTemplateUserRoles(templateId),
},
actions: {
assignTemplateUsers: assign({
templateUsers: (_, { data }) => data,
}),
},
},
)