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;








0















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.










share|improve this question






























    0















    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.










    share|improve this question


























      0












      0








      0








      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.










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 24 at 14:35









      Frank van Puffelen

      255k32410436




      255k32410436










      asked Mar 24 at 10:45









      Uğur CanbulatUğur Canbulat

      66




      66






















          1 Answer
          1






          active

          oldest

          votes


















          0














          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)





          share|improve this answer























            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
            );



            );













            draft saved

            draft discarded


















            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









            0














            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)





            share|improve this answer



























              0














              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)





              share|improve this answer

























                0












                0








                0







                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)





                share|improve this answer













                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)






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 24 at 14:46









                Frank van PuffelenFrank van Puffelen

                255k32410436




                255k32410436





























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                    Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript