In the database I have a field called resources, in it I keep the permissions of a user, in the format Json:
[
{
"rota":"reserva",
"sref":"oQueFazer",
"ordem":"1",
"recursos":[
"index",
"show",
"store",
"update"
],
"descricao":"Reservar",
"controller":"ReservasController"
},
{
"rota":"reserva",
"sref":"oQueFazer",
"ordem":"2",
"recursos":[
"index",
"show"
],
"descricao":"Reservas",
"controller":"ReservasController"
},
{
"rota":"usuario",
"sref":"oQueFazer",
"ordem":"3",
"recursos":[
"index",
"show"
],
"descricao":"Usuários",
"controller":"UsuariosController"
},
{
"rota":"feriado",
"sref":"home.feriado",
"ordem":"4",
"recursos":[
"index",
"show",
"store",
"update",
"destroy"
],
"descricao":"Feriados",
"controller":"FeriadosController"
},
{
"rota":"sala",
"sref":"home.sala",
"ordem":"5",
"recursos":[
"index",
"show"
],
"descricao":"Salas",
"controller":"SalasController"
}
]
When I run the query below, it gives me the correct return of which user is allowed:
SELECT recursos from perfis
WHERE
JSON_CONTAINS(recursos, '{"controller": "FeriadosController"}');
Almost there, with select
up I get the record line I'm looking for, the problem is that it shows me the whole json collection that is in the resources field. (Of course he was going to do this, that's what I asked to run).
So for it to bring me the permissions that are allowed for a user in a given controller, I made the select below:
SELECT JSON_EXTRACT(recursos, '$[0].recursos') permite from perfis
WHERE
JSON_CONTAINS(recursos, '{"controller": "FeriadosController"}');
And the return was:
["index", "show", "store", "update"]
That is, everything OK, it shows the permissions that the user has in a certain controller, THE PROBLEM is that it show the permissions of the JSON collection of the first line '$[0].recursos'
but that's not quite what I'm wanting, I want to return :
["index", "show", "store", "update", "destroy"]
What is the permission that the user has for the controller FeriadosController
So, I'm getting the controller to scan json, but I'm not able to show the part of json that was searched, does anyone have a solution for that, jpa went through this?