feat: Users API, ownership transfer and removal of the legacy role string

This commit is contained in:
Florian Sylvain committed 2026-10-27 03:08:15 +01:00
1 parent 094df63a7f
commit 80f7037d3a
124 files changed
+4644 -824

No files matched your search

+9 -5
View File
@@ -184,8 +184,9 @@ func TestPostgresMigration(t *testing.T) {
}
})
t.Run("the first user lacking a role becomes owner and the others admin", func(t *testing.T) {
t.Run("a legacy users.role column is backfilled into role_id and the invites get Admin", func(t *testing.T) {
_, _, db := migratedPostgres(t)
addLegacyRoleColumn(t, db)
for _, name := range []string{"first", "second", "third"} {
insert := db.Exec("INSERT INTO users (username, password, email, role, is_verified, token_version) VALUES (?, 'x', ?, '', true, 0)", name, name+"@x.example")
if insert.Error != nil {
@@ -197,15 +198,18 @@ func TestPostgresMigration(t *testing.T) {
t.Fatalf("migrate: %v", err)
}
roles := map[string]string{}
roles := map[string]uint32{}
var users []models.User
db.Find(&users)
for _, user := range users {
roles[user.Username] = user.Role
for _, stored := range users {
roles[stored.Username] = roleIDOf(stored)
}
if roles["first"] != "owner" || roles["second"] != "admin" || roles["third"] != "admin" {
if roles["first"] != storedRole(t, db, "Owner").ID || roles["second"] != storedRole(t, db, "Admin").ID || roles["third"] != storedRole(t, db, "Admin").ID {
t.Errorf("unexpected roles %v", roles)
}
if !db.Migrator().HasColumn("users", "role") {
t.Errorf("the legacy column must stay")
}
})
}