From 57bfecf7f77bf33881a0368d25b7c1004f03d535 Mon Sep 17 00:00:00 2001 From: Livio Spring Date: Tue, 25 Mar 2025 12:07:54 +0100 Subject: [PATCH] fix(actions): correctly handle api.v1.appendUserGrant (#9598) # Which Problems Are Solved It was not possible to use the `api.v1.appendUserGrant` function in the `postCreation` trigger action as documented. # How the Problems Are Solved - Correctly initialize the javascript / Goja function - Added `projectID` and `projectGrantID` (as documented), but kept `projectId` and `projectGrantId` (for backwards compatibility) when mapping the object in the `appendUserGrant` function # Additional Changes None # Additional Context - A customer reached out to support regarding this issue. - requires back port to 2.70.x --- internal/actions/fields.go | 10 ++++++---- internal/actions/object/user_grant.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/internal/actions/fields.go b/internal/actions/fields.go index de668b82b7..7d0919497e 100644 --- a/internal/actions/fields.go +++ b/internal/actions/fields.go @@ -62,10 +62,12 @@ func (f *FieldConfig) set(name string, value interface{}) { logging.WithFields("name", name).Error("tried to overwrite field") panic("tried to overwrite field") } - v, ok := value.(func(*FieldConfig) interface{}) - if ok { + switch v := value.(type) { + case func(config *FieldConfig) interface{}: f.fields[name] = v(f) - return + case func(config *FieldConfig) func(call goja.FunctionCall) goja.Value: + f.fields[name] = v(f) + default: + f.fields[name] = value } - f.fields[name] = value } diff --git a/internal/actions/object/user_grant.go b/internal/actions/object/user_grant.go index efa8f9cc66..2cc693c202 100644 --- a/internal/actions/object/user_grant.go +++ b/internal/actions/object/user_grant.go @@ -158,9 +158,9 @@ func UserGrantsToDomain(userID string, actionUserGrants []UserGrant) []*domain.U func mapObjectToGrant(object *goja.Object, grant *UserGrant) { for _, key := range object.Keys() { switch key { - case "projectId": + case "projectId", "projectID": grant.ProjectID = object.Get(key).String() - case "projectGrantId": + case "projectGrantId", "projectGrantID": grant.ProjectGrantID = object.Get(key).String() case "roles": if roles, ok := object.Get(key).Export().([]interface{}); ok {