-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #150 from r00tat/feature/groups
Add Feature groups
- Loading branch information
Showing
50 changed files
with
1,194 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
rules_version = '2'; | ||
service cloud.firestore { | ||
match /databases/{database}/documents { | ||
|
||
function authorizedUser() { | ||
return request.auth != null && ( | ||
request.auth.token.email.matches(".*@ff-neusiedlamsee.at") || | ||
get(/databases/$(database)/documents/user/$(request.auth.uid)).data.authorized in [true, 'on', 'yes', 'y'] | ||
); | ||
} | ||
|
||
function adminUser() { | ||
return request.auth != null && | ||
get(/databases/$(database)/documents/user/$(request.auth.uid)).data.isAdmin == true; | ||
} | ||
|
||
match /hydrant/{doc=*} { | ||
allow read: if authorizedUser() | ||
} | ||
match /saugstelle/{doc=*} { | ||
allow read: if authorizedUser() | ||
} | ||
match /loeschteich/{doc=*} { | ||
allow read: if authorizedUser() | ||
} | ||
match /risikoobjekt/{doc=*} { | ||
allow read: if authorizedUser() | ||
} | ||
|
||
match /gefahrobjekt/{doc=*} { | ||
allow read: if authorizedUser() | ||
} | ||
|
||
match /call/{doc=**} { | ||
allow read, write: if authorizedUser() | ||
&& resource.data.group in get(/databases/$(database)/documents/user/$(request.auth.uid)).data.groups | ||
} | ||
|
||
match /clusters/{doc=**} { | ||
allow read: if authorizedUser(); | ||
} | ||
|
||
match /clusters6/{doc=**} { | ||
allow read: if authorizedUser(); | ||
allow write: if adminUser(); | ||
} | ||
|
||
match /tokens/{doc=**} { | ||
allow read: if authorizedUser() && request.auth.uid == resource.data.owner; | ||
allow delete: if authorizedUser() && request.auth.uid == resource.data.owner; | ||
allow write: if authorizedUser() && request.auth.uid == request.resource.data.owner; | ||
} | ||
|
||
match /user/{doc=*} { | ||
allow read: if request.auth != null && request.auth.uid == doc | ||
} | ||
|
||
match /{document=**} { | ||
allow read, write: if adminUser(); | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
{ | ||
"indexes": [ | ||
{ | ||
"collectionGroup": "call", | ||
"queryScope": "COLLECTION", | ||
"fields": [ | ||
{ | ||
"fieldPath": "deleted", | ||
"order": "ASCENDING" | ||
}, | ||
{ | ||
"fieldPath": "date", | ||
"order": "DESCENDING" | ||
} | ||
] | ||
}, | ||
{ | ||
"collectionGroup": "call", | ||
"queryScope": "COLLECTION", | ||
"fields": [ | ||
{ | ||
"fieldPath": "group", | ||
"order": "ASCENDING" | ||
}, | ||
{ | ||
"fieldPath": "date", | ||
"order": "DESCENDING" | ||
} | ||
] | ||
}, | ||
{ | ||
"collectionGroup": "call", | ||
"queryScope": "COLLECTION", | ||
"fields": [ | ||
{ | ||
"fieldPath": "deleted", | ||
"order": "ASCENDING" | ||
}, | ||
{ | ||
"fieldPath": "group", | ||
"order": "ASCENDING" | ||
}, | ||
{ | ||
"fieldPath": "date", | ||
"order": "DESCENDING" | ||
} | ||
] | ||
} | ||
], | ||
"fieldOverrides": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
'use server'; | ||
|
||
import { UserRecordExtended } from '../../common/users'; | ||
import { | ||
Firecall, | ||
FIRECALL_COLLECTION_ID, | ||
USER_COLLECTION_ID, | ||
} from '../../components/firebase/firestore'; | ||
import { firestore } from '../../server/firebase/admin'; | ||
import { actionAdminRequired } from '../auth'; | ||
|
||
export async function setAuthorizedToBool(): Promise<UserRecordExtended[]> { | ||
await actionAdminRequired(); | ||
const badUsers = await firestore | ||
.collection(USER_COLLECTION_ID) | ||
.where('authorized', '==', 'on') | ||
.get(); | ||
await Promise.all( | ||
badUsers.docs.map(async (user) => | ||
firestore | ||
.collection(USER_COLLECTION_ID) | ||
.doc(user.id) | ||
.update({ authorized: true }) | ||
) | ||
); | ||
return badUsers.docs.map( | ||
(user) => | ||
({ ...user.data(), uid: user.id } as unknown as UserRecordExtended) | ||
); | ||
} | ||
|
||
export async function setEmptyFirecallGroup() { | ||
await actionAdminRequired(); | ||
const calls = ( | ||
await firestore.collection(FIRECALL_COLLECTION_ID).get() | ||
).docs.filter((call) => call.data().group === undefined); | ||
|
||
await Promise.all( | ||
calls.map((call) => | ||
firestore | ||
.collection(FIRECALL_COLLECTION_ID) | ||
.doc(call.id) | ||
.update({ group: 'ffnd' }) | ||
) | ||
); | ||
|
||
return calls.map( | ||
(call) => | ||
({ | ||
...call.data(), | ||
id: call.id, | ||
} as unknown as Firecall) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
import Button from '@mui/material/Button'; | ||
import Typography from '@mui/material/Typography'; | ||
import { useCallback, useState } from 'react'; | ||
import { setAuthorizedToBool, setEmptyFirecallGroup } from './adminActions'; | ||
import Box from '@mui/material/Box'; | ||
|
||
export default function AdminPage() { | ||
const [status, setStatus] = useState(''); | ||
|
||
const updateAuthorized = useCallback(async () => { | ||
const fixedUsers = await setAuthorizedToBool(); | ||
setStatus( | ||
`${fixedUsers.length} users corrected. (${fixedUsers | ||
.map((user) => user.email) | ||
.join(', ')})` | ||
); | ||
}, []); | ||
const setFirecallGroup = useCallback(async () => { | ||
const calls = await setEmptyFirecallGroup(); | ||
setStatus( | ||
`${calls.length} calls corrected. (${calls | ||
.map((call) => call.name) | ||
.join(', ')})` | ||
); | ||
}, []); | ||
|
||
return ( | ||
<Box margin={2}> | ||
<Typography variant="h3">Admin Actions</Typography> | ||
<Typography>{status}</Typography> | ||
<Typography> | ||
Set authorized from on to true{' '} | ||
<Button onClick={updateAuthorized} variant="contained"> | ||
Fix users authorized | ||
</Button> | ||
</Typography> | ||
<Typography> | ||
Set ffnd as default group on firecalls{' '} | ||
<Button onClick={setFirecallGroup} variant="contained"> | ||
Fix empty firecall group | ||
</Button> | ||
</Typography> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.