diff --git a/.gitignore b/.gitignore index b8d9ddb..517a04c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ node_modules -rules/* -rulez.config.js firebase.json \ No newline at end of file diff --git a/test/firestore.rules b/test/firestore.rules index bba9488..421d615 100644 --- a/test/firestore.rules +++ b/test/firestore.rules @@ -2,6 +2,31 @@ rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { + + //////////////////////////////////////////////////////// + /////////// Local Functions: + //////////////////////////////////////////////////////// + function isModeratorOrMores() { + return request.auth.token.role == 'moderator' || + request.auth.token.role == 'admin' || + request.auth.token.role == 'superadmin' + } + + function isAdminOrMore() { + return request.auth.token.role == 'admin' || + request.auth.token.role == 'superadmin' + } + + function isSuperadmin() { + return request.auth.token.role == 'superadmin' + } + + //////////////////////////////////////////////////////// + /////////// Getters: + //////////////////////////////////////////////////////// + function getCurrentUser() { + return get(/databases/$(database)/documents/users/$(authUserEmail())).data + } //////////////////////////////////////////////////////// /////////// Allow all for admins: diff --git a/test/rulez.config.js b/test/rulez.config.js new file mode 100644 index 0000000..08938b7 --- /dev/null +++ b/test/rulez.config.js @@ -0,0 +1,6 @@ +module.exports = { + // Enables helper functions as specified below + helpers: true, + rules_version: '2', + custom_helpers_folder: "helpers", +}