feat: Users API, ownership transfer and removal of the legacy role string
This commit is contained in:
1 parent
094df63a7f
commit
80f7037d3a
124 files changed
+4644
-824
No files matched your search
@@ -72,8 +72,9 @@ func TestMySQLMigration(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 := migratedMySQL(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', ?, '', 1, 0)", name, name+"@x.example")
|
||||
if insert.Error != nil {
|
||||
@@ -85,15 +86,18 @@ func TestMySQLMigration(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")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user