Action values

What are the values that Refine uses for action in the context of access control? So far I've come across: list, show, edit, delete & create. Is there a type or interface that defines them and that can be used to reference them programatically?
1 Reply
kapa.ai
kapa.ai2mo ago
Hi @Nitai. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- In Refine, the action values used in the context of access control and other functionalities include list, show, edit, delete, create, and clone. These actions are used to define what operations can be performed on resources. The action values can be referenced programmatically using the useResourceParams and useResource hooks, which provide the action property. Here are the relevant details: useResourceParams Hook The useResourceParams hook provides the action property among others:
| Property | Type | Description |
| --- | --- | --- |
| id | `**BaseKey** (<https://refine.dev/docs/core/interface-references/#basekey>)` | |
| resource | `string` | |
| action | `"create" | "edit" | "list" | "show" | "clone"` | |
| Property | Type | Description |
| --- | --- | --- |
| id | `**BaseKey** (<https://refine.dev/docs/core/interface-references/#basekey>)` | |
| resource | `string` | |
| action | `"create" | "edit" | "list" | "show" | "clone"` | |
Source (https://refine.dev/docs/routing/hooks/use-resource-params/#properties) useResource Hook The useResource hook also provides the action property:
| Description | Type |
| --- | --- |
| resources | **`IResourceItem[]`** (<https://refine.dev/docs/routing/hooks/use-resource/#interfaces>) |
| resource | **`IResourceItem` | `undefined`** (<https://refine.dev/docs/routing/hooks/use-resource/#interfaces>) |
| resourceName | `string` | `undefined` |
| id | **`BaseKey`** (<https://refine.dev/docs/core/interface-references/#basekey>) |
| action | `undefined` | `"list"` | `"create"` | `"edit"` | `"show"` | `"clone"` |
| select | `(resourceName: string, force?: boolean) => { resource: IResourceItem` | `undefined, identifier: string` | `undefined}` |
| identifier | `string` | `undefined` |
| Description | Type |
| --- | --- |
| resources | **`IResourceItem[]`** (<https://refine.dev/docs/routing/hooks/use-resource/#interfaces>) |
| resource | **`IResourceItem` | `undefined`** (<https://refine.dev/docs/routing/hooks/use-resource/#interfaces>) |
| resourceName | `string` | `undefined` |
| id | **`BaseKey`** (<https://refine.dev/docs/core/interface-references/#basekey>) |
| action | `undefined` | `"list"` | `"create"` | `"edit"` | `"show"` | `"clone"` |
| select | `(resourceName: string, force?: boolean) => { resource: IResourceItem` | `undefined, identifier: string` | `undefined}` |
| identifier | `string` | `undefined` |
Source (https://refine.dev/docs/routing/hooks/use-resource/#return-value) Access Control Provider The Access Control Provider uses these actions to determine if a user can perform a certain action on a resource:
import { AccessControlProvider } from "@refinedev/core";

export const accessControlProvider: AccessControlProvider = {
can: async ({ resource, action, params }) => {
console.log(resource); // products, orders, etc.
console.log(action); // list, edit, delete, etc.
console.log(params); // { id: 1 }, { id: 2 }, etc.

if (meetSomeCondition) {
return { can: true };
}

return {
can: false,
reason: "Unauthorized",
};
},
};
import { AccessControlProvider } from "@refinedev/core";

export const accessControlProvider: AccessControlProvider = {
can: async ({ resource, action, params }) => {
console.log(resource); // products, orders, etc.
console.log(action); // list, edit, delete, etc.
console.log(params); // { id: 1 }, { id: 2 }, etc.

if (meetSomeCondition) {
return { can: true };
}

return {
can: false,
reason: "Unauthorized",
};
},
};
Source (https://refine.dev/docs/guides-concepts/authorization/#access-control-provider) Command Palette The refine-kbar package also uses these actions to create default actions:
`refine-kbar` uses your resources to create default actions. Which includes; `list`, `create`, `edit`, `show` and `delete`. It will hide the current action of the page you are in.
`refine-kbar` uses your resources to create default actions. Which includes; `list`, `create`, `edit`, `show` and `delete`. It will hide the current action of the page you are in.
Source (https://refine.dev/docs/packages/command-palette/#actions) These hooks and providers ensure that the actions are consistently referenced and used throughout your Refine application. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------