-
-
Notifications
You must be signed in to change notification settings - Fork 407
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 #911 from ONEARMY/master
v1.0.3
- Loading branch information
Showing
17 changed files
with
165 additions
and
152 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
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,31 @@ | ||
// WiP - CC - 2020-02-24 | ||
// As part of future security update will make better use of firestore rules, as stubbed out below | ||
|
||
service cloud.firestore { | ||
// rules will apply to all docs in database | ||
match /databases/{database}/documents { | ||
// Function to check whether request user has specific permission set in user database | ||
function hasUserRole(username,role){ | ||
// TODO - look up a profile to see if the user has specific role (e.g. admin) | ||
// NOTE - this is not currently possible as the username is not sent with a request | ||
// but could be made possible by setting the firebase auth name to the username | ||
// and ensuring all users had a userRoles property | ||
// NOTE 2 - possible code below but would need testing (https://firebase.google.com/docs/reference/rules/rules.List) | ||
// return role in get(/databases/$(database)/documents/v3_users/$(username)).data.userRoles | ||
return true | ||
} | ||
// Function to check if request to modify a document is by the auth owner | ||
function isSameUser(username){ | ||
return get(/databases/$(database)/documents/v3_users/$(username)).data._authID==request.auth.uid | ||
} | ||
match /v3_users/{username} { | ||
allow read, write: if hasUserRole('admin') | ||
allow read,write | ||
} | ||
// users can read/write their own user docs | ||
match /v3_users/{username} { | ||
allow read, write: if isSameUser(username) | ||
} | ||
} | ||
} | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,29 @@ | ||
import * as functions from 'firebase-functions' | ||
import { IDBEndpoint } from '../models' | ||
import { db } from '..//Firebase/firestoreDB' | ||
|
||
const USER_ENDPOINT: IDBEndpoint = 'v3_users' | ||
|
||
/** | ||
* Example function to show how an automated email can be triggered | ||
* In this case it is being used temporarily to help debug | ||
* https://github.com/ONEARMY/community-platform/issues/883 | ||
*/ | ||
export const notifyEmailDemo = functions.firestore | ||
.document(`${USER_ENDPOINT}/precious-plastic`) | ||
.onWrite(async (change, context) => { | ||
return db.collection('mail').add({ | ||
to: 'chris.m.clarke@live.co.uk', | ||
message: { | ||
subject: 'PP Profile Edited', | ||
html: ` | ||
<p>Just thought you should know that an edit has been made to your profile</p> | ||
<h2>Before</h2> | ||
<code>${JSON.stringify(change.before.data())}</code> | ||
<h2>After</h2> | ||
<code>${JSON.stringify(change.after.data())}</code> | ||
<p>To see a clear breakdown of differences you could copy-paste each section into http://www.jsondiff.com</p> | ||
`, | ||
}, | ||
}) | ||
}) |
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,22 @@ | ||
import * as functions from 'firebase-functions' | ||
import { DBDoc, IDBEndpoint } from '../models' | ||
const USERS_ENDPOINT: IDBEndpoint = 'v3_users' | ||
|
||
/** | ||
* Automatically create user revision on update | ||
* Nests revision as subcollection of original document, | ||
* labeled by previous _modified timestamp | ||
*/ | ||
export const FirebaseUserBackup = functions.firestore | ||
.document(`${USERS_ENDPOINT}/{username}`) | ||
.onUpdate((change, context) => { | ||
const { before, after } = change | ||
const rev = before.data() as DBDoc | ||
if (rev && rev._modified) { | ||
return before.ref | ||
.collection('revisions') | ||
.doc(rev._modified) | ||
.set(rev) | ||
} | ||
return null | ||
}) |
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
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.