UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

108 lines 4.63 kB
import { z } from 'zod'; import { globalOptionsZod } from '../../../../Command.js'; import request from '../../../../request.js'; import GraphCommand from '../../../base/GraphCommand.js'; import commands from '../../commands.js'; export const options = z.strictObject({ ...globalOptionsZod.shape, classifications: z.string().alias('c'), defaultClassification: z.string().alias('d'), usageGuidelinesUrl: z.string().optional().alias('u'), guestUsageGuidelinesUrl: z.string().optional().alias('g') }); class EntraSiteClassificationEnableCommand extends GraphCommand { get name() { return commands.SITECLASSIFICATION_ENABLE; } get description() { return 'Enables site classification configuration'; } get schema() { return options; } async commandAction(logger, args) { try { let requestOptions = { url: `${this.resource}/v1.0/groupSettingTemplates`, headers: { accept: 'application/json;odata.metadata=none' }, responseType: 'json' }; const res = await request.get(requestOptions); const unifiedGroupSetting = res.value.filter((directorySetting) => { return directorySetting.displayName === 'Group.Unified'; }); if (!unifiedGroupSetting || unifiedGroupSetting.length === 0) { throw "Missing DirectorySettingTemplate for \"Group.Unified\""; } const updatedDirSettings = { values: [], templateId: unifiedGroupSetting[0].id }; unifiedGroupSetting[0].values.forEach((directorySetting) => { switch (directorySetting.name) { case "ClassificationList": updatedDirSettings.values.push({ "name": directorySetting.name, "value": args.options.classifications }); break; case "DefaultClassification": updatedDirSettings.values.push({ "name": directorySetting.name, "value": args.options.defaultClassification }); break; case "UsageGuidelinesUrl": if (args.options.usageGuidelinesUrl) { updatedDirSettings.values.push({ "name": directorySetting.name, "value": args.options.usageGuidelinesUrl }); } else { updatedDirSettings.values.push({ "name": directorySetting.name, "value": directorySetting.defaultValue }); } break; case "GuestUsageGuidelinesUrl": if (args.options.guestUsageGuidelinesUrl) { updatedDirSettings.values.push({ "name": directorySetting.name, "value": args.options.guestUsageGuidelinesUrl }); } else { updatedDirSettings.values.push({ "name": directorySetting.name, "value": directorySetting.defaultValue }); } break; default: updatedDirSettings.values.push({ "name": directorySetting.name, "value": directorySetting.defaultValue }); break; } }); requestOptions = { url: `${this.resource}/v1.0/groupSettings`, headers: { accept: 'application/json;odata.metadata=none', 'content-type': 'application/json' }, responseType: 'json', data: updatedDirSettings }; await request.post(requestOptions); } catch (err) { this.handleRejectedODataJsonPromise(err); } } } export default new EntraSiteClassificationEnableCommand(); //# sourceMappingURL=siteclassification-enable.js.map