another one
This commit is contained in:
@@ -2,7 +2,6 @@ package db
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"git.haelnorr.com/h/oslstats/internal/roles"
|
||||
"github.com/pkg/errors"
|
||||
@@ -66,17 +65,13 @@ func HasRole(ctx context.Context, tx bun.Tx, userID int, roleName roles.Role) (b
|
||||
if roleName == "" {
|
||||
return false, errors.New("roleName cannot be empty")
|
||||
}
|
||||
user := new(User)
|
||||
err := tx.NewSelect().
|
||||
Model(user).
|
||||
Relation("Roles").
|
||||
Where("u.id = ?", userID).
|
||||
Scan(ctx)
|
||||
user, err := GetByID[User](tx, userID).
|
||||
Relation("Roles").GetFirst(ctx)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
return false, nil
|
||||
}
|
||||
return false, errors.Wrap(err, "tx.NewSelect")
|
||||
return false, errors.Wrap(err, "GetByID")
|
||||
}
|
||||
if user == nil {
|
||||
return false, nil
|
||||
}
|
||||
for _, role := range user.Roles {
|
||||
if role.Name == roleName {
|
||||
|
||||
Reference in New Issue
Block a user