From 8ee16cc7cd13593213e295310a23a9e3876f5b1f Mon Sep 17 00:00:00 2001 From: waldekmastykarz Date: Sat, 21 Sep 2024 13:13:06 +0200 Subject: [PATCH] Fixes handling multi-value properties in 'external item add'. Closes #6374 --- docs/docs/cmd/external/item/item-add.mdx | 6 +++--- src/m365/external/commands/item/item-add.spec.ts | 5 +---- src/m365/external/commands/item/item-add.ts | 8 ++------ 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/docs/docs/cmd/external/item/item-add.mdx b/docs/docs/cmd/external/item/item-add.mdx index 70c0efd791e..5f4945b4ccb 100644 --- a/docs/docs/cmd/external/item/item-add.mdx +++ b/docs/docs/cmd/external/item/item-add.mdx @@ -63,13 +63,13 @@ For more information about using these options, see the Microsoft Graph API docu Creates an external item with simple properties that everyone is allowed to access ```sh -m365 external item add --id "pnp-ensure-siteassets-library" --connectionId "samplesolutiongallery" --content "Ensure that the Site Assets library is created." --title "Ensure the Site Assets Library is created" --description "Ensure that the Site Assets library is created." --authors "Phil Harding" --acls "grant,everyone,everyone" +m365 external item add --id "pnp-ensure-siteassets-library" --externalConnectionId "samplesolutiongallery" --content "Ensure that the Site Assets library is created." --title "Ensure the Site Assets Library is created" --description "Ensure that the Site Assets library is created." --authors "Phil Harding" --acls "grant,everyone,everyone" ``` Creates an external item with multi-value properties accessible only to users from the specified Entra group ```sh -m365 external item add --id "pnp-ensure-siteassets-library" --connectionId "samplesolutiongallery" --content "Ensure that the Site Assets library is created." --title "Ensure the Site Assets Library is created" --description "Ensure that the Site Assets library is created." --authors@odata.type "Collection(String)" --authors "Phil Harding;#Steve Smith" --acls "grant,group,Super users" +m365 external item add --id "pnp-ensure-siteassets-library" --externalConnectionId "samplesolutiongallery" --content "Ensure that the Site Assets library is created." --title "Ensure the Site Assets Library is created" --description "Ensure that the Site Assets library is created." --authors@odata.type "Collection(String)" --authors "Phil Harding;#Steve Smith" --acls "grant,group,Super users" ``` ## Response @@ -123,7 +123,7 @@ m365 external item add --id "pnp-ensure-siteassets-library" --connectionId "samp ```md - # m365 external item add --id "pnp-ensure-siteassets-library" --connectionId "samplesolutiongallery" --content "Ensure that the Site Assets library is created." --title "Ensure the Site Assets Library is created" --description "Ensure that the Site Assets library is created." --authors "Phil Harding" --acls "grant,everyone,everyone" + # m365 external item add --id "pnp-ensure-siteassets-library" --externalConnectionId "samplesolutiongallery" --content "Ensure that the Site Assets library is created." --title "Ensure the Site Assets Library is created" --description "Ensure that the Site Assets library is created." --authors "Phil Harding" --acls "grant,everyone,everyone" Date: 2023-10-28 diff --git a/src/m365/external/commands/item/item-add.spec.ts b/src/m365/external/commands/item/item-add.spec.ts index db3600eea8e..fb5aa8d081f 100644 --- a/src/m365/external/commands/item/item-add.spec.ts +++ b/src/m365/external/commands/item/item-add.spec.ts @@ -129,10 +129,7 @@ describe(commands.ITEM_ADD, () => { acls: 'grant,group,Admins', ticketTitle: 'Something went wrong ticket', priority: 'high', - // this is how assignee@odata.type is parsed by minimist - 'assignee@odata': { - type: 'Collection(String)' - }, + 'assignee@odata.type': 'Collection(String)', assignee: 'Steve;#Brian' }; await command.action(logger, { options } as any); diff --git a/src/m365/external/commands/item/item-add.ts b/src/m365/external/commands/item/item-add.ts index bbc96e24432..afbac904636 100644 --- a/src/m365/external/commands/item/item-add.ts +++ b/src/m365/external/commands/item/item-add.ts @@ -125,8 +125,7 @@ class ExternalItemAddCommand extends GraphCommand { }; // we need to rewrite the @odata properties to the correct format - // because . in @odata.type is interpreted by minimist as a child property - // we also need to extract multiple values for collections into arrays + // to extract multiple values for collections into arrays this.rewriteCollectionProperties(args.options); this.addUnknownOptionsToPayload(requestBody.properties, args.options); @@ -166,13 +165,10 @@ class ExternalItemAddCommand extends GraphCommand { private rewriteCollectionProperties(options: any): void { Object.getOwnPropertyNames(options).forEach(name => { - if (!name.endsWith('@odata')) { + if (!name.includes('@odata')) { return; } - options[`${name}.type`] = options[name].type; - delete options[name]; - // convert the value of a collection to an array const nameWithoutOData: string = name.substring(0, name.indexOf('@odata')); if (options[nameWithoutOData]) {