I'm developing an admin dashboard with different areas, where different users may have different permissions. For example:
- News
- John: edit, view, add, remove;
- Carlos: edit, view;
- Mario: --;
- Support
- John: view;
- Carlos: edit, view;
- Mario: edit, view, add, remove;
The way I control this permission is via JSON array, containing each area and list of permission. I save this in my MySql database (serializing first) and also on the localStorage. This way I can check on the frontend but also make a final validation on the server side, via PHP.
JSON example:
{
"area": "news",
"permission": [
{"field": "access", "value": true},
{"field": "read", "value": true},
{"field": "edit", "value": true},
{"field": "add", "value": true},
{"field": "remove", "value": true}
]
},
{
"area": "support",
"permission": [
{"field": "access", "value": true},
{"field": "read", "value": true},
{"field": "edit", "value": false},
{"field": "add", "value": false},
{"field": "remove", "value": false}
]
},
...
I'm with doubts about this system because, first, I never did anything like this and didn't found any example, so I don't know if this is the proper way to do this. Also, I'm storing this as JSON because there are admin users who need to edit (with checkbox) this permissions, so it's easier to display this on the frontend.
But I'm very open to change this method based on other criterias you think it's better. I just want to have it security first and also easy to maintain.