Skip to content

Commit c3247dc

Browse files
authored
Merge pull request #10846 from marmelab/doc/backport_rbac_doc
[Doc] Backport RBAC's doc
2 parents c56b228 + b364d63 commit c3247dc

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

docs/SimpleForm.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -846,3 +846,47 @@ const ProductEdit = () => (
846846
</Edit>
847847
);
848848
```
849+
850+
`@react-admin/ra-rbac` `<SimpleForm>` also accepts a `showReadOnly` prop. If set to `true`, inputs for which users have only `read` access will be displayed but will be read only:
851+
852+
```tsx
853+
import { Edit, TextInput } from 'react-admin';
854+
import { SimpleForm } from '@react-admin/ra-rbac';
855+
856+
const authProvider = {
857+
// ...
858+
canAccess: async ({ action, record, resource }) =>
859+
canAccessWithPermissions({
860+
permissions: [
861+
// 'delete' is missing
862+
{ action: ['list', 'edit'], resource: 'products' },
863+
{ action: 'write', resource: 'products.reference' },
864+
{ action: 'write', resource: 'products.width' },
865+
{ action: 'write', resource: 'products.height' },
866+
// 'products.description' is read-only
867+
{ action: 'read', resource: 'products.description' },
868+
{ action: 'write', resource: 'products.thumbnail' },
869+
// 'products.image' is missing
870+
]
871+
action,
872+
record,
873+
resource,
874+
}),
875+
};
876+
877+
const ProductEdit = () => (
878+
<Edit>
879+
<SimpleForm>
880+
<TextInput source="reference" />
881+
<TextInput source="width" />
882+
<TextInput source="height" />
883+
{/* read-only */}
884+
<TextInput source="description" />
885+
{/* not displayed */}
886+
<TextInput source="image" />
887+
<TextInput source="thumbnail" />
888+
{/* no delete button */}
889+
</SimpleForm>
890+
</Edit>
891+
);
892+
```

docs/TabbedForm.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,3 +1024,56 @@ const ProductEdit = () => (
10241024
</Edit>
10251025
);
10261026
```
1027+
1028+
`@react-admin/ra-rbac` `<TabbedForm>` also accepts a `showReadOnly` prop. If set to `true`, inputs for which users have only `read` access will be displayed but will be read only:
1029+
1030+
```tsx
1031+
import { Edit, TextInput } from 'react-admin';
1032+
import { TabbedForm } from '@react-admin/ra-rbac';
1033+
1034+
const authProvider = {
1035+
// ...
1036+
canAccess: async ({ action, record, resource }) =>
1037+
canAccessWithPermissions({
1038+
permissions: [
1039+
{ action: ['list', 'edit'], resource: 'products' },
1040+
{ action: 'write', resource: 'products.reference' },
1041+
{ action: 'write', resource: 'products.width' },
1042+
{ action: 'write', resource: 'products.height' },
1043+
// 'products.description' is read-only
1044+
{ action: 'read', resource: 'products.description' },
1045+
{ action: 'write', resource: 'products.thumbnail' },
1046+
// 'products.image' is missing
1047+
{ action: 'write', resource: 'products.tab.description' },
1048+
// 'products.tab.stock' is missing
1049+
{ action: 'write', resource: 'products.tab.images' },
1050+
],
1051+
action,
1052+
record,
1053+
resource,
1054+
})
1055+
};
1056+
1057+
const ProductEdit = () => (
1058+
<Edit>
1059+
<TabbedForm showReadOnly>
1060+
<TabbedForm.Tab label="Description" name="description">
1061+
<TextInput source="reference" />
1062+
<TextInput source="width" />
1063+
<TextInput source="height" />
1064+
{/* Input Description is read-only */}
1065+
<TextInput source="description" />
1066+
</TabbedForm.Tab>
1067+
{/* Tab Stock is not displayed */}
1068+
<TabbedForm.Tab label="Stock" name="stock">
1069+
<TextInput source="stock" />
1070+
</TabbedForm.Tab>
1071+
<TabbedForm.Tab label="Images" name="images">
1072+
{/* Input Image is not displayed */}
1073+
<TextInput source="image" />
1074+
<TextInput source="thumbnail" />
1075+
</TabbedForm.Tab>
1076+
</TabbedForm>
1077+
</Edit>
1078+
);
1079+
```

0 commit comments

Comments
 (0)