I am building services integration for this module, and it would be useful to be able to specify separate access control for viewing a variable and for setting it. Patch to follow introduces an 'access callback' key in the variable info array which takes an op ('view' or 'edit') as the first argument. I have tried to keep the API intact, so if you do not specify an access callback, the default behavior is as it was, and variable_access() defaults to using the 'edit' op -- there's a new function: variable_access_op() to do the op-specific check.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | 2132781-3-variable-access-op.patch | 5.76 KB | wodenx |
| #1 | 2132781-variable-access-op.patch | 5.71 KB | wodenx |
Comments
Comment #1
wodenx commentedComment #2
jose reyero commentedThe patch looks good, just two minor issues:
- Following the example of other Drupal access callbacks, we should move the $op value to the second place with some default ('edit'?) so it becomes optional.
- Better name for the new API function (variable_access_op), maybe 'variable_check_access' or something more meaningful, and use that one from now on for everything, keeping the old one only for backwards compatibility.
Comment #3
wodenx commentedNot sure about this - hook_node_access() seems to be an anomaly in this respect. For example, entity api puts the $op in the first position:
As does hook_field_access():
Renaming the funciton makes sense - have done so in the attached patch.
Comment #4
jose reyero commentedOk about the order of parameters, still some issues:
- Latest patch seems to be an inter-diff, please send full patch.
- Somehow this 'services_variable_access' function slipped in:
- Are we removing the 'group' access feature? That one should stay just for backwards compatibility. Maybe we can just add-in group defaults, and then check the array only once. I mean
About the tests, we need a test for both cases ('edit' and 'view') (it may be a variable in variable_example).