You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Default policies (`'*': 'somePolicy'`) will not work by default for update requests. See *Usage:Policies are not applied on custom actions for updates (PATCH method)* for details on how to fix it.
20
21
- Being a set of blueprints this only works if `sails.config.blueprints.rest` is set to true (is it by default)
21
22
-`sails.config.blueprints.pluralize` will be set to true to match the JSON API specification
22
23
- Default responses will be overridden to respond with valid JSON API errors
@@ -47,6 +48,29 @@ As shown in [tests/dummy/api/controllers/UserController.js:24](https://github.co
47
48
-`destroyOneRecord` DELETE /{model}
48
49
-`updateOneRecord` PATCH /{model}/{id}
49
50
51
+
## Policies are not applied on custom actions for updates (PATCH method)
52
+
53
+
By default, due to the fact updates are handled with PUT methods and not PATCH methods in sails, *sails-json-api-blueprints* have to inject a route redirecting all incoming PATCH request to the update action. This is transparent for the user, but this means requests do no go though default policies if any.
54
+
55
+
To fix this, create a new route in `config/routes.js`:
56
+
57
+
````
58
+
'PATCH /api/:model/:id': {
59
+
controller: 'App', // replace with an actual controller
60
+
action: 'update' // This can be any name
61
+
}
62
+
````
63
+
64
+
Then in `AppController.js`, add the following `update` method:
65
+
66
+
````
67
+
update: function(req, res) {
68
+
return JsonApiService.updateMethod(req, res);
69
+
}
70
+
````
71
+
72
+
This way you are guaranteed incoming requests go through default policies before being redirected to the update blueprint.
73
+
50
74
## Data validation
51
75
52
76
This module is compatible with default Sails.js waterline validations and *sails-hook-validation*. It will produce a JSON API error compliant object.
0 commit comments