UNPKG

@pnp/cli-microsoft365

Version:

Manage Microsoft 365 and SharePoint Framework projects on any platform

133 lines 5.71 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().optional().alias('c'), defaultClassification: z.string().optional().alias('d'), usageGuidelinesUrl: z.string().optional().alias('u'), guestUsageGuidelinesUrl: z.string().optional().alias('g') }); class EntraSiteClassificationSetCommand extends GraphCommand { get name() { return commands.SITECLASSIFICATION_SET; } get description() { return 'Updates site classification configuration'; } get schema() { return options; } getRefinedSchema(schema) { return schema .refine(options => options.classifications || options.defaultClassification || options.usageGuidelinesUrl || options.guestUsageGuidelinesUrl, { error: 'Specify at least one property to update', params: { customCode: 'required' } }); } async commandAction(logger, args) { try { let requestOptions = { url: `${this.resource}/v1.0/groupSettings`, 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 "There is no previous defined site classification which can updated."; } const updatedDirSettings = { values: [] }; unifiedGroupSetting[0].values.forEach((directorySetting) => { switch (directorySetting.name) { case "ClassificationList": if (args.options.classifications) { updatedDirSettings.values.push({ name: directorySetting.name, value: args.options.classifications }); } else { updatedDirSettings.values.push({ name: directorySetting.name, value: directorySetting.value }); } break; case "DefaultClassification": if (args.options.defaultClassification) { updatedDirSettings.values.push({ name: directorySetting.name, value: args.options.defaultClassification }); } else { updatedDirSettings.values.push({ name: directorySetting.name, value: directorySetting.value }); } 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.value }); } 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.value }); } break; default: updatedDirSettings.values.push({ name: directorySetting.name, value: directorySetting.value }); break; } }); requestOptions = { url: `${this.resource}/v1.0/groupSettings/${unifiedGroupSetting[0].id}`, headers: { accept: 'application/json;odata.metadata=none', 'content-type': 'application/json' }, responseType: 'json', data: updatedDirSettings }; await request.patch(requestOptions); } catch (err) { this.handleRejectedODataJsonPromise(err); } } } export default new EntraSiteClassificationSetCommand(); //# sourceMappingURL=siteclassification-set.js.map