[]
        
(Showing Draft Content)

Permissions

SpreadJS Sheets Coollaboration provides two document modes: View Mode and Edit Mode. Through the Permissions feature, the workbook can configure specific operational permissions in View Mode, striking a balance between flexibility and security in a collaborative environment.

Functionality Description

IPermission

The IPermission interface defines the specific permissions of a workbook, including the following properties:

  • mode: BrowsingMode

    Specifies the workbook access mode, taking values from the BrowsingMode enum:

    • BrowsingMode.edit: The workbook is editable.

    • BrowsingMode.view: The workbook is view-only but may have additional permissions.

  • viewModePermissions: PermissionTypes (optional)

    Specifies additional permissions when the workbook is in view mode. This property is a bit field, allowing multiple PermissionTypes values to be combined using bitwise operations.

export type IPermission {
    mode: GC.Spread.Sheets.Collaboration.BrowsingMode;
    viewModePermissions?: GC.Spread.Sheets.Collaboration.PermissionTypes;
}

Enumeration Types

BrowsingMode

Defines the workbook's browsing mode:

  • edit = 0: Edit mode, where the workbook can be modified.

    view = 1: View mode, where the workbook is read-only.

/**
 * Enumerates the browsing modes for document interaction.
 * @enum {number}
 */
export enum BrowsingMode {
    /** The workbook is editable.
     * @type {number}
     */
    edit,
    /** The workbook is view-only.
     * @type {number}
     */
    view,
}

Edit Mode

  • The workbook has unrestricted editing permissions.

  • All modifications are synchronized in real-time with other collaborators.

  • This is the default mode for workbook.

View Mode

  • The workbook is view-only.

  • Certain UI operations (e.g., hiding rows, adjusting column width) can be enabled via permissions, but these operations only take effect locally and are not synchronized.

  • In View Mode, by default, all reversible commands are disabled. However, users can customize the following permissions to allow specific operations, optimizing the viewing experience without compromising data integrity:

    • allowNonDataModifyingOperations: Allows viewer could execute non-data modifying operations.

    • allowHideRowsOrColumns: Allows hiding or showing rows or columns.

    • allowResizeRowsOrColumns: Allows resizing rows or columns.

    • allowFilter: Allows filtering data.

    • allowSort: Allows sorting data.

Policy Points

  • In View Mode, all Command operations (including built-in commands and custom Commands) are restricted, but APIs are not limited.

  • In View Mode, any data changes resulting from permission-enabled operations take effect only locally and are not synchronized.

Application Scenarios

  • Data Viewing: The workbook in View Mode can adjust the UI (e.g., hide rows, filter data) to analyze data without affecting other users’ workbooks.

  • Security: Fine-grained permission controls prevent unauthorized modifications, protecting data in the collaborative environment.

  • Team Collaboration: Combined with status tracking, users can see others’ operations while retaining control over their own capabilities.

Methods

Users can bind user information to the workbook using the UserManager.current and setPermission method or simultaneously bind presence and user information to the workbook using the bindPresence method.

Usage

The following example demonstrates how to set the active user and workbook permission to View Mode and allow them to hide/show rows/columns, resize rows/columns, and filter data:

  • Initialize workbook and user information.

    //Set current user.
    GC.Spread.Common.UserManager.current("896736#B1WZd2yQ");
    
    const workbook = new GC.Spread.Sheets.Workbook("ss");
    //Set the workbook permission.
    workbook.collaboration.setPermission({
      mode: GC.Spread.Sheets.Collaboration.BrowsingMode.view,
      viewModePermissions: GC.Spread.Sheets.Collaboration.PermissionTypes.allowHideRowsOrColumns
        | GC.Spread.Sheets.Collaboration.PermissionTypes.allowResizeRowsOrColumns
        | GC.Spread.Sheets.Collaboration.PermissionTypes.allowFilter
    });
  • Bind both presence and user information with permission information to the workbook.

    const presence = new Presence<IPresence>(conn);
    const workbook = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 2 });
    const user = {
        id: "896736#B1WZd2yQ",
        name: "chris",
        color: "#FF0000",
        permission: {
          mode: GC.Spread.Sheets.Collaboration.BrowsingMode.view,
          viewModePermissions: GC.Spread.Sheets.Collaboration.PermissionTypes.allowHideRowsOrColumns
          | GC.Spread.Sheets.Collaboration.PermissionTypes.allowResizeRowsOrColumns
          | GC.Spread.Sheets.Collaboration.PermissionTypes.allowFilter
        }
    };
    bindPresence(workbook, presence, user);