@pnp/cli-microsoft365 10.6.0-beta.55e3c97 → 10.6.0-beta.a7465c9
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.
|
@@ -4,16 +4,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _SpoWebRoleAssignmentAddCommand_instances, _SpoWebRoleAssignmentAddCommand_initTelemetry, _SpoWebRoleAssignmentAddCommand_initOptions, _SpoWebRoleAssignmentAddCommand_initValidators, _SpoWebRoleAssignmentAddCommand_initOptionSets;
|
|
7
|
-
import { cli } from '../../../../cli/cli.js';
|
|
8
7
|
import request from '../../../../request.js';
|
|
8
|
+
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
9
|
+
import { spo } from '../../../../utils/spo.js';
|
|
9
10
|
import { validation } from '../../../../utils/validation.js';
|
|
10
11
|
import SpoCommand from '../../../base/SpoCommand.js';
|
|
11
12
|
import commands from '../../commands.js';
|
|
12
|
-
import spoGroupGetCommand from '../group/group-get.js';
|
|
13
|
-
import spoRoleDefinitionListCommand from '../roledefinition/roledefinition-list.js';
|
|
14
|
-
import spoUserGetCommand from '../user/user-get.js';
|
|
15
|
-
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
16
|
-
import { spo } from '../../../../utils/spo.js';
|
|
17
13
|
class SpoWebRoleAssignmentAddCommand extends SpoCommand {
|
|
18
14
|
get name() {
|
|
19
15
|
return commands.WEB_ROLEASSIGNMENT_ADD;
|
|
@@ -34,12 +30,14 @@ class SpoWebRoleAssignmentAddCommand extends SpoCommand {
|
|
|
34
30
|
await logger.logToStderr(`Adding role assignment to web ${args.options.webUrl}...`);
|
|
35
31
|
}
|
|
36
32
|
try {
|
|
37
|
-
|
|
33
|
+
const roleDefinitionId = await this.getRoleDefinitionId(args.options, logger);
|
|
38
34
|
if (args.options.upn) {
|
|
39
|
-
|
|
35
|
+
const principalId = await this.getUserPrincipalId(args.options, logger);
|
|
36
|
+
await this.addRoleAssignment(args.options.webUrl, principalId, roleDefinitionId, logger);
|
|
40
37
|
}
|
|
41
38
|
else if (args.options.groupName) {
|
|
42
|
-
|
|
39
|
+
const principalId = await this.getGroupPrincipalId(args.options, logger);
|
|
40
|
+
await this.addRoleAssignment(args.options.webUrl, principalId, roleDefinitionId, logger);
|
|
43
41
|
}
|
|
44
42
|
else if (args.options.entraGroupId || args.options.entraGroupName) {
|
|
45
43
|
if (this.verbose) {
|
|
@@ -49,17 +47,19 @@ class SpoWebRoleAssignmentAddCommand extends SpoCommand {
|
|
|
49
47
|
? await entraGroup.getGroupById(args.options.entraGroupId)
|
|
50
48
|
: await entraGroup.getGroupByDisplayName(args.options.entraGroupName);
|
|
51
49
|
const siteUser = await spo.ensureEntraGroup(args.options.webUrl, group);
|
|
52
|
-
args.options.
|
|
50
|
+
await this.addRoleAssignment(args.options.webUrl, siteUser.Id, roleDefinitionId, logger);
|
|
53
51
|
}
|
|
54
|
-
await this.addRoleAssignment(logger, args.options);
|
|
55
52
|
}
|
|
56
53
|
catch (err) {
|
|
57
54
|
this.handleRejectedODataJsonPromise(err);
|
|
58
55
|
}
|
|
59
56
|
}
|
|
60
|
-
async addRoleAssignment(
|
|
57
|
+
async addRoleAssignment(webUrl, principalId, roleDefinitionId, logger) {
|
|
58
|
+
if (this.verbose) {
|
|
59
|
+
await logger.logToStderr('Adding role assignment...');
|
|
60
|
+
}
|
|
61
61
|
const requestOptions = {
|
|
62
|
-
url: `${
|
|
62
|
+
url: `${webUrl}/_api/web/roleassignments/addroleassignment(principalid='${principalId}',roledefid='${roleDefinitionId}')`,
|
|
63
63
|
method: 'POST',
|
|
64
64
|
headers: {
|
|
65
65
|
'accept': 'application/json;odata=nometadata',
|
|
@@ -69,45 +69,20 @@ class SpoWebRoleAssignmentAddCommand extends SpoCommand {
|
|
|
69
69
|
};
|
|
70
70
|
await request.post(requestOptions);
|
|
71
71
|
}
|
|
72
|
-
async getRoleDefinitionId(options) {
|
|
72
|
+
async getRoleDefinitionId(options, logger) {
|
|
73
73
|
if (!options.roleDefinitionName) {
|
|
74
74
|
return options.roleDefinitionId;
|
|
75
75
|
}
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
output: 'json',
|
|
79
|
-
debug: this.debug,
|
|
80
|
-
verbose: this.verbose
|
|
81
|
-
};
|
|
82
|
-
const output = await cli.executeCommandWithOutput(spoRoleDefinitionListCommand, { options: { ...roleDefinitionListCommandOptions, _: [] } });
|
|
83
|
-
const getRoleDefinitionListOutput = JSON.parse(output.stdout);
|
|
84
|
-
const roleDefinitionId = getRoleDefinitionListOutput.find((role) => role.Name === options.roleDefinitionName).Id;
|
|
85
|
-
return roleDefinitionId;
|
|
76
|
+
const roledefinition = await spo.getRoleDefinitionByName(options.webUrl, options.roleDefinitionName, logger, this.verbose);
|
|
77
|
+
return roledefinition.Id;
|
|
86
78
|
}
|
|
87
|
-
async getGroupPrincipalId(options) {
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
name: options.groupName,
|
|
91
|
-
output: 'json',
|
|
92
|
-
debug: this.debug,
|
|
93
|
-
verbose: this.verbose
|
|
94
|
-
};
|
|
95
|
-
const output = await cli.executeCommandWithOutput(spoGroupGetCommand, { options: { ...groupGetCommandOptions, _: [] } });
|
|
96
|
-
const getGroupOutput = JSON.parse(output.stdout);
|
|
97
|
-
return getGroupOutput.Id;
|
|
79
|
+
async getGroupPrincipalId(options, logger) {
|
|
80
|
+
const group = await spo.getGroupByName(options.webUrl, options.groupName, logger, this.verbose);
|
|
81
|
+
return group.Id;
|
|
98
82
|
}
|
|
99
|
-
async getUserPrincipalId(options) {
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
email: options.upn,
|
|
103
|
-
id: undefined,
|
|
104
|
-
output: 'json',
|
|
105
|
-
debug: this.debug,
|
|
106
|
-
verbose: this.verbose
|
|
107
|
-
};
|
|
108
|
-
const output = await cli.executeCommandWithOutput(spoUserGetCommand, { options: { ...userGetCommandOptions, _: [] } });
|
|
109
|
-
const getUserOutput = JSON.parse(output.stdout);
|
|
110
|
-
return getUserOutput.Id;
|
|
83
|
+
async getUserPrincipalId(options, logger) {
|
|
84
|
+
const user = await spo.getUserByEmail(options.webUrl, options.upn, logger, this.verbose);
|
|
85
|
+
return user.Id;
|
|
111
86
|
}
|
|
112
87
|
}
|
|
113
88
|
_SpoWebRoleAssignmentAddCommand_instances = new WeakSet(), _SpoWebRoleAssignmentAddCommand_initTelemetry = function _SpoWebRoleAssignmentAddCommand_initTelemetry() {
|
|
@@ -4,15 +4,13 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
6
|
var _SpoWebRoleAssignmentRemoveCommand_instances, _SpoWebRoleAssignmentRemoveCommand_initTelemetry, _SpoWebRoleAssignmentRemoveCommand_initOptions, _SpoWebRoleAssignmentRemoveCommand_initValidators, _SpoWebRoleAssignmentRemoveCommand_initOptionSets;
|
|
7
|
-
import { cli } from '../../../../cli/cli.js';
|
|
8
7
|
import request from '../../../../request.js';
|
|
9
8
|
import { validation } from '../../../../utils/validation.js';
|
|
10
9
|
import SpoCommand from '../../../base/SpoCommand.js';
|
|
11
10
|
import commands from '../../commands.js';
|
|
12
|
-
import spoGroupGetCommand from '../group/group-get.js';
|
|
13
|
-
import spoUserGetCommand from '../user/user-get.js';
|
|
14
11
|
import { entraGroup } from '../../../../utils/entraGroup.js';
|
|
15
12
|
import { spo } from '../../../../utils/spo.js';
|
|
13
|
+
import { cli } from '../../../../cli/cli.js';
|
|
16
14
|
class SpoWebRoleAssignmentRemoveCommand extends SpoCommand {
|
|
17
15
|
get name() {
|
|
18
16
|
return commands.WEB_ROLEASSIGNMENT_REMOVE;
|
|
@@ -45,10 +43,12 @@ class SpoWebRoleAssignmentRemoveCommand extends SpoCommand {
|
|
|
45
43
|
}
|
|
46
44
|
try {
|
|
47
45
|
if (options.upn) {
|
|
48
|
-
|
|
46
|
+
const principalId = await this.getUserPrincipalId(options, logger);
|
|
47
|
+
await this.removeRoleAssignmentWithOptions(options.webUrl, principalId, logger);
|
|
49
48
|
}
|
|
50
49
|
else if (options.groupName) {
|
|
51
|
-
|
|
50
|
+
const principalId = await this.getGroupPrincipalId(options, logger);
|
|
51
|
+
await this.removeRoleAssignmentWithOptions(options.webUrl, principalId, logger);
|
|
52
52
|
}
|
|
53
53
|
else if (options.entraGroupId || options.entraGroupName) {
|
|
54
54
|
if (this.verbose) {
|
|
@@ -58,17 +58,19 @@ class SpoWebRoleAssignmentRemoveCommand extends SpoCommand {
|
|
|
58
58
|
? await entraGroup.getGroupById(options.entraGroupId)
|
|
59
59
|
: await entraGroup.getGroupByDisplayName(options.entraGroupName);
|
|
60
60
|
const siteUser = await spo.ensureEntraGroup(options.webUrl, group);
|
|
61
|
-
options.
|
|
61
|
+
await this.removeRoleAssignmentWithOptions(options.webUrl, siteUser.Id, logger);
|
|
62
62
|
}
|
|
63
|
-
await this.removeRoleAssignmentWithOptions(logger, options);
|
|
64
63
|
}
|
|
65
64
|
catch (err) {
|
|
66
65
|
this.handleRejectedODataJsonPromise(err);
|
|
67
66
|
}
|
|
68
67
|
}
|
|
69
|
-
async removeRoleAssignmentWithOptions(
|
|
68
|
+
async removeRoleAssignmentWithOptions(webUrl, principalId, logger) {
|
|
69
|
+
if (this.verbose) {
|
|
70
|
+
await logger.logToStderr('Removing role assignment...');
|
|
71
|
+
}
|
|
70
72
|
const requestOptions = {
|
|
71
|
-
url: `${
|
|
73
|
+
url: `${webUrl}/_api/web/roleassignments/removeroleassignment(principalid='${principalId}')`,
|
|
72
74
|
method: 'POST',
|
|
73
75
|
headers: {
|
|
74
76
|
'accept': 'application/json;odata=nometadata',
|
|
@@ -78,30 +80,13 @@ class SpoWebRoleAssignmentRemoveCommand extends SpoCommand {
|
|
|
78
80
|
};
|
|
79
81
|
await request.post(requestOptions);
|
|
80
82
|
}
|
|
81
|
-
async getGroupPrincipalId(options) {
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
name: options.groupName,
|
|
85
|
-
output: 'json',
|
|
86
|
-
debug: this.debug,
|
|
87
|
-
verbose: this.verbose
|
|
88
|
-
};
|
|
89
|
-
const output = await cli.executeCommandWithOutput(spoGroupGetCommand, { options: { ...groupGetCommandOptions, _: [] } });
|
|
90
|
-
const getGroupOutput = JSON.parse(output.stdout);
|
|
91
|
-
return getGroupOutput.Id;
|
|
83
|
+
async getGroupPrincipalId(options, logger) {
|
|
84
|
+
const group = await spo.getGroupByName(options.webUrl, options.groupName, logger, this.verbose);
|
|
85
|
+
return group.Id;
|
|
92
86
|
}
|
|
93
|
-
async getUserPrincipalId(options) {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
email: options.upn,
|
|
97
|
-
id: undefined,
|
|
98
|
-
output: 'json',
|
|
99
|
-
debug: this.debug,
|
|
100
|
-
verbose: this.verbose
|
|
101
|
-
};
|
|
102
|
-
const output = await cli.executeCommandWithOutput(spoUserGetCommand, { options: { ...userGetCommandOptions, _: [] } });
|
|
103
|
-
const getUserOutput = JSON.parse(output.stdout);
|
|
104
|
-
return getUserOutput.Id;
|
|
87
|
+
async getUserPrincipalId(options, logger) {
|
|
88
|
+
const user = await spo.getUserByEmail(options.webUrl, options.upn, logger, this.verbose);
|
|
89
|
+
return user.Id;
|
|
105
90
|
}
|
|
106
91
|
}
|
|
107
92
|
_SpoWebRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoWebRoleAssignmentRemoveCommand_initTelemetry = function _SpoWebRoleAssignmentRemoveCommand_initTelemetry() {
|
package/dist/utils/spo.js
CHANGED
|
@@ -519,10 +519,11 @@ export const spo = {
|
|
|
519
519
|
},
|
|
520
520
|
/**
|
|
521
521
|
* Retrieves the spo user by email.
|
|
522
|
+
* Returns a user object
|
|
522
523
|
* @param webUrl Web url
|
|
523
524
|
* @param email The email of the user
|
|
524
525
|
* @param logger the Logger object
|
|
525
|
-
* @param verbose
|
|
526
|
+
* @param verbose Set for verbose logging
|
|
526
527
|
*/
|
|
527
528
|
async getUserByEmail(webUrl, email, logger, verbose) {
|
|
528
529
|
if (verbose && logger) {
|
|
@@ -593,10 +594,11 @@ export const spo = {
|
|
|
593
594
|
},
|
|
594
595
|
/**
|
|
595
596
|
* Retrieves the spo group by name.
|
|
597
|
+
* Returns a group object
|
|
596
598
|
* @param webUrl Web url
|
|
597
599
|
* @param name The name of the group
|
|
598
600
|
* @param logger the Logger object
|
|
599
|
-
* @param verbose
|
|
601
|
+
* @param verbose Set for verbose logging
|
|
600
602
|
*/
|
|
601
603
|
async getGroupByName(webUrl, name, logger, verbose) {
|
|
602
604
|
if (verbose && logger) {
|
|
@@ -615,10 +617,11 @@ export const spo = {
|
|
|
615
617
|
},
|
|
616
618
|
/**
|
|
617
619
|
* Retrieves the role definition by name.
|
|
620
|
+
* Returns a RoleDefinition object
|
|
618
621
|
* @param webUrl Web url
|
|
619
622
|
* @param name the name of the role definition
|
|
620
623
|
* @param logger the Logger object
|
|
621
|
-
* @param verbose
|
|
624
|
+
* @param verbose Set for verbose logging
|
|
622
625
|
*/
|
|
623
626
|
async getRoleDefinitionByName(webUrl, name, logger, verbose) {
|
|
624
627
|
if (verbose && logger) {
|
package/package.json
CHANGED