Skip to content

Commit

Permalink
Update on "[Events] Add project notification settings"
Browse files Browse the repository at this point in the history
[Events] Add project notification settings

    ghstack-source-id: 2b4044a63b5cc394bfe66af8706764450703d904
    Pull Request resolved: #18


    This PR adds a new model for project notifications. The semantics of the model is explained in `notifications.proto`.

    1. Adds a the model to the db model in metadata_svc and exposed it in the project store.
    2. Expose setters/getters to notification settings in metadata svc.
    3. Expose APIs to manipulate the notification settings. I opted into having a single endpoint for updating the notification setting json for convenience.

    Later, we can also add this to the CLI.

    Test plan:

    ```
    ~/repos/cronback/cronback ❯❯❯ cargo cli --localhost --secret-token adminkey admin projects create                                                                                                              ✘ 130
    Project 'prj_026601H699SE7VY0YEFHRXXE75117B' was created successfully.
    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer POST http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings examples/notifications.json


    ~/repos/cronback/cronback ❯❯❯ http -b --auth adminkey --auth-type bearer GET http://localhost:8888/v1/admin/projects/prj_026601H699SE7VY0YEFHRXXE75117B/notification_settings
    {
        "channels": {
            "email": {
                "address": "testgmail.com",
                "type": "email",
                "verified": false
            }
        },
        "subscriptions": [
            {
                "channel_names": [
                    "email"
                ],
                "event": {
                    "type": "on_run_failure"
                }
            }
        ]
    }
    ```





[ghstack-poisoned]
  • Loading branch information
MohamedBassem committed Jul 26, 2023
1 parent a0933d5 commit 0590b15
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cronback-services/src/metadata/metadata_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ impl MetadataStore {
#[cfg(test)]
mod tests {

use std::collections::HashMap;

use super::*;
use crate::metadata::db_model::notifications::{
EmailNotification,
NotificationChannel,
NotificationEvent,
NotificationSubscription,
OnRunFailure,
};
use crate::metadata::migrate_up;

fn build_project(status: ProjectStatus) -> Project {
Expand Down Expand Up @@ -153,6 +162,30 @@ mod tests {
Err(DatabaseError::DB(sea_orm::DbErr::RecordNotUpdated))
));

// Test notification setters / getters
{
let email = EmailNotification {
address: "[email protected]".to_string(),
verified: true,
};
let mut channels = HashMap::new();
channels
.insert("email".to_string(), NotificationChannel::Email(email));
let setting = NotificationSettings {
channels,
subscriptions: vec![NotificationSubscription {
channel_names: vec!["email".to_string()],
event: NotificationEvent::OnRunFailure(OnRunFailure {}),
}],
};
store
.set_notification_settings(&project2.id, setting.clone())
.await?;

let found = store.get_notification_settings(&project2.id).await?;
assert_eq!(found, Some(setting));
}

Ok(())
}
}

0 comments on commit 0590b15

Please sign in to comment.