feat: enforce friend add and curfew policies
This commit is contained in:
@@ -857,6 +857,9 @@ func createIMUserProductTables(tx *sql.Tx) error {
|
||||
region VARCHAR(128) NOT NULL DEFAULT '',
|
||||
email VARCHAR(128) NOT NULL DEFAULT '',
|
||||
public_account VARCHAR(64) NOT NULL DEFAULT '',
|
||||
friend_add_enabled TINYINT NOT NULL DEFAULT 1,
|
||||
friend_add_disabled_reason VARCHAR(255) NOT NULL DEFAULT '',
|
||||
friend_add_policy_version INT NOT NULL DEFAULT 1,
|
||||
version INT NOT NULL DEFAULT 1,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
|
||||
@@ -3192,7 +3192,7 @@ func (a *adapter) ensureUserProfile(ctx context.Context, uid t.Uid) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if _, err := a.db.ExecContext(ctx, `INSERT IGNORE INTO im_user_profiles(id,user_id,public_account) VALUES(?,?,?)`, profileID, decodeUID(uid), uid.UserId()); err != nil {
|
||||
if _, err := a.db.ExecContext(ctx, `INSERT IGNORE INTO im_user_profiles(id,user_id,public_account,friend_add_enabled,friend_add_policy_version) VALUES(?,?,?,?,?)`, profileID, decodeUID(uid), uid.UserId(), true, 1); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
@@ -3885,35 +3885,41 @@ func (a *adapter) feedbackByIdempotency(ctx context.Context, uid t.Uid, idempote
|
||||
|
||||
func (a *adapter) userProfileByUID(ctx context.Context, uid t.Uid) (*t.UserProfile, error) {
|
||||
row := struct {
|
||||
UserID int64 `db:"user_id"`
|
||||
AvatarFileID string `db:"avatar_file_id"`
|
||||
Nickname string
|
||||
BirthDate sql.NullTime `db:"birth_date"`
|
||||
Signature string
|
||||
Gender string
|
||||
Region string
|
||||
Email string
|
||||
PublicAccount string `db:"public_account"`
|
||||
Version int
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
UserID int64 `db:"user_id"`
|
||||
AvatarFileID string `db:"avatar_file_id"`
|
||||
Nickname string
|
||||
BirthDate sql.NullTime `db:"birth_date"`
|
||||
Signature string
|
||||
Gender string
|
||||
Region string
|
||||
Email string
|
||||
PublicAccount string `db:"public_account"`
|
||||
FriendAddEnabled bool `db:"friend_add_enabled"`
|
||||
FriendAddDisabledReason string `db:"friend_add_disabled_reason"`
|
||||
FriendAddPolicyVersion int `db:"friend_add_policy_version"`
|
||||
Version int
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
}{}
|
||||
if err := sqlx.GetContext(ctx, a.db, &row, `SELECT user_id,avatar_file_id,nickname,birth_date,signature,gender,region,email,
|
||||
public_account,version,created_at,updated_at FROM im_user_profiles WHERE user_id=?`, decodeUID(uid)); err != nil {
|
||||
public_account,friend_add_enabled,friend_add_disabled_reason,friend_add_policy_version,version,created_at,updated_at FROM im_user_profiles WHERE user_id=?`, decodeUID(uid)); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
profile := &t.UserProfile{
|
||||
UserID: store.EncodeUid(row.UserID),
|
||||
AvatarFileID: row.AvatarFileID,
|
||||
Nickname: row.Nickname,
|
||||
Signature: row.Signature,
|
||||
Gender: row.Gender,
|
||||
Region: row.Region,
|
||||
Email: row.Email,
|
||||
PublicAccount: row.PublicAccount,
|
||||
Version: row.Version,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
UserID: store.EncodeUid(row.UserID),
|
||||
AvatarFileID: row.AvatarFileID,
|
||||
Nickname: row.Nickname,
|
||||
Signature: row.Signature,
|
||||
Gender: row.Gender,
|
||||
Region: row.Region,
|
||||
Email: row.Email,
|
||||
PublicAccount: row.PublicAccount,
|
||||
FriendAddEnabled: row.FriendAddEnabled,
|
||||
FriendAddDisabledReason: row.FriendAddDisabledReason,
|
||||
FriendAddPolicyVersion: row.FriendAddPolicyVersion,
|
||||
Version: row.Version,
|
||||
CreatedAt: row.CreatedAt,
|
||||
UpdatedAt: row.UpdatedAt,
|
||||
}
|
||||
if row.BirthDate.Valid {
|
||||
profile.BirthDate = row.BirthDate.Time.Format("2006-01-02")
|
||||
|
||||
@@ -65,7 +65,11 @@ func ensureUserIdentitySchema(db *sqlx.DB) error {
|
||||
avatar_file_id VARCHAR(64) NOT NULL DEFAULT '',nickname VARCHAR(64) NOT NULL DEFAULT '',
|
||||
birth_date DATE,signature VARCHAR(256) NOT NULL DEFAULT '',gender VARCHAR(16) NOT NULL DEFAULT '',
|
||||
region VARCHAR(128) NOT NULL DEFAULT '',email VARCHAR(128) NOT NULL DEFAULT '',
|
||||
public_account VARCHAR(64) NOT NULL DEFAULT '',version INT NOT NULL DEFAULT 1,
|
||||
public_account VARCHAR(64) NOT NULL DEFAULT '',
|
||||
friend_add_enabled TINYINT NOT NULL DEFAULT 1,
|
||||
friend_add_disabled_reason VARCHAR(255) NOT NULL DEFAULT '',
|
||||
friend_add_policy_version INT NOT NULL DEFAULT 1,
|
||||
version INT NOT NULL DEFAULT 1,
|
||||
created_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
|
||||
updated_at DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
|
||||
PRIMARY KEY(id),UNIQUE INDEX uk_im_user_profiles_user(`+profileUniqueKey+`))`); err != nil {
|
||||
@@ -99,6 +103,27 @@ func ensureUserIdentitySchema(db *sqlx.DB) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if exists, err := identityColumnExists(ctx, conn, "im_user_profiles", "friend_add_enabled"); err != nil {
|
||||
return err
|
||||
} else if !exists {
|
||||
if _, err = conn.ExecContext(ctx, "ALTER TABLE im_user_profiles ADD COLUMN friend_add_enabled TINYINT NOT NULL DEFAULT 1 AFTER public_account"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if exists, err := identityColumnExists(ctx, conn, "im_user_profiles", "friend_add_disabled_reason"); err != nil {
|
||||
return err
|
||||
} else if !exists {
|
||||
if _, err = conn.ExecContext(ctx, "ALTER TABLE im_user_profiles ADD COLUMN friend_add_disabled_reason VARCHAR(255) NOT NULL DEFAULT '' AFTER friend_add_enabled"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if exists, err := identityColumnExists(ctx, conn, "im_user_profiles", "friend_add_policy_version"); err != nil {
|
||||
return err
|
||||
} else if !exists {
|
||||
if _, err = conn.ExecContext(ctx, "ALTER TABLE im_user_profiles ADD COLUMN friend_add_policy_version INT NOT NULL DEFAULT 1 AFTER friend_add_disabled_reason"); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if err = backfillUserPhones(ctx, conn, usersScoped); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user