Massive rework of platform layer user/organization

The goal of this rework is to make it so I can pass around platform.User
instead of a pair of models.Organization and models.User. This is useful
for reason I kind of forget now, but it started with working on
notifications and ballooned massively from there into refactoring a
number of things that were bugging me.

This also includes a tiny amount of work on server-side events (SSE).

 * background stuff lives inside the platform now, which I need for
   having it push updates through SSE
 * userfile now lives in the platform, under file, so other platform
   functions can safely use it
 * oauth is broken into pieces and inside platform because other stuff
   was calling it already, but badly.
 * notifications go into the platform as well
This commit is contained in:
Eli Ribble 2026-03-12 23:49:16 +00:00
parent 32dcc50c94
commit 44c4f17f32
No known key found for this signature in database
85 changed files with 1492 additions and 1384 deletions

View file

@ -1,48 +0,0 @@
package db
import (
"context"
"github.com/Gleipnir-Technology/nidus-sync/db/models"
"github.com/google/uuid"
"github.com/rs/zerolog/log"
)
func NoteAudioCreate(ctx context.Context, org *models.Organization, userID int32, setter models.NoteAudioSetter) error {
err := org.InsertNoteAudios(ctx, PGInstance.BobDB, &setter)
if err == nil {
return nil
}
// Just ignore this failure, it means we already have this content
if err.Error() == "insertOrganizationNoteAudios0: ERROR: duplicate key value violates unique constraint \"note_audio_pkey\" (SQLSTATE 23505)" {
return nil
}
log.Warn().Err(err).Msg("Unrecognized error creating note audio")
return err
}
func NoteAudioGetLatest(ctx context.Context, uuid string) (*models.NoteAudio, error) {
return nil, nil
}
func NoteAudioNormalized(uuid string) error {
return nil
}
func NoteAudioTranscodedToOgg(uuid string) error {
return nil
}
func NoteImageCreate(ctx context.Context, org *models.Organization, userID int32, setter models.NoteImageSetter) error {
err := org.InsertNoteImages(ctx, PGInstance.BobDB, &setter)
if err == nil {
return nil
}
// Just ignore this failure, it means we already have this content
if err.Error() == "insertOrganizationNoteImages0: ERROR: duplicate key value violates unique constraint \"note_image_pkey\" (SQLSTATE 23505)" {
return nil
}
log.Warn().Err(err).Msg("Unrecognized error creating note audio")
return err
}
func NoteUpdate(ctx context.Context, noteUUID uuid.UUID, setter models.NoteAudioSetter) error {
return nil
}

View file

@ -1,118 +0,0 @@
// Code generated by BobGen psql v0.42.5. DO NOT EDIT.
// This file is meant to be re-generated in place and/or deleted at any time.
package sql
import (
"context"
_ "embed"
"io"
"iter"
"time"
"github.com/Gleipnir-Technology/bob"
"github.com/Gleipnir-Technology/bob/dialect/psql"
"github.com/Gleipnir-Technology/bob/dialect/psql/dialect"
"github.com/Gleipnir-Technology/bob/orm"
enums "github.com/Gleipnir-Technology/nidus-sync/db/enums"
"github.com/aarondl/opt/null"
"github.com/stephenafamo/scan"
)
//go:embed user_by_username.bob.sql
var formattedQueries_user_by_username string
var userByUsernameSQL = formattedQueries_user_by_username[152:806]
type UserByUsernameQuery = orm.ModQuery[*dialect.SelectQuery, userByUsername, UserByUsernameRow, []UserByUsernameRow, userByUsernameTransformer]
func UserByUsername(Username string) *UserByUsernameQuery {
var expressionTypArgs userByUsername
expressionTypArgs.Username = psql.Arg(Username)
return &UserByUsernameQuery{
Query: orm.Query[userByUsername, UserByUsernameRow, []UserByUsernameRow, userByUsernameTransformer]{
ExecQuery: orm.ExecQuery[userByUsername]{
BaseQuery: bob.BaseQuery[userByUsername]{
Expression: expressionTypArgs,
Dialect: dialect.Dialect,
QueryType: bob.QueryTypeSelect,
},
},
Scanner: func(context.Context, []string) (func(*scan.Row) (any, error), func(any) (UserByUsernameRow, error)) {
return func(row *scan.Row) (any, error) {
var t UserByUsernameRow
row.ScheduleScanByIndex(0, &t.ID)
row.ScheduleScanByIndex(1, &t.ArcgisAccessToken)
row.ScheduleScanByIndex(2, &t.ArcgisLicense)
row.ScheduleScanByIndex(3, &t.ArcgisRefreshToken)
row.ScheduleScanByIndex(4, &t.ArcgisRefreshTokenExpires)
row.ScheduleScanByIndex(5, &t.ArcgisRole)
row.ScheduleScanByIndex(6, &t.DisplayName)
row.ScheduleScanByIndex(7, &t.Email)
row.ScheduleScanByIndex(8, &t.OrganizationID)
row.ScheduleScanByIndex(9, &t.Username)
row.ScheduleScanByIndex(10, &t.PasswordHashType)
row.ScheduleScanByIndex(11, &t.PasswordHash)
row.ScheduleScanByIndex(12, &t.Role)
return &t, nil
}, func(v any) (UserByUsernameRow, error) {
return *(v.(*UserByUsernameRow)), nil
}
},
},
Mod: bob.ModFunc[*dialect.SelectQuery](func(q *dialect.SelectQuery) {
q.AppendSelect(expressionTypArgs.subExpr(7, 577))
q.SetTable(expressionTypArgs.subExpr(583, 595))
q.AppendWhere(expressionTypArgs.subExpr(603, 654))
}),
}
}
type UserByUsernameRow = struct {
ID int32 `db:"id"`
ArcgisAccessToken null.Val[string] `db:"arcgis_access_token"`
ArcgisLicense null.Val[enums.Arcgislicensetype] `db:"arcgis_license"`
ArcgisRefreshToken null.Val[string] `db:"arcgis_refresh_token"`
ArcgisRefreshTokenExpires null.Val[time.Time] `db:"arcgis_refresh_token_expires"`
ArcgisRole null.Val[string] `db:"arcgis_role"`
DisplayName string `db:"display_name"`
Email null.Val[string] `db:"email"`
OrganizationID int32 `db:"organization_id"`
Username string `db:"username"`
PasswordHashType enums.Hashtype `db:"password_hash_type"`
PasswordHash string `db:"password_hash"`
Role enums.Userrole `db:"role"`
}
type userByUsernameTransformer = bob.SliceTransformer[UserByUsernameRow, []UserByUsernameRow]
type userByUsername struct {
Username bob.Expression
}
func (o userByUsername) args() iter.Seq[orm.ArgWithPosition] {
return func(yield func(arg orm.ArgWithPosition) bool) {
if !yield(orm.ArgWithPosition{
Name: "username",
Start: 614,
Stop: 616,
Expression: o.Username,
}) {
return
}
}
}
func (o userByUsername) raw(from, to int) string {
return userByUsernameSQL[from:to]
}
func (o userByUsername) subExpr(from, to int) bob.Expression {
return orm.ArgsToExpression(userByUsernameSQL, from, to, o.args())
}
func (o userByUsername) WriteSQL(ctx context.Context, w io.StringWriter, d bob.Dialect, start int) ([]any, error) {
return o.subExpr(0, len(userByUsernameSQL)).WriteSQL(ctx, w, d, start)
}

View file

@ -1,7 +0,0 @@
-- Code generated by BobGen psql v0.42.5. DO NOT EDIT.
-- This file is meant to be re-generated in place and/or deleted at any time.
-- UserByUsername
SELECT "user_"."id" AS "id", "user_"."arcgis_access_token" AS "arcgis_access_token", "user_"."arcgis_license" AS "arcgis_license", "user_"."arcgis_refresh_token" AS "arcgis_refresh_token", "user_"."arcgis_refresh_token_expires" AS "arcgis_refresh_token_expires", "user_"."arcgis_role" AS "arcgis_role", "user_"."display_name" AS "display_name", "user_"."email" AS "email", "user_"."organization_id" AS "organization_id", "user_"."username" AS "username", "user_"."password_hash_type" AS "password_hash_type", "user_"."password_hash" AS "password_hash", "user_"."role" AS "role" FROM public.user_ WHERE
username = $1 AND
password_hash_type = 'bcrypt-14';