Fix permission issues for unauthenticated users
All checks were successful
cacert-boardvoting/pipeline/head This commit looks good

This commit is contained in:
Jan Dittberner 2022-10-16 11:37:51 +02:00
parent fd287e4f55
commit c9d3f2a20a
3 changed files with 12 additions and 6 deletions

View file

@ -199,12 +199,10 @@ func (app *Application) Routes() http.Handler {
r.Get("/newmotion/", motionHandler.NewForm)
r.Post("/newmotion/", motionHandler.New)
r.Route("/motions/{tag}", func(r chi.Router) {
r.Get("/edit", motionHandler.EditForm)
r.Post("/edit", motionHandler.Edit)
r.Get("/withdraw", motionHandler.WithdrawForm)
r.Post("/withdraw", motionHandler.Withdraw)
})
r.Get("/motions/{tag}/edit", motionHandler.EditForm)
r.Post("/motions/{tag}/edit", motionHandler.Edit)
r.Get("/motions/{tag}/withdraw", motionHandler.WithdrawForm)
r.Post("/motions/{tag}/withdraw", motionHandler.Withdraw)
})
r.Group(func(r chi.Router) {

View file

@ -34,6 +34,10 @@ import (
)
func checkRole(v *models.User, roles ...models.RoleName) (bool, error) {
if v == nil {
return false, nil
}
hasRole, err := v.HasRole(roles...)
if err != nil {
return false, fmt.Errorf("could not determine user roles: %w", err)

View file

@ -251,6 +251,10 @@ WHERE e.address IN (?)`, emails)
}
}
if count == 0 {
return nil, nil
}
if user.roles, err = m.Roles(ctx, &user); err != nil {
return nil, fmt.Errorf("could not retrieve roles for user %s: %w", user.Name, err)
}