LDAP: validate organization role during parsing (#37188)

* LDAP: validate organization role during parsing

* Trigger a new build

* Check if grafana_admin is present
This commit is contained in:
Krzysztof Dąbrowski
2022-05-04 09:35:10 +02:00
committed by GitHub
parent 18f089d1bd
commit c41397a6e7
3 changed files with 24 additions and 34 deletions

View File

@@ -1,9 +1,9 @@
package models
import (
"encoding/json"
"errors"
"fmt"
"strings"
"time"
)
@@ -61,18 +61,14 @@ func (r RoleType) Parents() []RoleType {
}
}
func (r *RoleType) UnmarshalJSON(data []byte) error {
var str string
err := json.Unmarshal(data, &str)
if err != nil {
return err
}
func (r *RoleType) UnmarshalText(data []byte) error {
// make sure "viewer" and "Viewer" are both correct
str := strings.Title(string(data))
*r = RoleType(str)
if !r.IsValid() {
if (*r) != "" {
return fmt.Errorf("JSON validation error: invalid role value: %s", *r)
return fmt.Errorf("invalid role value: %s", *r)
}
*r = ROLE_VIEWER