@pnp/cli-microsoft365 5.5.0 → 5.6.0-beta.8b9dde0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const cli_1 = require("../../../../cli");
4
+ const request_1 = require("../../../../request");
5
+ const utils_1 = require("../../../../utils");
6
+ const SpoCommand_1 = require("../../../base/SpoCommand");
7
+ const commands_1 = require("../../commands");
8
+ const removeCommand = require('./file-remove');
9
+ class SpoFileRenameCommand extends SpoCommand_1.default {
10
+ get name() {
11
+ return commands_1.default.FILE_RENAME;
12
+ }
13
+ get description() {
14
+ return 'Renames a file';
15
+ }
16
+ getTelemetryProperties(args) {
17
+ const telemetryProps = super.getTelemetryProperties(args);
18
+ telemetryProps.force = !!args.options.force;
19
+ return telemetryProps;
20
+ }
21
+ commandAction(logger, args, cb) {
22
+ const webUrl = args.options.webUrl;
23
+ const originalFileServerRelativeUrl = utils_1.urlUtil.getServerRelativePath(args.options.webUrl, args.options.sourceUrl);
24
+ this
25
+ .getFile(originalFileServerRelativeUrl, webUrl)
26
+ .then((_) => {
27
+ if (args.options.force) {
28
+ return this.deleteFile(webUrl, args.options.sourceUrl, args.options.targetFileName);
29
+ }
30
+ return Promise.resolve();
31
+ })
32
+ .then(_ => {
33
+ const requestBody = {
34
+ formValues: [{
35
+ FieldName: 'FileLeafRef',
36
+ FieldValue: args.options.targetFileName
37
+ }]
38
+ };
39
+ const requestOptions = {
40
+ url: `${webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(originalFileServerRelativeUrl)}')/ListItemAllFields/ValidateUpdateListItem()`,
41
+ headers: {
42
+ 'accept': 'application/json;odata=nometadata'
43
+ },
44
+ data: requestBody,
45
+ responseType: 'json'
46
+ };
47
+ return request_1.default.post(requestOptions);
48
+ })
49
+ .then((resp) => {
50
+ logger.log(resp.value);
51
+ cb();
52
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
53
+ }
54
+ getFile(originalFileServerRelativeUrl, webUrl) {
55
+ const requestUrl = `${webUrl}/_api/web/GetFileByServerRelativeUrl('${encodeURIComponent(originalFileServerRelativeUrl)}')?$select=UniqueId`;
56
+ const requestOptions = {
57
+ url: requestUrl,
58
+ headers: {
59
+ 'accept': 'application/json;odata=nometadata'
60
+ },
61
+ responseType: 'json'
62
+ };
63
+ return request_1.default.get(requestOptions);
64
+ }
65
+ deleteFile(webUrl, sourceUrl, targetFileName) {
66
+ const targetFileServerRelativeUrl = `${utils_1.urlUtil.getServerRelativePath(webUrl, sourceUrl.substring(0, sourceUrl.lastIndexOf('/')))}/${targetFileName}`;
67
+ const options = {
68
+ webUrl: webUrl,
69
+ url: targetFileServerRelativeUrl,
70
+ recycle: true,
71
+ confirm: true,
72
+ debug: this.debug,
73
+ verbose: this.verbose
74
+ };
75
+ return cli_1.Cli.executeCommandWithOutput(removeCommand, { options: Object.assign(Object.assign({}, options), { _: [] }) })
76
+ .then(_ => {
77
+ return Promise.resolve();
78
+ }, (err) => {
79
+ if (err.error !== null && err.error.message !== null && err.error.message.includes('does not exist')) {
80
+ return Promise.resolve();
81
+ }
82
+ return Promise.reject(err);
83
+ });
84
+ }
85
+ options() {
86
+ const options = [
87
+ {
88
+ option: '-u, --webUrl <webUrl>'
89
+ },
90
+ {
91
+ option: '-s, --sourceUrl <sourceUrl>'
92
+ },
93
+ {
94
+ option: '-t, --targetFileName <targetFileName>'
95
+ },
96
+ {
97
+ option: '--force'
98
+ }
99
+ ];
100
+ const parentOptions = super.options();
101
+ return options.concat(parentOptions);
102
+ }
103
+ validate(args) {
104
+ return utils_1.validation.isValidSharePointUrl(args.options.webUrl);
105
+ }
106
+ }
107
+ module.exports = new SpoFileRenameCommand();
108
+ //# sourceMappingURL=file-rename.js.map
@@ -15,6 +15,7 @@ class SpoGroupGetCommand extends SpoCommand_1.default {
15
15
  const telemetryProps = super.getTelemetryProperties(args);
16
16
  telemetryProps.id = (!(!args.options.id)).toString();
17
17
  telemetryProps.name = (!(!args.options.name)).toString();
18
+ telemetryProps.associatedGroup = args.options.associatedGroup;
18
19
  return telemetryProps;
19
20
  }
20
21
  commandAction(logger, args, cb) {
@@ -28,6 +29,19 @@ class SpoGroupGetCommand extends SpoCommand_1.default {
28
29
  else if (args.options.name) {
29
30
  requestUrl = `${args.options.webUrl}/_api/web/sitegroups/GetByName('${encodeURIComponent(args.options.name)}')`;
30
31
  }
32
+ else if (args.options.associatedGroup) {
33
+ switch (args.options.associatedGroup.toLowerCase()) {
34
+ case 'owner':
35
+ requestUrl = `${args.options.webUrl}/_api/web/AssociatedOwnerGroup`;
36
+ break;
37
+ case 'member':
38
+ requestUrl = `${args.options.webUrl}/_api/web/AssociatedMemberGroup`;
39
+ break;
40
+ case 'visitor':
41
+ requestUrl = `${args.options.webUrl}/_api/web/AssociatedVisitorGroup`;
42
+ break;
43
+ }
44
+ }
31
45
  const requestOptions = {
32
46
  url: requestUrl,
33
47
  method: 'GET',
@@ -53,21 +67,27 @@ class SpoGroupGetCommand extends SpoCommand_1.default {
53
67
  },
54
68
  {
55
69
  option: '--name [name]'
70
+ },
71
+ {
72
+ option: '--associatedGroup [associatedGroup]',
73
+ autocomplete: ['Owner', 'Member', 'Visitor']
56
74
  }
57
75
  ];
58
76
  const parentOptions = super.options();
59
77
  return options.concat(parentOptions);
60
78
  }
79
+ optionSets() {
80
+ return [
81
+ ['id', 'name', 'associatedGroup']
82
+ ];
83
+ }
61
84
  validate(args) {
62
- if (args.options.id && args.options.name) {
63
- return 'Use either "id" or "name", but not all.';
64
- }
65
- if (!args.options.id && !args.options.name) {
66
- return 'Specify id or name, one is required';
67
- }
68
85
  if (args.options.id && isNaN(args.options.id)) {
69
86
  return `Specified id ${args.options.id} is not a number`;
70
87
  }
88
+ if (args.options.associatedGroup && ['owner', 'member', 'visitor'].indexOf(args.options.associatedGroup.toLowerCase()) === -1) {
89
+ return `${args.options.associatedGroup} is not a valid associatedGroup value. Allowed values are Owner|Member|Visitor.`;
90
+ }
71
91
  return utils_1.validation.isValidSharePointUrl(args.options.webUrl);
72
92
  }
73
93
  }
@@ -73,7 +73,7 @@ class SpoSiteAppPermissionAddCommand extends GraphCommand_1.default {
73
73
  }
74
74
  mapRequestBody(permission, appInfo) {
75
75
  const requestBody = {
76
- roles: permission.split(',')
76
+ roles: [permission]
77
77
  };
78
78
  requestBody.grantedToIdentities = [];
79
79
  requestBody.grantedToIdentities.push({ application: { "id": appInfo.appId, "displayName": appInfo.displayName } });
@@ -129,11 +129,8 @@ class SpoSiteAppPermissionAddCommand extends GraphCommand_1.default {
129
129
  if (args.options.appId && !utils_1.validation.isValidGuid(args.options.appId)) {
130
130
  return `${args.options.appId} is not a valid GUID`;
131
131
  }
132
- const permissions = args.options.permission.split(',');
133
- for (let i = 0; i < permissions.length; i++) {
134
- if (['read', 'write'].indexOf(permissions[i]) === -1) {
135
- return `${permissions[i]} is not a valid permission value. Allowed values read|write|read,write`;
136
- }
132
+ if (['read', 'write', 'owner'].indexOf(args.options.permission) === -1) {
133
+ return `${args.options.permission} is not a valid permission value. Allowed values are read|write|owner`;
137
134
  }
138
135
  return utils_1.validation.isValidSharePointUrl(args.options.siteUrl);
139
136
  }
@@ -83,7 +83,7 @@ class SpoSiteAppPermissionSetCommand extends GraphCommand_1.default {
83
83
  'content-type': 'application/json;odata=nometadata'
84
84
  },
85
85
  data: {
86
- roles: args.options.permission.split(',')
86
+ roles: [args.options.permission]
87
87
  },
88
88
  responseType: 'json'
89
89
  };
@@ -122,11 +122,8 @@ class SpoSiteAppPermissionSetCommand extends GraphCommand_1.default {
122
122
  if (args.options.appId && !utils_1.validation.isValidGuid(args.options.appId)) {
123
123
  return `${args.options.appId} is not a valid GUID`;
124
124
  }
125
- const permissions = args.options.permission.split(',');
126
- for (let i = 0; i < permissions.length; i++) {
127
- if (['read', 'write'].indexOf(permissions[i]) === -1) {
128
- return `${permissions[i]} is not a valid permission value. Allowed values are read|write|read,write`;
129
- }
125
+ if (['read', 'write', 'owner'].indexOf(args.options.permission) === -1) {
126
+ return `${args.options.permission} is not a valid permission value. Allowed values are read|write|owner`;
130
127
  }
131
128
  return utils_1.validation.isValidSharePointUrl(args.options.siteUrl);
132
129
  }
@@ -54,6 +54,7 @@ exports.default = {
54
54
  FILE_LIST: `${prefix} file list`,
55
55
  FILE_MOVE: `${prefix} file move`,
56
56
  FILE_REMOVE: `${prefix} file remove`,
57
+ FILE_RENAME: `${prefix} file rename`,
57
58
  FILE_SHARINGINFO_GET: `${prefix} file sharinginfo get`,
58
59
  FOLDER_ADD: `${prefix} folder add`,
59
60
  FOLDER_COPY: `${prefix} folder copy`,
@@ -0,0 +1,43 @@
1
+ # spo file rename
2
+
3
+ Renames a file
4
+
5
+ ## Usage
6
+
7
+ ```sh
8
+ m365 spo file rename [options]
9
+ ```
10
+
11
+ ## Options
12
+
13
+ `-u, --webUrl <webUrl>`
14
+ : The URL of the site where the file is located
15
+
16
+ `-s, --sourceUrl <sourceUrl>`
17
+ : Site-relative URL of the file to rename
18
+
19
+ `-t, --targetFileName <targetFileName>`
20
+ : New file name of the file
21
+
22
+ `--force`
23
+ : If a file already exists with target file name, it will be moved to the recycle bin. If omitted, the rename operation will be canceled if a file already exists with the specified file name
24
+
25
+ --8<-- "docs/cmd/_global.md"
26
+
27
+ ## Remarks
28
+
29
+ If you try to rename a file without the `--force` flag and a file with this name already exists, the operation will be cancelled.
30
+
31
+ ## Examples
32
+
33
+ Renames a file with server-relative URL _/Shared Documents/Test1.docx_ located in site _<https://contoso.sharepoint.com/sites/project-x>_ to _Test2.docx_
34
+
35
+ ```sh
36
+ m365 spo file rename --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl '/Shared Documents/Test1.docx' --targetFileName 'Test2.docx'
37
+ ```
38
+
39
+ Renames a file with server-relative URL _/Shared Documents/Test1.docx_ located in site _<https://contoso.sharepoint.com/sites/project-x>_ to _Test2.docx_. If the file with the target file name already exists, this file will be moved to the recycle bin
40
+
41
+ ```sh
42
+ m365 spo file rename --webUrl https://contoso.sharepoint.com/sites/project-x --sourceUrl '/Shared Documents/Test1.docx' --targetFileName 'Test2.docx' --force
43
+ ```
@@ -11,13 +11,16 @@ m365 spo group get [options]
11
11
  ## Options
12
12
 
13
13
  `-u, --webUrl <webUrl>`
14
- : URL of the site where the group is located
14
+ : URL of the site where the group is located.
15
15
 
16
16
  `-i, --id [id]`
17
- : ID of the site group to get. Use either `id` or `name`, but not all. e.g `7`
17
+ : ID of the site group to get. Use either `id`, `name` or `associatedGroup` but not multiple.
18
18
 
19
19
  `--name [name]`
20
- : Name of the site group to get. Specify either `id` or `name` but not both e.g `Team Site Members`
20
+ : Name of the site group to get. Use either `id`, `name` or `associatedGroup` but not multiple.
21
+
22
+ `--associatedGroup [associatedGroup]`
23
+ : Type of the associated group to get. Available values: `Owner`, `Member`, `Visitor`. Use either `id`, `name` or `associatedGroup` but not multiple.
21
24
 
22
25
  --8<-- "docs/cmd/_global.md"
23
26
 
@@ -34,3 +37,9 @@ Get group with name _Team Site Members_ for web _https://contoso.sharepoint.com/
34
37
  ```sh
35
38
  m365 spo group get --webUrl https://contoso.sharepoint.com/sites/project-x --name "Team Site Members"
36
39
  ```
40
+
41
+ Get the associated owner group of a specified site
42
+
43
+ ```sh
44
+ m365 spo group get --webUrl https://contoso.sharepoint.com/sites/project-x --associatedGroup Owner
45
+ ```
@@ -14,7 +14,7 @@ m365 spo site apppermission add [options]
14
14
  : URL of the site collection to add the permission
15
15
 
16
16
  `-p, --permission <permission>`
17
- : Permission to site (`read`, `write`, `read,write`). If multiple permissions have to be granted, they have to be comma separated ex. `read,write`
17
+ : Permission to site (`read`, `write`, or `owner`)
18
18
 
19
19
  `-i, --appId [appId]`
20
20
  : Client ID of the Azure AD app for which to grant permissions
@@ -23,7 +23,7 @@ m365 spo site apppermission set [options]
23
23
  : Display name of the Azure AD app for which to update permissions. Specify `permissionId`, `appId` or `appDisplayName`
24
24
 
25
25
  `-p, --permission <permission>`
26
- : Permission to site (`read`, `write`, `read,write`). If multiple permissions have to be granted, they have to be comma separated ex. `read,write`
26
+ : Permission to site (`read`, `write`, or `owner`)
27
27
 
28
28
  --8<-- "docs/cmd/_global.md"
29
29
 
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "5.5.0",
3
+ "version": "5.6.0",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@pnp/cli-microsoft365",
9
- "version": "5.5.0",
9
+ "version": "5.6.0",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@azure/msal-node": "^1.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pnp/cli-microsoft365",
3
- "version": "5.5.0",
3
+ "version": "5.6.0-beta.8b9dde0",
4
4
  "description": "Manage Microsoft 365 and SharePoint Framework projects on any platform",
5
5
  "license": "MIT",
6
6
  "main": "./dist/api.js",
@@ -239,4 +239,4 @@
239
239
  "sinon": "^14.0.0",
240
240
  "source-map-support": "^0.5.21"
241
241
  }
242
- }
242
+ }