Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add role template configuration overwriting #10

Open
gabipetrovay opened this issue Sep 5, 2013 · 3 comments
Open

Add role template configuration overwriting #10

gabipetrovay opened this issue Sep 5, 2013 · 3 comments

Comments

@gabipetrovay
Copy link
Contributor

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:

  • when a key starts with !, regardless of its value, this key must be removed from the template
  • otherwise (no !)
    • if the value is a simple value or an Array (but not a object), or an Object with overwrite: true, this value overrides the value in the initial template.
    • if the value is an Object (but not an Array) with no overwrite options (or set to false) the merging recurses into this object. And the same story from the beginning ...
@lucaboieru
Copy link
Contributor

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
Copy link
Contributor Author

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:

  • default: basic key values only
  • !: delete
  • "overwrite": true: stop recursion and replace the entire object.

@ghost ghost assigned ottiker Sep 25, 2013
@gabipetrovay
Copy link
Contributor Author

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

@ottiker ottiker removed their assignment Aug 26, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants