changed privilige handling
This commit is contained in:
@@ -16,18 +16,6 @@ const (
|
||||
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 {
|
||||
AM string
|
||||
A1 string
|
||||
@@ -78,10 +66,22 @@ var Priviliges = struct {
|
||||
Update int8
|
||||
Delete int8
|
||||
}{
|
||||
View: 0,
|
||||
Update: 10,
|
||||
Create: 20,
|
||||
Delete: 30,
|
||||
View: 1,
|
||||
Update: 4,
|
||||
Create: 4,
|
||||
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{
|
||||
|
||||
@@ -1,25 +1,13 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"GoMembership/internal/constants"
|
||||
"GoMembership/internal/models"
|
||||
"errors"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func HasPrivilige(user *models.User, privilige int8) bool {
|
||||
switch 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
|
||||
}
|
||||
return user.RoleID >= privilige
|
||||
}
|
||||
|
||||
// FilterAllowedStructFields filters allowed fields recursively in a struct and modifies structToModify in place.
|
||||
|
||||
Reference in New Issue
Block a user