Disable public toggle if user is not the playlist's owner

This commit is contained in:
Deluan 2020-06-08 19:19:38 -04:00
parent b4e06c416d
commit b636565c62

View File

@ -20,7 +20,7 @@ const PlaylistFilter = (props) => (
</Filter> </Filter>
) )
const TogglePublicInput = ({ resource, record, source }) => { const TogglePublicInput = ({ permissions, resource, record, source }) => {
const notify = useNotify() const notify = useNotify()
const [togglePublic] = useUpdate( const [togglePublic] = useUpdate(
resource, resource,
@ -43,10 +43,20 @@ const TogglePublicInput = ({ resource, record, source }) => {
e.stopPropagation() e.stopPropagation()
} }
return <Switch checked={record[source]} onClick={handleClick} /> const canChange =
permissions === 'admin' ||
localStorage.getItem('username') === record['owner']
return (
<Switch
checked={record[source]}
onClick={handleClick}
disabled={!canChange}
/>
)
} }
const PlaylistList = (props) => ( const PlaylistList = ({ permissions, ...props }) => (
<List {...props} exporter={false} filters={<PlaylistFilter />}> <List {...props} exporter={false} filters={<PlaylistFilter />}>
<Datagrid rowClick="show" isRowSelectable={(r) => isWritable(r && r.owner)}> <Datagrid rowClick="show" isRowSelectable={(r) => isWritable(r && r.owner)}>
<TextField source="name" /> <TextField source="name" />
@ -54,7 +64,7 @@ const PlaylistList = (props) => (
<NumberField source="songCount" /> <NumberField source="songCount" />
<DurationField source="duration" /> <DurationField source="duration" />
<DateField source="updatedAt" /> <DateField source="updatedAt" />
<TogglePublicInput source="public" /> <TogglePublicInput source="public" permissions={permissions} />
<Writable> <Writable>
<EditButton /> <EditButton />
</Writable> </Writable>