3 Commits

  1. 1
      cmd/server/main.go
  2. 2
      flake.nix
  3. 2
      server/models/role.go
  4. 4
      server/models/user.go
  5. 2
      server/server.go

1
cmd/server/main.go

@ -59,6 +59,7 @@ func main() {
config.Database.Name, config.Database.Name,
config.Database.Port))) config.Database.Port)))
case "sqlite": case "sqlite":
fallthrough
default: default:
db, _ = gorm.Open(sqlite.Open(config.Database.File), &gorm.Config{}) db, _ = gorm.Open(sqlite.Open(config.Database.File), &gorm.Config{})
} }

2
flake.nix

@ -23,7 +23,7 @@
''; '';
myUsersTest = pkgs.writeShellScriptBin "users-test" '' myUsersTest = pkgs.writeShellScriptBin "users-test" ''
pushd ${myUsersDir} > /dev/null && pushd ${myUsersDir} > /dev/null &&
${pkgs.parallel}/bin/parallel :: ${myUsersDir}/bin/users-server ${myUsersDir}/bin/users-gateway
${pkgs.parallel}/bin/parallel ::: ${myUsersDir}/bin/users-server ${myUsersDir}/bin/users-gateway
popd > /dev/null popd > /dev/null
''; '';
in in

2
server/models/role.go

@ -5,5 +5,5 @@ import "gorm.io/gorm"
type Role struct { type Role struct {
gorm.Model gorm.Model
Name string Name string
Users []User
Users []*User `gorm:"many2many:user_roles;"`
} }

4
server/models/user.go

@ -7,6 +7,6 @@ type User struct {
UUID string UUID string
Email string Email string
Password string Password string
Roles []Role
Sessions []Session
Roles []*Role `gorm:"many2many:user_roles;"`
Sessions []*Session
} }

2
server/server.go

@ -270,7 +270,7 @@ func (m *usersServer) SetRoles(ctx context.Context, in *proto.SetRolesRequest) (
var r models.Role var r models.Role
for _, x := range in.Roles { for _, x := range in.Roles {
if tx := m.db.First(&r, "id = ?", x.Id); tx.RowsAffected != 0 { if tx := m.db.First(&r, "id = ?", x.Id); tx.RowsAffected != 0 {
u.Roles = append(u.Roles, r)
u.Roles = append(u.Roles, &r)
} }
} }

Loading…
Cancel
Save