fix user edit bug, allow to delete users from the database (#40)

This commit is contained in:
Christoph Haas
2022-03-15 23:34:55 +01:00
parent cc50fcf8e6
commit 83271b5d34
7 changed files with 73 additions and 27 deletions

View File

@@ -161,9 +161,14 @@ func (m Manager) UpdateUser(user *User) error {
return nil
}
func (m Manager) DeleteUser(user *User) error {
func (m Manager) DeleteUser(user *User, soft bool) error {
user.Email = strings.ToLower(user.Email)
res := m.db.Delete(user)
var res *gorm.DB
if soft {
res = m.db.Delete(user)
} else {
res = m.db.Unscoped().Delete(user)
}
if res.Error != nil {
return errors.Wrapf(res.Error, "failed to update user %s", user.Email)
}

View File

@@ -29,7 +29,7 @@ type User struct {
// required fields
Email string `gorm:"primaryKey" form:"email" binding:"required,email"`
Source UserSource
IsAdmin bool
IsAdmin bool `form:"isadmin"`
// optional fields
Firstname string `form:"firstname" binding:"required"`