Skip to content

Commit

Permalink
chore: fix historical user open issue (AppFlowy-IO#3106)
Browse files Browse the repository at this point in the history
  • Loading branch information
appflowy authored Aug 3, 2023
1 parent 03518c9 commit 135d8a8
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-user/protobuf.dart';
import 'package:dartz/dartz.dart';
import 'package:appflowy_backend/dispatch/dispatch.dart';
Expand All @@ -16,7 +17,10 @@ class UserBackendService {

static Future<Either<FlowyError, UserProfilePB>>
getCurrentUserProfile() async {
final result = await UserEventGetUserProfile().send();
final result = await UserEventGetUserProfile().send().then((value) {
value.fold((l) => null, (r) => Log.error(r));
return value;
});
return result.swap();
}

Expand Down
26 changes: 23 additions & 3 deletions frontend/rust-lib/flowy-user/src/services/session_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use chrono::prelude::*;
use serde::de::{Deserializer, MapAccess, Visitor};
use serde::Deserialize;
use serde::Serialize;
use serde_json::Value;

use flowy_user_deps::entities::{SignInResponse, UserWorkspace};

Expand Down Expand Up @@ -44,7 +45,9 @@ impl<'de> Visitor<'de> for SessionVisitor {
"user_workspace" => {
user_workspace = Some(map.next_value()?);
},
_ => {},
_ => {
let _ = map.next_value::<Value>();
},
}
}
let user_id = user_id.ok_or(serde::de::Error::missing_field("user_id"))?;
Expand Down Expand Up @@ -102,23 +105,40 @@ impl std::convert::From<Session> for String {
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;

#[derive(serde::Serialize)]
struct OldSession {
user_id: i64,
workspace_id: String,
name: String,
}

#[test]
fn deserialize_user_workspace_from_workspace_id() {
// For historical reasons, the session used to contain a workspace_id field.
let old = OldSession {
user_id: 1,
workspace_id: uuid::Uuid::new_v4().to_string(),
user_id: 223238635422486528,
workspace_id: "f58f5492-ee0a-4a9f-8cf1-dacb459a55f6".to_string(),
name: "Me".to_string(),
};
let s = serde_json::to_string(&old).unwrap();
let new = serde_json::from_str::<Session>(&s).unwrap();
assert_eq!(old.user_id, new.user_id);
assert_eq!(old.workspace_id, new.user_workspace.id);

let json = json!({
"user_id": 2232386,
"workspace_id": "f58f5492-ee0a-4a9f-8cf1-dacb459a55f6",
"name": "Me",
"token": null,
"email": "[email protected]"
});
let new = serde_json::from_value::<Session>(json).unwrap();
assert_eq!(new.user_id, 2232386);
assert_eq!(
new.user_workspace.id,
"f58f5492-ee0a-4a9f-8cf1-dacb459a55f6"
);
}
}

0 comments on commit 135d8a8

Please sign in to comment.