Custom filters for Records
Permissions filters for Records are set up under the permissions
field in the parent Form. There are the 4 basics type of permissions and also a unicity filter:
permissions.canCreateRecords
permissions.canSeeRecords
permissions.canUpdateRecords
permissions.canDeleteRecords
permissions.recordsUnicity
CanCreateRecords
The create permission works the same as other Permissions in Oort. This property is an array of Role IDs which have the permission to create a record.
E. g. : With canCreateRecords: [5fc7a0c57b24a13a92f998d0, 5fc7a254c2ec093bec0e1c13]
, I can create records if I have at least one of the two roles In my user’s roles list.
CanSeeRecords (CanUpdateRecords, CanDeleteRecords)
The read permission filter works the same way as the update and the delete permission. The canSeeRecords
property is an array of objects containing two fields: role: ObjectId
and access: Object
.
canSeeRecords: [
{
role: ObjectId
access: {
condition: String,
rules: [
{
field: String,
operator: Enum,
value: String
}]
}
}]
Between each element of the canSeeRecords
array, there is an implicit or logic. There is also an implicit and between role
and access
. It means that we will define conditions for each role separately.
RecordsUnicity
The recordsUnicity
property define rules which should help to find a unique record per user. It works exactly the same way as the access
field in canSeeRecords
:
recordsUnicity: {
condition: String,
rules: [
{
field: String,
operator: Enum,
value: String
}]
}
Access
The access object goal is to define a filter that will be then converted in a mongo query in the back-end. For this purpose, you must first specify a condition
that will be used between each of the rules
. At the moment, you have only two choices: or / and.
Rules
A rule is divide into three parts: a field
, an operator
and a value
.
Operator
It is the operator used to link the field
and the value
. At the moment the following are supported:
Operators | Description |
`=`, `!=` | Query records with `field` matching/not matching exactly `value`. |
`<`, `<=`, `>`, `>=` | Used when `field` type is number or date. Query records with `field` matching de condition with `value`. |
`in`, `not in` | Query records with `field` in/not in the array `value`. |
`contains` | Query records with fields corresponding to the regex value. |
`match` | Used when `field` is an array and `value` an object. Query records with at least one element of the `field` array is matching with conditions in `value`. E. g. :
|
Value
It’s a string defining the value we use to compare with the corresponding field
. The string can be directly the value to use or a code to fetch a value from the database.
JSON.stringify()
method.Currently there is only one code supported:
Code | Value |
---|---|
$$own | Current user (type: User) with all his fields populated. |
We can then access embedded values using dots in the same way as for the field
attribute.
E. g. : $$own.positionAttributes.value
Then, it is possible to apply some filters to these value using again another code:
Code | Action |
$$where:<field>:<value> | Used on an array, it will filter this array to keep only elements which have a certain <field> equals to a certain <value>. If there is only one element corresponding to this filter, it returns the element itself and not an array with a single element. info It can then be chained with nested field access. method. $$own.positionAttributes.$$where:category:6034e020bcffc3001f7003b0.value Returns fields value from positionAttributes from the current user where the category is equals to a specific ObjectId. |