From 1b48bcb3c94feaf591979229db8e57950d0796cd Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sun, 11 Apr 2021 19:18:28 +0200 Subject: [PATCH] Check the availability of Firebase before accepting new tokens --- src/api_data/server_config.rs | 2 +- src/controllers/push_notifications_controller.rs | 4 ++++ src/data/api_client.rs | 6 ++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/api_data/server_config.rs b/src/api_data/server_config.rs index c895228..a450734 100644 --- a/src/api_data/server_config.rs +++ b/src/api_data/server_config.rs @@ -77,7 +77,7 @@ impl ServerConfig { android_direct_download_url: conf().android_direct_download_url.clone(), notifications: NotificationsConfig { - has_firebase: c.firebase_token.is_some(), + has_firebase: c.is_firebase_available(), has_independent: conf().independent_push_service.is_some(), }, diff --git a/src/controllers/push_notifications_controller.rs b/src/controllers/push_notifications_controller.rs index 6190c40..6ba8204 100644 --- a/src/controllers/push_notifications_controller.rs +++ b/src/controllers/push_notifications_controller.rs @@ -26,6 +26,10 @@ pub fn configure(r: &mut HttpRequestHandler) -> RequestResult { "disabled" => PushNotificationToken::NONE, "firebase" => { + if !r.api_client().is_firebase_available() { + return r.bad_request("Firebase is unavailable!".to_string()); + } + PushNotificationToken::FIREBASE(r.post_string("firebase_token")?) } diff --git a/src/data/api_client.rs b/src/data/api_client.rs index add0af3..4f82853 100644 --- a/src/data/api_client.rs +++ b/src/data/api_client.rs @@ -9,4 +9,10 @@ pub struct APIClient { pub comment: Option, pub default_expiration_time: u64, pub firebase_token: Option, +} + +impl APIClient { + pub fn is_firebase_available(&self) -> bool { + self.firebase_token.is_some() + } } \ No newline at end of file