mirror of
https://github.com/andwati/zitadel.git
synced 2026-12-04 18:08:50 +00:00
feat: actions (#2377)
* 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 <[email protected]>
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user