From ac6ed3d939fe9dad81aadbd04541e905c625ca82 Mon Sep 17 00:00:00 2001 From: tobi <31960611+tsmethurst@users.noreply.github.com> Date: Mon, 15 Aug 2022 12:35:05 +0200 Subject: [chore] Update bun / sqlite versions; update gtsmodels (#754) * upstep bun and sqlite versions * allow specific columns to be updated in the db * only update necessary columns for user * bit tidier * only update necessary fields of media_attachment * only update relevant instance fields * update tests * update only specific account columns * use bool pointers on gtsmodels includes attachment, status, account, user * update columns more selectively * test all default fields on new account insert * updating remaining bools on gtsmodels * initialize pointer fields when extracting AP emoji * copy bools properly * add copyBoolPtr convenience function + test it * initialize false bool ptrs a bit more neatly --- cmd/gotosocial/action/admin/account/account.go | 36 +++++++++++++++++++------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'cmd') diff --git a/cmd/gotosocial/action/admin/account/account.go b/cmd/gotosocial/action/admin/account/account.go index 05f5a776b..83b98ac72 100644 --- a/cmd/gotosocial/action/admin/account/account.go +++ b/cmd/gotosocial/action/admin/account/account.go @@ -97,10 +97,13 @@ var Confirm action.GTSAction = func(ctx context.Context) error { return err } - u.Approved = true + updatingColumns := []string{"approved", "email", "confirmed_at", "updated_at"} + approved := true + u.Approved = &approved u.Email = u.UnconfirmedEmail u.ConfirmedAt = time.Now() - if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil { + u.UpdatedAt = time.Now() + if err := dbConn.UpdateByPrimaryKey(ctx, u, updatingColumns...); err != nil { return err } @@ -131,8 +134,12 @@ var Promote action.GTSAction = func(ctx context.Context) error { if err := dbConn.GetWhere(ctx, []db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil { return err } - u.Admin = true - if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil { + + updatingColumns := []string{"admin", "updated_at"} + admin := true + u.Admin = &admin + u.UpdatedAt = time.Now() + if err := dbConn.UpdateByPrimaryKey(ctx, u, updatingColumns...); err != nil { return err } @@ -163,8 +170,12 @@ var Demote action.GTSAction = func(ctx context.Context) error { if err := dbConn.GetWhere(ctx, []db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil { return err } - u.Admin = false - if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil { + + updatingColumns := []string{"admin", "updated_at"} + admin := false + u.Admin = &admin + u.UpdatedAt = time.Now() + if err := dbConn.UpdateByPrimaryKey(ctx, u, updatingColumns...); err != nil { return err } @@ -195,8 +206,12 @@ var Disable action.GTSAction = func(ctx context.Context) error { if err := dbConn.GetWhere(ctx, []db.Where{{Key: "account_id", Value: a.ID}}, u); err != nil { return err } - u.Disabled = true - if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil { + + updatingColumns := []string{"disabled", "updated_at"} + disabled := true + u.Disabled = &disabled + u.UpdatedAt = time.Now() + if err := dbConn.UpdateByPrimaryKey(ctx, u, updatingColumns...); err != nil { return err } @@ -247,9 +262,10 @@ var Password action.GTSAction = func(ctx context.Context) error { return fmt.Errorf("error hashing password: %s", err) } + updatingColumns := []string{"encrypted_password", "updated_at"} u.EncryptedPassword = string(pw) - - if err := dbConn.UpdateByPrimaryKey(ctx, u); err != nil { + u.UpdatedAt = time.Now() + if err := dbConn.UpdateByPrimaryKey(ctx, u, updatingColumns...); err != nil { return err } -- cgit v1.3