@pnp/cli-microsoft365
Version:
Manage Microsoft 365 and SharePoint Framework projects on any platform
88 lines • 4.17 kB
JavaScript
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
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");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _VivaEngageGroupUserRemoveCommand_instances, _VivaEngageGroupUserRemoveCommand_initTelemetry, _VivaEngageGroupUserRemoveCommand_initOptions, _VivaEngageGroupUserRemoveCommand_initValidators;
import { cli } from '../../../../cli/cli.js';
import request from '../../../../request.js';
import VivaEngageCommand from "../../../base/VivaEngageCommand.js";
import commands from '../../commands.js';
class VivaEngageGroupUserRemoveCommand extends VivaEngageCommand {
get name() {
return commands.ENGAGE_GROUP_USER_REMOVE;
}
get description() {
return 'Removes a user from a Viva Engage group';
}
constructor() {
super();
_VivaEngageGroupUserRemoveCommand_instances.add(this);
__classPrivateFieldGet(this, _VivaEngageGroupUserRemoveCommand_instances, "m", _VivaEngageGroupUserRemoveCommand_initTelemetry).call(this);
__classPrivateFieldGet(this, _VivaEngageGroupUserRemoveCommand_instances, "m", _VivaEngageGroupUserRemoveCommand_initOptions).call(this);
__classPrivateFieldGet(this, _VivaEngageGroupUserRemoveCommand_instances, "m", _VivaEngageGroupUserRemoveCommand_initValidators).call(this);
}
async commandAction(logger, args) {
if (args.options.force) {
await this.executeRemoveAction(args.options);
}
else {
let messagePrompt = `Are you sure you want to leave group ${args.options.groupId}?`;
if (args.options.id) {
messagePrompt = `Are you sure you want to remove the user ${args.options.id} from the group ${args.options.groupId}?`;
}
const result = await cli.promptForConfirmation({ message: messagePrompt });
if (result) {
await this.executeRemoveAction(args.options);
}
}
}
async executeRemoveAction(options) {
const requestOptions = {
url: `${this.resource}/v1/group_memberships.json`,
headers: {
accept: 'application/json;odata.metadata=none',
'content-type': 'application/json;odata=nometadata'
},
responseType: 'json',
data: {
group_id: options.groupId,
user_id: options.id
}
};
try {
await request.delete(requestOptions);
}
catch (err) {
this.handleRejectedODataJsonPromise(err);
}
}
}
_VivaEngageGroupUserRemoveCommand_instances = new WeakSet(), _VivaEngageGroupUserRemoveCommand_initTelemetry = function _VivaEngageGroupUserRemoveCommand_initTelemetry() {
this.telemetry.push((args) => {
Object.assign(this.telemetryProperties, {
userId: args.options.id !== undefined,
force: (!(!args.options.force)).toString()
});
});
}, _VivaEngageGroupUserRemoveCommand_initOptions = function _VivaEngageGroupUserRemoveCommand_initOptions() {
this.options.unshift({
option: '--groupId <groupId>'
}, {
option: '--id [id]'
}, {
option: '-f, --force'
});
}, _VivaEngageGroupUserRemoveCommand_initValidators = function _VivaEngageGroupUserRemoveCommand_initValidators() {
this.validators.push(async (args) => {
if (args.options.groupId && typeof args.options.groupId !== 'number') {
return `${args.options.groupId} is not a number`;
}
if (args.options.id && typeof args.options.id !== 'number') {
return `${args.options.id} is not a number`;
}
return true;
});
};
export default new VivaEngageGroupUserRemoveCommand();
//# sourceMappingURL=engage-group-user-remove.js.map