@pnp/cli-microsoft365 5.8.0-beta.5250f08 → 5.8.0-beta.57eff68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,206 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpoListItemRoleAssignmentRemoveCommand_instances, _SpoListItemRoleAssignmentRemoveCommand_initTelemetry, _SpoListItemRoleAssignmentRemoveCommand_initOptions, _SpoListItemRoleAssignmentRemoveCommand_initValidators;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const cli_1 = require("../../../../cli");
19
+ const request_1 = require("../../../../request");
20
+ const utils_1 = require("../../../../utils");
21
+ const SpoCommand_1 = require("../../../base/SpoCommand");
22
+ const commands_1 = require("../../commands");
23
+ const SpoUserGetCommand = require("../user/user-get");
24
+ const SpoGroupGetCommand = require("../group/group-get");
25
+ class SpoListItemRoleAssignmentRemoveCommand extends SpoCommand_1.default {
26
+ constructor() {
27
+ super();
28
+ _SpoListItemRoleAssignmentRemoveCommand_instances.add(this);
29
+ __classPrivateFieldGet(this, _SpoListItemRoleAssignmentRemoveCommand_instances, "m", _SpoListItemRoleAssignmentRemoveCommand_initTelemetry).call(this);
30
+ __classPrivateFieldGet(this, _SpoListItemRoleAssignmentRemoveCommand_instances, "m", _SpoListItemRoleAssignmentRemoveCommand_initOptions).call(this);
31
+ __classPrivateFieldGet(this, _SpoListItemRoleAssignmentRemoveCommand_instances, "m", _SpoListItemRoleAssignmentRemoveCommand_initValidators).call(this);
32
+ }
33
+ get name() {
34
+ return commands_1.default.LISTITEM_ROLEASSIGNMENT_REMOVE;
35
+ }
36
+ get description() {
37
+ return 'Removes a role assignment from list item permissions';
38
+ }
39
+ commandAction(logger, args, cb) {
40
+ const removeRoleAssignment = () => {
41
+ if (this.verbose) {
42
+ logger.logToStderr(`Removing role assignment from listitem in site at ${args.options.webUrl}...`);
43
+ }
44
+ let requestUrl = `${args.options.webUrl}/_api/web/`;
45
+ if (args.options.listId) {
46
+ requestUrl += `lists(guid'${utils_1.formatting.encodeQueryParameter(args.options.listId)}')/`;
47
+ }
48
+ else if (args.options.listTitle) {
49
+ requestUrl += `lists/getByTitle('${utils_1.formatting.encodeQueryParameter(args.options.listTitle)}')/`;
50
+ }
51
+ else if (args.options.listUrl) {
52
+ const listServerRelativeUrl = utils_1.urlUtil.getServerRelativePath(args.options.webUrl, args.options.listUrl);
53
+ requestUrl += `GetList('${utils_1.formatting.encodeQueryParameter(listServerRelativeUrl)}')/`;
54
+ }
55
+ requestUrl += `items(${args.options.listItemId})/`;
56
+ if (args.options.upn) {
57
+ this.GetUserPrincipalId(args.options)
58
+ .then((userPrincipalId) => {
59
+ args.options.principalId = userPrincipalId;
60
+ this.RemoveRoleAssignment(requestUrl, logger, args.options, cb);
61
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
62
+ }
63
+ else if (args.options.groupName) {
64
+ this.GetGroupPrincipalId(args.options)
65
+ .then((groupPrincipalId) => {
66
+ args.options.principalId = groupPrincipalId;
67
+ this.RemoveRoleAssignment(requestUrl, logger, args.options, cb);
68
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
69
+ }
70
+ else {
71
+ this.RemoveRoleAssignment(requestUrl, logger, args.options, cb);
72
+ }
73
+ };
74
+ if (args.options.confirm) {
75
+ removeRoleAssignment();
76
+ }
77
+ else {
78
+ cli_1.Cli.prompt({
79
+ type: 'confirm',
80
+ name: 'continue',
81
+ default: false,
82
+ message: `Are you sure you want to remove role assignment from listitem ${args.options.listItemId} from list ${args.options.listId || args.options.listTitle} from site ${args.options.webUrl}?`
83
+ }, (result) => {
84
+ if (!result.continue) {
85
+ cb();
86
+ }
87
+ else {
88
+ removeRoleAssignment();
89
+ }
90
+ });
91
+ }
92
+ }
93
+ RemoveRoleAssignment(requestUrl, logger, options, cb) {
94
+ const requestOptions = {
95
+ url: `${requestUrl}roleassignments/removeroleassignment(principalid='${options.principalId}')`,
96
+ method: 'POST',
97
+ headers: {
98
+ 'accept': 'application/json;odata=nometadata',
99
+ 'content-type': 'application/json'
100
+ },
101
+ responseType: 'json'
102
+ };
103
+ request_1.default
104
+ .post(requestOptions)
105
+ .then(_ => cb(), (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
106
+ }
107
+ GetGroupPrincipalId(options) {
108
+ const groupGetCommandOptions = {
109
+ webUrl: options.webUrl,
110
+ name: options.groupName,
111
+ output: 'json',
112
+ debug: this.debug,
113
+ verbose: this.verbose
114
+ };
115
+ return cli_1.Cli.executeCommandWithOutput(SpoGroupGetCommand, { options: Object.assign(Object.assign({}, groupGetCommandOptions), { _: [] }) })
116
+ .then((output) => {
117
+ const getGroupOutput = JSON.parse(output.stdout);
118
+ return Promise.resolve(getGroupOutput.Id);
119
+ }, (err) => {
120
+ return Promise.reject(err);
121
+ });
122
+ }
123
+ GetUserPrincipalId(options) {
124
+ const userGetCommandOptions = {
125
+ webUrl: options.webUrl,
126
+ email: options.upn,
127
+ id: undefined,
128
+ output: 'json',
129
+ debug: this.debug,
130
+ verbose: this.verbose
131
+ };
132
+ return cli_1.Cli.executeCommandWithOutput(SpoUserGetCommand, { options: Object.assign(Object.assign({}, userGetCommandOptions), { _: [] }) })
133
+ .then((output) => {
134
+ const getUserOutput = JSON.parse(output.stdout);
135
+ return Promise.resolve(getUserOutput.Id);
136
+ }, (err) => {
137
+ return Promise.reject(err);
138
+ });
139
+ }
140
+ }
141
+ _SpoListItemRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoListItemRoleAssignmentRemoveCommand_initTelemetry = function _SpoListItemRoleAssignmentRemoveCommand_initTelemetry() {
142
+ this.telemetry.push((args) => {
143
+ Object.assign(this.telemetryProperties, {
144
+ listId: typeof args.options.listId !== 'undefined',
145
+ listTitle: typeof args.options.listTitle !== 'undefined',
146
+ listUrl: typeof args.options.listUrl !== 'undefined',
147
+ principalId: typeof args.options.principalId !== 'undefined',
148
+ upn: typeof args.options.upn !== 'undefined',
149
+ groupName: typeof args.options.groupName !== 'undefined',
150
+ confirm: (!(!args.options.confirm)).toString()
151
+ });
152
+ });
153
+ }, _SpoListItemRoleAssignmentRemoveCommand_initOptions = function _SpoListItemRoleAssignmentRemoveCommand_initOptions() {
154
+ this.options.unshift({
155
+ option: '-u, --webUrl <webUrl>'
156
+ }, {
157
+ option: '-i, --listId [listId]'
158
+ }, {
159
+ option: '-t, --listTitle [listTitle]'
160
+ }, {
161
+ option: '--listUrl [listUrl]'
162
+ }, {
163
+ option: '--listItemId <listItemId>'
164
+ }, {
165
+ option: '--principalId [principalId]'
166
+ }, {
167
+ option: '--upn [upn]'
168
+ }, {
169
+ option: '--groupName [groupName]'
170
+ }, {
171
+ option: '--confirm'
172
+ });
173
+ }, _SpoListItemRoleAssignmentRemoveCommand_initValidators = function _SpoListItemRoleAssignmentRemoveCommand_initValidators() {
174
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
175
+ const isValidSharePointUrl = utils_1.validation.isValidSharePointUrl(args.options.webUrl);
176
+ if (isValidSharePointUrl !== true) {
177
+ return isValidSharePointUrl;
178
+ }
179
+ if (args.options.listId && !utils_1.validation.isValidGuid(args.options.listId)) {
180
+ return `${args.options.listId} is not a valid GUID`;
181
+ }
182
+ if (args.options.listItemId && isNaN(args.options.listItemId)) {
183
+ return `Specified listItemId ${args.options.listItemId} is not a number`;
184
+ }
185
+ if (args.options.principalId && isNaN(args.options.principalId)) {
186
+ return `Specified principalId ${args.options.principalId} is not a number`;
187
+ }
188
+ const listOptions = [args.options.listId, args.options.listTitle, args.options.listUrl];
189
+ if (listOptions.some(item => item !== undefined) && listOptions.filter(item => item !== undefined).length > 1) {
190
+ return `Specify either list id or title or list url`;
191
+ }
192
+ if (listOptions.filter(item => item !== undefined).length === 0) {
193
+ return `Specify at least list id or title or list url`;
194
+ }
195
+ const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName];
196
+ if (principalOptions.some(item => item !== undefined) && principalOptions.filter(item => item !== undefined).length > 1) {
197
+ return `Specify either principalId id or upn or groupName`;
198
+ }
199
+ if (principalOptions.filter(item => item !== undefined).length === 0) {
200
+ return `Specify at least principalId id or upn or groupName`;
201
+ }
202
+ return true;
203
+ }));
204
+ };
205
+ module.exports = new SpoListItemRoleAssignmentRemoveCommand();
206
+ //# sourceMappingURL=listitem-roleassignment-remove.js.map
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpoWebRoleAssignmentAddCommand_instances, _SpoWebRoleAssignmentAddCommand_initTelemetry, _SpoWebRoleAssignmentAddCommand_initOptions, _SpoWebRoleAssignmentAddCommand_initValidators;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const cli_1 = require("../../../../cli");
19
+ const request_1 = require("../../../../request");
20
+ const utils_1 = require("../../../../utils");
21
+ const SpoCommand_1 = require("../../../base/SpoCommand");
22
+ const commands_1 = require("../../commands");
23
+ const SpoUserGetCommand = require("../user/user-get");
24
+ const SpoGroupGetCommand = require("../group/group-get");
25
+ const SpoRoleDefinitionListCommand = require("../roledefinition/roledefinition-list");
26
+ class SpoWebRoleAssignmentAddCommand extends SpoCommand_1.default {
27
+ constructor() {
28
+ super();
29
+ _SpoWebRoleAssignmentAddCommand_instances.add(this);
30
+ __classPrivateFieldGet(this, _SpoWebRoleAssignmentAddCommand_instances, "m", _SpoWebRoleAssignmentAddCommand_initTelemetry).call(this);
31
+ __classPrivateFieldGet(this, _SpoWebRoleAssignmentAddCommand_instances, "m", _SpoWebRoleAssignmentAddCommand_initOptions).call(this);
32
+ __classPrivateFieldGet(this, _SpoWebRoleAssignmentAddCommand_instances, "m", _SpoWebRoleAssignmentAddCommand_initValidators).call(this);
33
+ }
34
+ get name() {
35
+ return commands_1.default.WEB_ROLEASSIGNMENT_ADD;
36
+ }
37
+ get description() {
38
+ return 'Adds a role assignment to web';
39
+ }
40
+ commandAction(logger, args, cb) {
41
+ if (this.verbose) {
42
+ logger.logToStderr(`Adding role assignment to web ${args.options.webUrl}...`);
43
+ }
44
+ this.GetRoleDefinitionId(args.options)
45
+ .then((roleDefinitionId) => {
46
+ args.options.roleDefinitionId = roleDefinitionId;
47
+ if (args.options.upn) {
48
+ this.GetUserPrincipalId(args.options)
49
+ .then((userPrincipalId) => {
50
+ args.options.principalId = userPrincipalId;
51
+ this.AddRoleAssignment(logger, args.options, cb);
52
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
53
+ }
54
+ else if (args.options.groupName) {
55
+ this.GetGroupPrincipalId(args.options)
56
+ .then((groupPrincipalId) => {
57
+ args.options.principalId = groupPrincipalId;
58
+ this.AddRoleAssignment(logger, args.options, cb);
59
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
60
+ }
61
+ else {
62
+ this.AddRoleAssignment(logger, args.options, cb);
63
+ }
64
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
65
+ }
66
+ AddRoleAssignment(logger, options, cb) {
67
+ const requestOptions = {
68
+ url: `${options.webUrl}/_api/web/roleassignments/addroleassignment(principalid='${options.principalId}',roledefid='${options.roleDefinitionId}')`,
69
+ method: 'POST',
70
+ headers: {
71
+ 'accept': 'application/json;odata=nometadata',
72
+ 'content-type': 'application/json'
73
+ },
74
+ responseType: 'json'
75
+ };
76
+ request_1.default
77
+ .post(requestOptions)
78
+ .then(_ => cb(), (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
79
+ }
80
+ GetRoleDefinitionId(options) {
81
+ if (!options.roleDefinitionName) {
82
+ return Promise.resolve(options.roleDefinitionId);
83
+ }
84
+ const roleDefinitionListCommandOptions = {
85
+ webUrl: options.webUrl,
86
+ output: 'json',
87
+ debug: this.debug,
88
+ verbose: this.verbose
89
+ };
90
+ return cli_1.Cli.executeCommandWithOutput(SpoRoleDefinitionListCommand, { options: Object.assign(Object.assign({}, roleDefinitionListCommandOptions), { _: [] }) })
91
+ .then((output) => {
92
+ const getRoleDefinitionListOutput = JSON.parse(output.stdout);
93
+ const roleDefinitionId = getRoleDefinitionListOutput.find((role) => role.Name === options.roleDefinitionName).Id;
94
+ return Promise.resolve(roleDefinitionId);
95
+ }, (err) => {
96
+ return Promise.reject(err);
97
+ });
98
+ }
99
+ GetGroupPrincipalId(options) {
100
+ const groupGetCommandOptions = {
101
+ webUrl: options.webUrl,
102
+ name: options.groupName,
103
+ output: 'json',
104
+ debug: this.debug,
105
+ verbose: this.verbose
106
+ };
107
+ return cli_1.Cli.executeCommandWithOutput(SpoGroupGetCommand, { options: Object.assign(Object.assign({}, groupGetCommandOptions), { _: [] }) })
108
+ .then((output) => {
109
+ const getGroupOutput = JSON.parse(output.stdout);
110
+ return Promise.resolve(getGroupOutput.Id);
111
+ }, (err) => {
112
+ return Promise.reject(err);
113
+ });
114
+ }
115
+ GetUserPrincipalId(options) {
116
+ const userGetCommandOptions = {
117
+ webUrl: options.webUrl,
118
+ email: options.upn,
119
+ id: undefined,
120
+ output: 'json',
121
+ debug: this.debug,
122
+ verbose: this.verbose
123
+ };
124
+ return cli_1.Cli.executeCommandWithOutput(SpoUserGetCommand, { options: Object.assign(Object.assign({}, userGetCommandOptions), { _: [] }) })
125
+ .then((output) => {
126
+ const getUserOutput = JSON.parse(output.stdout);
127
+ return Promise.resolve(getUserOutput.Id);
128
+ }, (err) => {
129
+ return Promise.reject(err);
130
+ });
131
+ }
132
+ }
133
+ _SpoWebRoleAssignmentAddCommand_instances = new WeakSet(), _SpoWebRoleAssignmentAddCommand_initTelemetry = function _SpoWebRoleAssignmentAddCommand_initTelemetry() {
134
+ this.telemetry.push((args) => {
135
+ Object.assign(this.telemetryProperties, {
136
+ principalId: typeof args.options.principalId !== 'undefined',
137
+ upn: typeof args.options.upn !== 'undefined',
138
+ groupName: typeof args.options.groupName !== 'undefined',
139
+ roleDefinitionId: typeof args.options.roleDefinitionId !== 'undefined',
140
+ roleDefinitionName: typeof args.options.roleDefinitionName !== 'undefined'
141
+ });
142
+ });
143
+ }, _SpoWebRoleAssignmentAddCommand_initOptions = function _SpoWebRoleAssignmentAddCommand_initOptions() {
144
+ this.options.unshift({
145
+ option: '-u, --webUrl <webUrl>'
146
+ }, {
147
+ option: '--principalId [principalId]'
148
+ }, {
149
+ option: '--upn [upn]'
150
+ }, {
151
+ option: '--groupName [groupName]'
152
+ }, {
153
+ option: '--roleDefinitionId [roleDefinitionId]'
154
+ }, {
155
+ option: '--roleDefinitionName [roleDefinitionName]'
156
+ });
157
+ }, _SpoWebRoleAssignmentAddCommand_initValidators = function _SpoWebRoleAssignmentAddCommand_initValidators() {
158
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
159
+ const isValidSharePointUrl = utils_1.validation.isValidSharePointUrl(args.options.webUrl);
160
+ if (isValidSharePointUrl !== true) {
161
+ return isValidSharePointUrl;
162
+ }
163
+ if (args.options.principalId && isNaN(args.options.principalId)) {
164
+ return `Specified principalId ${args.options.principalId} is not a number`;
165
+ }
166
+ if (args.options.roleDefinitionId && isNaN(args.options.roleDefinitionId)) {
167
+ return `Specified roleDefinitionId ${args.options.roleDefinitionId} is not a number`;
168
+ }
169
+ const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName];
170
+ if (principalOptions.some(item => item !== undefined) && principalOptions.filter(item => item !== undefined).length > 1) {
171
+ return `Specify either principalId id or upn or groupName`;
172
+ }
173
+ if (principalOptions.filter(item => item !== undefined).length === 0) {
174
+ return `Specify at least principalId id or upn or groupName`;
175
+ }
176
+ const roleDefinitionOptions = [args.options.roleDefinitionId, args.options.roleDefinitionName];
177
+ if (roleDefinitionOptions.some(item => item !== undefined) && roleDefinitionOptions.filter(item => item !== undefined).length > 1) {
178
+ return `Specify either roleDefinitionId id or roleDefinitionName`;
179
+ }
180
+ if (roleDefinitionOptions.filter(item => item !== undefined).length === 0) {
181
+ return `Specify at least roleDefinitionId id or roleDefinitionName`;
182
+ }
183
+ return true;
184
+ }));
185
+ };
186
+ module.exports = new SpoWebRoleAssignmentAddCommand();
187
+ //# sourceMappingURL=web-roleassignment-add.js.map
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ 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");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _SpoWebRoleAssignmentRemoveCommand_instances, _SpoWebRoleAssignmentRemoveCommand_initTelemetry, _SpoWebRoleAssignmentRemoveCommand_initOptions, _SpoWebRoleAssignmentRemoveCommand_initValidators;
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ const cli_1 = require("../../../../cli");
19
+ const request_1 = require("../../../../request");
20
+ const utils_1 = require("../../../../utils");
21
+ const SpoCommand_1 = require("../../../base/SpoCommand");
22
+ const commands_1 = require("../../commands");
23
+ const SpoUserGetCommand = require("../user/user-get");
24
+ const SpoGroupGetCommand = require("../group/group-get");
25
+ class SpoWebRoleAssignmentRemoveCommand extends SpoCommand_1.default {
26
+ constructor() {
27
+ super();
28
+ _SpoWebRoleAssignmentRemoveCommand_instances.add(this);
29
+ __classPrivateFieldGet(this, _SpoWebRoleAssignmentRemoveCommand_instances, "m", _SpoWebRoleAssignmentRemoveCommand_initTelemetry).call(this);
30
+ __classPrivateFieldGet(this, _SpoWebRoleAssignmentRemoveCommand_instances, "m", _SpoWebRoleAssignmentRemoveCommand_initOptions).call(this);
31
+ __classPrivateFieldGet(this, _SpoWebRoleAssignmentRemoveCommand_instances, "m", _SpoWebRoleAssignmentRemoveCommand_initValidators).call(this);
32
+ }
33
+ get name() {
34
+ return commands_1.default.WEB_ROLEASSIGNMENT_REMOVE;
35
+ }
36
+ get description() {
37
+ return 'Removes a role assignment from web permissions';
38
+ }
39
+ commandAction(logger, args, cb) {
40
+ const removeRoleAssignment = () => {
41
+ if (this.verbose) {
42
+ logger.logToStderr(`Removing role assignment from web ${args.options.webUrl}...`);
43
+ }
44
+ if (args.options.upn) {
45
+ this.GetUserPrincipalId(args.options)
46
+ .then((userPrincipalId) => {
47
+ args.options.principalId = userPrincipalId;
48
+ this.RemoveRoleAssignment(logger, args.options, cb);
49
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
50
+ }
51
+ else if (args.options.groupName) {
52
+ this.GetGroupPrincipalId(args.options)
53
+ .then((groupPrincipalId) => {
54
+ args.options.principalId = groupPrincipalId;
55
+ this.RemoveRoleAssignment(logger, args.options, cb);
56
+ }, (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
57
+ }
58
+ else {
59
+ this.RemoveRoleAssignment(logger, args.options, cb);
60
+ }
61
+ };
62
+ if (args.options.confirm) {
63
+ removeRoleAssignment();
64
+ }
65
+ else {
66
+ cli_1.Cli.prompt({
67
+ type: 'confirm',
68
+ name: 'continue',
69
+ default: false,
70
+ message: `Are you sure you want to remove role assignment from web ${args.options.webUrl}?`
71
+ }, (result) => {
72
+ if (!result.continue) {
73
+ cb();
74
+ }
75
+ else {
76
+ removeRoleAssignment();
77
+ }
78
+ });
79
+ }
80
+ }
81
+ RemoveRoleAssignment(logger, options, cb) {
82
+ const requestOptions = {
83
+ url: `${options.webUrl}/_api/web/roleassignments/removeroleassignment(principalid='${options.principalId}')`,
84
+ method: 'POST',
85
+ headers: {
86
+ 'accept': 'application/json;odata=nometadata',
87
+ 'content-type': 'application/json'
88
+ },
89
+ responseType: 'json'
90
+ };
91
+ request_1.default
92
+ .post(requestOptions)
93
+ .then(_ => cb(), (err) => this.handleRejectedODataJsonPromise(err, logger, cb));
94
+ }
95
+ GetGroupPrincipalId(options) {
96
+ const groupGetCommandOptions = {
97
+ webUrl: options.webUrl,
98
+ name: options.groupName,
99
+ output: 'json',
100
+ debug: this.debug,
101
+ verbose: this.verbose
102
+ };
103
+ return cli_1.Cli.executeCommandWithOutput(SpoGroupGetCommand, { options: Object.assign(Object.assign({}, groupGetCommandOptions), { _: [] }) })
104
+ .then((output) => {
105
+ const getGroupOutput = JSON.parse(output.stdout);
106
+ return Promise.resolve(getGroupOutput.Id);
107
+ }, (err) => {
108
+ return Promise.reject(err);
109
+ });
110
+ }
111
+ GetUserPrincipalId(options) {
112
+ const userGetCommandOptions = {
113
+ webUrl: options.webUrl,
114
+ email: options.upn,
115
+ id: undefined,
116
+ output: 'json',
117
+ debug: this.debug,
118
+ verbose: this.verbose
119
+ };
120
+ return cli_1.Cli.executeCommandWithOutput(SpoUserGetCommand, { options: Object.assign(Object.assign({}, userGetCommandOptions), { _: [] }) })
121
+ .then((output) => {
122
+ const getUserOutput = JSON.parse(output.stdout);
123
+ return Promise.resolve(getUserOutput.Id);
124
+ }, (err) => {
125
+ return Promise.reject(err);
126
+ });
127
+ }
128
+ }
129
+ _SpoWebRoleAssignmentRemoveCommand_instances = new WeakSet(), _SpoWebRoleAssignmentRemoveCommand_initTelemetry = function _SpoWebRoleAssignmentRemoveCommand_initTelemetry() {
130
+ this.telemetry.push((args) => {
131
+ Object.assign(this.telemetryProperties, {
132
+ principalId: typeof args.options.principalId !== 'undefined',
133
+ upn: typeof args.options.upn !== 'undefined',
134
+ groupName: typeof args.options.groupName !== 'undefined',
135
+ confirm: (!(!args.options.confirm)).toString()
136
+ });
137
+ });
138
+ }, _SpoWebRoleAssignmentRemoveCommand_initOptions = function _SpoWebRoleAssignmentRemoveCommand_initOptions() {
139
+ this.options.unshift({
140
+ option: '-u, --webUrl <webUrl>'
141
+ }, {
142
+ option: '--principalId [principalId]'
143
+ }, {
144
+ option: '--upn [upn]'
145
+ }, {
146
+ option: '--groupName [groupName]'
147
+ }, {
148
+ option: '--confirm'
149
+ });
150
+ }, _SpoWebRoleAssignmentRemoveCommand_initValidators = function _SpoWebRoleAssignmentRemoveCommand_initValidators() {
151
+ this.validators.push((args) => __awaiter(this, void 0, void 0, function* () {
152
+ const isValidSharePointUrl = utils_1.validation.isValidSharePointUrl(args.options.webUrl);
153
+ if (isValidSharePointUrl !== true) {
154
+ return isValidSharePointUrl;
155
+ }
156
+ if (args.options.principalId && isNaN(args.options.principalId)) {
157
+ return `Specified principalId ${args.options.principalId} is not a number`;
158
+ }
159
+ const principalOptions = [args.options.principalId, args.options.upn, args.options.groupName];
160
+ if (principalOptions.some(item => item !== undefined) && principalOptions.filter(item => item !== undefined).length > 1) {
161
+ return `Specify either principalId id or upn or groupName`;
162
+ }
163
+ if (principalOptions.filter(item => item !== undefined).length === 0) {
164
+ return `Specify at least principalId id or upn or groupName`;
165
+ }
166
+ return true;
167
+ }));
168
+ };
169
+ module.exports = new SpoWebRoleAssignmentRemoveCommand();
170
+ //# sourceMappingURL=web-roleassignment-remove.js.map
@@ -128,6 +128,7 @@ exports.default = {
128
128
  LISTITEM_RECORD_DECLARE: `${prefix} listitem record declare`,
129
129
  LISTITEM_RECORD_UNDECLARE: `${prefix} listitem record undeclare`,
130
130
  LISTITEM_REMOVE: `${prefix} listitem remove`,
131
+ LISTITEM_ROLEASSIGNMENT_REMOVE: `${prefix} listitem roleassignment remove`,
131
132
  LISTITEM_ROLEINHERITANCE_BREAK: `${prefix} listitem roleinheritance break`,
132
133
  LISTITEM_ROLEINHERITANCE_RESET: `${prefix} listitem roleinheritance reset`,
133
134
  LISTITEM_SET: `${prefix} listitem set`,
@@ -270,6 +271,8 @@ exports.default = {
270
271
  WEB_LIST: `${prefix} web list`,
271
272
  WEB_REINDEX: `${prefix} web reindex`,
272
273
  WEB_REMOVE: `${prefix} web remove`,
274
+ WEB_ROLEASSIGNMENT_REMOVE: `${prefix} web roleassignment remove`,
275
+ WEB_ROLEASSIGNMENT_ADD: `${prefix} web roleassignment add`,
273
276
  WEB_ROLEINHERITANCE_RESET: `${prefix} web roleinheritance reset`,
274
277
  WEB_SET: `${prefix} web set`
275
278
  };
package/dist/request.js CHANGED
@@ -128,7 +128,8 @@ class Request {
128
128
  return Promise.resolve('');
129
129
  }
130
130
  else {
131
- const resource = Auth_1.Auth.getResourceFromUrl(options.url);
131
+ const url = options.headers && options.headers['x-resource'] ? options.headers['x-resource'] : options.url;
132
+ const resource = Auth_1.Auth.getResourceFromUrl(url);
132
133
  return Auth_1.default.ensureAccessToken(resource, this._logger, this._debug);
133
134
  }
134
135
  })()
@@ -137,7 +138,10 @@ class Request {
137
138
  if (options.headers['x-anonymous']) {
138
139
  delete options.headers['x-anonymous'];
139
140
  }
140
- else {
141
+ if (options.headers['x-resource']) {
142
+ delete options.headers['x-resource'];
143
+ }
144
+ if (accessToken !== '') {
141
145
  options.headers.authorization = `Bearer ${accessToken}`;
142
146
  }
143
147
  }
@@ -116,23 +116,3 @@ Send custom card with card data
116
116
  ```sh
117
117
  m365 adaptivecard send --url https://contoso.webhook.office.com/webhookb2/892e8ed3-997c-4b6e-8f8a-7f32728a8a87@f7322380-f203-42ff-93e8-66e266f6d2e4/IncomingWebhook/fcc6565ec7a944928bd43d6fc193b258/4f0482d4-b147-4f67-8a61-11f0a5019547 --card '{"type":"AdaptiveCard","body":[{"type":"TextBlock","size":"Medium","weight":"Bolder","text":"${title}"},{"type":"TextBlock","text":"${description}","wrap":true},{"type":"FactSet","facts":[{"$data":"${properties}","title":"${key}:","value":"${value}"}]}],"actions":[{"type":"Action.OpenUrl","title":"View","url":"${viewUrl}"}],"$schema":"http://adaptivecards.io/schemas/adaptive-card.json","version":"1.2"}' --cardData '{"title":"Publish Adaptive Card Schema","description":"Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.","creator":{"name":"Matt Hidinger","profileImage":"https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg"},"createdUtc":"2017-02-14T06:08:39Z","viewUrl":"https://adaptivecards.io","properties":[{"key":"Board","value":"Adaptive Cards"},{"key":"List","value":"Backlog"},{"key":"Assigned to","value":"Matt Hidinger"},{"key":"Due date","value":"Not set"}]}'
118
118
  ```
119
-
120
- ## Examples for PowerShell
121
-
122
- Send custom card with all known options merged
123
-
124
- ```powershell
125
- m365 adaptivecard send --url https://contoso.webhook.office.com/webhookb2/892e8ed3-997c-4b6e-8f8a-7f32728a8a87@f7322380-f203-42ff-93e8-66e266f6d2e4/IncomingWebhook/fcc6565ec7a944928bd43d6fc193b258/4f0482d4-b147-4f67-8a61-11f0a5019547 --card "{\"type\":\"AdaptiveCard\",\"body\":[{\"type\":\"TextBlock\",\"size\":\"Medium\",\"weight\":\"Bolder\",\"text\":\"${title}\"},{\"type\":\"TextBlock\",\"text\":\"${description}\",\"wrap\":true},{\"type\":\"FactSet\",\"facts\":[{\"$data\":\"${properties}\",\"title\":\"${key}:\",\"value\":\"${value}\"}]}],\"actions\":[{\"type\":\"Action.OpenUrl\",\"title\":\"View\",\"url\":\"${actionUrl}\"}],\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"version\":\"1.2\"}" --title "CLI for Microsoft 365 v3.4" --description "New release of CLI for Microsoft 365" --imageUrl "https://contoso.com/image.gif" --actionUrl "https://aka.ms/cli-m365"
126
- ```
127
-
128
- Send custom card with unknown option merged
129
-
130
- ```powershell
131
- m365 adaptivecard send --url https://contoso.webhook.office.com/webhookb2/892e8ed3-997c-4b6e-8f8a-7f32728a8a87@f7322380-f203-42ff-93e8-66e266f6d2e4/IncomingWebhook/fcc6565ec7a944928bd43d6fc193b258/4f0482d4-b147-4f67-8a61-11f0a5019547 --card "{\"type\":\"AdaptiveCard\",\"body\":[{\"type\":\"TextBlock\",\"size\":\"Medium\",\"weight\":\"Bolder\",\"text\":\"${Title}\"}],\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"version\":\"1.2\"}" --Title "CLI for Microsoft 365 v3.4"
132
- ```
133
-
134
- Send custom card with card data
135
-
136
- ```powershell
137
- m365 adaptivecard send --url https://contoso.webhook.office.com/webhookb2/892e8ed3-997c-4b6e-8f8a-7f32728a8a87@f7322380-f203-42ff-93e8-66e266f6d2e4/IncomingWebhook/fcc6565ec7a944928bd43d6fc193b258/4f0482d4-b147-4f67-8a61-11f0a5019547 --card "{\"type\":\"AdaptiveCard\",\"body\":[{\"type\":\"TextBlock\",\"size\":\"Medium\",\"weight\":\"Bolder\",\"text\":\"${title}\"},{\"type\":\"TextBlock\",\"text\":\"${description}\",\"wrap\":true},{\"type\":\"FactSet\",\"facts\":[{\"$data\":\"${properties}\",\"title\":\"${key}:\",\"value\":\"${value}\"}]}],\"actions\":[{\"type\":\"Action.OpenUrl\",\"title\":\"View\",\"url\":\"${viewUrl}\"}],\"$schema\":\"http://adaptivecards.io/schemas/adaptive-card.json\",\"version\":\"1.2\"}" --cardData "{\"title\":\"Publish Adaptive Card Schema\",\"description\":\"Now that we have defined the main rules and features of the format, we need to produce a schema and publish it to GitHub. The schema will be the starting point of our reference documentation.\",\"creator\":{\"name\":\"Matt Hidinger\",\"profileImage\":\"https://pbs.twimg.com/profile_images/3647943215/d7f12830b3c17a5a9e4afcc370e3a37e_400x400.jpeg\"},\"createdUtc\":\"2017-02-14T06:08:39Z\",\"viewUrl\":\"https://adaptivecards.io\",\"properties\":[{\"key\":\"Board\",\"value\":\"Adaptive Cards\"},{\"key\":\"List\",\"value\":\"Backlog\"},{\"key\":\"Assigned to\",\"value\":\"Matt Hidinger\"},{\"key\":\"Due date\",\"value\":\"Not set\"}]}"
138
- ```