62 lines
2.3 KiB
Plaintext
62 lines
2.3 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 ||
|
|
exists(/databases/$(database)/documents/Admins/$(request.auth.uid)) ||
|
|
(request.auth.token.email != null && exists(/databases/$(database)/documents/Admins/$(request.auth.token.email)))
|
|
);
|
|
}
|
|
|
|
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()
|
|
);
|
|
}
|
|
|
|
// Benutzerprofile: Nutzer verwaltet eigenes Profil, Admins haben Vollzugriff
|
|
match /Users/{userId} {
|
|
allow read: if isAuthenticated() && (request.auth.uid == userId || isAdmin());
|
|
allow create, update: if isAuthenticated() && (request.auth.uid == userId || isAdmin());
|
|
allow delete: if isAdmin();
|
|
}
|
|
|
|
// Admins-Sammlung: Angemeldete Nutzer können prüfen, nur Admins schreiben
|
|
match /Admins/{adminDoc} {
|
|
allow read: if isAuthenticated();
|
|
allow write: if 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: News nur Admin; Mängel und Ideen für angemeldete Nutzer
|
|
allow create: if collection == 'News'
|
|
? isAdmin()
|
|
: (isAuthenticated() && collection in ['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();
|
|
}
|
|
}
|
|
}
|