How can I compare 2 record for permission (Firestore-Rule)Is it possible to set storage rules using firestore of Firebase?Firestore security rule get() not workingFirestore security rules for `list` requestFirestore security rules with spaces in pathValidate map keys in Firestore rulesFirestore rule to read collectionFirestore Rules Simulator - Resource undefinedDoes firestore rule simulator account for existing documents actual collections?Firestore create security rule not behaving as expectedDynamic Firestore rules?
How do I get a cleat that's stuck in a pedal, detached from the shoe, out?
The term for the person/group a political party aligns themselves with to appear concerned about the general public
Is the capacitor drawn or wired wrongly?
Coding Challenge Solution - Good Range
Why would Lupin kill Pettigrew?
Are academic associations obliged to comply with the US government?
Order by does not work as I expect
Why is Colorado so different politically from nearby states?
Why does the UK have more political parties than the US?
Can The Malloreon be read without first reading The Belgariad?
How can a single Member of the House block a Congressional bill?
TV show or movie: Diseased people are exiled to a spaceship
What are the problems in teaching guitar via Skype?
How to properly maintain eye contact with people that have distinctive facial features?
The qvolume of an integer
Why were the Night's Watch required to be celibate?
How to write a vulnerable moment without it seeming cliche or mushy?
Does Peach's float negate shorthop knockback multipliers?
Recording the inputs of a command and producing a list of them later on
How can I offer a test ride while selling a bike?
How do I get a list of only the files (not the directories) from a package?
Bringing Food from Hometown for Out-of-Town Interview?
What is a natural deduction proof from ~(A↔B) to ~(A→B)?
How can I grammatically understand "Wir über uns"?
How can I compare 2 record for permission (Firestore-Rule)
Is it possible to set storage rules using firestore of Firebase?Firestore security rule get() not workingFirestore security rules for `list` requestFirestore security rules with spaces in pathValidate map keys in Firestore rulesFirestore rule to read collectionFirestore Rules Simulator - Resource undefinedDoes firestore rule simulator account for existing documents actual collections?Firestore create security rule not behaving as expectedDynamic Firestore rules?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm defining rules for my firestore database and i stuck there.
I have an post collection and an userProfile collection. If a user banned you you can't reach his post. You can reach which user shared the post under 'document/user'
So I try this command but not worked. When i simulate it every one get reject.
match /posts/currentDocument
allow read: if !exists(
/databases/$(database)/documents/userProfile/$(request.auth.uid)/banned/
$(/databases/$(database)/documents/posts/$(currentDocument)/user)
)
So I wantto accept everyone's read request except banned users.
firebase google-cloud-firestore firebase-security-rules
add a comment |
I'm defining rules for my firestore database and i stuck there.
I have an post collection and an userProfile collection. If a user banned you you can't reach his post. You can reach which user shared the post under 'document/user'
So I try this command but not worked. When i simulate it every one get reject.
match /posts/currentDocument
allow read: if !exists(
/databases/$(database)/documents/userProfile/$(request.auth.uid)/banned/
$(/databases/$(database)/documents/posts/$(currentDocument)/user)
)
So I wantto accept everyone's read request except banned users.
firebase google-cloud-firestore firebase-security-rules
add a comment |
I'm defining rules for my firestore database and i stuck there.
I have an post collection and an userProfile collection. If a user banned you you can't reach his post. You can reach which user shared the post under 'document/user'
So I try this command but not worked. When i simulate it every one get reject.
match /posts/currentDocument
allow read: if !exists(
/databases/$(database)/documents/userProfile/$(request.auth.uid)/banned/
$(/databases/$(database)/documents/posts/$(currentDocument)/user)
)
So I wantto accept everyone's read request except banned users.
firebase google-cloud-firestore firebase-security-rules
I'm defining rules for my firestore database and i stuck there.
I have an post collection and an userProfile collection. If a user banned you you can't reach his post. You can reach which user shared the post under 'document/user'
So I try this command but not worked. When i simulate it every one get reject.
match /posts/currentDocument
allow read: if !exists(
/databases/$(database)/documents/userProfile/$(request.auth.uid)/banned/
$(/databases/$(database)/documents/posts/$(currentDocument)/user)
)
So I wantto accept everyone's read request except banned users.
firebase google-cloud-firestore firebase-security-rules
firebase google-cloud-firestore firebase-security-rules
edited Mar 24 at 14:35
Frank van Puffelen
255k32410436
255k32410436
asked Mar 24 at 10:45
Uğur CanbulatUğur Canbulat
66
66
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
It depends on how you're trying to read from the collection.
If you're trying to read a specific document (e.g. /posts/post123
) that is not from a banned user, the read should work. And if you're trying to read a specific document from a banned user, the read should be rejected.
If you're trying to read the entire /posts
collection, that will indeed fail with the above security rules. The reason for that is that security rules don't filter your data; they merely ensure that the read operation only tries to read data that it's authorized for. And reading all of /posts
is not authorized, since there are certain documents that are not readable.
To read all posts from unbanned users, you'll need to attach a listener that only tried to read those documents. In pseudo-code that would be something like:
db.collection('posts').where('user', 'not in', '/bannedusers')
But this unfortunately isn't possible in Firestore since it'd require a server-side join, which would make it impossible for Firestore to meet its performance guarantees.
But say for example that you have an approval flow, where each post needs to be approved before it can be read by other users. In that case you could enforce this in your security rules with:
// anyone can read approved posts, but only the author can read unapproved posts
allow read: if resource.data.approved == true || request.auth.uid == resource.data.author
And then query for only approved posts with:
db.collection("posts").where("approved", "==", true).get()
In this last example, the security rules can validate that the query only requests posts that they have access to, so it allows the query.
For more on this, see:
- The Firestore documentation on securing queries
- The video series Getting to know Cloud Firestore, specifically the [episode on security rules](Getting to know Cloud Firestore)
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322977%2fhow-can-i-compare-2-record-for-permission-firestore-rule%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It depends on how you're trying to read from the collection.
If you're trying to read a specific document (e.g. /posts/post123
) that is not from a banned user, the read should work. And if you're trying to read a specific document from a banned user, the read should be rejected.
If you're trying to read the entire /posts
collection, that will indeed fail with the above security rules. The reason for that is that security rules don't filter your data; they merely ensure that the read operation only tries to read data that it's authorized for. And reading all of /posts
is not authorized, since there are certain documents that are not readable.
To read all posts from unbanned users, you'll need to attach a listener that only tried to read those documents. In pseudo-code that would be something like:
db.collection('posts').where('user', 'not in', '/bannedusers')
But this unfortunately isn't possible in Firestore since it'd require a server-side join, which would make it impossible for Firestore to meet its performance guarantees.
But say for example that you have an approval flow, where each post needs to be approved before it can be read by other users. In that case you could enforce this in your security rules with:
// anyone can read approved posts, but only the author can read unapproved posts
allow read: if resource.data.approved == true || request.auth.uid == resource.data.author
And then query for only approved posts with:
db.collection("posts").where("approved", "==", true).get()
In this last example, the security rules can validate that the query only requests posts that they have access to, so it allows the query.
For more on this, see:
- The Firestore documentation on securing queries
- The video series Getting to know Cloud Firestore, specifically the [episode on security rules](Getting to know Cloud Firestore)
add a comment |
It depends on how you're trying to read from the collection.
If you're trying to read a specific document (e.g. /posts/post123
) that is not from a banned user, the read should work. And if you're trying to read a specific document from a banned user, the read should be rejected.
If you're trying to read the entire /posts
collection, that will indeed fail with the above security rules. The reason for that is that security rules don't filter your data; they merely ensure that the read operation only tries to read data that it's authorized for. And reading all of /posts
is not authorized, since there are certain documents that are not readable.
To read all posts from unbanned users, you'll need to attach a listener that only tried to read those documents. In pseudo-code that would be something like:
db.collection('posts').where('user', 'not in', '/bannedusers')
But this unfortunately isn't possible in Firestore since it'd require a server-side join, which would make it impossible for Firestore to meet its performance guarantees.
But say for example that you have an approval flow, where each post needs to be approved before it can be read by other users. In that case you could enforce this in your security rules with:
// anyone can read approved posts, but only the author can read unapproved posts
allow read: if resource.data.approved == true || request.auth.uid == resource.data.author
And then query for only approved posts with:
db.collection("posts").where("approved", "==", true).get()
In this last example, the security rules can validate that the query only requests posts that they have access to, so it allows the query.
For more on this, see:
- The Firestore documentation on securing queries
- The video series Getting to know Cloud Firestore, specifically the [episode on security rules](Getting to know Cloud Firestore)
add a comment |
It depends on how you're trying to read from the collection.
If you're trying to read a specific document (e.g. /posts/post123
) that is not from a banned user, the read should work. And if you're trying to read a specific document from a banned user, the read should be rejected.
If you're trying to read the entire /posts
collection, that will indeed fail with the above security rules. The reason for that is that security rules don't filter your data; they merely ensure that the read operation only tries to read data that it's authorized for. And reading all of /posts
is not authorized, since there are certain documents that are not readable.
To read all posts from unbanned users, you'll need to attach a listener that only tried to read those documents. In pseudo-code that would be something like:
db.collection('posts').where('user', 'not in', '/bannedusers')
But this unfortunately isn't possible in Firestore since it'd require a server-side join, which would make it impossible for Firestore to meet its performance guarantees.
But say for example that you have an approval flow, where each post needs to be approved before it can be read by other users. In that case you could enforce this in your security rules with:
// anyone can read approved posts, but only the author can read unapproved posts
allow read: if resource.data.approved == true || request.auth.uid == resource.data.author
And then query for only approved posts with:
db.collection("posts").where("approved", "==", true).get()
In this last example, the security rules can validate that the query only requests posts that they have access to, so it allows the query.
For more on this, see:
- The Firestore documentation on securing queries
- The video series Getting to know Cloud Firestore, specifically the [episode on security rules](Getting to know Cloud Firestore)
It depends on how you're trying to read from the collection.
If you're trying to read a specific document (e.g. /posts/post123
) that is not from a banned user, the read should work. And if you're trying to read a specific document from a banned user, the read should be rejected.
If you're trying to read the entire /posts
collection, that will indeed fail with the above security rules. The reason for that is that security rules don't filter your data; they merely ensure that the read operation only tries to read data that it's authorized for. And reading all of /posts
is not authorized, since there are certain documents that are not readable.
To read all posts from unbanned users, you'll need to attach a listener that only tried to read those documents. In pseudo-code that would be something like:
db.collection('posts').where('user', 'not in', '/bannedusers')
But this unfortunately isn't possible in Firestore since it'd require a server-side join, which would make it impossible for Firestore to meet its performance guarantees.
But say for example that you have an approval flow, where each post needs to be approved before it can be read by other users. In that case you could enforce this in your security rules with:
// anyone can read approved posts, but only the author can read unapproved posts
allow read: if resource.data.approved == true || request.auth.uid == resource.data.author
And then query for only approved posts with:
db.collection("posts").where("approved", "==", true).get()
In this last example, the security rules can validate that the query only requests posts that they have access to, so it allows the query.
For more on this, see:
- The Firestore documentation on securing queries
- The video series Getting to know Cloud Firestore, specifically the [episode on security rules](Getting to know Cloud Firestore)
answered Mar 24 at 14:46
Frank van PuffelenFrank van Puffelen
255k32410436
255k32410436
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55322977%2fhow-can-i-compare-2-record-for-permission-firestore-rule%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown