Skip to content

Commit f9a0eec

Browse files
committed
Add test and doc for recordHandler
1 parent f94f825 commit f9a0eec

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ These features match features in v1 (see branch "v1"):
107107
- [ ] Supports file upload from web forms (multipart/form-data)
108108
- [ ] ~~Condensed JSON output: first row contains field names~~
109109
- [x] Sanitize and validate input using callbacks
110-
- [ ] Permission system for databases, tables, columns and records
110+
- [x] Permission system for databases, tables, columns and records
111111
- [ ] Multi-tenant database layouts are supported
112112
- [x] Multi-domain CORS support for cross-domain requests
113113
- [x] Support for reading joined results from multiple tables
@@ -158,6 +158,7 @@ You can tune the middleware behavior using middleware specific configuration par
158158
- "cors.maxAge": The time that the CORS grant is valid in seconds ("1728000")
159159
- "authorization.tableHandler": Handler to implement table authorization rules ("")
160160
- "authorization.columnHandler": Handler to implement column authorization rules ("")
161+
- "authorization.recordHandler": Handler to implement record authorization filter rules ("")
161162
- "basicAuth.passwordFile": The file to read for username/password combinations (".htpasswd")
162163
- "basicAuth.realm": Message shown when asking for credentials ("Username and password required")
163164
- "firewall.reverseProxy": Set to "true" when a reverse proxy is used ("")
@@ -569,6 +570,12 @@ The above example will restrict access to the table 'license_keys' in all API ca
569570

570571
The above example will restrict access to the 'password' field from the 'users' table in all API calls.
571572

573+
'authorization.recordHandler' => function ($method, $path, $databaseName, $tableName, $columnName) {
574+
return ($tableName == 'users') ? 'filter=username,neq,admin' : '';
575+
},
576+
577+
This will disallow viewing the user records where the username is 'admin'. It allows you to add a filter to every query.
578+
572579
### Sanitizing input
573580

574581
By default all input is accepted and sent to the database. If you want to strip (certain) HTML tags before storing you may add

tests/config/base.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
return !($columnName == 'invisible');
1212
},
1313
'authorization.recordHandler' => function ($method, $path, $databaseName, $tableName) {
14-
return ($tableName == 'comments') ? 'filter=id,neq,3' : '';
14+
return ($tableName == 'comments') ? 'filter=message,neq,invisible' : '';
1515
},
1616
'sanitation.handler' => function ($method, $tableName, $column, $value) {
1717
return is_string($value) ? strip_tags($value) : $value;
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
POST /records/comments
2+
3+
{"user_id":1,"post_id":2,"message":"invisible"}
4+
===
5+
200
6+
Content-Type: application/json
7+
Content-Length: 1
8+
9+
6
10+
===
11+
GET /records/comments/6
12+
===
13+
404
14+
Content-Type: application/json
15+
Content-Length: 46
16+
17+
{"code":1003,"message":"Record '6' not found"}

0 commit comments

Comments
 (0)