Audit of cde5089
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
ALTER TABLE users ADD COLUMN notify_questions INTEGER NOT NULL DEFAULT 1;
|
||||
ALTER TABLE users ADD COLUMN notify_reports INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE users ADD COLUMN notify_errors INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE users ADD COLUMN notify_rate_limits INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE users ADD COLUMN notify_ready INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE users ADD COLUMN notify_discard INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE users ADD COLUMN notify_merge_problems INTEGER NOT NULL DEFAULT 0;
|
||||
ALTER TABLE users ADD COLUMN notify_workflows INTEGER NOT NULL DEFAULT 0;
|
||||
|
||||
UPDATE users SET
|
||||
notify_questions = coalesce(json_extract(notification_prefs, '$.questions'), 0),
|
||||
notify_reports = coalesce(json_extract(notification_prefs, '$.reports'), 0),
|
||||
notify_errors = coalesce(json_extract(notification_prefs, '$.errors'), 0),
|
||||
notify_rate_limits = coalesce(json_extract(notification_prefs, '$.rate_limits'), 0),
|
||||
notify_ready = coalesce(json_extract(notification_prefs, '$.ready'), 0),
|
||||
notify_discard = coalesce(json_extract(notification_prefs, '$.discard'), 0),
|
||||
notify_merge_problems = coalesce(json_extract(notification_prefs, '$.merge_problems'), 0),
|
||||
notify_workflows = coalesce(json_extract(notification_prefs, '$.workflows'), 0);
|
||||
|
||||
ALTER TABLE users DROP COLUMN notification_prefs;
|
||||
@@ -3,18 +3,14 @@ package store
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
|
||||
"g.fc.run/ai/byre/internal/api"
|
||||
)
|
||||
|
||||
func (s *Store) UpdateNotificationPrefs(ctx context.Context, login string, prefs api.NotificationPrefs) (api.User, error) {
|
||||
b, err := json.Marshal(prefs)
|
||||
if err != nil {
|
||||
return api.User{}, err
|
||||
}
|
||||
err = s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
_, err := tx.ExecContext(ctx, `UPDATE users SET notification_prefs = ? WHERE login = ?`, string(b), login)
|
||||
err := s.write(ctx, func(tx *sql.Tx, emit emitFunc) error {
|
||||
_, err := tx.ExecContext(ctx, `UPDATE users SET notify_questions = ?, notify_reports = ?, notify_errors = ?, notify_rate_limits = ?, notify_ready = ?, notify_discard = ?, notify_merge_problems = ?, notify_workflows = ? WHERE login = ?`,
|
||||
prefs.Questions, prefs.Reports, prefs.Errors, prefs.RateLimits, prefs.Ready, prefs.Discard, prefs.MergeProblems, prefs.Workflows, login)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -237,16 +237,12 @@ func (s *Store) EnsureUser(ctx context.Context, login, displayName string) (api.
|
||||
|
||||
func (s *Store) GetUser(ctx context.Context, login string) (api.User, error) {
|
||||
u := api.User{}
|
||||
prefs := ""
|
||||
err := s.db.QueryRowContext(ctx, `SELECT login, display_name, git_name, git_email, notification_prefs, default_model, away FROM users WHERE login = ?`, login).
|
||||
Scan(&u.Login, &u.DisplayName, &u.GitName, &u.GitEmail, &prefs, &u.DefaultModel, &u.Away)
|
||||
p := &u.NotificationPrefs
|
||||
err := s.db.QueryRowContext(ctx, `SELECT login, display_name, git_name, git_email, notify_questions, notify_reports, notify_errors, notify_rate_limits, notify_ready, notify_discard, notify_merge_problems, notify_workflows, default_model, away FROM users WHERE login = ?`, login).
|
||||
Scan(&u.Login, &u.DisplayName, &u.GitName, &u.GitEmail, &p.Questions, &p.Reports, &p.Errors, &p.RateLimits, &p.Ready, &p.Discard, &p.MergeProblems, &p.Workflows, &u.DefaultModel, &u.Away)
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return u, ErrNotFound
|
||||
}
|
||||
if err != nil {
|
||||
return u, err
|
||||
}
|
||||
err = json.Unmarshal([]byte(prefs), &u.NotificationPrefs)
|
||||
return u, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user