Skip to content

Commit

Permalink
Fix disabling options in profile settings
Browse files Browse the repository at this point in the history
Unchecking options like API access was not working, because unchecked
checkboxes are not sent as form values.

This change first unsets all booleans, which may or may not be enabled
again through the form.

Signed-off-by: Jo Vandeginste <[email protected]>
  • Loading branch information
jovandeginste committed Jun 13, 2024
1 parent ac79270 commit 18d9b44
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pkg/app/self_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ func (a *App) userProfileUpdateHandler(c echo.Context) error {
u := a.getCurrentUser(c)
p := &u.Profile

p.ResetBools()

if err := c.Bind(p); err != nil {
return a.redirectWithError(c, a.echo.Reverse("user-profile"), err)
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/database/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func (u UserPreferredUnits) Speed() string {
}
}

func (p *Profile) ResetBools() {
p.PreferFullDate = false
p.APIActive = false
p.SocialsDisabled = false
}

func (p *Profile) Save(db *gorm.DB) error {
return db.Save(p).Error
}
Expand Down

0 comments on commit 18d9b44

Please sign in to comment.