jxmono / crud

:fork_and_knife: CRUD for mono
MIT License
0 stars 1 forks source link

Add role template configuration overwriting #10

Open gabipetrovay opened 11 years ago

gabipetrovay commented 11 years ago

Each role should be able to define/overwrite its own template configuration. Add this to a config key in the role object. The config value is an object and this object is recursively merged into the template configuration as follows:

lucaboieru commented 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!

gabipetrovay commented 11 years ago

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:

gabipetrovay commented 11 years ago

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