How to hide/show some json fields of a struct depending on the User role? We don't really want to create x different types of our struct. Or x types of an database user or multiple (same) sql commands. Do you guys have some recommendations? Which crate fits there? On Golang we used a reflect package to compare if the field tag containts the role.
The Export example should be equal like this:
Filtering with role user:
{
"id": "1",
"name": "Jack"
}
Filtering with role hr:
{
"id": "1",
"name": "Jack",
"salary": 100000,
"boss": {
"id": "2",
"name": "John",
"salary": 120000,
"password": "pwd",
"rights": {
"create": true,
"update": true
}
}
}
Filtering with role admin:
{
"id": "1",
"name": "Jack",
"salary": 100000,
"password": "password321",
"rights": {
"create": false,
"update": false
},
"boss": {
"id": "2",
"name": "John",
"salary": 120000,
"password": "pwd",
"rights": {
"create": true,
"update": true
}
}
}
These question is similar to the question and answer asked with the language golang GOALNG :Control field visibility depending on User role but how does it look like in rust?