refactor: read user profile fields from profile table

This commit is contained in:
richjohnrambo
2026-09-21 13:44:04 +08:00
parent d398467fb9
commit 5f717c2162
9 changed files with 117 additions and 203 deletions
+16 -8
View File
@@ -289,8 +289,8 @@ func TestTenantAuthIsolation(t *testing.T) {
userBID := userAID + 1
for index, userID := range []int64{userAID, userBID} {
tenantDB := quoteIdent(dbNames[index])
if _, err := db.Exec("INSERT INTO "+tenantDB+".im_users(id,account_no,username,createdat,updatedat,state,access,phone,public,trusted) "+
"VALUES(?,?,?,?,?,?,?,?,?,?)", userID, 1000+index, "alice", now, now, types.StateOK, `{}`, "13800000000", nil, nil); err != nil {
if _, err := db.Exec("INSERT INTO "+tenantDB+".im_users(id,account_no,username,createdat,updatedat,state,access,phone,trusted) "+
"VALUES(?,?,?,?,?,?,?,?,?)", userID, 1000+index, "alice", now, now, types.StateOK, `{}`, "13800000000", nil); err != nil {
t.Fatal(err)
}
if _, err := db.Exec("INSERT INTO "+tenantDB+".im_auth(userid,authlvl,secret) VALUES(?,?,?)",
@@ -354,17 +354,25 @@ func TestTenantUserSearchMatchesUsernamePhoneAndPublicAccount(t *testing.T) {
id int64
username string
phone any
public string
nickname string
}{
{viewerID, "viewerx", nil, `{"fn":"Viewer"}`},
{targetID, "potter", "+8615500000002", `{"fn":"Potter"}`},
{viewerID, "viewerx", nil, "Viewer"},
{targetID, "potter", "+8615500000002", "Potter"},
} {
if _, err := db.Exec(
`INSERT INTO im_users(id,account_no,username,createdat,updatedat,state,access,phone,public,trusted)
VALUES(?,?,?,?,?,?,?,?,?,?)`,
user.id, user.id%1000000, user.username, now, now, types.StateOK, `{"Auth":"JRWPAS","Anon":"N"}`, user.phone, user.public, `{}`); err != nil {
`INSERT INTO im_users(id,account_no,username,createdat,updatedat,state,access,phone,trusted)
VALUES(?,?,?,?,?,?,?,?,?)`,
user.id, user.id%1000000, user.username, now, now, types.StateOK, `{"Auth":"JRWPAS","Anon":"N"}`, user.phone, `{}`); err != nil {
t.Fatal(err)
}
if user.id != targetID {
if _, err := db.Exec(
`INSERT INTO im_user_profiles(id,user_id,nickname,public_account,created_at,updated_at)
VALUES(?,?,?,?,?,?)`,
user.id+2000, user.id, user.nickname, store.EncodeUid(user.id).UserId(), now, now); err != nil {
t.Fatal(err)
}
}
if _, err := db.Exec(
`INSERT INTO im_user_privacy_settings(id,user_id,add_me_methods,created_at,updated_at)
VALUES(?,?,?,?,?)`,