11package liman
22
33import (
4+ "encoding/json"
45 "strings"
56
67 "github.com/gofiber/fiber/v2"
@@ -11,14 +12,14 @@ import (
1112)
1213
1314// GetPermissions Gets user and extensions permissons and variables
14- func GetPermissions (user * models.User , extFilter string ) ([]string , map [string ]string , error ) {
15+ func GetPermissions (user * models.User , extFilter string ) ([]string , map [string ]interface {} , error ) {
1516 roles , err := getRoleMaps (user )
1617 if err != nil {
1718 return nil , nil , err
1819 }
1920
2021 permissions := []string {}
21- variables := make (map [string ]string )
22+ variables := make (map [string ]interface {} )
2223 for _ , role := range roles {
2324 permission , variable , err := getPermissionsFromMorph (role , strings .ToLower (extFilter ))
2425 if err != nil {
@@ -27,7 +28,7 @@ func GetPermissions(user *models.User, extFilter string) ([]string, map[string]s
2728
2829 permissions = append (permissions , permission ... )
2930
30- variables = helpers .MergeStringMaps (variables , variable )
31+ variables = helpers .MergeInterfaceMaps (variables , variable )
3132 }
3233
3334 if user .AuthType == "keycloak" {
@@ -63,7 +64,7 @@ func GetObjectPermissions(user *models.User) ([]string, error) {
6364}
6465
6566// getPermissionsFromMorph Searches db for morph relationships and returns permissions
66- func getPermissionsFromMorph (morphID string , extFilter string ) ([]string , map [string ]string , error ) {
67+ func getPermissionsFromMorph (morphID string , extFilter string ) ([]string , map [string ]interface {} , error ) {
6768 permission := []* models.Permission {}
6869
6970 err := database .Connection ().Find (& permission , "morph_id = ?" , morphID ).Error
@@ -72,7 +73,7 @@ func getPermissionsFromMorph(morphID string, extFilter string) ([]string, map[st
7273 }
7374
7475 funcPerms := []string {}
75- varPerms := make (map [string ]string )
76+ varPerms := make (map [string ]interface {} )
7677
7778 for _ , item := range permission {
7879 if item .Type == "function" {
@@ -86,7 +87,32 @@ func getPermissionsFromMorph(morphID string, extFilter string) ([]string, map[st
8687 }
8788
8889 if item .Type == "variable" {
89- varPerms [item .Key ] = item .Value
90+ if item .Extra == "multiselect" || item .Extra == "array" {
91+ var value []interface {}
92+ json .Unmarshal ([]byte (item .Value ), & value )
93+ varPerms [item .Key ] = value
94+ continue
95+ }
96+
97+ // Check if item is a json object
98+ if item .Extra == "json" {
99+ var value interface {}
100+ json .Unmarshal ([]byte (item .Value ), & value )
101+ varPerms [item .Key ] = value
102+ continue
103+ }
104+
105+ if existing , ok := varPerms [item .Key ]; ok {
106+ if existingSlice , ok := existing .([]string ); ok {
107+ existingSlice = append (existingSlice , item .Value )
108+ varPerms [item .Key ] = existingSlice
109+ } else {
110+ // If it's not a slice, convert it to a slice
111+ varPerms [item .Key ] = []string {existing .(string ), item .Value }
112+ }
113+ } else {
114+ varPerms [item .Key ] = item .Value
115+ }
90116 }
91117 }
92118
0 commit comments