Skip to content

Commit

Permalink
feat: add acl selection to documents, see #20
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcath committed Aug 15, 2024
1 parent ee17a61 commit cf3e0e3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
26 changes: 23 additions & 3 deletions app/routes/app.documents.$document.edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,13 @@ import {invariant} from '@arcath/utils'
import {ensureUser} from '~/lib/utils/ensure-user'
import {getPrisma} from '~/lib/prisma.server'
import {Button} from '~/lib/components/button'
import {Label, Input, HelperText, TextArea} from '~/lib/components/input'
import {
Label,
Input,
HelperText,
TextArea,
Select
} from '~/lib/components/input'
import {pageTitle} from '~/lib/utils/page-title'

export const loader = async ({request, params}: LoaderFunctionArgs) => {
Expand All @@ -25,7 +31,9 @@ export const loader = async ({request, params}: LoaderFunctionArgs) => {
where: {id: params.document}
})

return json({user, document})
const acls = await prisma.aCL.findMany({orderBy: {name: 'asc'}})

return json({user, document, acls})
}

export const action = async ({request, params}: ActionFunctionArgs) => {
Expand Down Expand Up @@ -71,7 +79,7 @@ export const meta: MetaFunction<typeof loader> = ({data}) => {
}

const DocumentEdit = () => {
const {document} = useLoaderData<typeof loader>()
const {document, acls} = useLoaderData<typeof loader>()

return (
<div className="entry">
Expand All @@ -91,6 +99,18 @@ const DocumentEdit = () => {
/>
<HelperText>Document body in Markdown</HelperText>
</Label>
<Label>
ACL
<Select name="acl" defaultValue={document.aclId}>
{acls.map(({id, name}) => {
return (
<option key={id} value={id}>
{name}
</option>
)
})}
</Select>
</Label>
<Button className="bg-success">Edit Document</Button>
</form>
</div>
Expand Down
32 changes: 30 additions & 2 deletions app/routes/app.documents.add.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,32 @@ import {
json,
redirect
} from '@remix-run/node'
import {useLoaderData} from '@remix-run/react'
import {invariant} from '@arcath/utils'

import {ensureUser} from '~/lib/utils/ensure-user'
import {getPrisma} from '~/lib/prisma.server'
import {Button} from '~/lib/components/button'
import {Label, Input, HelperText, TextArea} from '~/lib/components/input'
import {
Label,
Input,
HelperText,
TextArea,
Select
} from '~/lib/components/input'
import {pageTitle} from '~/lib/utils/page-title'
import {getDefaultACLID} from '~/lib/rbac.server'

export const loader = async ({request}: LoaderFunctionArgs) => {
const user = await ensureUser(request, 'document:add', {})

return json({user})
const prisma = getPrisma()

const acls = await prisma.aCL.findMany({orderBy: {name: 'asc'}})

const defaultAclId = await getDefaultACLID()

return json({user, acls, defaultAclId})
}

export const action = async ({request}: ActionFunctionArgs) => {
Expand Down Expand Up @@ -46,6 +60,8 @@ export const meta: MetaFunction = () => {
}

const DocumentAdd = () => {
const {acls, defaultAclId} = useLoaderData<typeof loader>()

return (
<div className="entry">
<h2>Add Document</h2>
Expand All @@ -60,6 +76,18 @@ const DocumentAdd = () => {
<TextArea name="body" className="min-h-[50vh]" />
<HelperText>Document body in Markdown</HelperText>
</Label>
<Label>
ACL
<Select name="acl" defaultValue={defaultAclId}>
{acls.map(({id, name}) => {
return (
<option key={id} value={id}>
{name}
</option>
)
})}
</Select>
</Label>
<Button className="bg-success">Add Document</Button>
</form>
</div>
Expand Down

0 comments on commit cf3e0e3

Please sign in to comment.