mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 04:57:33 +00:00
feat(actions): allow getting metadata of organizations from user grants (#7782)
* feat(actions): allow getting metadata of (other) organizations from user grants * docs add action example
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package object
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/dop251/goja"
|
||||
@@ -44,6 +45,8 @@ type userGrant struct {
|
||||
|
||||
ProjectId string
|
||||
ProjectName string
|
||||
|
||||
GetOrgMetadata func(goja.FunctionCall) goja.Value
|
||||
}
|
||||
|
||||
func AppendGrantFunc(userGrants *UserGrants) func(c *actions.FieldConfig) func(call goja.FunctionCall) goja.Value {
|
||||
@@ -58,10 +61,11 @@ func AppendGrantFunc(userGrants *UserGrants) func(c *actions.FieldConfig) func(c
|
||||
}
|
||||
}
|
||||
|
||||
func UserGrantsFromQuery(c *actions.FieldConfig, userGrants *query.UserGrants) goja.Value {
|
||||
func UserGrantsFromQuery(ctx context.Context, queries *query.Queries, c *actions.FieldConfig, userGrants *query.UserGrants) goja.Value {
|
||||
if userGrants == nil {
|
||||
return c.Runtime.ToValue(nil)
|
||||
}
|
||||
orgMetadata := make(map[string]goja.Value)
|
||||
grantList := &userGrantList{
|
||||
Count: userGrants.Count,
|
||||
Sequence: userGrants.Sequence,
|
||||
@@ -84,16 +88,24 @@ func UserGrantsFromQuery(c *actions.FieldConfig, userGrants *query.UserGrants) g
|
||||
UserGrantResourceOwnerName: grant.OrgName,
|
||||
ProjectId: grant.ProjectID,
|
||||
ProjectName: grant.ProjectName,
|
||||
GetOrgMetadata: func(call goja.FunctionCall) goja.Value {
|
||||
if md, ok := orgMetadata[grant.ResourceOwner]; ok {
|
||||
return md
|
||||
}
|
||||
orgMetadata[grant.ResourceOwner] = GetOrganizationMetadata(ctx, queries, c, grant.ResourceOwner)
|
||||
return orgMetadata[grant.ResourceOwner]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
return c.Runtime.ToValue(grantList)
|
||||
}
|
||||
|
||||
func UserGrantsFromSlice(c *actions.FieldConfig, userGrants []query.UserGrant) goja.Value {
|
||||
func UserGrantsFromSlice(ctx context.Context, queries *query.Queries, c *actions.FieldConfig, userGrants []query.UserGrant) goja.Value {
|
||||
if userGrants == nil {
|
||||
return c.Runtime.ToValue(nil)
|
||||
}
|
||||
orgMetadata := make(map[string]goja.Value)
|
||||
grantList := &userGrantList{
|
||||
Count: uint64(len(userGrants)),
|
||||
Grants: make([]*userGrant, len(userGrants)),
|
||||
@@ -114,6 +126,13 @@ func UserGrantsFromSlice(c *actions.FieldConfig, userGrants []query.UserGrant) g
|
||||
UserGrantResourceOwnerName: grant.OrgName,
|
||||
ProjectId: grant.ProjectID,
|
||||
ProjectName: grant.ProjectName,
|
||||
GetOrgMetadata: func(goja.FunctionCall) goja.Value {
|
||||
if md, ok := orgMetadata[grant.ResourceOwner]; ok {
|
||||
return md
|
||||
}
|
||||
orgMetadata[grant.ResourceOwner] = GetOrganizationMetadata(ctx, queries, c, grant.ResourceOwner)
|
||||
return orgMetadata[grant.ResourceOwner]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user