46 lines
1.6 KiB
Plaintext
46 lines
1.6 KiB
Plaintext
rules_version = '2';
|
|
service cloud.firestore {
|
|
match /databases/{database}/documents {
|
|
|
|
// Hilfsfunktionen
|
|
function isAuthenticated() {
|
|
return request.auth != null;
|
|
}
|
|
|
|
function isAdmin() {
|
|
return request.auth != null && (
|
|
request.auth.token.admin == true ||
|
|
request.auth.token.email == 'nicolas@gruber.info'
|
|
);
|
|
}
|
|
|
|
function isAuthorOrAdmin() {
|
|
return isAuthenticated() && (
|
|
(resource.data.author_uid != null && resource.data.author_uid == request.auth.uid) ||
|
|
(resource.data.authorUid != null && resource.data.authorUid == request.auth.uid) ||
|
|
isAdmin()
|
|
);
|
|
}
|
|
|
|
// Öffentliche Sammlungen: News, Mängel (Issues) & Ideen (CitizensForum)
|
|
match /{collection}/{document=**} {
|
|
// Jeder darf News, Mängel & Ideen öffentlich lesen
|
|
allow read: if collection in ['News', 'Issues', 'CitizensForum'];
|
|
|
|
// Erstellen darf jeder freigeschaltete/angemeldete Nutzer
|
|
allow create: if isAuthenticated() && collection in ['News', 'Issues', 'CitizensForum'];
|
|
|
|
// Ändern/Löschen nur der eigene Autor oder Admin
|
|
allow update, delete: if isAuthorOrAdmin() && collection in ['News', 'Issues', 'CitizensForum'];
|
|
}
|
|
|
|
// Kontakt-Nachrichten: Geschützt (nur registrierte Nutzer senden, Lesen nur Admin & Autor)
|
|
match /ContactMessages/{document} {
|
|
// Senden nur für registrierte Nutzer (nicht-anonym)
|
|
allow create: if isAuthenticated() && request.auth.token.firebase.sign_in_provider != 'anonymous';
|
|
// Lesen, Ändern und Löschen für Admin und Autor
|
|
allow read, update, delete: if isAuthorOrAdmin();
|
|
}
|
|
}
|
|
}
|