rules_version = '2'; service cloud.firestore { match /databases/{database}/documents { function isSignedIn() { return request.auth != null; } function isOwner(userId) { return isSignedIn() && request.auth.uid == userId; } function reservationCreateIsValid() { return request.resource.data.userId == request.auth.uid && request.resource.data.userEmail is string && request.resource.data.officeId is string && request.resource.data.officeName is string && request.resource.data.date is string && request.resource.data.startTime is string && request.resource.data.endTime is string && request.resource.data.status == 'active'; } function reservationUpdateIsValid() { return request.resource.data.userId == resource.data.userId && request.resource.data.officeId == resource.data.officeId && request.resource.data.officeName == resource.data.officeName && request.resource.data.userEmail == resource.data.userEmail && request.resource.data.date == resource.data.date && request.resource.data.startTime == resource.data.startTime && request.resource.data.endTime == resource.data.endTime && request.resource.data.status in ['active', 'completed', 'cancelled']; } match /users/{userId} { allow create: if isOwner(userId); allow read: if isOwner(userId); allow update: if isOwner(userId); allow delete: if false; } match /users/{userId}/favorites/{officeId} { allow create: if isOwner(userId) && request.resource.data.officeId == officeId; allow read: if isOwner(userId); allow delete: if isOwner(userId); allow update: if false; } match /offices/{officeId} { allow read: if isSignedIn(); allow write: if false; } match /reservations/{reservationId} { allow create: if isSignedIn() && reservationCreateIsValid(); allow read: if isOwner(resource.data.userId); allow update: if isOwner(resource.data.userId) && reservationUpdateIsValid(); allow delete: if false; } match /reservationLocks/{lockId} { allow read: if isSignedIn(); allow create: if isSignedIn() && request.resource.data.userId == request.auth.uid && request.resource.data.officeId is string && request.resource.data.date is string && request.resource.data.time is string && request.resource.data.reservationId is string; allow delete: if isOwner(resource.data.userId); allow update: if false; } match /{document=**} { allow read, write: if false; } } }