I want to give .write
permission to posts
' node for admins/moderators only. But for its two attributes stars
and starCount
any authenticated/valid user can write.
i.e I want to give .write
permission to two nodes(stars and starCount) to every valid user. How to achieve this?
My current database rules:
{
"rules": {
"users":{
"$uid":{
".read":"auth.uid === $uid",
".write":"auth.uid === $uid",
".validate": "!data.exists() && newData.hasChildren(['id','photoUrl','role','username']) && auth.uid === $uid"
}
},
"posts":{
"$post":{
".read":"auth.uid != null",
"stars":{
".write":"auth.uid != null"
},
"starCount":{
".write":"auth.uid != null",
},
"author":{
".write":"auth.token.role.matches(/moderator$/)"
},
"approvedBy":{
".write":"auth.token.role.matches(/moderator$/)"
},
"body":{
".write":"auth.token.role.matches(/moderator$/)"
},
"commentcount":{
".write":"auth.token.role.matches(/moderator$/)"
},
"title":{
".write":"auth.token.role.matches(/moderator$/)"
},
"timeStamp":{
".write":"auth.token.role.matches(/moderator$/)"
},
"url":{
".write":"auth.token.role.matches(/moderator$/)"
},
"uid":{
".write":"auth.token.role.matches(/moderator$/)"
},
"url_profile_pic":{
".write":"auth.token.role.matches(/moderator$/)"
}
}
Database Schema Image: