Last active
January 20, 2016 16:32
-
-
Save rockwotj/e65f8829d514940dba2e to your computer and use it in GitHub Desktop.
Firebase bolt rules for the Weatherpics With Auth App
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Weatherpic { | |
caption: String | Null, | |
imageUrl: String, | |
uid: UserID | |
} | |
type UserID extends String; | |
path /weatherpics { | |
read() { true } | |
index() { "uid" } | |
} | |
path /weatherpics/{pic} is Weatherpic { | |
write() { accessByCurrentUser(this.uid, prior(this.uid)) } | |
} | |
accessByCurrentUser(newUid, oldUid) { auth != null && ( created(newUid, oldUid) || edited(newUid, oldUid)|| deleted(newUid, oldUid) ) } | |
created(newUid, oldUid) { newUid == auth.uid && oldUid == null } | |
edited(newUid, oldUid) { newUid == auth.uid && newUid == oldUid } | |
deleted(newUid, oldUid) { oldUid == auth.uid && newUid == null } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"rules": { | |
"weatherpics": { | |
".read": "true", | |
".indexOn": [ | |
"uid" | |
], | |
"$pic": { | |
".validate": "newData.hasChildren(['imageUrl', 'uid'])", | |
"caption": { | |
".validate": "newData.isString() || newData.val() == null" | |
}, | |
"imageUrl": { | |
".validate": "newData.isString()" | |
}, | |
"uid": { | |
".validate": "newData.isString()" | |
}, | |
"$other": { | |
".validate": "false" | |
}, | |
".write": "auth != null && (newData.child('uid').val() == auth.uid && data.child('uid').val() == null || newData.child('uid').val() == auth.uid && newData.child('uid').val() == data.child('uid').val() || data.child('uid').val() == auth.uid && newData.child('uid').val() == null)" | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment