Add API call for frontend to fetch list of valid roles from backend

- only relevant for admin config (addUser, editRole)
- admin only (double-checked)
This commit is contained in:
Christoph Kluge
2023-01-30 17:01:11 +01:00
parent 7d4f4ab2c8
commit 7fb94c33cf
5 changed files with 78 additions and 28 deletions

View File

@@ -12,6 +12,7 @@ import (
"net/http"
"os"
"time"
"fmt"
"github.com/ClusterCockpit/cc-backend/pkg/log"
"github.com/gorilla/sessions"
@@ -139,6 +140,15 @@ func IsValidRole(role string) bool {
return false
}
func GetValidRoles(user *User) ([5]string, error) {
var vals [5]string
if (!user.HasRole(RoleAdmin)) {
return vals, fmt.Errorf("%#v: only admins are allowed to fetch a list of roles", user.Username)
} else {
return validRoles, nil
}
}
func GetUser(ctx context.Context) *User {
x := ctx.Value(ContextUserKey)
if x == nil {