fix: multi role with oauth (#61)

This commit is contained in:
Lakhan Samani
2021-10-19 12:57:59 +05:30
committed by GitHub
parent b376ee3b73
commit f4992010ed
6 changed files with 82 additions and 78 deletions

View File

@@ -19,7 +19,7 @@ func WriteToFile(filename string, data string) error {
return file.Sync()
}
func StringContains(s []string, e string) bool {
func StringSliceContains(s []string, e string) bool {
for _, a := range s {
if a == e {
return true

View File

@@ -18,6 +18,11 @@ func InitServer() {
Role: val,
})
}
for _, val := range constants.PROTECTED_ROLES {
roles = append(roles, db.Role{
Role: val,
})
}
err := db.Mgr.SaveRoles(roles)
if err != nil {
log.Println(`Error saving roles`, err)

View File

@@ -43,7 +43,7 @@ func IsSuperAdmin(gc *gin.Context) bool {
func IsValidRoles(userRoles []string, roles []string) bool {
valid := true
for _, role := range roles {
if !StringContains(userRoles, role) {
if !StringSliceContains(userRoles, role) {
valid = false
break
}