BilimWay / firestore.rules
musabek77's picture
Deploy to Hugging Face Spaces with corrected permissions
99ddd4c
Raw History Blame Contribute Delete
5.2 kB
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
// Global safety net: default deny
match /{document=**} {
allow read, write: if false;
}
// Matchmaking and active chess duels
match /chess_duels/{duelId} {
allow read: if request.auth != null;
allow create: if request.auth != null;
// Allow updates if user is authenticated and part of the duel
allow update: if request.auth != null && (
resource.data.playerWhite.uid == request.auth.uid ||
resource.data.playerBlack == null ||
resource.data.playerBlack.uid == request.auth.uid
);
allow delete: if false;
}
// Persistent User Profiles
match /users/{userId} {
allow read, write: if request.auth != null && (
request.auth.uid == userId ||
request.auth.token.email.matches("(?i)^musabekqurbonov89@gmail\\.com$") ||
request.auth.token.email.matches("(?i)^musabekqurbonov10@gmail\\.com$")
);
}
// Payment claims/proofs for premium subscriptions activation
match /payment_claims/{claimId} {
// Allow administrators to manage payment claims
allow read, write: if request.auth != null && (
request.auth.token.email.matches("(?i)^musabekqurbonov89@gmail\\.com$") ||
request.auth.token.email.matches("(?i)^musabekqurbonov10@gmail\\.com$")
);
// Allow authenticated users to create a payment claim, and view their own claims
allow create: if request.auth != null;
allow get, list: if request.auth != null && (
resource.data.userId == request.auth.uid ||
request.auth.token.email.matches("(?i)^musabekqurbonov89@gmail\\.com$") ||
request.auth.token.email.matches("(?i)^musabekqurbonov10@gmail\\.com$")
);
}
// Password Reset verification codes - permits access without signup so users can verify resets
match /passwordResetCodes/{email} {
allow get, create, update: if true;
allow delete: if false;
}
// Auth status records for unauthenticated password changes
match /users_auth_status/{email} {
allow get, create, update: if true;
allow delete: if false;
}
// Simulated transaction logs
match /payments/{paymentId} {
allow create: if true;
allow read: if request.auth != null;
}
// Interactive Grammatika Kutubxonasi custom added books collection
match /library_books/{bookId} {
allow read: if true;
allow create, update, delete: if request.auth != null && (
request.auth.token.email.matches("(?i)^musabekqurbonov89@gmail\\.com$") ||
request.auth.token.email.matches("(?i)^musabekqurbonov10@gmail\\.com$")
);
}
// Online Lessons videos collection
match /online_lessons/{lessonId} {
allow read: if true;
allow create, delete: if request.auth != null && (
request.auth.token.email.matches("(?i)^musabekqurbonov89@gmail\\.com$") ||
request.auth.token.email.matches("(?i)^musabekqurbonov10@gmail\\.com$")
);
allow update: if request.auth != null && (
request.auth.token.email.matches("(?i)^musabekqurbonov89@gmail\\.com$") ||
request.auth.token.email.matches("(?i)^musabekqurbonov10@gmail\\.com$") ||
(request.resource.data.diff(resource.data).affectedKeys().hasOnly(['views', 'likes', 'likesCount', 'commentsCount', 'thumbnailUrl', 'title', 'videoUrl', 'createdAt']))
);
// Comments subcollection
match /comments/{commentId} {
allow read: if request.auth != null;
allow create: if request.auth != null;
allow delete: if request.auth != null && (
resource.data.userId == request.auth.uid ||
request.auth.token.email.matches("(?i)^musabekqurbonov(89|10)@gmail\\.com$")
);
}
}
// Admin dashboard news/announcements collection
match /news/{newsId} {
allow read: if true;
allow create, update, delete: if request.auth != null && (
request.auth.token.email.matches("(?i)^musabekqurbonov89@gmail\\.com$") ||
request.auth.token.email.matches("(?i)^musabekqurbonov10@gmail\\.com$")
);
}
// Student lesson study notes matching firebase-blueprint.json config
match /lesson_notes/{noteId} {
allow get: if request.auth != null;
allow list: if request.auth != null && (
resource.data.userId == request.auth.uid ||
request.auth.token.email.matches("(?i)^musabekqurbonov(89|10)@gmail\\.com$")
);
allow create: if request.auth != null && (
request.resource.data.userId == request.auth.uid ||
request.auth.token.email.matches("(?i)^musabekqurbonov(89|10)@gmail\\.com$")
);
allow update: if request.auth != null && (
resource.data.userId == request.auth.uid ||
request.auth.token.email.matches("(?i)^musabekqurbonov(89|10)@gmail\\.com$")
);
allow delete: if request.auth != null && (
resource.data.userId == request.auth.uid ||
request.auth.token.email.matches("(?i)^musabekqurbonov(89|10)@gmail\\.com$")
);
}
}
}