feat(admin): grant full admin permissions in app and security rules to nicolas@gruber.info
This commit is contained in:
+4
-1
@@ -8,7 +8,10 @@ service cloud.firestore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isAdmin() {
|
function isAdmin() {
|
||||||
return request.auth != null && request.auth.token.admin == true;
|
return request.auth != null && (
|
||||||
|
request.auth.token.admin == true ||
|
||||||
|
request.auth.token.email == 'nicolas@gruber.info'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isAuthorOrAdmin() {
|
function isAuthorOrAdmin() {
|
||||||
|
|||||||
@@ -51,7 +51,9 @@ class InfoScreen extends StatelessWidget {
|
|||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
// Bürgerforum Access & Account Card
|
// Bürgerforum Access & Account Card
|
||||||
Card(
|
Card(
|
||||||
color: auth.isRegisteredUser
|
color: auth.isAdmin
|
||||||
|
? Colors.indigo.shade50
|
||||||
|
: auth.isRegisteredUser
|
||||||
? Colors.green.shade50
|
? Colors.green.shade50
|
||||||
: auth.isCommunityUnlocked
|
: auth.isCommunityUnlocked
|
||||||
? Colors.teal.shade50
|
? Colors.teal.shade50
|
||||||
@@ -65,12 +67,16 @@ class InfoScreen extends StatelessWidget {
|
|||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Icon(
|
Icon(
|
||||||
auth.isRegisteredUser
|
auth.isAdmin
|
||||||
|
? Icons.admin_panel_settings
|
||||||
|
: auth.isRegisteredUser
|
||||||
? Icons.account_circle
|
? Icons.account_circle
|
||||||
: auth.isCommunityUnlocked
|
: auth.isCommunityUnlocked
|
||||||
? Icons.verified_user
|
? Icons.verified_user
|
||||||
: Icons.lock_outline,
|
: Icons.lock_outline,
|
||||||
color: auth.isRegisteredUser
|
color: auth.isAdmin
|
||||||
|
? Colors.indigo.shade700
|
||||||
|
: auth.isRegisteredUser
|
||||||
? Colors.green.shade700
|
? Colors.green.shade700
|
||||||
: auth.isCommunityUnlocked
|
: auth.isCommunityUnlocked
|
||||||
? Colors.teal.shade800
|
? Colors.teal.shade800
|
||||||
@@ -83,7 +89,9 @@ class InfoScreen extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
auth.isRegisteredUser
|
auth.isAdmin
|
||||||
|
? 'Administrator'
|
||||||
|
: auth.isRegisteredUser
|
||||||
? (auth.displayName?.isNotEmpty == true
|
? (auth.displayName?.isNotEmpty == true
|
||||||
? auth.displayName!
|
? auth.displayName!
|
||||||
: 'Bürger-Konto')
|
: 'Bürger-Konto')
|
||||||
@@ -95,7 +103,9 @@ class InfoScreen extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
const SizedBox(height: 2),
|
const SizedBox(height: 2),
|
||||||
Text(
|
Text(
|
||||||
auth.isRegisteredUser
|
auth.isAdmin
|
||||||
|
? '${auth.email ?? "Angemeldet"} (Admin-Rechte aktiv)'
|
||||||
|
: auth.isRegisteredUser
|
||||||
? auth.email ?? 'Angemeldet'
|
? auth.email ?? 'Angemeldet'
|
||||||
: auth.isCommunityUnlocked
|
: auth.isCommunityUnlocked
|
||||||
? 'Mängel & Ideen freigeschaltet'
|
? 'Mängel & Ideen freigeschaltet'
|
||||||
|
|||||||
@@ -47,8 +47,17 @@ class AuthService extends ChangeNotifier {
|
|||||||
_initAuth();
|
_initAuth();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const List<String> adminEmails = [
|
||||||
|
'nicolas@gruber.info',
|
||||||
|
];
|
||||||
|
|
||||||
Future<void> _checkAdminClaim(User? user) async {
|
Future<void> _checkAdminClaim(User? user) async {
|
||||||
if (user != null && !user.isAnonymous) {
|
if (user != null && !user.isAnonymous) {
|
||||||
|
final email = user.email?.trim().toLowerCase();
|
||||||
|
if (email != null && adminEmails.contains(email)) {
|
||||||
|
_isAdmin = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
final tokenResult = await user.getIdTokenResult();
|
final tokenResult = await user.getIdTokenResult();
|
||||||
_isAdmin = tokenResult.claims?['admin'] == true;
|
_isAdmin = tokenResult.claims?['admin'] == true;
|
||||||
|
|||||||
+2
-1
@@ -15,7 +15,8 @@ service firebase.storage {
|
|||||||
// Nur der Verfasser oder ein Admin darf sein Foto löschen
|
// Nur der Verfasser oder ein Admin darf sein Foto löschen
|
||||||
allow delete: if request.auth != null && (
|
allow delete: if request.auth != null && (
|
||||||
request.auth.uid == userId ||
|
request.auth.uid == userId ||
|
||||||
request.auth.token.admin == true
|
request.auth.token.admin == true ||
|
||||||
|
request.auth.token.email == 'nicolas@gruber.info'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user