Open gabipetrovay opened 11 years ago
I don't get it... What is this supposed to do in the end? Why do we need it? (maybe you can give me an example where it can be used... I saw a "recursive merge" function in many other modules). Thanks!
Imagine you have the "Articles" template (like we do in CCTool). Imagine now that the application defines two roles (like we also do in CCTool). One role can only view the template data. The other can also write data for it. We currently solve the access rights by defining an additional template (articleReadTemplate
and articleWriteTemplate
) in order to give the 2nd template a different HTML.
Imagine if we had now only 1 template articleTemplate
with 2 roles in it. Currently this structure looks like (how data/templates.js
builds it):
{
"roles": {
"caller_role_object_id": {
"access": "r"
},
"admin_role_object_id": {
"access": "crud"
}
}
}
with the difference that the two roles are currently separated in the two different templates. The access
means the operations this role can performs: c
for create, r
for read, u
for update, d
for delete.
But now assume the roles in a template look like:
{
"roles": {
"caller_role_object_id": {
"access": "crud",
"config": {
"html": "path_that_will_overwrite_default.html"
"!order": "remove the order, the value of this key does not matter",
"label": {
"de": "New German label only"
},
"schema": {
"price": {
"overwrite": true,
"type": "string",
"label": {
"ro": "Preț"
}
}
}
}
}
}
}
The examples in the snippet above give you the different ways to overwrite:
!
: delete"overwrite": true
: stop recursion and replace the entire object.I have started this in CC-Tooland you have a sample here.
There are still problems with schema overwriting because the cached template schema is flat and the role schema is hierarchic.
Also the !
and overwrite
are not supported yet
Each role should be able to define/overwrite its own template configuration. Add this to a
config
key in the role object. Theconfig
value is an object and this object is recursively merged into the template configuration as follows:!
, regardless of its value, this key must be removed from the template!
)overwrite: true
, this value overrides the value in the initial template.overwrite
options (or set tofalse
) the merging recurses into this object. And the same story from the beginning ...