@pnp/cli-microsoft365 10.3.0-beta.cd20f0c → 10.3.0-beta.df85113
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.
- package/.eslintrc.cjs +2 -0
- package/README.md +11 -6
- package/allCommands.json +1 -1
- package/allCommandsFull.json +1 -1
- package/dist/config.js +2 -1
- package/dist/m365/commands/login.js +6 -6
- package/dist/m365/entra/commands/app/app-add.js +3 -0
- package/dist/m365/entra/commands/approleassignment/approleassignment-remove.js +1 -1
- package/dist/m365/entra/commands/group/group-list.js +3 -2
- package/dist/m365/entra/commands/pim/pim-role-assignment-remove.js +186 -0
- package/dist/m365/entra/commands/roledefinition/roledefinition-add.js +58 -0
- package/dist/m365/entra/commands/roledefinition/roledefinition-set.js +84 -0
- package/dist/m365/entra/commands/rolepermission/rolepermission-list.js +42 -0
- package/dist/m365/entra/commands.js +4 -0
- package/dist/m365/exo/commands/approleassignment/approleassignment-add.js +235 -0
- package/dist/m365/exo/commands.js +5 -0
- package/dist/m365/outlook/commands/mailbox/mailbox-settings-set.js +163 -0
- package/dist/m365/outlook/commands.js +1 -0
- package/dist/m365/pp/commands/website/website-get.js +60 -0
- package/dist/m365/pp/commands.js +2 -1
- package/dist/m365/spe/commands/container/container-activate.js +50 -0
- package/dist/m365/spe/commands.js +1 -0
- package/dist/m365/spo/commands/file/file-roleassignment-add.js +26 -2
- package/dist/m365/spo/commands/file/file-roleassignment-remove.js +26 -2
- package/dist/m365/spo/commands/folder/folder-roleassignment-add.js +27 -24
- package/dist/m365/spo/commands/folder/folder-roleassignment-remove.js +24 -7
- package/dist/m365/spo/commands/list/list-defaultvalue-clear.js +184 -0
- package/dist/m365/spo/commands/list/list-defaultvalue-list.js +140 -0
- package/dist/m365/spo/commands/list/list-defaultvalue-remove.js +181 -0
- package/dist/m365/spo/commands/list/list-defaultvalue-set.js +210 -0
- package/dist/m365/spo/commands/listitem/listitem-roleassignment-add.js +25 -7
- package/dist/m365/spo/commands/listitem/listitem-roleassignment-remove.js +22 -5
- package/dist/m365/spo/commands/web/web-roleassignment-add.js +22 -5
- package/dist/m365/spo/commands/web/web-roleassignment-remove.js +22 -5
- package/dist/m365/spo/commands.js +4 -0
- package/dist/m365/tenant/commands/people/people-pronouns-set.js +46 -0
- package/dist/m365/tenant/commands/report/report-settings-set.js +47 -0
- package/dist/m365/tenant/commands.js +2 -0
- package/dist/utils/customAppScope.js +29 -0
- package/dist/utils/entraServicePrincipal.js +46 -0
- package/dist/utils/powerPlatform.js +38 -0
- package/dist/utils/roleDefinition.js +23 -0
- package/dist/utils/validation.js +4 -0
- package/docs/docs/cmd/entra/app/app-add.mdx +1 -1
- package/docs/docs/cmd/entra/pim/pim-role-assignment-remove.mdx +197 -0
- package/docs/docs/cmd/entra/roledefinition/roledefinition-add.mdx +131 -0
- package/docs/docs/cmd/entra/roledefinition/roledefinition-set.mdx +64 -0
- package/docs/docs/cmd/entra/rolepermission/rolepermission-list.mdx +162 -0
- package/docs/docs/cmd/exo/approleassignment/approleassignment-add.mdx +170 -0
- package/docs/docs/cmd/outlook/mailbox/mailbox-settings-set.mdx +166 -0
- package/docs/docs/cmd/pp/website/website-get.mdx +153 -0
- package/docs/docs/cmd/spe/container/container-activate.mdx +34 -0
- package/docs/docs/cmd/spo/file/file-roleassignment-add.mdx +21 -4
- package/docs/docs/cmd/spo/file/file-roleassignment-remove.mdx +21 -3
- package/docs/docs/cmd/spo/folder/folder-roleassignment-add.mdx +15 -3
- package/docs/docs/cmd/spo/folder/folder-roleassignment-remove.mdx +15 -3
- package/docs/docs/cmd/spo/list/list-defaultvalue-clear.mdx +62 -0
- package/docs/docs/cmd/spo/list/list-defaultvalue-list.mdx +110 -0
- package/docs/docs/cmd/spo/list/list-defaultvalue-remove.mdx +62 -0
- package/docs/docs/cmd/spo/list/list-defaultvalue-set.mdx +112 -0
- package/docs/docs/cmd/spo/listitem/listitem-roleassignment-add.mdx +15 -3
- package/docs/docs/cmd/spo/listitem/listitem-roleassignment-remove.mdx +17 -5
- package/docs/docs/cmd/spo/web/web-roleassignment-add.mdx +15 -3
- package/docs/docs/cmd/spo/web/web-roleassignment-remove.mdx +15 -3
- package/docs/docs/cmd/tenant/people/people-pronouns-set.mdx +82 -0
- package/docs/docs/cmd/tenant/report/report-settings-set.mdx +32 -0
- package/npm-shrinkwrap.json +54 -74
- package/package.json +9 -9
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import SpoCommand from '../../../base/SpoCommand.js';
|
|
2
|
+
import { globalOptionsZod } from '../../../../Command.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { zod } from '../../../../utils/zod.js';
|
|
5
|
+
import commands from '../../commands.js';
|
|
6
|
+
import { DOMParser } from '@xmldom/xmldom';
|
|
7
|
+
import { validation } from '../../../../utils/validation.js';
|
|
8
|
+
import { urlUtil } from '../../../../utils/urlUtil.js';
|
|
9
|
+
import request from '../../../../request.js';
|
|
10
|
+
import { formatting } from '../../../../utils/formatting.js';
|
|
11
|
+
import { cli } from '../../../../cli/cli.js';
|
|
12
|
+
const options = globalOptionsZod
|
|
13
|
+
.extend({
|
|
14
|
+
webUrl: zod.alias('u', z.string()
|
|
15
|
+
.refine(url => validation.isValidSharePointUrl(url) === true, url => ({
|
|
16
|
+
message: `'${url}' is not a valid SharePoint Online site URL.`
|
|
17
|
+
}))),
|
|
18
|
+
listId: zod.alias('i', z.string().optional()
|
|
19
|
+
.refine(id => id === undefined || validation.isValidGuid(id), id => ({
|
|
20
|
+
message: `'${id}' is not a valid GUID.`
|
|
21
|
+
}))),
|
|
22
|
+
listTitle: zod.alias('t', z.string().optional()),
|
|
23
|
+
listUrl: z.string().optional(),
|
|
24
|
+
fieldName: z.string(),
|
|
25
|
+
folderUrl: z.string().optional(),
|
|
26
|
+
force: zod.alias('f', z.boolean().optional())
|
|
27
|
+
})
|
|
28
|
+
.strict();
|
|
29
|
+
class SpoListDefaultValueRemoveCommand extends SpoCommand {
|
|
30
|
+
get name() {
|
|
31
|
+
return commands.LIST_DEFAULTVALUE_REMOVE;
|
|
32
|
+
}
|
|
33
|
+
get description() {
|
|
34
|
+
return 'Removes a specific default column value for a specific document library';
|
|
35
|
+
}
|
|
36
|
+
get schema() {
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
getRefinedSchema(schema) {
|
|
40
|
+
return schema
|
|
41
|
+
.refine(options => [options.listId, options.listTitle, options.listUrl].filter(o => o !== undefined).length === 1, {
|
|
42
|
+
message: 'Use one of the following options: listId, listTitle, listUrl.'
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
async commandAction(logger, args) {
|
|
46
|
+
if (!args.options.force) {
|
|
47
|
+
const result = await cli.promptForConfirmation({ message: `Are you sure you want to remove default column value '${args.options.fieldName}' from ${args.options.folderUrl ? `'${args.options.folderUrl}'` : 'the root of the list'}?` });
|
|
48
|
+
if (!result) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
if (this.verbose) {
|
|
54
|
+
await logger.logToStderr(`Removing default column value '${args.options.fieldName}' from ${args.options.folderUrl ? `'${args.options.folderUrl}'` : 'the root of the list'}.`);
|
|
55
|
+
await logger.logToStderr(`Getting server-relative URL of the list...`);
|
|
56
|
+
}
|
|
57
|
+
const listServerRelUrl = await this.getServerRelativeListUrl(args.options);
|
|
58
|
+
let folderUrl = listServerRelUrl;
|
|
59
|
+
if (args.options.folderUrl) {
|
|
60
|
+
folderUrl = urlUtil.getServerRelativePath(args.options.webUrl, urlUtil.removeTrailingSlashes(args.options.folderUrl));
|
|
61
|
+
}
|
|
62
|
+
if (this.verbose) {
|
|
63
|
+
await logger.logToStderr(`Getting default column values...`);
|
|
64
|
+
}
|
|
65
|
+
const defaultValuesXml = await this.getDefaultColumnValuesXml(args.options.webUrl, listServerRelUrl);
|
|
66
|
+
const removeDefaultValueResult = this.removeFieldFromXml(defaultValuesXml, args.options.fieldName, folderUrl);
|
|
67
|
+
if (!removeDefaultValueResult.isFieldFound) {
|
|
68
|
+
throw `Default column value '${args.options.fieldName}' was not found.`;
|
|
69
|
+
}
|
|
70
|
+
if (this.verbose) {
|
|
71
|
+
await logger.logToStderr(`Uploading default column values to list...`);
|
|
72
|
+
}
|
|
73
|
+
await this.uploadDefaultColumnValuesXml(args.options.webUrl, listServerRelUrl, removeDefaultValueResult.xml);
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
this.handleRejectedODataJsonPromise(err);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async getServerRelativeListUrl(options) {
|
|
80
|
+
const requestOptions = {
|
|
81
|
+
url: `${options.webUrl}/_api/Web`,
|
|
82
|
+
headers: {
|
|
83
|
+
accept: 'application/json;odata=nometadata'
|
|
84
|
+
},
|
|
85
|
+
responseType: 'json'
|
|
86
|
+
};
|
|
87
|
+
if (options.listUrl) {
|
|
88
|
+
const serverRelativeUrl = urlUtil.getServerRelativePath(options.webUrl, options.listUrl);
|
|
89
|
+
requestOptions.url += `/GetList('${formatting.encodeQueryParameter(serverRelativeUrl)}')`;
|
|
90
|
+
}
|
|
91
|
+
else if (options.listId) {
|
|
92
|
+
requestOptions.url += `/Lists('${options.listId}')`;
|
|
93
|
+
}
|
|
94
|
+
else if (options.listTitle) {
|
|
95
|
+
requestOptions.url += `/Lists/GetByTitle('${formatting.encodeQueryParameter(options.listTitle)}')`;
|
|
96
|
+
}
|
|
97
|
+
requestOptions.url += '?$expand=RootFolder&$select=RootFolder/ServerRelativeUrl,BaseTemplate';
|
|
98
|
+
try {
|
|
99
|
+
const response = await request.get(requestOptions);
|
|
100
|
+
if (response.BaseTemplate !== 101) {
|
|
101
|
+
throw `The specified list is not a document library.`;
|
|
102
|
+
}
|
|
103
|
+
return response.RootFolder.ServerRelativeUrl;
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
if (error.status === 404) {
|
|
107
|
+
throw `List '${options.listId || options.listTitle || options.listUrl}' was not found.`;
|
|
108
|
+
}
|
|
109
|
+
throw error;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
async getDefaultColumnValuesXml(webUrl, listServerRelUrl) {
|
|
113
|
+
try {
|
|
114
|
+
const requestOptions = {
|
|
115
|
+
url: `${webUrl}/_api/Web/GetFileByServerRelativePath(decodedUrl='${formatting.encodeQueryParameter(listServerRelUrl + '/Forms/client_LocationBasedDefaults.html')}')/$value`,
|
|
116
|
+
headers: {
|
|
117
|
+
accept: 'application/json;odata=nometadata'
|
|
118
|
+
},
|
|
119
|
+
responseType: 'json'
|
|
120
|
+
};
|
|
121
|
+
const defaultValuesXml = await request.get(requestOptions);
|
|
122
|
+
return defaultValuesXml;
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
// For lists that have never had default column values set, the client_LocationBasedDefaults.html file does not exist.
|
|
126
|
+
if (err.status === 404) {
|
|
127
|
+
return null;
|
|
128
|
+
}
|
|
129
|
+
throw err;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
removeFieldFromXml(xml, fieldName, folderUrl) {
|
|
133
|
+
if (xml === null) {
|
|
134
|
+
return { isFieldFound: false };
|
|
135
|
+
}
|
|
136
|
+
// Encode all spaces in the folder URL
|
|
137
|
+
const encodedFolderUrl = folderUrl.replace(/ /g, '%20');
|
|
138
|
+
const parser = new DOMParser();
|
|
139
|
+
const doc = parser.parseFromString(xml, 'application/xml');
|
|
140
|
+
const folderLinks = doc.getElementsByTagName('a');
|
|
141
|
+
for (let i = 0; i < folderLinks.length; i++) {
|
|
142
|
+
const folderNode = folderLinks[i];
|
|
143
|
+
const folderNodeUrl = folderNode.getAttribute('href');
|
|
144
|
+
if (encodedFolderUrl.toLowerCase() !== folderNodeUrl.toLowerCase()) {
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
const defaultValues = folderNode.getElementsByTagName('DefaultValue');
|
|
148
|
+
for (let j = 0; j < defaultValues.length; j++) {
|
|
149
|
+
const defaultValueNode = defaultValues[j];
|
|
150
|
+
const defaultValueNodeField = defaultValueNode.getAttribute('FieldName');
|
|
151
|
+
if (defaultValueNodeField !== fieldName) {
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (folderNode.childNodes.length === 1) {
|
|
155
|
+
// No other default values found in the folder, let's remove the folder node
|
|
156
|
+
folderNode.parentNode.removeChild(folderNode);
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
// Default value node found, let's remove it
|
|
160
|
+
folderNode.removeChild(defaultValueNode);
|
|
161
|
+
}
|
|
162
|
+
return { isFieldFound: true, xml: doc.toString() };
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return { isFieldFound: false };
|
|
166
|
+
}
|
|
167
|
+
async uploadDefaultColumnValuesXml(webUrl, listServerRelUrl, xml) {
|
|
168
|
+
const requestOptions = {
|
|
169
|
+
url: `${webUrl}/_api/Web/GetFileByServerRelativePath(decodedUrl='${formatting.encodeQueryParameter(listServerRelUrl + '/Forms/client_LocationBasedDefaults.html')}')/$value`,
|
|
170
|
+
headers: {
|
|
171
|
+
accept: 'application/json;odata=nometadata',
|
|
172
|
+
'content-type': 'text/plain'
|
|
173
|
+
},
|
|
174
|
+
responseType: 'json',
|
|
175
|
+
data: xml
|
|
176
|
+
};
|
|
177
|
+
await request.put(requestOptions);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
export default new SpoListDefaultValueRemoveCommand();
|
|
181
|
+
//# sourceMappingURL=list-defaultvalue-remove.js.map
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import SpoCommand from '../../../base/SpoCommand.js';
|
|
2
|
+
import { globalOptionsZod } from '../../../../Command.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { zod } from '../../../../utils/zod.js';
|
|
5
|
+
import commands from '../../commands.js';
|
|
6
|
+
import { DOMParser } from '@xmldom/xmldom';
|
|
7
|
+
import { validation } from '../../../../utils/validation.js';
|
|
8
|
+
import { urlUtil } from '../../../../utils/urlUtil.js';
|
|
9
|
+
import request from '../../../../request.js';
|
|
10
|
+
import { formatting } from '../../../../utils/formatting.js';
|
|
11
|
+
const options = globalOptionsZod
|
|
12
|
+
.extend({
|
|
13
|
+
webUrl: zod.alias('u', z.string()
|
|
14
|
+
.refine(url => validation.isValidSharePointUrl(url) === true, url => ({
|
|
15
|
+
message: `'${url}' is not a valid SharePoint Online site URL.`
|
|
16
|
+
}))),
|
|
17
|
+
listId: zod.alias('i', z.string().optional()
|
|
18
|
+
.refine(id => id === undefined || validation.isValidGuid(id), id => ({
|
|
19
|
+
message: `'${id}' is not a valid GUID.`
|
|
20
|
+
}))),
|
|
21
|
+
listTitle: zod.alias('t', z.string().optional()),
|
|
22
|
+
listUrl: z.string().optional(),
|
|
23
|
+
fieldName: z.string(),
|
|
24
|
+
fieldValue: z.string()
|
|
25
|
+
.refine(value => value !== '', `The value cannot be empty. Use 'spo list defaultvalue remove' to remove a default column value.`),
|
|
26
|
+
folderUrl: z.string().optional()
|
|
27
|
+
.refine(url => url === undefined || (!url.includes('#') && !url.includes('%')), 'Due to limitations in SharePoint Online, setting default column values for folders with a # or % character in their path is not supported.')
|
|
28
|
+
})
|
|
29
|
+
.strict();
|
|
30
|
+
class SpoListDefaultValueSetCommand extends SpoCommand {
|
|
31
|
+
get name() {
|
|
32
|
+
return commands.LIST_DEFAULTVALUE_SET;
|
|
33
|
+
}
|
|
34
|
+
get description() {
|
|
35
|
+
return 'Sets default column values for a specific document library';
|
|
36
|
+
}
|
|
37
|
+
get schema() {
|
|
38
|
+
return options;
|
|
39
|
+
}
|
|
40
|
+
getRefinedSchema(schema) {
|
|
41
|
+
return schema
|
|
42
|
+
.refine(options => [options.listId, options.listTitle, options.listUrl].filter(o => o !== undefined).length === 1, {
|
|
43
|
+
message: 'Use one of the following options: listId, listTitle, listUrl.'
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
async commandAction(logger, args) {
|
|
47
|
+
try {
|
|
48
|
+
if (this.verbose) {
|
|
49
|
+
await logger.logToStderr(`Setting default column value '${args.options.fieldValue}' for field '${args.options.fieldName}'...`);
|
|
50
|
+
await logger.logToStderr(`Getting server-relative URL of the list...`);
|
|
51
|
+
}
|
|
52
|
+
const listServerRelUrl = await this.getServerRelativeListUrl(args.options);
|
|
53
|
+
let folderUrl = listServerRelUrl;
|
|
54
|
+
if (args.options.folderUrl) {
|
|
55
|
+
if (this.verbose) {
|
|
56
|
+
await logger.logToStderr(`Getting server-relative URL of folder '${args.options.folderUrl}'...`);
|
|
57
|
+
}
|
|
58
|
+
// Casing of the folder URL is important, let's retrieve the correct URL
|
|
59
|
+
const serverRelativeFolderUrl = urlUtil.getServerRelativePath(args.options.webUrl, urlUtil.removeTrailingSlashes(args.options.folderUrl));
|
|
60
|
+
folderUrl = await this.getCorrectFolderUrl(args.options.webUrl, serverRelativeFolderUrl);
|
|
61
|
+
}
|
|
62
|
+
if (this.verbose) {
|
|
63
|
+
await logger.logToStderr(`Getting default column values...`);
|
|
64
|
+
}
|
|
65
|
+
const defaultValuesXml = await this.ensureDefaultColumnValuesXml(args.options.webUrl, listServerRelUrl);
|
|
66
|
+
const modifiedXml = await this.updateFieldValueXml(logger, defaultValuesXml, args.options.fieldName, args.options.fieldValue, folderUrl);
|
|
67
|
+
await this.uploadDefaultColumnValuesXml(logger, args.options.webUrl, listServerRelUrl, modifiedXml);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
this.handleRejectedODataJsonPromise(err);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async getServerRelativeListUrl(options) {
|
|
74
|
+
const requestOptions = {
|
|
75
|
+
url: `${options.webUrl}/_api/Web`,
|
|
76
|
+
headers: {
|
|
77
|
+
accept: 'application/json;odata=nometadata'
|
|
78
|
+
},
|
|
79
|
+
responseType: 'json'
|
|
80
|
+
};
|
|
81
|
+
if (options.listUrl) {
|
|
82
|
+
const serverRelativeUrl = urlUtil.getServerRelativePath(options.webUrl, options.listUrl);
|
|
83
|
+
requestOptions.url += `/GetList('${formatting.encodeQueryParameter(serverRelativeUrl)}')`;
|
|
84
|
+
}
|
|
85
|
+
else if (options.listId) {
|
|
86
|
+
requestOptions.url += `/Lists('${options.listId}')`;
|
|
87
|
+
}
|
|
88
|
+
else if (options.listTitle) {
|
|
89
|
+
requestOptions.url += `/Lists/GetByTitle('${formatting.encodeQueryParameter(options.listTitle)}')`;
|
|
90
|
+
}
|
|
91
|
+
requestOptions.url += '?$expand=RootFolder&$select=RootFolder/ServerRelativeUrl,BaseTemplate';
|
|
92
|
+
try {
|
|
93
|
+
const response = await request.get(requestOptions);
|
|
94
|
+
if (response.BaseTemplate !== 101) {
|
|
95
|
+
throw `The specified list is not a document library.`;
|
|
96
|
+
}
|
|
97
|
+
return response.RootFolder.ServerRelativeUrl;
|
|
98
|
+
}
|
|
99
|
+
catch (error) {
|
|
100
|
+
if (error.status === 404) {
|
|
101
|
+
throw `List '${options.listId || options.listTitle || options.listUrl}' was not found.`;
|
|
102
|
+
}
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
async getCorrectFolderUrl(webUrl, folderUrl) {
|
|
107
|
+
const requestOptions = {
|
|
108
|
+
// Using ListItemAllFields endpoint because GetFolderByServerRelativePath doesn't return the correctly cased URL
|
|
109
|
+
url: `${webUrl}/_api/Web/GetFolderByServerRelativePath(decodedUrl='${formatting.encodeQueryParameter(folderUrl)}')/ListItemAllFields?$select=FileRef`,
|
|
110
|
+
headers: {
|
|
111
|
+
accept: 'application/json;odata=nometadata'
|
|
112
|
+
},
|
|
113
|
+
responseType: 'json'
|
|
114
|
+
};
|
|
115
|
+
const response = await request.get(requestOptions);
|
|
116
|
+
if (!response.FileRef) {
|
|
117
|
+
throw `Folder '${folderUrl}' was not found.`;
|
|
118
|
+
}
|
|
119
|
+
return response.FileRef;
|
|
120
|
+
}
|
|
121
|
+
async ensureDefaultColumnValuesXml(webUrl, listServerRelUrl) {
|
|
122
|
+
try {
|
|
123
|
+
const requestOptions = {
|
|
124
|
+
url: `${webUrl}/_api/Web/GetFileByServerRelativePath(decodedUrl='${formatting.encodeQueryParameter(listServerRelUrl + '/Forms/client_LocationBasedDefaults.html')}')/$value`,
|
|
125
|
+
headers: {
|
|
126
|
+
accept: 'application/json;odata=nometadata'
|
|
127
|
+
},
|
|
128
|
+
responseType: 'json'
|
|
129
|
+
};
|
|
130
|
+
const defaultValuesXml = await request.get(requestOptions);
|
|
131
|
+
return defaultValuesXml;
|
|
132
|
+
}
|
|
133
|
+
catch (err) {
|
|
134
|
+
if (err.status !== 404) {
|
|
135
|
+
throw err;
|
|
136
|
+
}
|
|
137
|
+
// For lists that have never had default column values set, the client_LocationBasedDefaults.html file does not exist.
|
|
138
|
+
// In this case, we need to create the file with blank default metadata.
|
|
139
|
+
const requestOptions = {
|
|
140
|
+
url: `${webUrl}/_api/Web/GetFolderByServerRelativePath(decodedUrl='${formatting.encodeQueryParameter(listServerRelUrl + '/Forms')}')/Files/Add(url='client_LocationBasedDefaults.html', overwrite=false)`,
|
|
141
|
+
headers: {
|
|
142
|
+
accept: 'application/json;odata=nometadata',
|
|
143
|
+
'content-type': 'text/plain'
|
|
144
|
+
},
|
|
145
|
+
responseType: 'json',
|
|
146
|
+
data: '<MetadataDefaults />'
|
|
147
|
+
};
|
|
148
|
+
await request.post(requestOptions);
|
|
149
|
+
return requestOptions.data;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async updateFieldValueXml(logger, xml, fieldName, fieldValue, folderUrl) {
|
|
153
|
+
if (this.verbose) {
|
|
154
|
+
await logger.logToStderr(`Modifying default column values...`);
|
|
155
|
+
}
|
|
156
|
+
// Encode all spaces in the folder URL
|
|
157
|
+
const encodedFolderUrl = folderUrl.replace(/ /g, '%20');
|
|
158
|
+
const parser = new DOMParser();
|
|
159
|
+
const doc = parser.parseFromString(xml, 'application/xml');
|
|
160
|
+
// Create a new DefaultValue node
|
|
161
|
+
const newDefaultValueNode = doc.createElement('DefaultValue');
|
|
162
|
+
newDefaultValueNode.setAttribute('FieldName', fieldName);
|
|
163
|
+
newDefaultValueNode.textContent = fieldValue;
|
|
164
|
+
const folderLinks = doc.getElementsByTagName('a');
|
|
165
|
+
for (let i = 0; i < folderLinks.length; i++) {
|
|
166
|
+
const folderNode = folderLinks[i];
|
|
167
|
+
const folderNodeUrl = folderNode.getAttribute('href');
|
|
168
|
+
if (encodedFolderUrl !== folderNodeUrl) {
|
|
169
|
+
continue;
|
|
170
|
+
}
|
|
171
|
+
const defaultValues = folderNode.getElementsByTagName('DefaultValue');
|
|
172
|
+
for (let j = 0; j < defaultValues.length; j++) {
|
|
173
|
+
const defaultValueNode = defaultValues[j];
|
|
174
|
+
const defaultValueNodeField = defaultValueNode.getAttribute('FieldName');
|
|
175
|
+
if (defaultValueNodeField !== fieldName) {
|
|
176
|
+
continue;
|
|
177
|
+
}
|
|
178
|
+
// Default value node found, let's update the value
|
|
179
|
+
defaultValueNode.textContent = fieldValue;
|
|
180
|
+
return doc.toString();
|
|
181
|
+
}
|
|
182
|
+
// Default value node not found, let's create it
|
|
183
|
+
folderNode.appendChild(newDefaultValueNode);
|
|
184
|
+
return doc.toString();
|
|
185
|
+
}
|
|
186
|
+
// Folder node was not found, let's create it
|
|
187
|
+
const newFolderNode = doc.createElement('a');
|
|
188
|
+
newFolderNode.setAttribute('href', encodedFolderUrl);
|
|
189
|
+
newFolderNode.appendChild(newDefaultValueNode);
|
|
190
|
+
doc.documentElement.appendChild(newFolderNode);
|
|
191
|
+
return doc.toString();
|
|
192
|
+
}
|
|
193
|
+
async uploadDefaultColumnValuesXml(logger, webUrl, listServerRelUrl, xml) {
|
|
194
|
+
if (this.verbose) {
|
|
195
|
+
await logger.logToStderr(`Uploading default column values to list...`);
|
|
196
|
+
}
|
|
197
|
+
const requestOptions = {
|
|
198
|
+
url: `${webUrl}/_api/Web/GetFileByServerRelativePath(decodedUrl='${formatting.encodeQueryParameter(listServerRelUrl + '/Forms/client_LocationBasedDefaults.html')}')/$value`,
|
|
199
|
+
headers: {
|
|
200
|
+
accept: 'application/json;odata=nometadata',
|
|
201
|
+
'content-type': 'text/plain'
|
|
202
|
+
},
|
|
203
|
+
responseType: 'json',
|
|
204
|
+
data: xml
|
|
205
|
+
};
|
|
206
|
+
await request.put(requestOptions);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
export default new SpoListDefaultValueSetCommand();
|
|
210
|
+
//# sourceMappingURL=list-defaultvalue-set.js.map
|
|
@@ -6,6 +6,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
6
6
|
var _SpoListItemRoleAssignmentAddCommand_instances, _SpoListItemRoleAssignmentAddCommand_initTelemetry, _SpoListItemRoleAssignmentAddCommand_initOptions, _SpoListItemRoleAssignmentAddCommand_initValidators;
|
|
7
7
|
import { cli } from '../../../../cli/cli.js';
|
|
8
8
|
import request from '../../../../request.js';
|
|
9
|
+
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
9
10
|
import { formatting } from '../../../../utils/formatting.js';
|
|
10
11
|
import { urlUtil } from '../../../../utils/urlUtil.js';
|
|
11
12
|
import { validation } from '../../../../utils/validation.js';
|
|
@@ -14,6 +15,7 @@ import commands from '../../commands.js';
|
|
|
14
15
|
import spoGroupGetCommand from '../group/group-get.js';
|
|
15
16
|
import spoRoleDefinitionListCommand from '../roledefinition/roledefinition-list.js';
|
|
16
17
|
import spoUserGetCommand from '../user/user-get.js';
|
|
18
|
+
import { spo } from '../../../../utils/spo.js';
|
|
17
19
|
class SpoListItemRoleAssignmentAddCommand extends SpoCommand {
|
|
18
20
|
get name() {
|
|
19
21
|
return commands.LISTITEM_ROLEASSIGNMENT_ADD;
|
|
@@ -46,7 +48,7 @@ class SpoListItemRoleAssignmentAddCommand extends SpoCommand {
|
|
|
46
48
|
}
|
|
47
49
|
requestUrl += `items(${args.options.listItemId})/`;
|
|
48
50
|
const roleDefinitionId = await this.getRoleDefinitionId(args.options);
|
|
49
|
-
let principalId =
|
|
51
|
+
let principalId = args.options.principalId;
|
|
50
52
|
if (args.options.upn) {
|
|
51
53
|
principalId = await this.getUserPrincipalId(args.options);
|
|
52
54
|
await this.addRoleAssignment(requestUrl, roleDefinitionId, principalId);
|
|
@@ -55,10 +57,17 @@ class SpoListItemRoleAssignmentAddCommand extends SpoCommand {
|
|
|
55
57
|
principalId = await this.getGroupPrincipalId(args.options);
|
|
56
58
|
await this.addRoleAssignment(requestUrl, roleDefinitionId, principalId);
|
|
57
59
|
}
|
|
58
|
-
else {
|
|
59
|
-
|
|
60
|
-
|
|
60
|
+
else if (args.options.entraGroupId || args.options.entraGroupName) {
|
|
61
|
+
if (this.verbose) {
|
|
62
|
+
await logger.logToStderr('Retrieving group information...');
|
|
63
|
+
}
|
|
64
|
+
const group = args.options.entraGroupId
|
|
65
|
+
? await entraGroup.getGroupById(args.options.entraGroupId)
|
|
66
|
+
: await entraGroup.getGroupByDisplayName(args.options.entraGroupName);
|
|
67
|
+
const siteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
|
|
68
|
+
principalId = siteUser.Id;
|
|
61
69
|
}
|
|
70
|
+
await this.addRoleAssignment(requestUrl, roleDefinitionId, principalId);
|
|
62
71
|
}
|
|
63
72
|
catch (err) {
|
|
64
73
|
this.handleRejectedODataJsonPromise(err);
|
|
@@ -126,6 +135,8 @@ _SpoListItemRoleAssignmentAddCommand_instances = new WeakSet(), _SpoListItemRole
|
|
|
126
135
|
principalId: typeof args.options.principalId !== 'undefined',
|
|
127
136
|
upn: typeof args.options.upn !== 'undefined',
|
|
128
137
|
groupName: typeof args.options.groupName !== 'undefined',
|
|
138
|
+
entraGroupId: typeof args.options.entraGroupId !== 'undefined',
|
|
139
|
+
entraGroupName: typeof args.options.entraGroupName !== 'undefined',
|
|
129
140
|
roleDefinitionId: typeof args.options.roleDefinitionId !== 'undefined',
|
|
130
141
|
roleDefinitionName: typeof args.options.roleDefinitionName !== 'undefined'
|
|
131
142
|
});
|
|
@@ -147,6 +158,10 @@ _SpoListItemRoleAssignmentAddCommand_instances = new WeakSet(), _SpoListItemRole
|
|
|
147
158
|
option: '--upn [upn]'
|
|
148
159
|
}, {
|
|
149
160
|
option: '--groupName [groupName]'
|
|
161
|
+
}, {
|
|
162
|
+
option: '--entraGroupId [entraGroupId]'
|
|
163
|
+
}, {
|
|
164
|
+
option: '--entraGroupName [entraGroupName]'
|
|
150
165
|
}, {
|
|
151
166
|
option: '--roleDefinitionId [roleDefinitionId]'
|
|
152
167
|
}, {
|
|
@@ -177,12 +192,15 @@ _SpoListItemRoleAssignmentAddCommand_instances = new WeakSet(), _SpoListItemRole
|
|
|
177
192
|
if (listOptions.filter(item => item !== undefined).length === 0) {
|
|
178
193
|
return `Specify at least list id or title or list url`;
|
|
179
194
|
}
|
|
180
|
-
const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName];
|
|
195
|
+
const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName, args.options.entraGroupId, args.options.entraGroupName];
|
|
181
196
|
if (!principalOptions.some(item => item !== undefined)) {
|
|
182
|
-
return `Specify either principalId, upn or
|
|
197
|
+
return `Specify either principalId, upn, groupName, entraGroupId or entraGroupName`;
|
|
183
198
|
}
|
|
184
199
|
if (principalOptions.filter(item => item !== undefined).length > 1) {
|
|
185
|
-
return `Specify either principalId, upn or
|
|
200
|
+
return `Specify either principalId, upn, groupName, entraGroupId or entraGroupName but not multiple`;
|
|
201
|
+
}
|
|
202
|
+
if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
|
|
203
|
+
return `'${args.options.entraGroupId}' is not a valid GUID for option entraGroupId.`;
|
|
186
204
|
}
|
|
187
205
|
const roleDefinitionOptions = [args.options.roleDefinitionId, args.options.roleDefinitionName];
|
|
188
206
|
if (!roleDefinitionOptions.some(item => item !== undefined)) {
|
|
@@ -13,6 +13,8 @@ import SpoCommand from '../../../base/SpoCommand.js';
|
|
|
13
13
|
import commands from '../../commands.js';
|
|
14
14
|
import spoGroupGetCommand from '../group/group-get.js';
|
|
15
15
|
import spoUserGetCommand from '../user/user-get.js';
|
|
16
|
+
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
17
|
+
import { spo } from '../../../../utils/spo.js';
|
|
16
18
|
class SpoListItemRoleAssignmentRemoveCommand extends SpoCommand {
|
|
17
19
|
get name() {
|
|
18
20
|
return commands.LISTITEM_ROLEASSIGNMENT_REMOVE;
|
|
@@ -58,15 +60,21 @@ class SpoListItemRoleAssignmentRemoveCommand extends SpoCommand {
|
|
|
58
60
|
requestUrl += `items(${options.listItemId})/`;
|
|
59
61
|
if (options.upn) {
|
|
60
62
|
options.principalId = await this.getUserPrincipalId(options);
|
|
61
|
-
await this.removeRoleAssignmentWithRequestUrl(requestUrl, logger, options);
|
|
62
63
|
}
|
|
63
64
|
else if (options.groupName) {
|
|
64
65
|
options.principalId = await this.getGroupPrincipalId(options);
|
|
65
|
-
await this.removeRoleAssignmentWithRequestUrl(requestUrl, logger, options);
|
|
66
66
|
}
|
|
67
|
-
else {
|
|
68
|
-
|
|
67
|
+
else if (options.entraGroupId || options.entraGroupName) {
|
|
68
|
+
if (this.verbose) {
|
|
69
|
+
await logger.logToStderr('Retrieving group information...');
|
|
70
|
+
}
|
|
71
|
+
const group = options.entraGroupId
|
|
72
|
+
? await entraGroup.getGroupById(options.entraGroupId)
|
|
73
|
+
: await entraGroup.getGroupByDisplayName(options.entraGroupName);
|
|
74
|
+
const siteUser = await spo.ensureEntraGroup(options.webUrl, group);
|
|
75
|
+
options.principalId = siteUser.Id;
|
|
69
76
|
}
|
|
77
|
+
await this.removeRoleAssignmentWithRequestUrl(requestUrl, logger, options);
|
|
70
78
|
}
|
|
71
79
|
catch (err) {
|
|
72
80
|
this.handleRejectedODataJsonPromise(err);
|
|
@@ -119,6 +127,8 @@ _SpoListItemRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoListItemR
|
|
|
119
127
|
principalId: typeof args.options.principalId !== 'undefined',
|
|
120
128
|
upn: typeof args.options.upn !== 'undefined',
|
|
121
129
|
groupName: typeof args.options.groupName !== 'undefined',
|
|
130
|
+
entraGroupId: typeof args.options.entraGroupId !== 'undefined',
|
|
131
|
+
entraGroupName: typeof args.options.entraGroupName !== 'undefined',
|
|
122
132
|
force: (!(!args.options.force)).toString()
|
|
123
133
|
});
|
|
124
134
|
});
|
|
@@ -139,6 +149,10 @@ _SpoListItemRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoListItemR
|
|
|
139
149
|
option: '--upn [upn]'
|
|
140
150
|
}, {
|
|
141
151
|
option: '--groupName [groupName]'
|
|
152
|
+
}, {
|
|
153
|
+
option: '--entraGroupId [entraGroupId]'
|
|
154
|
+
}, {
|
|
155
|
+
option: '--entraGroupName [entraGroupName]'
|
|
142
156
|
}, {
|
|
143
157
|
option: '-f, --force'
|
|
144
158
|
});
|
|
@@ -157,10 +171,13 @@ _SpoListItemRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoListItemR
|
|
|
157
171
|
if (args.options.principalId && isNaN(args.options.principalId)) {
|
|
158
172
|
return `Specified principalId ${args.options.principalId} is not a number`;
|
|
159
173
|
}
|
|
174
|
+
if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
|
|
175
|
+
return `'${args.options.entraGroupId}' is not a valid GUID for option entraGroupId.`;
|
|
176
|
+
}
|
|
160
177
|
return true;
|
|
161
178
|
});
|
|
162
179
|
}, _SpoListItemRoleAssignmentRemoveCommand_initOptionSets = function _SpoListItemRoleAssignmentRemoveCommand_initOptionSets() {
|
|
163
|
-
this.optionSets.push({ options: ['listId', 'listTitle', 'listUrl'] }, { options: ['principalId', 'upn', 'groupName'] });
|
|
180
|
+
this.optionSets.push({ options: ['listId', 'listTitle', 'listUrl'] }, { options: ['principalId', 'upn', 'groupName', 'entraGroupId', 'entraGroupName'] });
|
|
164
181
|
};
|
|
165
182
|
export default new SpoListItemRoleAssignmentRemoveCommand();
|
|
166
183
|
//# sourceMappingURL=listitem-roleassignment-remove.js.map
|
|
@@ -12,6 +12,8 @@ import commands from '../../commands.js';
|
|
|
12
12
|
import spoGroupGetCommand from '../group/group-get.js';
|
|
13
13
|
import spoRoleDefinitionListCommand from '../roledefinition/roledefinition-list.js';
|
|
14
14
|
import spoUserGetCommand from '../user/user-get.js';
|
|
15
|
+
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
16
|
+
import { spo } from '../../../../utils/spo.js';
|
|
15
17
|
class SpoWebRoleAssignmentAddCommand extends SpoCommand {
|
|
16
18
|
get name() {
|
|
17
19
|
return commands.WEB_ROLEASSIGNMENT_ADD;
|
|
@@ -35,15 +37,21 @@ class SpoWebRoleAssignmentAddCommand extends SpoCommand {
|
|
|
35
37
|
args.options.roleDefinitionId = await this.getRoleDefinitionId(args.options);
|
|
36
38
|
if (args.options.upn) {
|
|
37
39
|
args.options.principalId = await this.getUserPrincipalId(args.options);
|
|
38
|
-
await this.addRoleAssignment(logger, args.options);
|
|
39
40
|
}
|
|
40
41
|
else if (args.options.groupName) {
|
|
41
42
|
args.options.principalId = await this.getGroupPrincipalId(args.options);
|
|
42
|
-
await this.addRoleAssignment(logger, args.options);
|
|
43
43
|
}
|
|
44
|
-
else {
|
|
45
|
-
|
|
44
|
+
else if (args.options.entraGroupId || args.options.entraGroupName) {
|
|
45
|
+
if (this.verbose) {
|
|
46
|
+
await logger.logToStderr('Retrieving group information...');
|
|
47
|
+
}
|
|
48
|
+
const group = args.options.entraGroupId
|
|
49
|
+
? await entraGroup.getGroupById(args.options.entraGroupId)
|
|
50
|
+
: await entraGroup.getGroupByDisplayName(args.options.entraGroupName);
|
|
51
|
+
const siteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
|
|
52
|
+
args.options.principalId = siteUser.Id;
|
|
46
53
|
}
|
|
54
|
+
await this.addRoleAssignment(logger, args.options);
|
|
47
55
|
}
|
|
48
56
|
catch (err) {
|
|
49
57
|
this.handleRejectedODataJsonPromise(err);
|
|
@@ -108,6 +116,8 @@ _SpoWebRoleAssignmentAddCommand_instances = new WeakSet(), _SpoWebRoleAssignment
|
|
|
108
116
|
principalId: typeof args.options.principalId !== 'undefined',
|
|
109
117
|
upn: typeof args.options.upn !== 'undefined',
|
|
110
118
|
groupName: typeof args.options.groupName !== 'undefined',
|
|
119
|
+
entraGroupId: typeof args.options.entraGroupId !== 'undefined',
|
|
120
|
+
entraGroupName: typeof args.options.entraGroupName !== 'undefined',
|
|
111
121
|
roleDefinitionId: typeof args.options.roleDefinitionId !== 'undefined',
|
|
112
122
|
roleDefinitionName: typeof args.options.roleDefinitionName !== 'undefined'
|
|
113
123
|
});
|
|
@@ -121,6 +131,10 @@ _SpoWebRoleAssignmentAddCommand_instances = new WeakSet(), _SpoWebRoleAssignment
|
|
|
121
131
|
option: '--upn [upn]'
|
|
122
132
|
}, {
|
|
123
133
|
option: '--groupName [groupName]'
|
|
134
|
+
}, {
|
|
135
|
+
option: '--entraGroupId [entraGroupId]'
|
|
136
|
+
}, {
|
|
137
|
+
option: '--entraGroupName [entraGroupName]'
|
|
124
138
|
}, {
|
|
125
139
|
option: '--roleDefinitionId [roleDefinitionId]'
|
|
126
140
|
}, {
|
|
@@ -138,10 +152,13 @@ _SpoWebRoleAssignmentAddCommand_instances = new WeakSet(), _SpoWebRoleAssignment
|
|
|
138
152
|
if (args.options.roleDefinitionId && isNaN(args.options.roleDefinitionId)) {
|
|
139
153
|
return `Specified roleDefinitionId ${args.options.roleDefinitionId} is not a number`;
|
|
140
154
|
}
|
|
155
|
+
if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
|
|
156
|
+
return `'${args.options.entraGroupId}' is not a valid GUID for option entraGroupId.`;
|
|
157
|
+
}
|
|
141
158
|
return true;
|
|
142
159
|
});
|
|
143
160
|
}, _SpoWebRoleAssignmentAddCommand_initOptionSets = function _SpoWebRoleAssignmentAddCommand_initOptionSets() {
|
|
144
|
-
this.optionSets.push({ options: ['principalId', 'upn', 'groupName'] }, { options: ['roleDefinitionId', 'roleDefinitionName'] });
|
|
161
|
+
this.optionSets.push({ options: ['principalId', 'upn', 'groupName', 'entraGroupId', 'entraGroupName'] }, { options: ['roleDefinitionId', 'roleDefinitionName'] });
|
|
145
162
|
};
|
|
146
163
|
export default new SpoWebRoleAssignmentAddCommand();
|
|
147
164
|
//# sourceMappingURL=web-roleassignment-add.js.map
|