@pnp/cli-microsoft365 9.1.0-beta.8c76288 → 9.1.0-beta.94ae9ed
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/allCommands.json +1 -1
- package/allCommandsFull.json +1 -1
- package/dist/m365/flow/commands/recyclebinitem/recyclebinitem-list.js +47 -0
- package/dist/m365/flow/commands/recyclebinitem/recyclebinitem-restore.js +48 -0
- package/dist/m365/flow/commands.js +2 -0
- package/dist/m365/spo/commands/folder/folder-sharinglink-add.js +143 -0
- package/dist/m365/spo/commands/folder/folder-sharinglink-clear.js +111 -0
- package/dist/m365/spo/commands/folder/folder-sharinglink-remove.js +95 -0
- package/dist/m365/spo/commands/site/SiteAdmin.js +2 -0
- package/dist/m365/spo/commands/site/site-admin-add.js +252 -0
- package/dist/m365/spo/commands/site/site-admin-list.js +2 -27
- package/dist/m365/spo/commands/user/user-get.js +67 -9
- package/dist/m365/spo/commands.js +4 -0
- package/dist/m365/spp/commands/contentcenter/contentcenter-list.js +56 -0
- package/dist/m365/spp/commands.js +5 -0
- package/dist/utils/spo.js +45 -0
- package/docs/docs/cmd/flow/recyclebinitem/recyclebinitem-list.mdx +132 -0
- package/docs/docs/cmd/flow/recyclebinitem/recyclebinitem-restore.mdx +55 -0
- package/docs/docs/cmd/spo/folder/folder-sharinglink-add.mdx +125 -0
- package/docs/docs/cmd/spo/folder/folder-sharinglink-clear.mdx +50 -0
- package/docs/docs/cmd/spo/folder/folder-sharinglink-remove.mdx +50 -0
- package/docs/docs/cmd/spo/site/site-admin-add.mdx +67 -0
- package/docs/docs/cmd/spo/user/user-get.mdx +35 -9
- package/docs/docs/cmd/spp/contentcenter/contentcenter-list.mdx +289 -0
- package/package.json +1 -1
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var _SpoSiteAdminAddCommand_instances, _SpoSiteAdminAddCommand_initTelemetry, _SpoSiteAdminAddCommand_initOptions, _SpoSiteAdminAddCommand_initValidators, _SpoSiteAdminAddCommand_initOptionSets, _SpoSiteAdminAddCommand_initTypes;
|
|
7
|
+
import config from '../../../../config.js';
|
|
8
|
+
import request from '../../../../request.js';
|
|
9
|
+
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
10
|
+
import { entraUser } from '../../../../utils/entraUser.js';
|
|
11
|
+
import { formatting } from '../../../../utils/formatting.js';
|
|
12
|
+
import { spo } from '../../../../utils/spo.js';
|
|
13
|
+
import { validation } from '../../../../utils/validation.js';
|
|
14
|
+
import SpoCommand from '../../../base/SpoCommand.js';
|
|
15
|
+
import commands from '../../commands.js';
|
|
16
|
+
class SpoSiteAdminAddCommand extends SpoCommand {
|
|
17
|
+
get name() {
|
|
18
|
+
return commands.SITE_ADMIN_ADD;
|
|
19
|
+
}
|
|
20
|
+
get description() {
|
|
21
|
+
return 'Adds a user or group as a site collection administrator';
|
|
22
|
+
}
|
|
23
|
+
constructor() {
|
|
24
|
+
super();
|
|
25
|
+
_SpoSiteAdminAddCommand_instances.add(this);
|
|
26
|
+
__classPrivateFieldGet(this, _SpoSiteAdminAddCommand_instances, "m", _SpoSiteAdminAddCommand_initTelemetry).call(this);
|
|
27
|
+
__classPrivateFieldGet(this, _SpoSiteAdminAddCommand_instances, "m", _SpoSiteAdminAddCommand_initOptions).call(this);
|
|
28
|
+
__classPrivateFieldGet(this, _SpoSiteAdminAddCommand_instances, "m", _SpoSiteAdminAddCommand_initValidators).call(this);
|
|
29
|
+
__classPrivateFieldGet(this, _SpoSiteAdminAddCommand_instances, "m", _SpoSiteAdminAddCommand_initOptionSets).call(this);
|
|
30
|
+
__classPrivateFieldGet(this, _SpoSiteAdminAddCommand_instances, "m", _SpoSiteAdminAddCommand_initTypes).call(this);
|
|
31
|
+
}
|
|
32
|
+
async commandAction(logger, args) {
|
|
33
|
+
try {
|
|
34
|
+
const loginNameToAdd = await this.getCorrectLoginName(args.options);
|
|
35
|
+
if (args.options.asAdmin) {
|
|
36
|
+
await this.callActionAsAdmin(logger, args, loginNameToAdd);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
await this.callAction(logger, args, loginNameToAdd);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
this.handleRejectedODataJsonPromise(err);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
async callActionAsAdmin(logger, args, loginNameToAdd) {
|
|
46
|
+
if (this.verbose) {
|
|
47
|
+
await logger.logToStderr('Adding site administrator as an administrator...');
|
|
48
|
+
}
|
|
49
|
+
const adminUrl = await spo.getSpoAdminUrl(logger, this.debug);
|
|
50
|
+
const siteId = await this.getSiteIdBasedOnUrl(args.options.siteUrl, logger);
|
|
51
|
+
const siteAdmins = (await this.getSiteAdmins(adminUrl, siteId)).map(u => u.loginName);
|
|
52
|
+
siteAdmins.push(loginNameToAdd);
|
|
53
|
+
await this.setSiteAdminsAsAdmin(adminUrl, siteId, siteAdmins);
|
|
54
|
+
if (args.options.primary) {
|
|
55
|
+
await this.setPrimaryAdminAsAdmin(adminUrl, siteId, loginNameToAdd);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async getSiteIdBasedOnUrl(siteUrl, logger) {
|
|
59
|
+
const siteGraphId = await spo.getSiteId(siteUrl, logger, this.verbose);
|
|
60
|
+
const match = siteGraphId.match(/,([a-f0-9\-]{36}),/i);
|
|
61
|
+
if (!match) {
|
|
62
|
+
throw `Site with URL ${siteUrl} not found`;
|
|
63
|
+
}
|
|
64
|
+
return match[1];
|
|
65
|
+
}
|
|
66
|
+
async getSiteAdmins(adminUrl, siteId) {
|
|
67
|
+
const requestOptions = {
|
|
68
|
+
url: `${adminUrl}/_api/SPO.Tenant/GetSiteAdministrators?siteId='${siteId}'`,
|
|
69
|
+
headers: {
|
|
70
|
+
accept: 'application/json;odata=nometadata',
|
|
71
|
+
'content-type': 'application/json;charset=utf-8'
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const response = await request.post(requestOptions);
|
|
75
|
+
const responseContent = JSON.parse(response);
|
|
76
|
+
return responseContent.value;
|
|
77
|
+
}
|
|
78
|
+
async getCorrectLoginName(options) {
|
|
79
|
+
if (options.userId || options.userName) {
|
|
80
|
+
const userPrincipalName = options.userName ? options.userName : await entraUser.getUpnByUserId(options.userId);
|
|
81
|
+
if (userPrincipalName) {
|
|
82
|
+
return `i:0#.f|membership|${userPrincipalName}`;
|
|
83
|
+
}
|
|
84
|
+
throw 'User not found.';
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const group = options.groupId ? await entraGroup.getGroupById(options.groupId) : await entraGroup.getGroupByDisplayName(options.groupName);
|
|
88
|
+
//for entra groups, M365 groups have an associated email and security groups don't
|
|
89
|
+
if (group?.mail) {
|
|
90
|
+
//M365 group is prefixed with c:0o.c|federateddirectoryclaimprovider
|
|
91
|
+
return `c:0o.c|federateddirectoryclaimprovider|${group.id}`;
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
//security group is prefixed with c:0t.c|tenant
|
|
95
|
+
return `c:0t.c|tenant|${group?.id}`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async setSiteAdminsAsAdmin(adminUrl, siteId, admins) {
|
|
100
|
+
const requestOptions = {
|
|
101
|
+
url: `${adminUrl}/_api/SPOInternalUseOnly.Tenant/SetSiteSecondaryAdministrators`,
|
|
102
|
+
headers: {
|
|
103
|
+
accept: 'application/json;odata=nometadata',
|
|
104
|
+
'content-type': 'application/json;charset=utf-8'
|
|
105
|
+
},
|
|
106
|
+
data: {
|
|
107
|
+
secondaryAdministratorsFieldsData: {
|
|
108
|
+
siteId: siteId,
|
|
109
|
+
secondaryAdministratorLoginNames: admins
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return request.post(requestOptions);
|
|
114
|
+
}
|
|
115
|
+
async setPrimaryAdminAsAdmin(adminUrl, siteId, adminLogin) {
|
|
116
|
+
const requestOptions = {
|
|
117
|
+
url: `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')`,
|
|
118
|
+
headers: {
|
|
119
|
+
accept: 'application/json;odata=nometadata',
|
|
120
|
+
'content-type': 'application/json;charset=utf-8'
|
|
121
|
+
},
|
|
122
|
+
data: {
|
|
123
|
+
Owner: adminLogin,
|
|
124
|
+
SetOwnerWithoutUpdatingSecondaryAdmin: true
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
return request.patch(requestOptions);
|
|
128
|
+
}
|
|
129
|
+
async callAction(logger, args, loginNameToAdd) {
|
|
130
|
+
if (this.verbose) {
|
|
131
|
+
await logger.logToStderr('Adding site administrator...');
|
|
132
|
+
}
|
|
133
|
+
const ensuredUserData = await this.ensureUser(args, loginNameToAdd);
|
|
134
|
+
await this.setSiteAdmin(args.options.siteUrl, loginNameToAdd);
|
|
135
|
+
if (args.options.primary) {
|
|
136
|
+
const siteId = await this.getSiteId(args.options.siteUrl);
|
|
137
|
+
const previousPrimaryOwner = await this.getSiteOwnerLoginName(args.options.siteUrl);
|
|
138
|
+
await this.setPrimaryOwnerLoginFromSite(logger, args.options.siteUrl, siteId, ensuredUserData);
|
|
139
|
+
await this.setSiteAdmin(args.options.siteUrl, previousPrimaryOwner);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
async ensureUser(args, loginName) {
|
|
143
|
+
const requestOptions = {
|
|
144
|
+
url: `${args.options.siteUrl}/_api/web/ensureuser`,
|
|
145
|
+
headers: {
|
|
146
|
+
accept: 'application/json;odata=nometadata'
|
|
147
|
+
},
|
|
148
|
+
data: {
|
|
149
|
+
logonName: loginName
|
|
150
|
+
},
|
|
151
|
+
responseType: 'json'
|
|
152
|
+
};
|
|
153
|
+
return request.post(requestOptions);
|
|
154
|
+
}
|
|
155
|
+
async setSiteAdmin(siteUrl, loginName) {
|
|
156
|
+
const requestOptions = {
|
|
157
|
+
url: `${siteUrl}/_api/web/siteusers('${formatting.encodeQueryParameter(loginName)}')`,
|
|
158
|
+
headers: {
|
|
159
|
+
'accept': 'application/json',
|
|
160
|
+
'X-Http-Method': 'MERGE',
|
|
161
|
+
'If-Match': '*'
|
|
162
|
+
},
|
|
163
|
+
data: { IsSiteAdmin: true },
|
|
164
|
+
responseType: 'json'
|
|
165
|
+
};
|
|
166
|
+
return request.post(requestOptions);
|
|
167
|
+
}
|
|
168
|
+
async getSiteId(siteUrl) {
|
|
169
|
+
const requestOptions = {
|
|
170
|
+
url: `${siteUrl}/_api/site?$select=Id`,
|
|
171
|
+
headers: {
|
|
172
|
+
accept: 'application/json;odata=nometadata'
|
|
173
|
+
},
|
|
174
|
+
responseType: 'json'
|
|
175
|
+
};
|
|
176
|
+
const response = await request.get(requestOptions);
|
|
177
|
+
return response.Id;
|
|
178
|
+
}
|
|
179
|
+
async getSiteOwnerLoginName(siteUrl) {
|
|
180
|
+
const requestOptions = {
|
|
181
|
+
url: `${siteUrl}/_api/site/owner?$select=LoginName`,
|
|
182
|
+
headers: {
|
|
183
|
+
accept: 'application/json;odata=nometadata'
|
|
184
|
+
},
|
|
185
|
+
responseType: 'json'
|
|
186
|
+
};
|
|
187
|
+
const response = await request.get(requestOptions);
|
|
188
|
+
return response.LoginName;
|
|
189
|
+
}
|
|
190
|
+
async setPrimaryOwnerLoginFromSite(logger, siteUrl, siteId, loginName) {
|
|
191
|
+
const res = await spo.ensureFormDigest(siteUrl, logger, undefined, this.debug);
|
|
192
|
+
const body = `<Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}"><Actions><SetProperty Id="10" ObjectPathId="2" Name="Owner"><Parameter ObjectPathId="3" /></SetProperty></Actions><ObjectPaths><Property Id="2" ParentId="0" Name="Site" /><Identity Id="3" Name="6d452ba1-40a8-8000-e00d-46e1adaa12bf|740c6a0b-85e2-48a0-a494-e0f1759d4aa7:site:${siteId}:u:${loginName.Id}" /><StaticProperty Id="0" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" /></ObjectPaths></Request>`;
|
|
193
|
+
const requestOptions = {
|
|
194
|
+
url: `${siteUrl}/_vti_bin/client.svc/ProcessQuery`,
|
|
195
|
+
headers: {
|
|
196
|
+
'X-RequestDigest': res.FormDigestValue
|
|
197
|
+
},
|
|
198
|
+
data: body
|
|
199
|
+
};
|
|
200
|
+
return request.post(requestOptions);
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
_SpoSiteAdminAddCommand_instances = new WeakSet(), _SpoSiteAdminAddCommand_initTelemetry = function _SpoSiteAdminAddCommand_initTelemetry() {
|
|
204
|
+
this.telemetry.push((args) => {
|
|
205
|
+
Object.assign(this.telemetryProperties, {
|
|
206
|
+
userId: typeof args.options.userId !== 'undefined',
|
|
207
|
+
userName: typeof args.options.userName !== 'undefined',
|
|
208
|
+
groupId: typeof args.options.groupId !== 'undefined',
|
|
209
|
+
groupName: typeof args.options.groupName !== 'undefined',
|
|
210
|
+
primary: !!args.options.primary,
|
|
211
|
+
asAdmin: !!args.options.asAdmin
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
}, _SpoSiteAdminAddCommand_initOptions = function _SpoSiteAdminAddCommand_initOptions() {
|
|
215
|
+
this.options.unshift({
|
|
216
|
+
option: '-u, --siteUrl <siteUrl>'
|
|
217
|
+
}, {
|
|
218
|
+
option: '--userId [userId]'
|
|
219
|
+
}, {
|
|
220
|
+
option: '--userName [userName]'
|
|
221
|
+
}, {
|
|
222
|
+
option: '--groupId [groupId]'
|
|
223
|
+
}, {
|
|
224
|
+
option: '--groupName [groupName]'
|
|
225
|
+
}, {
|
|
226
|
+
option: '--primary'
|
|
227
|
+
}, {
|
|
228
|
+
option: '--asAdmin'
|
|
229
|
+
});
|
|
230
|
+
}, _SpoSiteAdminAddCommand_initValidators = function _SpoSiteAdminAddCommand_initValidators() {
|
|
231
|
+
this.validators.push(async (args) => {
|
|
232
|
+
if (args.options.userId &&
|
|
233
|
+
!validation.isValidGuid(args.options.userId)) {
|
|
234
|
+
return `'${args.options.userId}' is not a valid GUID for option 'userId'`;
|
|
235
|
+
}
|
|
236
|
+
if (args.options.userName && !validation.isValidUserPrincipalName(args.options.userName)) {
|
|
237
|
+
return `'${args.options.userName}' is not a valid 'userName'`;
|
|
238
|
+
}
|
|
239
|
+
if (args.options.groupId &&
|
|
240
|
+
!validation.isValidGuid(args.options.groupId)) {
|
|
241
|
+
return `'${args.options.groupId}' is not a valid GUID for option 'groupId'`;
|
|
242
|
+
}
|
|
243
|
+
return validation.isValidSharePointUrl(args.options.siteUrl);
|
|
244
|
+
});
|
|
245
|
+
}, _SpoSiteAdminAddCommand_initOptionSets = function _SpoSiteAdminAddCommand_initOptionSets() {
|
|
246
|
+
this.optionSets.push({ options: ['userId', 'userName', 'groupId', 'groupName'] });
|
|
247
|
+
}, _SpoSiteAdminAddCommand_initTypes = function _SpoSiteAdminAddCommand_initTypes() {
|
|
248
|
+
this.types.string.push('siteUrl', 'userId', 'userName', 'groupId', 'groupName');
|
|
249
|
+
this.types.boolean.push('primary', 'asAdmin');
|
|
250
|
+
};
|
|
251
|
+
export default new SpoSiteAdminAddCommand();
|
|
252
|
+
//# sourceMappingURL=site-admin-add.js.map
|
|
@@ -52,7 +52,7 @@ class SpoSiteAdminListCommand extends SpoCommand {
|
|
|
52
52
|
};
|
|
53
53
|
const response = await request.post(requestOptions);
|
|
54
54
|
const responseContent = JSON.parse(response);
|
|
55
|
-
const primaryAdminLoginName = await
|
|
55
|
+
const primaryAdminLoginName = await spo.getPrimaryAdminLoginNameAsAdmin(adminUrl, siteId, logger, this.verbose);
|
|
56
56
|
const mappedResult = responseContent.value.map((u) => ({
|
|
57
57
|
Id: null,
|
|
58
58
|
Email: u.email,
|
|
@@ -72,18 +72,6 @@ class SpoSiteAdminListCommand extends SpoCommand {
|
|
|
72
72
|
}
|
|
73
73
|
return match[1];
|
|
74
74
|
}
|
|
75
|
-
async getPrimaryAdminLoginNameFromAdmin(adminUrl, siteId) {
|
|
76
|
-
const requestOptions = {
|
|
77
|
-
url: `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`,
|
|
78
|
-
headers: {
|
|
79
|
-
accept: 'application/json;odata=nometadata',
|
|
80
|
-
'content-type': 'application/json;charset=utf-8'
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
const response = await request.get(requestOptions);
|
|
84
|
-
const responseContent = JSON.parse(response);
|
|
85
|
-
return responseContent.OwnerLoginName;
|
|
86
|
-
}
|
|
87
75
|
async callAction(logger, args) {
|
|
88
76
|
if (this.verbose) {
|
|
89
77
|
await logger.logToStderr('Retrieving site administrators...');
|
|
@@ -97,7 +85,7 @@ class SpoSiteAdminListCommand extends SpoCommand {
|
|
|
97
85
|
responseType: 'json'
|
|
98
86
|
};
|
|
99
87
|
const responseContent = await request.get(requestOptions);
|
|
100
|
-
const primaryOwnerLogin = await
|
|
88
|
+
const primaryOwnerLogin = await spo.getPrimaryOwnerLoginFromSite(args.options.siteUrl, logger, this.verbose);
|
|
101
89
|
const mappedResult = responseContent.value.map((u) => ({
|
|
102
90
|
Id: u.Id,
|
|
103
91
|
LoginName: u.LoginName,
|
|
@@ -109,23 +97,10 @@ class SpoSiteAdminListCommand extends SpoCommand {
|
|
|
109
97
|
}));
|
|
110
98
|
await logger.log(mappedResult);
|
|
111
99
|
}
|
|
112
|
-
async getPrimaryOwnerLoginFromSite(siteUrl) {
|
|
113
|
-
const requestOptions = {
|
|
114
|
-
url: `${siteUrl}/_api/site/owner`,
|
|
115
|
-
method: 'GET',
|
|
116
|
-
headers: {
|
|
117
|
-
'accept': 'application/json;odata=nometadata'
|
|
118
|
-
},
|
|
119
|
-
responseType: 'json'
|
|
120
|
-
};
|
|
121
|
-
const responseContent = await request.get(requestOptions);
|
|
122
|
-
return responseContent?.LoginName ?? null;
|
|
123
|
-
}
|
|
124
100
|
}
|
|
125
101
|
_SpoSiteAdminListCommand_instances = new WeakSet(), _SpoSiteAdminListCommand_initTelemetry = function _SpoSiteAdminListCommand_initTelemetry() {
|
|
126
102
|
this.telemetry.push((args) => {
|
|
127
103
|
Object.assign(this.telemetryProperties, {
|
|
128
|
-
siteUrl: typeof args.options.siteUrl !== 'undefined',
|
|
129
104
|
asAdmin: !!args.options.asAdmin
|
|
130
105
|
});
|
|
131
106
|
});
|
|
@@ -3,8 +3,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var _SpoUserGetCommand_instances, _SpoUserGetCommand_initTelemetry, _SpoUserGetCommand_initOptions, _SpoUserGetCommand_initValidators, _SpoUserGetCommand_initOptionSets;
|
|
6
|
+
var _SpoUserGetCommand_instances, _SpoUserGetCommand_initTelemetry, _SpoUserGetCommand_initOptions, _SpoUserGetCommand_initTypes, _SpoUserGetCommand_initValidators, _SpoUserGetCommand_initOptionSets;
|
|
7
7
|
import request from '../../../../request.js';
|
|
8
|
+
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
8
9
|
import { formatting } from '../../../../utils/formatting.js';
|
|
9
10
|
import { validation } from '../../../../utils/validation.js';
|
|
10
11
|
import SpoCommand from '../../../base/SpoCommand.js';
|
|
@@ -23,23 +24,38 @@ class SpoUserGetCommand extends SpoCommand {
|
|
|
23
24
|
__classPrivateFieldGet(this, _SpoUserGetCommand_instances, "m", _SpoUserGetCommand_initOptions).call(this);
|
|
24
25
|
__classPrivateFieldGet(this, _SpoUserGetCommand_instances, "m", _SpoUserGetCommand_initValidators).call(this);
|
|
25
26
|
__classPrivateFieldGet(this, _SpoUserGetCommand_instances, "m", _SpoUserGetCommand_initOptionSets).call(this);
|
|
27
|
+
__classPrivateFieldGet(this, _SpoUserGetCommand_instances, "m", _SpoUserGetCommand_initTypes).call(this);
|
|
26
28
|
}
|
|
27
29
|
async commandAction(logger, args) {
|
|
28
30
|
if (this.verbose) {
|
|
29
31
|
await logger.logToStderr(`Retrieving information for user in site '${args.options.webUrl}'...`);
|
|
30
32
|
}
|
|
31
|
-
let requestUrl =
|
|
33
|
+
let requestUrl = `${args.options.webUrl}/_api/web/`;
|
|
32
34
|
if (args.options.id) {
|
|
33
|
-
requestUrl
|
|
35
|
+
requestUrl += `siteusers/GetById('${formatting.encodeQueryParameter(args.options.id.toString())}')`;
|
|
34
36
|
}
|
|
35
37
|
else if (args.options.email) {
|
|
36
|
-
requestUrl
|
|
38
|
+
requestUrl += `siteusers/GetByEmail('${formatting.encodeQueryParameter(args.options.email)}')`;
|
|
37
39
|
}
|
|
38
40
|
else if (args.options.loginName) {
|
|
39
|
-
requestUrl
|
|
41
|
+
requestUrl += `siteusers/GetByLoginName('${formatting.encodeQueryParameter(args.options.loginName)}')`;
|
|
42
|
+
}
|
|
43
|
+
else if (args.options.userName) {
|
|
44
|
+
const user = await this.getUser(requestUrl, args.options.userName);
|
|
45
|
+
requestUrl += `siteusers/GetById('${formatting.encodeQueryParameter(user.Id.toString())}')`;
|
|
46
|
+
}
|
|
47
|
+
else if (args.options.entraGroupId || args.options.entraGroupName) {
|
|
48
|
+
const entraGroup = await this.getEntraGroup(args.options.entraGroupId, args.options.entraGroupName);
|
|
49
|
+
// For entra groups, M365 groups have an associated email and security groups don't
|
|
50
|
+
if (entraGroup?.mail) {
|
|
51
|
+
requestUrl += `siteusers/GetByEmail('${formatting.encodeQueryParameter(entraGroup.mail)}')`;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
requestUrl += `siteusers/GetByLoginName('c:0t.c|tenant|${entraGroup?.id}')`;
|
|
55
|
+
}
|
|
40
56
|
}
|
|
41
57
|
else {
|
|
42
|
-
requestUrl
|
|
58
|
+
requestUrl += `currentuser`;
|
|
43
59
|
}
|
|
44
60
|
const requestOptions = {
|
|
45
61
|
url: requestUrl,
|
|
@@ -57,13 +73,38 @@ class SpoUserGetCommand extends SpoCommand {
|
|
|
57
73
|
this.handleRejectedODataJsonPromise(err);
|
|
58
74
|
}
|
|
59
75
|
}
|
|
76
|
+
async getUser(baseUrl, userName) {
|
|
77
|
+
const requestUrl = `${baseUrl}siteusers?$filter=UserPrincipalName eq ('${formatting.encodeQueryParameter(userName)}')`;
|
|
78
|
+
const requestOptions = {
|
|
79
|
+
url: requestUrl,
|
|
80
|
+
headers: {
|
|
81
|
+
accept: 'application/json;odata=nometadata'
|
|
82
|
+
},
|
|
83
|
+
responseType: 'json'
|
|
84
|
+
};
|
|
85
|
+
const userInstance = await request.get(requestOptions);
|
|
86
|
+
const userInstanceValue = userInstance.value[0];
|
|
87
|
+
if (!userInstanceValue) {
|
|
88
|
+
throw `User not found: ${userName}`;
|
|
89
|
+
}
|
|
90
|
+
return userInstanceValue;
|
|
91
|
+
}
|
|
92
|
+
async getEntraGroup(entraGroupId, entraGroupName) {
|
|
93
|
+
if (entraGroupId) {
|
|
94
|
+
return entraGroup.getGroupById(entraGroupId);
|
|
95
|
+
}
|
|
96
|
+
return entraGroup.getGroupByDisplayName(entraGroupName);
|
|
97
|
+
}
|
|
60
98
|
}
|
|
61
99
|
_SpoUserGetCommand_instances = new WeakSet(), _SpoUserGetCommand_initTelemetry = function _SpoUserGetCommand_initTelemetry() {
|
|
62
100
|
this.telemetry.push((args) => {
|
|
63
101
|
Object.assign(this.telemetryProperties, {
|
|
64
102
|
id: typeof args.options.id !== 'undefined',
|
|
65
103
|
email: typeof args.options.email !== 'undefined',
|
|
66
|
-
loginName: typeof args.options.loginName !== 'undefined'
|
|
104
|
+
loginName: typeof args.options.loginName !== 'undefined',
|
|
105
|
+
userName: typeof args.options.userName !== 'undefined',
|
|
106
|
+
entraGroupId: typeof args.options.entraGroupId !== 'undefined',
|
|
107
|
+
entraGroupName: typeof args.options.entraGroupName !== 'undefined'
|
|
67
108
|
});
|
|
68
109
|
});
|
|
69
110
|
}, _SpoUserGetCommand_initOptions = function _SpoUserGetCommand_initOptions() {
|
|
@@ -75,19 +116,36 @@ _SpoUserGetCommand_instances = new WeakSet(), _SpoUserGetCommand_initTelemetry =
|
|
|
75
116
|
option: '--email [email]'
|
|
76
117
|
}, {
|
|
77
118
|
option: '--loginName [loginName]'
|
|
119
|
+
}, {
|
|
120
|
+
option: '--userName [userName]'
|
|
121
|
+
}, {
|
|
122
|
+
option: '--entraGroupId [entraGroupId]'
|
|
123
|
+
}, {
|
|
124
|
+
option: '--entraGroupName [entraGroupName]'
|
|
78
125
|
});
|
|
126
|
+
}, _SpoUserGetCommand_initTypes = function _SpoUserGetCommand_initTypes() {
|
|
127
|
+
this.types.string.push('webUrl', 'id', 'email', 'loginName', 'userName', 'entraGroupId', 'entraGroupName');
|
|
79
128
|
}, _SpoUserGetCommand_initValidators = function _SpoUserGetCommand_initValidators() {
|
|
80
129
|
this.validators.push(async (args) => {
|
|
81
130
|
if (args.options.id &&
|
|
82
131
|
typeof args.options.id !== 'number') {
|
|
83
132
|
return `Specified id ${args.options.id} is not a number`;
|
|
84
133
|
}
|
|
134
|
+
if (args.options.entraGroupId && !validation.isValidGuid(args.options.entraGroupId)) {
|
|
135
|
+
return `${args.options.entraGroupId} is not a valid GUID.`;
|
|
136
|
+
}
|
|
137
|
+
if (args.options.userName && !validation.isValidUserPrincipalName(args.options.userName)) {
|
|
138
|
+
return `${args.options.userName} is not a valid userName.`;
|
|
139
|
+
}
|
|
140
|
+
if (args.options.email && !validation.isValidUserPrincipalName(args.options.email)) {
|
|
141
|
+
return `${args.options.email} is not a valid email.`;
|
|
142
|
+
}
|
|
85
143
|
return validation.isValidSharePointUrl(args.options.webUrl);
|
|
86
144
|
});
|
|
87
145
|
}, _SpoUserGetCommand_initOptionSets = function _SpoUserGetCommand_initOptionSets() {
|
|
88
146
|
this.optionSets.push({
|
|
89
|
-
options: ['id', 'email', 'loginName'],
|
|
90
|
-
runsWhen: (args) => args.options.id || args.options.loginName || args.options.
|
|
147
|
+
options: ['id', 'email', 'loginName', 'userName', 'entraGroupId', 'entraGroupName'],
|
|
148
|
+
runsWhen: (args) => args.options.id || args.options.email || args.options.loginName || args.options.userName || args.options.entraGroupId || args.options.entraGroupName
|
|
91
149
|
});
|
|
92
150
|
};
|
|
93
151
|
export default new SpoUserGetCommand();
|
|
@@ -100,8 +100,11 @@ export default {
|
|
|
100
100
|
FOLDER_ROLEASSIGNMENT_ADD: `${prefix} folder roleassignment add`,
|
|
101
101
|
FOLDER_ROLEINHERITANCE_BREAK: `${prefix} folder roleinheritance break`,
|
|
102
102
|
FOLDER_ROLEINHERITANCE_RESET: `${prefix} folder roleinheritance reset`,
|
|
103
|
+
FOLDER_SHARINGLINK_ADD: `${prefix} folder sharinglink add`,
|
|
104
|
+
FOLDER_SHARINGLINK_CLEAR: `${prefix} folder sharinglink clear`,
|
|
103
105
|
FOLDER_SHARINGLINK_GET: `${prefix} folder sharinglink get`,
|
|
104
106
|
FOLDER_SHARINGLINK_LIST: `${prefix} folder sharinglink list`,
|
|
107
|
+
FOLDER_SHARINGLINK_REMOVE: `${prefix} folder sharinglink remove`,
|
|
105
108
|
GET: `${prefix} get`,
|
|
106
109
|
GROUP_ADD: `${prefix} group add`,
|
|
107
110
|
GROUP_GET: `${prefix} group get`,
|
|
@@ -242,6 +245,7 @@ export default {
|
|
|
242
245
|
SERVICEPRINCIPAL_SET: `${prefix} serviceprincipal set`,
|
|
243
246
|
SET: `${prefix} set`,
|
|
244
247
|
SITE_ADD: `${prefix} site add`,
|
|
248
|
+
SITE_ADMIN_ADD: `${prefix} site admin add`,
|
|
245
249
|
SITE_ADMIN_LIST: `${prefix} site admin list`,
|
|
246
250
|
SITE_APPCATALOG_ADD: `${prefix} site appcatalog add`,
|
|
247
251
|
SITE_APPCATALOG_LIST: `${prefix} site appcatalog list`,
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import config from '../../../../config.js';
|
|
2
|
+
import request from '../../../../request.js';
|
|
3
|
+
import { spo } from '../../../../utils/spo.js';
|
|
4
|
+
import SpoCommand from '../../../base/SpoCommand.js';
|
|
5
|
+
import commands from '../../commands.js';
|
|
6
|
+
class SppContentCenterListCommand extends SpoCommand {
|
|
7
|
+
get name() {
|
|
8
|
+
return commands.CONTENTCENTER_LIST;
|
|
9
|
+
}
|
|
10
|
+
get description() {
|
|
11
|
+
return 'Gets information about the SharePoint Premium content centers';
|
|
12
|
+
}
|
|
13
|
+
defaultProperties() {
|
|
14
|
+
return ['Title', 'Url'];
|
|
15
|
+
}
|
|
16
|
+
async commandAction(logger) {
|
|
17
|
+
try {
|
|
18
|
+
if (this.verbose) {
|
|
19
|
+
await logger.logToStderr(`Retrieving list of content centers...`);
|
|
20
|
+
}
|
|
21
|
+
const spoAdminUrl = await spo.getSpoAdminUrl(logger, this.debug);
|
|
22
|
+
const allContentCenters = await this.getContentCenters(spoAdminUrl, logger);
|
|
23
|
+
await logger.log(allContentCenters);
|
|
24
|
+
}
|
|
25
|
+
catch (err) {
|
|
26
|
+
this.handleRejectedODataJsonPromise(err);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async getContentCenters(spoAdminUrl, logger) {
|
|
30
|
+
const allSites = [];
|
|
31
|
+
let currentStartIndex = '0';
|
|
32
|
+
const res = await spo.ensureFormDigest(spoAdminUrl, logger, undefined, this.debug);
|
|
33
|
+
do {
|
|
34
|
+
const requestBody = `<Request AddExpandoFieldTypeSuffix="true" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="${config.applicationName}" xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009"><Actions><ObjectPath Id="2" ObjectPathId="1" /><ObjectPath Id="4" ObjectPathId="3" /><Query Id="5" ObjectPathId="3"><Query SelectAllProperties="true"><Properties /></Query><ChildItemQuery SelectAllProperties="true"><Properties /></ChildItemQuery></Query></Actions><ObjectPaths><Constructor Id="1" TypeId="{268004ae-ef6b-4e9b-8425-127220d84719}" /><Method Id="3" ParentId="1" Name="GetSitePropertiesFromSharePointByFilters"><Parameters><Parameter TypeId="{b92aeee2-c92c-4b67-abcc-024e471bc140}"><Property Name="Filter" Type="String"></Property><Property Name="IncludeDetail" Type="Boolean">false</Property><Property Name="IncludePersonalSite" Type="Enum">0</Property><Property Name="StartIndex" Type="String">${currentStartIndex}</Property><Property Name="Template" Type="String">CONTENTCTR#0</Property></Parameter></Parameters></Method></ObjectPaths></Request>`;
|
|
35
|
+
const requestOptions = {
|
|
36
|
+
url: `${spoAdminUrl}/_vti_bin/client.svc/ProcessQuery`,
|
|
37
|
+
headers: {
|
|
38
|
+
'X-RequestDigest': res.FormDigestValue
|
|
39
|
+
},
|
|
40
|
+
data: requestBody
|
|
41
|
+
};
|
|
42
|
+
const response = await request.post(requestOptions);
|
|
43
|
+
const json = JSON.parse(response);
|
|
44
|
+
const responseContent = json[0];
|
|
45
|
+
if (responseContent.ErrorInfo) {
|
|
46
|
+
throw responseContent.ErrorInfo.ErrorMessage;
|
|
47
|
+
}
|
|
48
|
+
const sites = json[json.length - 1];
|
|
49
|
+
allSites.push(...sites._Child_Items_);
|
|
50
|
+
currentStartIndex = sites.NextStartIndexFromSharePoint;
|
|
51
|
+
} while (currentStartIndex);
|
|
52
|
+
return allSites;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export default new SppContentCenterListCommand();
|
|
56
|
+
//# sourceMappingURL=contentcenter-list.js.map
|
package/dist/utils/spo.js
CHANGED
|
@@ -1539,6 +1539,51 @@ export const spo = {
|
|
|
1539
1539
|
};
|
|
1540
1540
|
const file = await request.get(requestOptions);
|
|
1541
1541
|
return file;
|
|
1542
|
+
},
|
|
1543
|
+
/**
|
|
1544
|
+
* Gets the site collection URL for a given web URL using SP Admin site.
|
|
1545
|
+
* @param adminUrl The SharePoint admin URL
|
|
1546
|
+
* @param siteId The site ID
|
|
1547
|
+
* @param logger The logger object
|
|
1548
|
+
* @param verbose If in verbose mode
|
|
1549
|
+
* @returns Owner login name
|
|
1550
|
+
*/
|
|
1551
|
+
async getPrimaryAdminLoginNameAsAdmin(adminUrl, siteId, logger, verbose) {
|
|
1552
|
+
if (verbose) {
|
|
1553
|
+
await logger.logToStderr('Getting the primary admin login name...');
|
|
1554
|
+
}
|
|
1555
|
+
const requestOptions = {
|
|
1556
|
+
url: `${adminUrl}/_api/SPO.Tenant/sites('${siteId}')?$select=OwnerLoginName`,
|
|
1557
|
+
headers: {
|
|
1558
|
+
accept: 'application/json;odata=nometadata',
|
|
1559
|
+
'content-type': 'application/json;charset=utf-8'
|
|
1560
|
+
}
|
|
1561
|
+
};
|
|
1562
|
+
const response = await request.get(requestOptions);
|
|
1563
|
+
const responseContent = JSON.parse(response);
|
|
1564
|
+
return responseContent.OwnerLoginName;
|
|
1565
|
+
},
|
|
1566
|
+
/**
|
|
1567
|
+
* Gets the primary owner login from a site.
|
|
1568
|
+
* @param siteUrl The site URL
|
|
1569
|
+
* @param logger The logger object
|
|
1570
|
+
* @param verbose If in verbose mode
|
|
1571
|
+
* @returns Owner login name
|
|
1572
|
+
*/
|
|
1573
|
+
async getPrimaryOwnerLoginFromSite(siteUrl, logger, verbose) {
|
|
1574
|
+
if (verbose) {
|
|
1575
|
+
await logger.logToStderr('Getting the primary admin login name...');
|
|
1576
|
+
}
|
|
1577
|
+
const requestOptions = {
|
|
1578
|
+
url: `${siteUrl}/_api/site/owner`,
|
|
1579
|
+
method: 'GET',
|
|
1580
|
+
headers: {
|
|
1581
|
+
'accept': 'application/json;odata=nometadata'
|
|
1582
|
+
},
|
|
1583
|
+
responseType: 'json'
|
|
1584
|
+
};
|
|
1585
|
+
const responseContent = await request.get(requestOptions);
|
|
1586
|
+
return responseContent?.LoginName;
|
|
1542
1587
|
}
|
|
1543
1588
|
};
|
|
1544
1589
|
//# sourceMappingURL=spo.js.map
|