Server Options #
Options available within @easycrud/server for JSON Table Schema:
export type TableOperate = 'read' | 'create' | 'update' | 'delete';
interface Permission {
/**
* The name of the columns where values are used for permission check.
*/
column: string | string[];
/**
* Operations that require permission check.
*/
operates: TableOperate[];
/**
* The method of the permission check.
*/
method?: 'equal' | 'include'
}
export interface TableOptions extends BaseTableOptions {
/**
* The options for configuring table-level permissions.
*/
tablePermission?: Permission;
/**
* The options for configuring row-level permissions.
*/
rowPermission?: Permission;
}
Permissions #
Table Permission #
Row Permission #
Row Permission means that users can only operate the records of the table that they have permission to. This feature configured by rowPermission option of the table schemas.
// Example of a table schema
{
// ...
"options": {
"rowPermission": {
"column": "username",
"operates": ["read", "update", "delete"]
}
}
}
column: string | string[]The name of the columns where values are used for permission check. It can be a string or an array of strings. The program retrives the value of the column(s) from rows to compare with the return value of
getUserPermissionfunction. See also getUserPermission.operates: TableOperate[]Operations that require permission check. It can be
read,updateordelete. For each opeartion, the program will use the return value ofgetUserPermissionand build where clauses to filter the records.For
readoperation, the result will only contain the records that the user has permission to. Forupdateanddeleteoperations, the count of affected row is expected to be zero if the user has no permission to operate the record.If
readis not included inoperates, butupdateordeleterequires permission check. The records of response data ofreadoperation likeall,paginate,showwill be appended with a propertyforbidto indicate whether the user has permission to operate the record.json{ "forbid": { "update": false, "delete": true } }method?: 'equal' | 'include'The method of the permission check. Default is
equal. It can beequalorinclude.equal: The return value ofgetUserPermissionfunction should be equal to the value of the column(s).include: The return value ofgetUserPermissionfunction should be included in the value of the column(s).
For example, if the return value of
getUserPermissionis{username: 'admin', status: 1}, the value of the columnusernameisadmin;super;and the value of the columnstatusis1, the permission check will be failed ifmethodisequal. But it will be passed ifmethodisinclude.
EASYCRUD