@pnp/cli-microsoft365 8.1.0-beta.3bc5759 → 8.1.0-beta.a4eba60
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/Auth.js +1 -1
- package/dist/m365/connection/commands/connection-remove.js +6 -2
- package/dist/m365/connection/commands/connection-set.js +4 -1
- package/dist/m365/connection/commands/connection-use.js +25 -4
- package/dist/m365/entra/commands/m365group/m365group-user-add.js +109 -32
- package/dist/m365/entra/commands/m365group/m365group-user-set.js +159 -84
- package/dist/m365/entra/commands/multitenant/multitenant-add.js +65 -0
- package/dist/m365/entra/commands/multitenant/multitenant-remove.js +118 -0
- package/dist/m365/entra/commands/multitenant/multitenant-set.js +72 -0
- package/dist/m365/entra/commands.js +3 -0
- package/dist/m365/spo/commands/file/file-roleassignment-add.js +1 -1
- package/dist/m365/spo/commands/file/file-roleinheritance-break.js +1 -1
- package/dist/m365/spo/commands/file/file-roleinheritance-reset.js +1 -1
- package/dist/m365/spo/commands/folder/folder-retentionlabel-ensure.js +1 -1
- package/dist/m365/spo/commands/folder/folder-sharinglink-get.js +86 -0
- package/dist/m365/spo/commands/folder/folder-sharinglink-list.js +110 -0
- package/dist/m365/spo/commands/list/ListInstance.js +6 -1
- package/dist/m365/spo/commands/list/list-get.js +9 -3
- package/dist/m365/spo/commands/list/list-roleassignment-add.js +46 -21
- package/dist/m365/spo/commands/list/list-roleassignment-remove.js +48 -46
- package/dist/m365/spo/commands.js +2 -0
- package/dist/utils/drive.js +61 -0
- package/dist/utils/spo.js +69 -6
- package/docs/docs/cmd/connection/connection-use.mdx +8 -2
- package/docs/docs/cmd/entra/m365group/m365group-user-add.mdx +28 -10
- package/docs/docs/cmd/entra/m365group/m365group-user-set.mdx +35 -11
- package/docs/docs/cmd/entra/multitenant/multitenant-add.mdx +107 -0
- package/docs/docs/cmd/entra/multitenant/multitenant-remove.mdx +58 -0
- package/docs/docs/cmd/entra/multitenant/multitenant-set.mdx +53 -0
- package/docs/docs/cmd/planner/plan/plan-remove.mdx +1 -1
- package/docs/docs/cmd/spe/containertype/containertype-list.mdx +24 -53
- package/docs/docs/cmd/spo/applicationcustomizer/applicationcustomizer-get.mdx +4 -4
- package/docs/docs/cmd/spo/applicationcustomizer/applicationcustomizer-list.mdx +4 -4
- package/docs/docs/cmd/spo/file/file-retentionlabel-ensure.mdx +1 -1
- package/docs/docs/cmd/spo/file/file-roleassignment-add.mdx +2 -2
- package/docs/docs/cmd/spo/file/file-roleassignment-remove.mdx +1 -1
- package/docs/docs/cmd/spo/file/file-roleinheritance-break.mdx +1 -1
- package/docs/docs/cmd/spo/file/file-roleinheritance-reset.mdx +1 -1
- package/docs/docs/cmd/spo/folder/folder-retentionlabel-ensure.mdx +2 -2
- package/docs/docs/cmd/spo/folder/folder-sharinglink-get.mdx +110 -0
- package/docs/docs/cmd/spo/folder/folder-sharinglink-list.mdx +114 -0
- package/docs/docs/cmd/spo/list/list-get.mdx +6 -0
- package/docs/docs/cmd/spo/list/list-roleassignment-add.mdx +15 -3
- package/docs/docs/cmd/spo/list/list-roleassignment-remove.mdx +15 -3
- package/docs/docs/cmd/spo/listitem/listitem-retentionlabel-ensure.mdx +4 -4
- package/docs/docs/cmd/spo/listitem/listitem-retentionlabel-remove.mdx +1 -1
- package/docs/docs/cmd/spo/listitem/listitem-roleassignment-add.mdx +9 -9
- package/docs/docs/cmd/spo/listitem/listitem-roleassignment-remove.mdx +7 -7
- package/docs/docs/cmd/spo/site/site-recyclebinitem-list.mdx +1 -1
- package/docs/docs/cmd/spo/web/web-roleassignment-add.mdx +1 -1
- package/docs/docs/cmd/spo/web/web-roleassignment-remove.mdx +1 -1
- package/package.json +1 -1
package/dist/Auth.js
CHANGED
|
@@ -691,7 +691,7 @@ export class Auth {
|
|
|
691
691
|
const allConnections = await this.getAllConnections();
|
|
692
692
|
const connection = allConnections.find(i => i.name === name);
|
|
693
693
|
if (!connection) {
|
|
694
|
-
throw new CommandError(`The connection '${name}' cannot be found
|
|
694
|
+
throw new CommandError(`The connection '${name}' cannot be found.`);
|
|
695
695
|
}
|
|
696
696
|
return connection;
|
|
697
697
|
}
|
|
@@ -3,7 +3,7 @@ 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 _ConnectionRemoveCommand_instances, _ConnectionRemoveCommand_initTelemetry, _ConnectionRemoveCommand_initOptions;
|
|
6
|
+
var _ConnectionRemoveCommand_instances, _ConnectionRemoveCommand_initTelemetry, _ConnectionRemoveCommand_initOptions, _ConnectionRemoveCommand_initTypes;
|
|
7
7
|
import auth from '../../../Auth.js';
|
|
8
8
|
import commands from '../commands.js';
|
|
9
9
|
import Command, { CommandError } from '../../../Command.js';
|
|
@@ -20,6 +20,7 @@ class ConnectionRemoveCommand extends Command {
|
|
|
20
20
|
_ConnectionRemoveCommand_instances.add(this);
|
|
21
21
|
__classPrivateFieldGet(this, _ConnectionRemoveCommand_instances, "m", _ConnectionRemoveCommand_initTelemetry).call(this);
|
|
22
22
|
__classPrivateFieldGet(this, _ConnectionRemoveCommand_instances, "m", _ConnectionRemoveCommand_initOptions).call(this);
|
|
23
|
+
__classPrivateFieldGet(this, _ConnectionRemoveCommand_instances, "m", _ConnectionRemoveCommand_initTypes).call(this);
|
|
23
24
|
}
|
|
24
25
|
async commandAction(logger, args) {
|
|
25
26
|
const deleteConnection = async () => {
|
|
@@ -53,7 +54,7 @@ class ConnectionRemoveCommand extends Command {
|
|
|
53
54
|
_ConnectionRemoveCommand_instances = new WeakSet(), _ConnectionRemoveCommand_initTelemetry = function _ConnectionRemoveCommand_initTelemetry() {
|
|
54
55
|
this.telemetry.push((args) => {
|
|
55
56
|
Object.assign(this.telemetryProperties, {
|
|
56
|
-
force:
|
|
57
|
+
force: !!args.options.force
|
|
57
58
|
});
|
|
58
59
|
});
|
|
59
60
|
}, _ConnectionRemoveCommand_initOptions = function _ConnectionRemoveCommand_initOptions() {
|
|
@@ -62,6 +63,9 @@ _ConnectionRemoveCommand_instances = new WeakSet(), _ConnectionRemoveCommand_ini
|
|
|
62
63
|
}, {
|
|
63
64
|
option: '-f, --force'
|
|
64
65
|
});
|
|
66
|
+
}, _ConnectionRemoveCommand_initTypes = function _ConnectionRemoveCommand_initTypes() {
|
|
67
|
+
this.types.string.push('name');
|
|
68
|
+
this.types.boolean.push('force');
|
|
65
69
|
};
|
|
66
70
|
export default new ConnectionRemoveCommand();
|
|
67
71
|
//# sourceMappingURL=connection-remove.js.map
|
|
@@ -3,7 +3,7 @@ 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 _ConnectionSetCommand_instances, _ConnectionSetCommand_initOptions, _ConnectionSetCommand_initValidators;
|
|
6
|
+
var _ConnectionSetCommand_instances, _ConnectionSetCommand_initOptions, _ConnectionSetCommand_initValidators, _ConnectionSetCommand_initTypes;
|
|
7
7
|
import auth from '../../../Auth.js';
|
|
8
8
|
import commands from '../commands.js';
|
|
9
9
|
import Command, { CommandError } from '../../../Command.js';
|
|
@@ -19,6 +19,7 @@ class ConnectionSetCommand extends Command {
|
|
|
19
19
|
_ConnectionSetCommand_instances.add(this);
|
|
20
20
|
__classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initOptions).call(this);
|
|
21
21
|
__classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initValidators).call(this);
|
|
22
|
+
__classPrivateFieldGet(this, _ConnectionSetCommand_instances, "m", _ConnectionSetCommand_initTypes).call(this);
|
|
22
23
|
}
|
|
23
24
|
async commandAction(logger, args) {
|
|
24
25
|
const connection = await auth.getConnection(args.options.name);
|
|
@@ -51,6 +52,8 @@ _ConnectionSetCommand_instances = new WeakSet(), _ConnectionSetCommand_initOptio
|
|
|
51
52
|
}
|
|
52
53
|
return true;
|
|
53
54
|
});
|
|
55
|
+
}, _ConnectionSetCommand_initTypes = function _ConnectionSetCommand_initTypes() {
|
|
56
|
+
this.types.string.push('name', 'newName');
|
|
54
57
|
};
|
|
55
58
|
export default new ConnectionSetCommand();
|
|
56
59
|
//# sourceMappingURL=connection-set.js.map
|
|
@@ -3,10 +3,12 @@ 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 _ConnectionUseCommand_instances, _ConnectionUseCommand_initOptions;
|
|
6
|
+
var _ConnectionUseCommand_instances, _ConnectionUseCommand_initTelemetry, _ConnectionUseCommand_initOptions, _ConnectionUseCommand_initTypes;
|
|
7
7
|
import auth from '../../../Auth.js';
|
|
8
8
|
import commands from '../commands.js';
|
|
9
9
|
import Command, { CommandError } from '../../../Command.js';
|
|
10
|
+
import { formatting } from '../../../utils/formatting.js';
|
|
11
|
+
import { cli } from '../../../cli/cli.js';
|
|
10
12
|
class ConnectionUseCommand extends Command {
|
|
11
13
|
get name() {
|
|
12
14
|
return commands.USE;
|
|
@@ -18,9 +20,20 @@ class ConnectionUseCommand extends Command {
|
|
|
18
20
|
super();
|
|
19
21
|
_ConnectionUseCommand_instances.add(this);
|
|
20
22
|
__classPrivateFieldGet(this, _ConnectionUseCommand_instances, "m", _ConnectionUseCommand_initOptions).call(this);
|
|
23
|
+
__classPrivateFieldGet(this, _ConnectionUseCommand_instances, "m", _ConnectionUseCommand_initTelemetry).call(this);
|
|
24
|
+
__classPrivateFieldGet(this, _ConnectionUseCommand_instances, "m", _ConnectionUseCommand_initTypes).call(this);
|
|
21
25
|
}
|
|
22
26
|
async commandAction(logger, args) {
|
|
23
|
-
|
|
27
|
+
let connection;
|
|
28
|
+
if (args.options.name) {
|
|
29
|
+
connection = await auth.getConnection(args.options.name);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
const connections = await auth.getAllConnections();
|
|
33
|
+
connections.sort((a, b) => a.name.localeCompare(b.name));
|
|
34
|
+
const keyValuePair = formatting.convertArrayToHashTable('name', connections);
|
|
35
|
+
connection = await cli.handleMultipleResultsFound('Please select the connection you want to activate.', keyValuePair);
|
|
36
|
+
}
|
|
24
37
|
if (this.verbose) {
|
|
25
38
|
await logger.logToStderr(`Switching to connection '${connection.identityName}', appId: ${connection.appId}, tenantId: ${connection.identityTenantId}...`);
|
|
26
39
|
}
|
|
@@ -42,10 +55,18 @@ class ConnectionUseCommand extends Command {
|
|
|
42
55
|
await this.commandAction(logger, args);
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
|
-
_ConnectionUseCommand_instances = new WeakSet(),
|
|
58
|
+
_ConnectionUseCommand_instances = new WeakSet(), _ConnectionUseCommand_initTelemetry = function _ConnectionUseCommand_initTelemetry() {
|
|
59
|
+
this.telemetry.push((args) => {
|
|
60
|
+
Object.assign(this.telemetryProperties, {
|
|
61
|
+
name: typeof args.options.name !== 'undefined'
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
}, _ConnectionUseCommand_initOptions = function _ConnectionUseCommand_initOptions() {
|
|
46
65
|
this.options.unshift({
|
|
47
|
-
option: '-n, --name
|
|
66
|
+
option: '-n, --name [name]'
|
|
48
67
|
});
|
|
68
|
+
}, _ConnectionUseCommand_initTypes = function _ConnectionUseCommand_initTypes() {
|
|
69
|
+
this.types.string.push('name');
|
|
49
70
|
};
|
|
50
71
|
export default new ConnectionUseCommand();
|
|
51
72
|
//# sourceMappingURL=connection-use.js.map
|
|
@@ -3,14 +3,15 @@ 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 _EntraM365GroupUserAddCommand_instances, _EntraM365GroupUserAddCommand_initTelemetry, _EntraM365GroupUserAddCommand_initOptions, _EntraM365GroupUserAddCommand_initValidators, _EntraM365GroupUserAddCommand_initOptionSets;
|
|
6
|
+
var _EntraM365GroupUserAddCommand_instances, _EntraM365GroupUserAddCommand_initTelemetry, _EntraM365GroupUserAddCommand_initOptions, _EntraM365GroupUserAddCommand_initValidators, _EntraM365GroupUserAddCommand_initOptionSets, _EntraM365GroupUserAddCommand_initTypes;
|
|
7
7
|
import request from '../../../../request.js';
|
|
8
8
|
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
9
|
-
import { formatting } from '../../../../utils/formatting.js';
|
|
10
9
|
import { validation } from '../../../../utils/validation.js';
|
|
10
|
+
import { formatting } from '../../../../utils/formatting.js';
|
|
11
11
|
import GraphCommand from '../../../base/GraphCommand.js';
|
|
12
12
|
import teamsCommands from '../../../teams/commands.js';
|
|
13
13
|
import aadCommands from '../../aadCommands.js';
|
|
14
|
+
import { entraUser } from '../../../../utils/entraUser.js';
|
|
14
15
|
import commands from '../../commands.js';
|
|
15
16
|
class EntraM365GroupUserAddCommand extends GraphCommand {
|
|
16
17
|
get name() {
|
|
@@ -25,79 +26,155 @@ class EntraM365GroupUserAddCommand extends GraphCommand {
|
|
|
25
26
|
constructor() {
|
|
26
27
|
super();
|
|
27
28
|
_EntraM365GroupUserAddCommand_instances.add(this);
|
|
29
|
+
this.allowedRoles = ['owner', 'member'];
|
|
28
30
|
__classPrivateFieldGet(this, _EntraM365GroupUserAddCommand_instances, "m", _EntraM365GroupUserAddCommand_initTelemetry).call(this);
|
|
29
31
|
__classPrivateFieldGet(this, _EntraM365GroupUserAddCommand_instances, "m", _EntraM365GroupUserAddCommand_initOptions).call(this);
|
|
30
32
|
__classPrivateFieldGet(this, _EntraM365GroupUserAddCommand_instances, "m", _EntraM365GroupUserAddCommand_initValidators).call(this);
|
|
31
33
|
__classPrivateFieldGet(this, _EntraM365GroupUserAddCommand_instances, "m", _EntraM365GroupUserAddCommand_initOptionSets).call(this);
|
|
34
|
+
__classPrivateFieldGet(this, _EntraM365GroupUserAddCommand_instances, "m", _EntraM365GroupUserAddCommand_initTypes).call(this);
|
|
32
35
|
}
|
|
33
36
|
async commandAction(logger, args) {
|
|
34
37
|
await this.showDeprecationWarning(logger, aadCommands.M365GROUP_USER_ADD, commands.M365GROUP_USER_ADD);
|
|
38
|
+
if (args.options.userName) {
|
|
39
|
+
await this.warn(logger, `Option 'userName' is deprecated. Please use 'ids' or 'userNames' instead.`);
|
|
40
|
+
}
|
|
35
41
|
try {
|
|
36
|
-
const
|
|
42
|
+
const userNames = args.options.userNames || args.options.userName;
|
|
43
|
+
const providedGroupId = await this.getGroupId(logger, args);
|
|
37
44
|
const isUnifiedGroup = await entraGroup.isUnifiedGroup(providedGroupId);
|
|
38
45
|
if (!isUnifiedGroup) {
|
|
39
46
|
throw Error(`Specified group with id '${providedGroupId}' is not a Microsoft 365 group.`);
|
|
40
47
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
const userIds = await this.getUserIds(logger, args.options.ids, userNames);
|
|
49
|
+
if (this.verbose) {
|
|
50
|
+
await logger.logToStderr(`Adding user(s) ${args.options.ids || userNames} to group ${args.options.groupId || args.options.groupName || args.options.teamId || args.options.teamName}...`);
|
|
51
|
+
}
|
|
52
|
+
await this.addUsers(providedGroupId, userIds, args.options.role);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
this.handleRejectedODataJsonPromise(err);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
async getGroupId(logger, args) {
|
|
59
|
+
if (args.options.groupId) {
|
|
60
|
+
return args.options.groupId;
|
|
61
|
+
}
|
|
62
|
+
if (args.options.teamId) {
|
|
63
|
+
return args.options.teamId;
|
|
64
|
+
}
|
|
65
|
+
const name = args.options.groupName || args.options.teamName;
|
|
66
|
+
if (this.verbose) {
|
|
67
|
+
await logger.logToStderr('Retrieving Group ID by display name...');
|
|
68
|
+
}
|
|
69
|
+
return entraGroup.getGroupIdByDisplayName(name);
|
|
70
|
+
}
|
|
71
|
+
async getUserIds(logger, userIds, userNames) {
|
|
72
|
+
if (userIds) {
|
|
73
|
+
return formatting.splitAndTrim(userIds);
|
|
74
|
+
}
|
|
75
|
+
if (this.verbose) {
|
|
76
|
+
await logger.logToStderr('Retrieving user ID(s) by username(s)...');
|
|
77
|
+
}
|
|
78
|
+
return entraUser.getUserIdsByUpns(formatting.splitAndTrim(userNames));
|
|
79
|
+
}
|
|
80
|
+
async addUsers(groupId, userIds, role) {
|
|
81
|
+
for (let i = 0; i < userIds.length; i += 400) {
|
|
82
|
+
const userIdsBatch = userIds.slice(i, i + 400);
|
|
83
|
+
const requestOptions = {
|
|
84
|
+
url: `${this.resource}/v1.0/$batch`,
|
|
52
85
|
headers: {
|
|
53
|
-
'
|
|
86
|
+
'content-type': 'application/json;odata.metadata=none'
|
|
54
87
|
},
|
|
55
88
|
responseType: 'json',
|
|
56
|
-
data: {
|
|
89
|
+
data: {
|
|
90
|
+
requests: []
|
|
91
|
+
}
|
|
57
92
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
93
|
+
for (let j = 0; j < userIdsBatch.length; j += 20) {
|
|
94
|
+
const userIdsChunk = userIdsBatch.slice(j, j + 20);
|
|
95
|
+
requestOptions.data.requests.push({
|
|
96
|
+
id: j + 1,
|
|
97
|
+
method: 'PATCH',
|
|
98
|
+
url: `/groups/${groupId}`,
|
|
99
|
+
headers: {
|
|
100
|
+
'content-type': 'application/json;odata.metadata=none'
|
|
101
|
+
},
|
|
102
|
+
body: {
|
|
103
|
+
[`${((typeof role !== 'undefined') ? role : '').toLowerCase() === 'owner' ? 'owners' : 'members'}@odata.bind`]: userIdsChunk.map(u => `${this.resource}/v1.0/directoryObjects/${u}`)
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
const res = await request.post(requestOptions);
|
|
108
|
+
for (const response of res.responses) {
|
|
109
|
+
if (response.status !== 204) {
|
|
110
|
+
throw response.body;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
62
113
|
}
|
|
63
114
|
}
|
|
64
115
|
}
|
|
65
116
|
_EntraM365GroupUserAddCommand_instances = new WeakSet(), _EntraM365GroupUserAddCommand_initTelemetry = function _EntraM365GroupUserAddCommand_initTelemetry() {
|
|
66
117
|
this.telemetry.push((args) => {
|
|
67
118
|
Object.assign(this.telemetryProperties, {
|
|
68
|
-
role: args.options.role,
|
|
119
|
+
role: args.options.role !== 'undefined',
|
|
69
120
|
teamId: typeof args.options.teamId !== 'undefined',
|
|
70
|
-
groupId: typeof args.options.groupId !== 'undefined'
|
|
121
|
+
groupId: typeof args.options.groupId !== 'undefined',
|
|
122
|
+
teamName: typeof args.options.teamName !== 'undefined',
|
|
123
|
+
groupName: typeof args.options.groupName !== 'undefined',
|
|
124
|
+
ids: typeof args.options.ids !== 'undefined',
|
|
125
|
+
userNames: typeof args.options.userNames !== 'undefined',
|
|
126
|
+
userName: typeof args.options.userName !== 'undefined'
|
|
71
127
|
});
|
|
72
128
|
});
|
|
73
129
|
}, _EntraM365GroupUserAddCommand_initOptions = function _EntraM365GroupUserAddCommand_initOptions() {
|
|
74
130
|
this.options.unshift({
|
|
75
|
-
option: '-n, --userName
|
|
131
|
+
option: '-n, --userName [userName]'
|
|
76
132
|
}, {
|
|
77
|
-
option:
|
|
133
|
+
option: '--ids [ids]'
|
|
78
134
|
}, {
|
|
79
|
-
option:
|
|
135
|
+
option: '--userNames [userNames]'
|
|
136
|
+
}, {
|
|
137
|
+
option: '-i, --groupId [groupId]'
|
|
138
|
+
}, {
|
|
139
|
+
option: '--groupName [groupName]'
|
|
140
|
+
}, {
|
|
141
|
+
option: '--teamId [teamId]'
|
|
142
|
+
}, {
|
|
143
|
+
option: '--teamName [teamName]'
|
|
80
144
|
}, {
|
|
81
145
|
option: '-r, --role [role]',
|
|
82
|
-
autocomplete:
|
|
146
|
+
autocomplete: this.allowedRoles
|
|
83
147
|
});
|
|
84
148
|
}, _EntraM365GroupUserAddCommand_initValidators = function _EntraM365GroupUserAddCommand_initValidators() {
|
|
85
149
|
this.validators.push(async (args) => {
|
|
86
150
|
if (args.options.teamId && !validation.isValidGuid(args.options.teamId)) {
|
|
87
|
-
return
|
|
151
|
+
return `'${args.options.teamId}' is not a valid GUID for option 'teamId'.`;
|
|
88
152
|
}
|
|
89
153
|
if (args.options.groupId && !validation.isValidGuid(args.options.groupId)) {
|
|
90
|
-
return
|
|
154
|
+
return `'${args.options.groupId}' is not a valid GUID for option 'groupId'.`;
|
|
91
155
|
}
|
|
92
|
-
if (args.options.
|
|
93
|
-
|
|
94
|
-
|
|
156
|
+
if (args.options.ids) {
|
|
157
|
+
const isValidGUIDArrayResult = validation.isValidGuidArray(args.options.ids);
|
|
158
|
+
if (isValidGUIDArrayResult !== true) {
|
|
159
|
+
return `The following GUIDs are invalid for the option 'ids': ${isValidGUIDArrayResult}.`;
|
|
95
160
|
}
|
|
96
161
|
}
|
|
162
|
+
if (args.options.userNames) {
|
|
163
|
+
const isValidUPNArrayResult = validation.isValidUserPrincipalNameArray(args.options.userNames);
|
|
164
|
+
if (isValidUPNArrayResult !== true) {
|
|
165
|
+
return `The following user principal names are invalid for the option 'userNames': ${isValidUPNArrayResult}.`;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (args.options.role && !this.allowedRoles.some(role => role.toLowerCase() === args.options.role.toLowerCase())) {
|
|
169
|
+
return `'${args.options.role}' is not a valid role. Allowed values are: ${this.allowedRoles.join(',')}`;
|
|
170
|
+
}
|
|
97
171
|
return true;
|
|
98
172
|
});
|
|
99
173
|
}, _EntraM365GroupUserAddCommand_initOptionSets = function _EntraM365GroupUserAddCommand_initOptionSets() {
|
|
100
|
-
this.optionSets.push({ options: ['groupId', 'teamId'] });
|
|
174
|
+
this.optionSets.push({ options: ['groupId', 'groupName', 'teamId', 'teamName'] });
|
|
175
|
+
this.optionSets.push({ options: ['userName', 'ids', 'userNames'] });
|
|
176
|
+
}, _EntraM365GroupUserAddCommand_initTypes = function _EntraM365GroupUserAddCommand_initTypes() {
|
|
177
|
+
this.types.string.push('userName', 'ids', 'userNames', 'groupId', 'groupName', 'teamId', 'teamName', 'role');
|
|
101
178
|
};
|
|
102
179
|
export default new EntraM365GroupUserAddCommand();
|
|
103
180
|
//# sourceMappingURL=m365group-user-add.js.map
|
|
@@ -3,14 +3,15 @@ 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 _EntraM365GroupUserSetCommand_instances, _EntraM365GroupUserSetCommand_initTelemetry, _EntraM365GroupUserSetCommand_initOptions, _EntraM365GroupUserSetCommand_initValidators, _EntraM365GroupUserSetCommand_initOptionSets;
|
|
6
|
+
var _EntraM365GroupUserSetCommand_instances, _EntraM365GroupUserSetCommand_initTelemetry, _EntraM365GroupUserSetCommand_initOptions, _EntraM365GroupUserSetCommand_initValidators, _EntraM365GroupUserSetCommand_initOptionSets, _EntraM365GroupUserSetCommand_initTypes;
|
|
7
7
|
import request from '../../../../request.js';
|
|
8
|
-
import { odata } from '../../../../utils/odata.js';
|
|
9
8
|
import { validation } from '../../../../utils/validation.js';
|
|
9
|
+
import { formatting } from '../../../../utils/formatting.js';
|
|
10
10
|
import GraphCommand from '../../../base/GraphCommand.js';
|
|
11
11
|
import teamsCommands from '../../../teams/commands.js';
|
|
12
12
|
import commands from '../../commands.js';
|
|
13
13
|
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
14
|
+
import { entraUser } from '../../../../utils/entraUser.js';
|
|
14
15
|
import aadCommands from '../../aadCommands.js';
|
|
15
16
|
class EntraM365GroupUserSetCommand extends GraphCommand {
|
|
16
17
|
get name() {
|
|
@@ -25,135 +26,209 @@ class EntraM365GroupUserSetCommand extends GraphCommand {
|
|
|
25
26
|
constructor() {
|
|
26
27
|
super();
|
|
27
28
|
_EntraM365GroupUserSetCommand_instances.add(this);
|
|
29
|
+
this.allowedRoles = ['owner', 'member'];
|
|
28
30
|
__classPrivateFieldGet(this, _EntraM365GroupUserSetCommand_instances, "m", _EntraM365GroupUserSetCommand_initTelemetry).call(this);
|
|
29
31
|
__classPrivateFieldGet(this, _EntraM365GroupUserSetCommand_instances, "m", _EntraM365GroupUserSetCommand_initOptions).call(this);
|
|
30
32
|
__classPrivateFieldGet(this, _EntraM365GroupUserSetCommand_instances, "m", _EntraM365GroupUserSetCommand_initValidators).call(this);
|
|
31
33
|
__classPrivateFieldGet(this, _EntraM365GroupUserSetCommand_instances, "m", _EntraM365GroupUserSetCommand_initOptionSets).call(this);
|
|
34
|
+
__classPrivateFieldGet(this, _EntraM365GroupUserSetCommand_instances, "m", _EntraM365GroupUserSetCommand_initTypes).call(this);
|
|
32
35
|
}
|
|
33
36
|
async commandAction(logger, args) {
|
|
34
37
|
await this.showDeprecationWarning(logger, aadCommands.M365GROUP_USER_SET, commands.M365GROUP_USER_SET);
|
|
38
|
+
if (args.options.userName) {
|
|
39
|
+
await this.warn(logger, `Option 'userName' is deprecated. Please use 'ids' or 'userNames' instead.`);
|
|
40
|
+
}
|
|
35
41
|
try {
|
|
36
|
-
const
|
|
42
|
+
const userNames = args.options.userNames || args.options.userName;
|
|
43
|
+
const groupId = await this.getGroupId(logger, args);
|
|
37
44
|
const isUnifiedGroup = await entraGroup.isUnifiedGroup(groupId);
|
|
38
45
|
if (!isUnifiedGroup) {
|
|
39
46
|
throw Error(`Specified group with id '${groupId}' is not a Microsoft 365 group.`);
|
|
40
47
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
users
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
await logger.logToStderr((typeof args.options.groupId !== 'undefined') ? 'Group owners and members:' : 'Team owners and members:');
|
|
48
|
-
await logger.logToStderr(users);
|
|
49
|
-
await logger.logToStderr('');
|
|
50
|
-
}
|
|
51
|
-
if (users.filter(i => args.options.userName.toUpperCase() === i.userPrincipalName.toUpperCase()).length <= 0) {
|
|
52
|
-
const userNotInGroup = (typeof args.options.groupId !== 'undefined') ?
|
|
53
|
-
'The specified user does not belong to the given Microsoft 365 Group. Please use the \'m365group user add\' command to add new users.' :
|
|
54
|
-
'The specified user does not belong to the given Microsoft Teams team. Please use the \'graph teams user add\' command to add new users.';
|
|
55
|
-
throw new Error(userNotInGroup);
|
|
56
|
-
}
|
|
57
|
-
if (args.options.role === "Owner") {
|
|
58
|
-
const foundMember = users.find(e => args.options.userName.toUpperCase() === e.userPrincipalName.toUpperCase() && e.userType === 'Member');
|
|
59
|
-
if (foundMember !== undefined) {
|
|
60
|
-
const endpoint = `${this.resource}/v1.0/groups/${groupId}/owners/$ref`;
|
|
61
|
-
const requestOptions = {
|
|
62
|
-
url: endpoint,
|
|
63
|
-
headers: {
|
|
64
|
-
'accept': 'application/json;odata.metadata=none'
|
|
65
|
-
},
|
|
66
|
-
responseType: 'json',
|
|
67
|
-
data: { "@odata.id": "https://graph.microsoft.com/v1.0/directoryObjects/" + foundMember.id }
|
|
68
|
-
};
|
|
69
|
-
await request.post(requestOptions);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
const userAlreadyOwner = (typeof args.options.groupId !== 'undefined') ?
|
|
73
|
-
'The specified user is already an owner in the specified Microsoft 365 group, and thus cannot be promoted.' :
|
|
74
|
-
'The specified user is already an owner in the specified Microsoft Teams team, and thus cannot be promoted.';
|
|
75
|
-
throw new Error(userAlreadyOwner);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
const foundOwner = users.find(e => args.options.userName.toUpperCase() === e.userPrincipalName.toUpperCase() && e.userType === 'Owner');
|
|
80
|
-
if (foundOwner !== undefined) {
|
|
81
|
-
const endpoint = `${this.resource}/v1.0/groups/${groupId}/owners/${foundOwner.id}/$ref`;
|
|
82
|
-
const requestOptions = {
|
|
83
|
-
url: endpoint,
|
|
84
|
-
headers: {
|
|
85
|
-
'accept': 'application/json;odata.metadata=none'
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
await request.delete(requestOptions);
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
const userAlreadyMember = (typeof args.options.groupId !== 'undefined') ?
|
|
92
|
-
'The specified user is already a member in the specified Microsoft 365 group, and thus cannot be demoted.' :
|
|
93
|
-
'The specified user is already a member in the specified Microsoft Teams team, and thus cannot be demoted.';
|
|
94
|
-
throw new Error(userAlreadyMember);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
48
|
+
const userIds = await this.getUserIds(logger, args.options.ids, userNames);
|
|
49
|
+
// we can't simply switch the role
|
|
50
|
+
// first add users to the new role
|
|
51
|
+
await this.addUsers(groupId, userIds, args.options.role);
|
|
52
|
+
// remove users from the old role
|
|
53
|
+
await this.removeUsersFromRole(logger, groupId, userIds, args.options.role);
|
|
97
54
|
}
|
|
98
55
|
catch (err) {
|
|
99
56
|
this.handleRejectedODataJsonPromise(err);
|
|
100
57
|
}
|
|
101
58
|
}
|
|
102
|
-
async
|
|
59
|
+
async getGroupId(logger, args) {
|
|
60
|
+
if (args.options.groupId) {
|
|
61
|
+
return args.options.groupId;
|
|
62
|
+
}
|
|
63
|
+
if (args.options.teamId) {
|
|
64
|
+
return args.options.teamId;
|
|
65
|
+
}
|
|
66
|
+
const name = args.options.groupName || args.options.teamName;
|
|
103
67
|
if (this.verbose) {
|
|
104
|
-
await logger.logToStderr(
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
68
|
+
await logger.logToStderr('Retrieving Group ID by display name...');
|
|
69
|
+
}
|
|
70
|
+
return entraGroup.getGroupIdByDisplayName(name);
|
|
71
|
+
}
|
|
72
|
+
async getUserIds(logger, userIds, userNames) {
|
|
73
|
+
if (userIds) {
|
|
74
|
+
return formatting.splitAndTrim(userIds);
|
|
75
|
+
}
|
|
76
|
+
if (this.verbose) {
|
|
77
|
+
await logger.logToStderr('Retrieving user ID(s) by username(s)...');
|
|
78
|
+
}
|
|
79
|
+
return entraUser.getUserIdsByUpns(formatting.splitAndTrim(userNames));
|
|
114
80
|
}
|
|
115
|
-
async
|
|
81
|
+
async removeUsersFromRole(logger, groupId, userIds, role) {
|
|
82
|
+
const userIdsToRemove = [];
|
|
83
|
+
const currentRole = (role.toLowerCase() === 'member') ? 'owners' : 'members';
|
|
116
84
|
if (this.verbose) {
|
|
117
|
-
await logger.logToStderr(`
|
|
85
|
+
await logger.logToStderr(`Removing users from the old role '${currentRole}'.`);
|
|
86
|
+
}
|
|
87
|
+
for (let i = 0; i < userIds.length; i += 20) {
|
|
88
|
+
const userIdsBatch = userIds.slice(i, i + 20);
|
|
89
|
+
const requestOptions = this.getRequestOptions();
|
|
90
|
+
userIdsBatch.map(userId => {
|
|
91
|
+
requestOptions.data.requests.push({
|
|
92
|
+
id: userId,
|
|
93
|
+
method: 'GET',
|
|
94
|
+
url: `/groups/${groupId}/${currentRole}/$count?$filter=id eq '${userId}'`,
|
|
95
|
+
headers: {
|
|
96
|
+
'ConsistencyLevel': 'eventual'
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
// send batch request
|
|
101
|
+
const res = await request.post(requestOptions);
|
|
102
|
+
for (const response of res.responses) {
|
|
103
|
+
if (response.status === 200) {
|
|
104
|
+
if (response.body === 1) {
|
|
105
|
+
// user can be removed from current role
|
|
106
|
+
userIdsToRemove.push(response.id);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
else {
|
|
110
|
+
throw response.body;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
for (let i = 0; i < userIdsToRemove.length; i += 20) {
|
|
115
|
+
const userIdsBatch = userIds.slice(i, i + 20);
|
|
116
|
+
const requestOptions = this.getRequestOptions();
|
|
117
|
+
userIdsBatch.map(userId => {
|
|
118
|
+
requestOptions.data.requests.push({
|
|
119
|
+
id: userId,
|
|
120
|
+
method: 'DELETE',
|
|
121
|
+
url: `/groups/${groupId}/${currentRole}/${userId}/$ref`
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
const res = await request.post(requestOptions);
|
|
125
|
+
for (const response of res.responses) {
|
|
126
|
+
if (response.status !== 204) {
|
|
127
|
+
throw response.body;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
async addUsers(groupId, userIds, role) {
|
|
133
|
+
for (let i = 0; i < userIds.length; i += 400) {
|
|
134
|
+
const userIdsBatch = userIds.slice(i, i + 400);
|
|
135
|
+
const requestOptions = this.getRequestOptions();
|
|
136
|
+
for (let j = 0; j < userIdsBatch.length; j += 20) {
|
|
137
|
+
const userIdsChunk = userIdsBatch.slice(j, j + 20);
|
|
138
|
+
requestOptions.data.requests.push({
|
|
139
|
+
id: j + 1,
|
|
140
|
+
method: 'PATCH',
|
|
141
|
+
url: `/groups/${groupId}`,
|
|
142
|
+
headers: {
|
|
143
|
+
'content-type': 'application/json;odata.metadata=none'
|
|
144
|
+
},
|
|
145
|
+
body: {
|
|
146
|
+
[`${role.toLowerCase() === 'member' ? 'members' : 'owners'}@odata.bind`]: userIdsChunk.map(u => `${this.resource}/v1.0/directoryObjects/${u}`)
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const res = await request.post(requestOptions);
|
|
151
|
+
for (const response of res.responses) {
|
|
152
|
+
if (response.status !== 204) {
|
|
153
|
+
throw response.body;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
118
156
|
}
|
|
119
|
-
|
|
120
|
-
|
|
157
|
+
}
|
|
158
|
+
getRequestOptions() {
|
|
159
|
+
const requestOptions = {
|
|
160
|
+
url: `${this.resource}/v1.0/$batch`,
|
|
161
|
+
headers: {
|
|
162
|
+
'content-type': 'application/json;odata.metadata=none'
|
|
163
|
+
},
|
|
164
|
+
responseType: 'json',
|
|
165
|
+
data: {
|
|
166
|
+
requests: []
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return requestOptions;
|
|
121
170
|
}
|
|
122
171
|
}
|
|
123
172
|
_EntraM365GroupUserSetCommand_instances = new WeakSet(), _EntraM365GroupUserSetCommand_initTelemetry = function _EntraM365GroupUserSetCommand_initTelemetry() {
|
|
124
173
|
this.telemetry.push((args) => {
|
|
125
174
|
Object.assign(this.telemetryProperties, {
|
|
126
175
|
teamId: typeof args.options.teamId !== 'undefined',
|
|
176
|
+
teamName: typeof args.options.teamName !== 'undefined',
|
|
127
177
|
groupId: typeof args.options.groupId !== 'undefined',
|
|
128
|
-
|
|
178
|
+
groupName: typeof args.options.groupName !== 'undefined',
|
|
179
|
+
ids: typeof args.options.ids !== 'undefined',
|
|
180
|
+
userNames: typeof args.options.userNames !== 'undefined'
|
|
129
181
|
});
|
|
130
182
|
});
|
|
131
183
|
}, _EntraM365GroupUserSetCommand_initOptions = function _EntraM365GroupUserSetCommand_initOptions() {
|
|
132
184
|
this.options.unshift({
|
|
133
|
-
option:
|
|
185
|
+
option: '-n, --userName [userName]'
|
|
186
|
+
}, {
|
|
187
|
+
option: '--ids [ids]'
|
|
188
|
+
}, {
|
|
189
|
+
option: '--userNames [userNames]'
|
|
190
|
+
}, {
|
|
191
|
+
option: '-i, --groupId [groupId]'
|
|
134
192
|
}, {
|
|
135
|
-
option:
|
|
193
|
+
option: '--groupName [groupName]'
|
|
136
194
|
}, {
|
|
137
|
-
option: '
|
|
195
|
+
option: '--teamId [teamId]'
|
|
196
|
+
}, {
|
|
197
|
+
option: '--teamName [teamName]'
|
|
138
198
|
}, {
|
|
139
199
|
option: '-r, --role <role>',
|
|
140
|
-
autocomplete:
|
|
200
|
+
autocomplete: this.allowedRoles
|
|
141
201
|
});
|
|
142
202
|
}, _EntraM365GroupUserSetCommand_initValidators = function _EntraM365GroupUserSetCommand_initValidators() {
|
|
143
203
|
this.validators.push(async (args) => {
|
|
144
204
|
if (args.options.teamId && !validation.isValidGuid(args.options.teamId)) {
|
|
145
|
-
return
|
|
205
|
+
return `'${args.options.teamId}' is not a valid GUID for option 'teamId'.`;
|
|
146
206
|
}
|
|
147
207
|
if (args.options.groupId && !validation.isValidGuid(args.options.groupId)) {
|
|
148
|
-
return
|
|
208
|
+
return `'${args.options.groupId}' is not a valid GUID for option 'groupId'.`;
|
|
209
|
+
}
|
|
210
|
+
if (args.options.ids) {
|
|
211
|
+
const isValidGUIDArrayResult = validation.isValidGuidArray(args.options.ids);
|
|
212
|
+
if (isValidGUIDArrayResult !== true) {
|
|
213
|
+
return `The following GUIDs are invalid for the option 'ids': ${isValidGUIDArrayResult}.`;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (args.options.userNames) {
|
|
217
|
+
const isValidUPNArrayResult = validation.isValidUserPrincipalNameArray(args.options.userNames);
|
|
218
|
+
if (isValidUPNArrayResult !== true) {
|
|
219
|
+
return `The following user principal names are invalid for the option 'userNames': ${isValidUPNArrayResult}.`;
|
|
220
|
+
}
|
|
149
221
|
}
|
|
150
|
-
if (
|
|
151
|
-
return
|
|
222
|
+
if (args.options.role && !this.allowedRoles.some(role => role.toLowerCase() === args.options.role.toLowerCase())) {
|
|
223
|
+
return `'${args.options.role}' is not a valid role. Allowed values are: ${this.allowedRoles.join(',')}`;
|
|
152
224
|
}
|
|
153
225
|
return true;
|
|
154
226
|
});
|
|
155
227
|
}, _EntraM365GroupUserSetCommand_initOptionSets = function _EntraM365GroupUserSetCommand_initOptionSets() {
|
|
156
|
-
this.optionSets.push({ options: ['groupId', 'teamId'] });
|
|
228
|
+
this.optionSets.push({ options: ['groupId', 'groupName', 'teamId', 'teamName'] });
|
|
229
|
+
this.optionSets.push({ options: ['userName', 'ids', 'userNames'] });
|
|
230
|
+
}, _EntraM365GroupUserSetCommand_initTypes = function _EntraM365GroupUserSetCommand_initTypes() {
|
|
231
|
+
this.types.string.push('userName', 'ids', 'userNames', 'groupId', 'groupName', 'teamId', 'teamName', 'role');
|
|
157
232
|
};
|
|
158
233
|
export default new EntraM365GroupUserSetCommand();
|
|
159
234
|
//# sourceMappingURL=m365group-user-set.js.map
|