0
votes

I couldn't find a way to getting build-in get function in Rules.

I tried to make a simple pipeline to call 3 functions:

isAllowedToCRUD(getClubData(getEventData(eventId).club_id).id)

but in isAllowedToCRUD I getting below error:

Error running simulation — Error: simulator.rules line [], column []. Function not found error: Name: [get].; Error: Invalid argument provided to call. Function: [get], Argument: ["||invalid_argument||"] (viewing outdated simulation)

rules:

 service cloud.firestore {

   match /databases/{database}/documents {

      function isAllowedToCRUD(club_id){
        
        return IsUserIdExistsInClubs(request.auth.uid).club_id == club_id 
    }

    function getClubData(clubId){
        return get(/databases/$(database)/documents/clubs/$(clubId))
    }

   function IsUserIdExistsInClubs(clubUserId){
    
    // Getting error here!
    let personInCharge = get(/databases/$(database)/documents/persons_in_charge/$(clubUserId));
    return personInCharge.data
}

      match /events/{eventId} {

        allow read, list: if true;
  
          allow write,create, update, delete: if 

          isAllowedToCRUD(getClubData(getEventData(eventId).club_id).id)

        }
   }

Any Idea?

1

1 Answers

0
votes

You know guys, sometime you need to get some fresh air to retain your logical thinking!

There is no way to check data while that is not existing yet!

I changed my code to:

 function isAllowedToCRUD(club_id){
    let checkClubId = IsUserIdExistsInClubs(request.auth.uid).club_id;
     return checkClubId == club_id;
}

 match /events/{eventId} {
  allow read, list: if true;
  allow create,write, update, delete: if isAllowedToCRUD(request.resource.data.club_id);
  
 
}