{
  "rules": {
    ///---backend-manager---///
    ///---version=0.0.0---///

    // Sessions rules
    "sessions": {
      ".read": false,
      ".write": false,
			"$room": {
        ".read": "
        	(auth.uid != null && query.equalTo == auth.uid)
        ",
        ".write": false,
        ".indexOn": ["uid"],
        "$id": {
          ".read": "
          	// Allowed if user is authenticated AND is the owner of the doc
          	(auth != null && auth.uid == data.child('uid').val())
            // Allowed if uid is equal to the doc id [LEGACY FOR SOMIIBO]
            || (auth != null && auth.uid == $id)
          	// Allowed if user is not authenticated AND is the doc has no owner
          	|| (auth == null && (data.child('uid').val() == ''))
          ",
          ".write": "
          	// Allowed if the user is authenticated AND is the owner of the existing doc
          	(auth != null && auth.uid == data.child('uid').val())
          	// Allowed if the user is authenticated AND is the owner of the new doc
          	|| (auth != null && auth.uid == newData.child('uid').val())
            // Allowed if the user is authenticated AND is the owner of the existing doc
          	|| (auth != null && auth.uid == data.child('uid').val())
            // Allowed if uid is equal to the doc id [LEGACY FOR SOMIIBO]
            || (auth != null && auth.uid == $id)
            // Allowed if the existing doc has no owner
          	|| (data.child('uid').val() == '')
          	// Allowed if the new doc has no owner
          	|| (newData.child('uid').val() == '')
            // Allowed if it's a delete
          	|| (!newData.exists())
          ",
      	}
      }
    },
    "gatherings": {
      ".read": false,
      ".write": false,
			"$room": {
        ".read": "
        	(auth.uid != null && query.equalTo == auth.uid)
        ",
        ".write": false,
        ".indexOn": ["uid"],
        "$id": {
          ".read": "
          	// Allowed if user is authenticated AND is the owner of the doc
          	(auth != null && auth.uid == data.child('uid').val())
            // Allowed if uid is equal to the doc id [LEGACY FOR SOMIIBO]
            || (auth != null && auth.uid == $id)
          	// Allowed if user is not authenticated AND is the doc has no owner
          	|| (auth == null && (data.child('uid').val() == ''))
          ",
          ".write": "
          	// Allowed if the user is authenticated AND is the owner of the existing doc
          	(auth != null && auth.uid == data.child('uid').val())
          	// Allowed if the user is authenticated AND is the owner of the new doc
          	|| (auth != null && auth.uid == newData.child('uid').val())
            // Allowed if the user is authenticated AND is the owner of the existing doc
          	|| (auth != null && auth.uid == data.child('uid').val())
            // Allowed if uid is equal to the doc id [LEGACY FOR SOMIIBO]
            || (auth != null && auth.uid == $id)
            // Allowed if the existing doc has no owner
          	|| (data.child('uid').val() == '')
          	// Allowed if the new doc has no owner
          	|| (newData.child('uid').val() == '')
            // Allowed if it's a delete
          	|| (!newData.exists())
          ",
      	}
      }
    },
    ///---------end---------///
  }
}
