Skip to content

feat: admin notifications for org sign up #1768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

aaerhart
Copy link
Collaborator

Summary

Adding functions for notifications emails to users and admins. This draft in particular is just testing if organization sign up emails are added to the emails collection. See adminNotification function and its call in the onRequest.

Checklist

Screenshots

Known issues

Steps to test/reproduce

  1. Sign up as a new organization

Copy link

vercel bot commented Mar 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
maple-dev ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 9, 2025 1:04am

@aaerhart
Copy link
Collaborator Author

aaerhart commented Mar 26, 2025

@Mephistic Realizing there might be the new httpsDeliverAdminNotifications missing from firebase functions as it was never added. I have gcloud and firebase set up but then I run I get Failed to get Firebase project digital-testimony-dev. Please make sure the project exists and your account has permission to access it. I made the change we talked about to the function itself so I'm assuming that's not the issue

In the readme under #4 under Contributing Backend Features to Dev/Prod: I feel like there's something i'm not getting about the env variable. I manually added it to my .env and for good measure I added it to the .zshrc file

@Mephistic
Copy link
Collaborator

@Mephistic Realizing there might be the new httpsDeliverAdminNotifications missing from firebase functions as it was never added.

In this PR, it looks like a second firebase function is still being defined in adminNotification. The exported function should be a firebase function ala:

export const myNewFirebaseFunction = functions.firestore
   .document("profiles/{userId}")
   .onWrite((change, context) => { 
       if (shouldSendAdminNotification(change) {
          const { orgName, email } = getDataFromChange(change);
          await sendAdminNotification({orgName, email});
       }
    })

See

export const updateUserNotificationFrequency = functions.firestore

We talked about extracting out the common admin sending so there's some shared function:

export const sendAdminNotification = async ({ orgName, email }) => {
  doStuff();
}

that is used by a firestore trigger function (like above) and an https function (like):

export const firestoreTrigger = functions.https.onRequest(
   async (request, response) => {
     const {orgName, email) = getDataFromRequest(request)
     await sendAdminNotification({ orgName, email })
     response.send(200)
  }
)

The HTTPS function may be unnecessary - you can test firebase function directly from an emulator with yarn dev:functions - this runs the emulator functions shell with a mocked firestore, so you can just write myFunction(testData) in the shell and expect it to work. More info about testing firestore-trigger functions with this is available here: https://firebase.google.com/docs/functions/local-shell

@Mephistic
Copy link
Collaborator

I have gcloud and firebase set up but then I run I get Failed to get Firebase project digital-testimony-dev. Please make sure the project exists and your account has permission to access it. I made the change we talked about to the function itself so I'm assuming that's not the issue

In the readme under #4 under Contributing Backend Features to Dev/Prod: I feel like there's something i'm not getting about the env variable. I manually added it to my .env and for good measure I added it to the .zshrc file

Yeah, agreed that doesn't sound like an issue defining the function - just an auth issue. I confirmed that you have access to the dev project. When you open a new shell tab/window, can you confirm:

  • That you have the GOOGLE_APPLICATION_CREDENTIALS variable set to a file path (e.g. with echo $GOOGLE_APPLICATION_CREDENTIALS)
  • There is a file at that path that contains a JSON of google credentials info (e.g. with vim $GOOGLE_APPLICATION_CREDENTIALS)

If the above look as we'd expect, one thing that works sometimes is forcing a firebase auth refresh with firebase login --reauth - if the file is where you'd expect, I'd give that a try and report back. (If it works, I'll make a note to add it to the README section).

@aaerhart
Copy link
Collaborator Author

I have gcloud and firebase set up but then I run I get Failed to get Firebase project digital-testimony-dev. Please make sure the project exists and your account has permission to access it. I made the change we talked about to the function itself so I'm assuming that's not the issue
In the readme under #4 under Contributing Backend Features to Dev/Prod: I feel like there's something i'm not getting about the env variable. I manually added it to my .env and for good measure I added it to the .zshrc file

Yeah, agreed that doesn't sound like an issue defining the function - just an auth issue. I confirmed that you have access to the dev project. When you open a new shell tab/window, can you confirm:

  • That you have the GOOGLE_APPLICATION_CREDENTIALS variable set to a file path (e.g. with echo $GOOGLE_APPLICATION_CREDENTIALS)
  • There is a file at that path that contains a JSON of google credentials info (e.g. with vim $GOOGLE_APPLICATION_CREDENTIALS)

If the above look as we'd expect, one thing that works sometimes is forcing a firebase auth refresh with firebase login --reauth - if the file is where you'd expect, I'd give that a try and report back. (If it works, I'll make a note to add it to the README section).

Yeah, the firebase login --reauth did indeed log me in, thanks for the pointer.

I do have the application_default_credentials.json file with account, client_d, client_secret, quota_prooject_id, refresh_token, type, and universe_domain. The GOOGLE_APPLICATION_CREDENTIALS variable has been confirmed as having the path for that json file as its value.

@aaerhart
Copy link
Collaborator Author

@Mephistic Realizing there might be the new httpsDeliverAdminNotifications missing from firebase functions as it was never added.

In this PR, it looks like a second firebase function is still being defined in adminNotification. The exported function should be a firebase function ala:

export const myNewFirebaseFunction = functions.firestore
   .document("profiles/{userId}")
   .onWrite((change, context) => { 
       if (shouldSendAdminNotification(change) {
          const { orgName, email } = getDataFromChange(change);
          await sendAdminNotification({orgName, email});
       }
    })

See

export const updateUserNotificationFrequency = functions.firestore

We talked about extracting out the common admin sending so there's some shared function:

export const sendAdminNotification = async ({ orgName, email }) => {
  doStuff();
}

that is used by a firestore trigger function (like above) and an https function (like):

export const firestoreTrigger = functions.https.onRequest(
   async (request, response) => {
     const {orgName, email) = getDataFromRequest(request)
     await sendAdminNotification({ orgName, email })
     response.send(200)
  }
)

The HTTPS function may be unnecessary - you can test firebase function directly from an emulator with yarn dev:functions - this runs the emulator functions shell with a mocked firestore, so you can just write myFunction(testData) in the shell and expect it to work. More info about testing firestore-trigger functions with this is available here: https://firebase.google.com/docs/functions/local-shell

I'm getting Error: Process java -version has exited with code 1. Please make sure Java is installed and on your system PATH. -----Original stdout----- -----Original stderr----- The operation couldn’t be completed. Unable to locate a Java Runtime. Please visit http://www.java.com for information on installing Java.

when I run yarn dev:functions, but the emulator is otherwise straightforward and I'll get to testing it ASAP when I resolve that. I just made sure versions of everything are matching the parent package file so I'm not sure but I'll try to research it.

@Mephistic
Copy link
Collaborator

Based on that error, it sounds like you should just need to install Java and make sure it's in your $PATH to make things work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants