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
getUserPermission
function. See also getUserPermission.operates: TableOperate[]
Operations that require permission check. It can be
read
,update
ordelete
. For each opeartion, the program will use the return value ofgetUserPermission
and build where clauses to filter the records.For
read
operation, the result will only contain the records that the user has permission to. Forupdate
anddelete
operations, the count of affected row is expected to be zero if the user has no permission to operate the record.If
read
is not included inoperates
, butupdate
ordelete
requires permission check. The records of response data ofread
operation likeall
,paginate
,show
will be appended with a propertyforbid
to 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 beequal
orinclude
.equal
: The return value ofgetUserPermission
function should be equal to the value of the column(s).include
: The return value ofgetUserPermission
function should be included in the value of the column(s).
For example, if the return value of
getUserPermission
is{username: 'admin', status: 1}
, the value of the columnusername
isadmin;super;
and the value of the columnstatus
is1
, the permission check will be failed ifmethod
isequal
. But it will be passed ifmethod
isinclude
.