Skip to content

Commit

Permalink
Fixes handling multi-value properties in 'external item add'. Closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
waldekmastykarz authored and milanholemans committed Sep 21, 2024
1 parent 4f08034 commit 8ee16cc
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 13 deletions.
6 changes: 3 additions & 3 deletions docs/docs/cmd/external/item/item-add.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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." [email protected] "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." [email protected] "Collection(String)" --authors "Phil Harding;#Steve Smith" --acls "grant,group,Super users"
```

## Response
Expand Down Expand Up @@ -123,7 +123,7 @@ m365 external item add --id "pnp-ensure-siteassets-library" --connectionId "samp
<TabItem value="Markdown">

```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

Expand Down
5 changes: 1 addition & 4 deletions src/m365/external/commands/item/item-add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ describe(commands.ITEM_ADD, () => {
acls: 'grant,group,Admins',
ticketTitle: 'Something went wrong ticket',
priority: 'high',
// this is how [email protected] is parsed by minimist
'assignee@odata': {
type: 'Collection(String)'
},
'[email protected]': 'Collection(String)',
assignee: 'Steve;#Brian'
};
await command.action(logger, { options } as any);
Expand Down
8 changes: 2 additions & 6 deletions src/m365/external/commands/item/item-add.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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]) {
Expand Down

0 comments on commit 8ee16cc

Please sign in to comment.