Skip to content

Adds command spo site recyclebinitem clear, Closes #4724#4736

Closed
nicodecleyre wants to merge 3 commits intopnp:mainfrom
nicodecleyre:spo-site-recyclebinitem-clear
Closed

Adds command spo site recyclebinitem clear, Closes #4724#4736
nicodecleyre wants to merge 3 commits intopnp:mainfrom
nicodecleyre:spo-site-recyclebinitem-clear

Conversation

@nicodecleyre
Copy link
Copy Markdown
Contributor

Closes #4724

@milanholemans
Copy link
Copy Markdown
Contributor

Thank you @nicodecleyre, will review ASAP!

@nicodecleyre nicodecleyre force-pushed the spo-site-recyclebinitem-clear branch from 6822bf9 to 17a8cc9 Compare April 5, 2023 19:33
Copy link
Copy Markdown
Contributor

@milanholemans milanholemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great start, I made some comments while reviewing. Could you have a look at them please?

Comment thread docs/docs/cmd/spo/site/site-recyclebinitem-clear.md Outdated
Comment thread docs/docs/cmd/spo/site/site-recyclebinitem-clear.md
Comment thread src/m365/spo/commands/site/site-recyclebinitem-clear.ts Outdated
Comment thread src/m365/spo/commands/site/site-recyclebinitem-clear.ts Outdated
Comment thread src/m365/spo/commands/site/site-recyclebinitem-clear.ts Outdated
Comment thread src/m365/spo/commands/site/site-recyclebinitem-clear.spec.ts Outdated
Comment thread src/m365/spo/commands/site/site-recyclebinitem-clear.spec.ts Outdated
Comment thread src/m365/spo/commands/site/site-recyclebinitem-clear.spec.ts Outdated
throw error;
});

await assert.rejects(command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com', confirm: true } } as any), error.error);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wrap the error in a CommandError object.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here, can't wrap it in a CommandError object

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because your error message is not well structured. It should look to something like this:

const error = {
      error: {
        'odata.error': {
          message: {
            value: "The files cannot be removed from the second-stage recycle bin."
          }
        }
      }
    };

Now the test actually fails when the error message doesn't match. Before this, the test always succeeded, no matter what you entered as a value. This is not really a useful test. Let's try to avoid this.

Comment thread src/m365/spo/commands/site/site-recyclebinitem-clear.spec.ts
@milanholemans milanholemans marked this pull request as draft April 12, 2023 22:05
@nicodecleyre nicodecleyre marked this pull request as ready for review April 19, 2023 22:25
: Don't prompt for confirmation.

--8<-- "docs/cmd/_global.md"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like we should add a warning to inform the user again that it's a permanent deletion.


public async commandAction(logger: Logger, args: CommandArgs): Promise<void> {
if (this.verbose) {
logger.logToStderr(`Permanently removing all items in recycle bin of site ${args.options.siteUrl}...`);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this log into the function when the prompt is confirmed.

const error = {
'odata.error': {
message: {
value: "The files cannot be moved to the second-stage recycle bin."
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message looks odd for a command that permanently removes items.

throw error;
});

await assert.rejects(command.action(logger, { options: { siteUrl: 'https://contoso.sharepoint.com', confirm: true } } as any), error.error);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because your error message is not well structured. It should look to something like this:

const error = {
      error: {
        'odata.error': {
          message: {
            value: "The files cannot be removed from the second-stage recycle bin."
          }
        }
      }
    };

Now the test actually fails when the error message doesn't match. Before this, the test always succeeded, no matter what you entered as a value. This is not really a useful test. Let's try to avoid this.

Copy link
Copy Markdown
Contributor

@milanholemans milanholemans left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nicodecleyre first and for all sorry for the previous single reviews. GitHub was doing quite weird.
Anyhow, code looks good! Made few small changes before merging.

}

await request.post(requestOptions);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this is one of the stupid APIs that never return a failed status code. Even when the API fails, it returns a 200. We should check the response body for errors.

@nicodecleyre
Copy link
Copy Markdown
Contributor Author

Hi @nicodecleyre first and for all sorry for the previous single reviews. GitHub was doing quite weird. Anyhow, code looks good! Made few small changes before merging.

No problem, thank you for making these last changes ❤️

@milanholemans
Copy link
Copy Markdown
Contributor

Merged manually, thank you for this PR! 👏

@nicodecleyre nicodecleyre deleted the spo-site-recyclebinitem-clear branch May 10, 2023 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New command: spo site recyclebinitem clear

2 participants