66 "sync"
77
88 "github.com/GoCodeAlone/workflow-plugin-admin/internal/contracts"
9+ "google.golang.org/protobuf/types/known/structpb"
910)
1011
1112var dashboardModules = struct {
@@ -127,6 +128,11 @@ func contributionFromMap(args map[string]any) *contracts.AdminContribution {
127128 AppContext : stringValue (args , "app_context" ),
128129 Actions : stringSliceValue (args , "actions" ),
129130 }
131+ if metadata := mapValue (args , "metadata" ); len (metadata ) > 0 {
132+ if pbMetadata , err := structpb .NewStruct (metadata ); err == nil {
133+ contribution .Metadata = pbMetadata
134+ }
135+ }
130136 for _ , permission := range permissionValues (args ["permissions" ]) {
131137 contribution .Permissions = append (contribution .Permissions , permission )
132138 }
@@ -146,9 +152,17 @@ func contributionToMap(contribution *contracts.AdminContribution) map[string]any
146152 "app_context" : contribution .AppContext ,
147153 "actions" : append ([]string (nil ), contribution .Actions ... ),
148154 "permissions" : permissionMaps (contribution .Permissions ),
155+ "metadata" : contributionMetadataMap (contribution ),
149156 }
150157}
151158
159+ func contributionMetadataMap (contribution * contracts.AdminContribution ) map [string ]any {
160+ if contribution == nil || contribution .Metadata == nil {
161+ return map [string ]any {}
162+ }
163+ return contribution .Metadata .AsMap ()
164+ }
165+
152166func permissionValues (value any ) []* contracts.AdminPermission {
153167 switch permissions := value .(type ) {
154168 case []string :
@@ -204,6 +218,23 @@ func stringValue(args map[string]any, key string) string {
204218 return value
205219}
206220
221+ func mapValue (args map [string ]any , key string ) map [string ]any {
222+ switch value := args [key ].(type ) {
223+ case map [string ]any :
224+ return value
225+ case map [any ]any :
226+ out := make (map [string ]any , len (value ))
227+ for k , v := range value {
228+ if s , ok := k .(string ); ok {
229+ out [s ] = v
230+ }
231+ }
232+ return out
233+ default :
234+ return nil
235+ }
236+ }
237+
207238func stringSliceValue (args map [string ]any , key string ) []string {
208239 switch value := args [key ].(type ) {
209240 case []string :
0 commit comments