mirror of
https://github.com/ClusterCockpit/cc-backend
synced 2025-07-22 12:41:39 +02:00
implement removeTagFromList mutation, add tag mutation access checks
This commit is contained in:
@@ -85,6 +85,7 @@ func IsValidRole(role string) bool {
|
||||
return getRoleEnum(role) != RoleError
|
||||
}
|
||||
|
||||
// Check if User has SPECIFIED role AND role is VALID
|
||||
func (u *User) HasValidRole(role string) (hasRole bool, isValid bool) {
|
||||
if IsValidRole(role) {
|
||||
for _, r := range u.Roles {
|
||||
@@ -97,6 +98,7 @@ func (u *User) HasValidRole(role string) (hasRole bool, isValid bool) {
|
||||
return false, false
|
||||
}
|
||||
|
||||
// Check if User has SPECIFIED role
|
||||
func (u *User) HasRole(role Role) bool {
|
||||
for _, r := range u.Roles {
|
||||
if r == GetRoleString(role) {
|
||||
@@ -106,7 +108,7 @@ func (u *User) HasRole(role Role) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Role-Arrays are short: performance not impacted by nested loop
|
||||
// Check if User has ANY of the listed roles
|
||||
func (u *User) HasAnyRole(queryroles []Role) bool {
|
||||
for _, ur := range u.Roles {
|
||||
for _, qr := range queryroles {
|
||||
@@ -118,7 +120,7 @@ func (u *User) HasAnyRole(queryroles []Role) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// Role-Arrays are short: performance not impacted by nested loop
|
||||
// Check if User has ALL of the listed roles
|
||||
func (u *User) HasAllRoles(queryroles []Role) bool {
|
||||
target := len(queryroles)
|
||||
matches := 0
|
||||
@@ -138,7 +140,7 @@ func (u *User) HasAllRoles(queryroles []Role) bool {
|
||||
}
|
||||
}
|
||||
|
||||
// Role-Arrays are short: performance not impacted by nested loop
|
||||
// Check if User has NONE of the listed roles
|
||||
func (u *User) HasNotRoles(queryroles []Role) bool {
|
||||
matches := 0
|
||||
for _, ur := range u.Roles {
|
||||
|
Reference in New Issue
Block a user