summaryrefslogtreecommitdiff
path: root/internal/db/bundb/admin.go
diff options
context:
space:
mode:
authorLibravatar tobi <31960611+tsmethurst@users.noreply.github.com>2023-09-04 15:55:17 +0200
committerLibravatar GitHub <noreply@github.com>2023-09-04 14:55:17 +0100
commit3ed1ca68e52527f74103e1a57ae48ae533508c3a (patch)
treed6113d71d6f88a3d99bbd2215ead6ca1d4fa6153 /internal/db/bundb/admin.go
parent[chore]: Bump golang.org/x/image from 0.11.0 to 0.12.0 (#2178) (diff)
downloadgotosocial-3ed1ca68e52527f74103e1a57ae48ae533508c3a.tar.xz
[feature] Store admin actions in the db, prevent conflicting actions (#2167)
Diffstat (limited to 'internal/db/bundb/admin.go')
-rw-r--r--internal/db/bundb/admin.go66
1 files changed, 66 insertions, 0 deletions
diff --git a/internal/db/bundb/admin.go b/internal/db/bundb/admin.go
index 8af08973c..e189c508e 100644
--- a/internal/db/bundb/admin.go
+++ b/internal/db/bundb/admin.go
@@ -320,3 +320,69 @@ func (a *adminDB) CreateInstanceInstance(ctx context.Context) error {
log.Infof(ctx, "created instance instance %s with id %s", host, i.ID)
return nil
}
+
+/*
+ ACTION FUNCS
+*/
+
+func (a *adminDB) GetAdminAction(ctx context.Context, id string) (*gtsmodel.AdminAction, error) {
+ action := new(gtsmodel.AdminAction)
+
+ if err := a.db.
+ NewSelect().
+ Model(action).
+ Scan(ctx); err != nil {
+ return nil, err
+ }
+
+ return action, nil
+}
+
+func (a *adminDB) GetAdminActions(ctx context.Context) ([]*gtsmodel.AdminAction, error) {
+ actions := make([]*gtsmodel.AdminAction, 0)
+
+ if err := a.db.
+ NewSelect().
+ Model(&actions).
+ Scan(ctx); err != nil {
+ return nil, err
+ }
+
+ return actions, nil
+}
+
+func (a *adminDB) PutAdminAction(ctx context.Context, action *gtsmodel.AdminAction) error {
+ _, err := a.db.
+ NewInsert().
+ Model(action).
+ Exec(ctx)
+
+ return err
+}
+
+func (a *adminDB) UpdateAdminAction(ctx context.Context, action *gtsmodel.AdminAction, columns ...string) error {
+ // Update the action's last-updated
+ action.UpdatedAt = time.Now()
+ if len(columns) != 0 {
+ columns = append(columns, "updated_at")
+ }
+
+ _, err := a.db.
+ NewUpdate().
+ Model(action).
+ Where("? = ?", bun.Ident("admin_action.id"), action.ID).
+ Column(columns...).
+ Exec(ctx)
+
+ return err
+}
+
+func (a *adminDB) DeleteAdminAction(ctx context.Context, id string) error {
+ _, err := a.db.
+ NewDelete().
+ TableExpr("? AS ?", bun.Ident("admin_actions"), bun.Ident("admin_action")).
+ Where("? = ?", bun.Ident("admin_action"), id).
+ Exec(ctx)
+
+ return err
+}