Excel.SensitivityLabelTryUpdateOptions interface

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

为以下选项提供选项 SensitivityLabel.tryToUpdate。

注解

API 集:ExcelApi BETA (仅预览版)

使用方

示例

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/98-preview-apis/manage-sensitivity-labels.yaml

// Apply the selected sensitivity label with the chosen ABAC attribute values.
await Excel.run(async (context) => {
    const labelId = (document.getElementById("label-id") as HTMLSelectElement).value;
    if (!labelId) {
        console.warn("Get available labels and select a label first.");
        return;
    }

    const attributeControls = document.getElementById("abac-attributes")
        .querySelectorAll<HTMLSelectElement>("select");
    if (attributeControls.length === 0) {
        console.warn("Get catalog attributes and select attribute values first.");
        return;
    }

    const labelCatalog: Excel.SensitivityLabelsCatalog = context.sensitivityLabelsCatalog;
    if (!labelCatalog) {
        console.warn("The sensitivity label catalog isn't available in this version of Excel.");
        return;
    }

    labelCatalog.load("getLabelingCapabilities");
    await context.sync();
    if (labelCatalog.getLabelingCapabilities.indexOf(Excel.LabelingCapability.attributeBasedAccessControlEnabled) === -1) {
        console.warn("ABAC attributes aren't enabled or available for the current user.");
        return;
    }

    // Refresh the catalog to validate selections against the current policy.
    const catalogAttributes: OfficeExtension.ClientResult<Excel.SensitivityLabelAbacAttribute[]> =
        labelCatalog.getAttributes();
    await context.sync();

    const selectedAttributes: Excel.SensitivityLabelAbacAttribute[] = [];
    for (const select of Array.from(attributeControls)) {
        const selectedIds = Array.from(select.selectedOptions)
            .map((option) => option.value).filter((id) => id !== "");
        if (selectedIds.length === 0) {
            continue;
        }

        const attribute: Excel.SensitivityLabelAbacAttribute | undefined =
            catalogAttributes.value.find((attribute) => attribute.displayName === select.name);
        if (!attribute || !attribute.isActive || (!attribute.isMultiValued && selectedIds.length > 1)) {
            console.warn("The attribute selections are no longer valid. Get catalog attributes and select values again.");
            return;
        }

        const selectedValues: Excel.SensitivityLabelAbacAttributeValue[] =
            attribute.values.filter((value) => value.isActive && selectedIds.indexOf(value.id) !== -1);
        if (selectedValues.length !== selectedIds.length) {
            console.warn("The attribute selections are no longer valid. Get catalog attributes and select values again.");
            return;
        }

        const selectedAttribute: Excel.SensitivityLabelAbacAttribute = {
            ...attribute,
            values: selectedValues
        };
        selectedAttributes.push(selectedAttribute);
    }

    if (selectedAttributes.length === 0) {
        console.warn("Select at least one ABAC attribute value first.");
        return;
    }

    const options: Excel.SensitivityLabelTryUpdateOptions = {
        abacAttributes: selectedAttributes
    };
    const workbook: Excel.Workbook = context.workbook;
    const workbookLabel: Excel.SensitivityLabel = workbook.sensitivityLabel;
    const updateResult: OfficeExtension.ClientResult<Excel.SensitivityLabelUpdateResult> =
        workbookLabel.tryToUpdate(labelId, options);
    await context.sync();

    if (updateResult.value.status === Excel.SensitivityLabelUpdateStatus.success) {
        console.log("Applied the sensitivity label and ABAC attributes to the workbook.");
    } else {
        console.error(`The sensitivity label wasn't applied. Status: ${updateResult.value.status}`);
    }
});

属性

abacAttributes

如果提供,则指定要与标签一起应用的基于属性 (ABAC) 属性的访问控制。 对于未启用 ABAC 的标签,必须省略或为空;否则,更新结果将为 statusSensitivityLabelUpdateStatus.abacAttributesNotAllowed。 如果目标标签已启用 ABAC 且 SensitivityLabelDetails.isAbacAttributesRequired 为 true.

属性详细信息

abacAttributes

注意

此 API 以预览状态提供给开发者,可能根据我们收到的反馈更改。 请勿在生产环境中使用此 API。

如果提供,则指定要与标签一起应用的基于属性 (ABAC) 属性的访问控制。 对于未启用 ABAC 的标签,必须省略或为空;否则,更新结果将为 statusSensitivityLabelUpdateStatus.abacAttributesNotAllowed。 如果目标标签已启用 ABAC 且 SensitivityLabelDetails.isAbacAttributesRequired 为 true.

abacAttributes?: Excel.SensitivityLabelAbacAttribute[];

属性值

注解

API 集:ExcelApi BETA (仅预览版)