Browse Source

Addressed remarks given and some updates

- Addressed comments given during review
- Updated crates, including Rocket to the latest merged v0.5 changes
- Removed an extra header which should not be sent for websocket connections
pull/4001/head
BlackDex 2 years ago
parent
commit
917fb507d6
No known key found for this signature in database GPG Key ID: 58C80A2AA6C765E1
  1. 4
      .env.template
  2. 4
      src/api/admin.rs
  3. 43
      src/api/notifications.rs
  4. 4
      src/config.rs

4
.env.template

@ -84,8 +84,8 @@
### WebSocket ###
#################
## Disable websocket notifications
# WEBSOCKET_DISABLED=false
## Enable websocket notifications
# ENABLE_WEBSOCKET=true
##########################
### Push notifications ###

4
src/api/admin.rs

@ -316,7 +316,7 @@ async fn test_smtp(data: Json<InviteData>, _token: AdminToken) -> EmptyResult {
#[get("/logout")]
fn logout(cookies: &CookieJar<'_>) -> Redirect {
cookies.remove(Cookie::build(COOKIE_NAME).path(admin_path()));
cookies.remove(Cookie::build(COOKIE_NAME, "").path(admin_path()).finish());
Redirect::to(admin_path())
}
@ -797,7 +797,7 @@ impl<'r> FromRequest<'r> for AdminToken {
if decode_admin(access_token).is_err() {
// Remove admin cookie
cookies.remove(Cookie::build(COOKIE_NAME).path(admin_path()));
cookies.remove(Cookie::build(COOKIE_NAME, "").path(admin_path()).finish());
error!("Invalid or expired admin JWT. IP: {}.", &ip.ip);
return Outcome::Error((Status::Unauthorized, "Session expired"));
}

43
src/api/notifications.rs

@ -35,12 +35,14 @@ use super::{
push_send_update, push_user_update,
};
static NOTIFICATIONS_DISABLED: Lazy<bool> = Lazy::new(|| !CONFIG.enable_websocket() && !CONFIG.push_enabled());
pub fn routes() -> Vec<Route> {
if CONFIG.websocket_disabled() {
if CONFIG.enable_websocket() {
routes![websockets_hub, anonymous_websockets_hub]
} else {
info!("WebSocket are disabled, realtime sync functionality will not work!");
routes![]
} else {
routes![websockets_hub, anonymous_websockets_hub]
}
}
@ -339,7 +341,7 @@ impl WebSocketUsers {
// NOTE: The last modified date needs to be updated before calling these methods
pub async fn send_user_update(&self, ut: UpdateType, user: &User) {
// Skip any processing if both WebSockets and Push are not active
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
if *NOTIFICATIONS_DISABLED {
return;
}
let data = create_update(
@ -348,7 +350,7 @@ impl WebSocketUsers {
None,
);
if !CONFIG.websocket_disabled() {
if CONFIG.enable_websocket() {
self.send_update(&user.uuid, &data).await;
}
@ -359,7 +361,7 @@ impl WebSocketUsers {
pub async fn send_logout(&self, user: &User, acting_device_uuid: Option<String>) {
// Skip any processing if both WebSockets and Push are not active
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
if *NOTIFICATIONS_DISABLED {
return;
}
let data = create_update(
@ -368,7 +370,7 @@ impl WebSocketUsers {
acting_device_uuid.clone(),
);
if !CONFIG.websocket_disabled() {
if CONFIG.enable_websocket() {
self.send_update(&user.uuid, &data).await;
}
@ -385,7 +387,7 @@ impl WebSocketUsers {
conn: &mut DbConn,
) {
// Skip any processing if both WebSockets and Push are not active
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
if *NOTIFICATIONS_DISABLED {
return;
}
let data = create_update(
@ -398,7 +400,7 @@ impl WebSocketUsers {
Some(acting_device_uuid.into()),
);
if !CONFIG.websocket_disabled() {
if CONFIG.enable_websocket() {
self.send_update(&folder.user_uuid, &data).await;
}
@ -417,7 +419,7 @@ impl WebSocketUsers {
conn: &mut DbConn,
) {
// Skip any processing if both WebSockets and Push are not active
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
if *NOTIFICATIONS_DISABLED {
return;
}
let org_uuid = convert_option(cipher.organization_uuid.clone());
@ -445,7 +447,7 @@ impl WebSocketUsers {
Some(acting_device_uuid.into()),
);
if !CONFIG.websocket_disabled() {
if CONFIG.enable_websocket() {
for uuid in user_uuids {
self.send_update(uuid, &data).await;
}
@ -465,7 +467,7 @@ impl WebSocketUsers {
conn: &mut DbConn,
) {
// Skip any processing if both WebSockets and Push are not active
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
if *NOTIFICATIONS_DISABLED {
return;
}
let user_uuid = convert_option(send.user_uuid.clone());
@ -480,7 +482,7 @@ impl WebSocketUsers {
None,
);
if !CONFIG.websocket_disabled() {
if CONFIG.enable_websocket() {
for uuid in user_uuids {
self.send_update(uuid, &data).await;
}
@ -498,7 +500,7 @@ impl WebSocketUsers {
conn: &mut DbConn,
) {
// Skip any processing if both WebSockets and Push are not active
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
if *NOTIFICATIONS_DISABLED {
return;
}
let data = create_update(
@ -506,7 +508,7 @@ impl WebSocketUsers {
UpdateType::AuthRequest,
Some(acting_device_uuid.to_string()),
);
if !CONFIG.websocket_disabled() {
if CONFIG.enable_websocket() {
self.send_update(user_uuid, &data).await;
}
@ -523,7 +525,7 @@ impl WebSocketUsers {
conn: &mut DbConn,
) {
// Skip any processing if both WebSockets and Push are not active
if CONFIG.websocket_disabled() && !CONFIG.push_enabled() {
if *NOTIFICATIONS_DISABLED {
return;
}
let data = create_update(
@ -531,7 +533,7 @@ impl WebSocketUsers {
UpdateType::AuthRequestResponse,
approving_device_uuid.clone().into(),
);
if !CONFIG.websocket_disabled() {
if CONFIG.enable_websocket() {
self.send_update(auth_response_uuid, &data).await;
}
@ -557,14 +559,15 @@ impl AnonymousWebSocketSubscriptions {
}
pub async fn send_auth_response(&self, user_uuid: &String, auth_response_uuid: &str) {
if !CONFIG.enable_websocket() {
return;
}
let data = create_anonymous_update(
vec![("Id".into(), auth_response_uuid.to_owned().into()), ("UserId".into(), user_uuid.clone().into())],
UpdateType::AuthRequestResponse,
user_uuid.to_string(),
);
if !CONFIG.websocket_disabled() {
self.send_update(auth_response_uuid, &data).await;
}
self.send_update(auth_response_uuid, &data).await;
}
}

4
src/config.rs

@ -369,8 +369,8 @@ make_config! {
web_vault_folder: String, false, def, "web-vault/".to_string();
},
ws {
/// Disable websocket notifications
websocket_disabled: bool, false, def, false;
/// Enable websocket notifications
enable_websocket: bool, false, def, true;
},
push {
/// Enable push notifications

Loading…
Cancel
Save