From aca0452f8c4099a7a43a277111a7953dbc6186eb Mon Sep 17 00:00:00 2001 From: Pascal Luther Date: Tue, 22 Dec 2020 18:18:05 +0100 Subject: [PATCH] test: Updated files --- .gitignore | 2 -- test/firestore.rules | 25 +++++++++++++++++++++++++ test/rulez.config.js | 6 ++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 test/rulez.config.js 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", +}