mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-12 11:04:25 +00:00
ed80a8bb1e
* feat(actions): begin api * feat(actions): begin api * api and projections * fix: handle multiple statements for a single event in projections * export func type * fix test * update to new reduce interface * flows in login * feat: jwt idp * feat: command side * feat: add tests * actions and flows * fill idp views with jwt idps and return apis * add jwtEndpoint to jwt idp * begin jwt request handling * add feature * merge * merge * handle jwt idp * cleanup * bug fixes * autoregister * get token from specific header name * fix: proto * fixes * i18n * begin tests * fix and log http proxy * remove docker cache * fixes * usergrants in actions api * tests adn cleanup * cleanup * fix add user grant * set login context * i18n Co-authored-by: fabi <fabienne.gerschwiler@gmail.com>
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package actions
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/dop251/goja"
|
|
)
|
|
|
|
type UserGrant struct {
|
|
ProjectID string
|
|
ProjectGrantID string
|
|
Roles []string
|
|
}
|
|
|
|
func appendUserGrant(list *[]UserGrant) func(goja.FunctionCall) goja.Value {
|
|
return func(call goja.FunctionCall) goja.Value {
|
|
userGrantMap := call.Argument(0).Export()
|
|
userGrant, _ := userGrantFromMap(userGrantMap)
|
|
*list = append(*list, userGrant)
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func userGrantFromMap(grantMap interface{}) (UserGrant, error) {
|
|
m, ok := grantMap.(map[string]interface{})
|
|
if !ok {
|
|
return UserGrant{}, errors.New("invalid")
|
|
}
|
|
projectID, ok := m["projectID"].(string)
|
|
if !ok {
|
|
return UserGrant{}, errors.New("invalid")
|
|
}
|
|
var projectGrantID string
|
|
if id, ok := m["projectGrantID"]; ok {
|
|
projectGrantID, ok = id.(string)
|
|
if !ok {
|
|
return UserGrant{}, errors.New("invalid")
|
|
}
|
|
}
|
|
var roles []string
|
|
if r := m["roles"]; r != nil {
|
|
rs, ok := r.([]interface{})
|
|
if !ok {
|
|
return UserGrant{}, errors.New("invalid")
|
|
}
|
|
for _, role := range rs {
|
|
roles = append(roles, role.(string))
|
|
}
|
|
}
|
|
return UserGrant{
|
|
ProjectID: projectID,
|
|
ProjectGrantID: projectGrantID,
|
|
Roles: roles,
|
|
}, nil
|
|
}
|