changed privilige handling

This commit is contained in:
Alex
2025-02-28 11:56:26 +01:00
parent a2e8abbf6b
commit 658cc9aecd
2 changed files with 17 additions and 29 deletions

View File

@@ -16,18 +16,6 @@ const (
MailContactSubject = "Jemand hat das Kontaktformular gefunden" MailContactSubject = "Jemand hat das Kontaktformular gefunden"
) )
var Roles = struct {
Member int8
Viewer int8
Editor int8
Admin int8
}{
Member: 0,
Viewer: 1,
Editor: 4,
Admin: 8,
}
var Licences = struct { var Licences = struct {
AM string AM string
A1 string A1 string
@@ -78,10 +66,22 @@ var Priviliges = struct {
Update int8 Update int8
Delete int8 Delete int8
}{ }{
View: 0, View: 1,
Update: 10, Update: 4,
Create: 20, Create: 4,
Delete: 30, Delete: 4,
}
var Roles = struct {
Member int8
Viewer int8
Editor int8
Admin int8
}{
Member: 0,
Viewer: 1,
Editor: 4,
Admin: 8,
} }
var MemberUpdateFields = map[string]bool{ var MemberUpdateFields = map[string]bool{

View File

@@ -1,25 +1,13 @@
package utils package utils
import ( import (
"GoMembership/internal/constants"
"GoMembership/internal/models" "GoMembership/internal/models"
"errors" "errors"
"reflect" "reflect"
) )
func HasPrivilige(user *models.User, privilige int8) bool { func HasPrivilige(user *models.User, privilige int8) bool {
switch privilige { return user.RoleID >= privilige
case constants.Priviliges.View:
return user.RoleID >= constants.Roles.Viewer
case constants.Priviliges.Update:
return user.RoleID >= constants.Roles.Editor
case constants.Priviliges.Create:
return user.RoleID >= constants.Roles.Editor
case constants.Priviliges.Delete:
return user.RoleID >= constants.Roles.Editor
default:
return false
}
} }
// FilterAllowedStructFields filters allowed fields recursively in a struct and modifies structToModify in place. // FilterAllowedStructFields filters allowed fields recursively in a struct and modifies structToModify in place.