Skip to main content
All docs
V25.1
  • RangePermissionCollection Class

    A collection of RangePermission objects.

    Declaration

    export class RangePermissionCollection extends Collection<RangePermission>

    Remarks

    Range permissions are in effect when a document is protected. To protect a document, use the protect(password) method.

    Inherited Members

    Inheritance

    Collection<T>
    RangePermissionCollection

    Methods

    create(interval) Method

    Creates a range permission that allows a user/group to edit the specified interval.

    Declaration

    create(
        interval: IInterval,
        userName?: string,
        group?: string
    ): RangePermission

    Parameters

    Name Type Description
    interval IInterval

    An object that specifies the permitted range.

    userName string

    The name of the user with edit permission.

    group string

    The name of the user group with edit permission.

    Returns

    Type Description
    RangePermission

    The newly created range permission.

    Remarks

    Allow a user/group to edit a range.
    richEdit.document.rangePermissions.create({ start: 0, length: richEdit.document.paragraphs.getByIndex(5).interval.end}, 'projectmanager@somecompany.com');
    richEdit.document.rangePermissions.create(richEdit.document.paragraphs.getByIndex(6).interval, '', 'editors');
    
    Allow a user/group to edit the entire document.
    richEdit.document.rangePermissions.create(richEdit.document.interval, 'projectmanager@somecompany.com');
    richEdit.document.rangePermissions.create(richEdit.document.interval, '', 'owners');
    
    Allow everyone to edit a range.

    Use the everyone predefined group to allow every user to edit the specified range.

    richEdit.document.rangePermissions.create(richEdit.document.paragraphs.getByIndex(10).interval, '', 'everyone');
    // or
    richEdit.document.rangePermissions.create(richEdit.document.paragraphs.getByIndex(10).interval);
    

    Refer to the following help topic for more information: Document Protection.

    find(options) Method

    Returns a range permission array that matches the specified options.

    Declaration

    find(
        options: IRangePermissionSearchOptions
    ): RangePermission[]

    Parameters

    Name Type Description
    options IRangePermissionSearchOptions

    An object that specifies range permission options.

    Returns

    Type Description
    RangePermission[]

    An array of range permissions.

    Remarks

    var everyoneRangePermissions = richEdit.document.rangePermissions.find({group: 'everyone'});
    

    isAllowEdit(position) Method

    Indicates whether the specified range can be edited.

    Declaration

    isAllowEdit(
        position: number | IInterval | IInterval[]
    ): boolean

    Parameters

    Name Type Description
    position number | IInterval | IInterval[]

    A document position, an interval, or an array of intervals.

    Returns

    Type Description
    boolean

    true, if the specified range can be edited; false if the specified range is protected or contains protected intervals.

    Remarks

    richEdit.document.rangePermissions.isAllowEdit(richEdit.selection.active);
    richEdit.document.rangePermissions.isAllowEdit(richEdit.document.paragraphs.getByIndex(4).interval);
    

    protectRange(intervals) Method

    Creates range permissions that protect the specified interval from being edited.

    Declaration

    protectRange(
        intervals: IInterval[],
        userName?: string,
        group?: string
    ): RangePermission[]

    Parameters

    Name Type Description
    intervals IInterval[]

    An object that specifies the protected range.

    userName string

    The name of the user who is prohibited from editing the range.

    group string

    The name of the user group that is prohibited from editing the range.

    Returns

    Type Description
    RangePermission[]

    An array of newly created range permissions.

    Remarks

    The protectRange method creates range permissions (objects of the RangePermission type) that prevent the specified document range from being edited. You can specify the user or a group of users who are prohibited from editing the range.

    Call the protect(password) method to enable document protection.

    How It Works

    A RangePermission object specifies a permissions rule. When you call the protectRange method, RichEdit creates range permissions that allow a user/group to edit a document outside of the specified range.

    richEdit.document.rangePermissions.protectRange([{ start: 10, length: 20}]);
    // equals
    richEdit.document.rangePermissions.create({ start: 0, length: 10});
    richEdit.document.rangePermissions.create({ start: 30, length: richEdit.document.interval.end});
    
    Protect multiple ranges

    To protect multiple ranges, call the protectRange method once with an array of protected intervals as a parameter. Otherwise, if you call the method several times for one user/group, the allowed intervals can overlap and the range permissions do not work.

    // protects fields from being edited
    var protectedRanges = [];
    var count = document.fields.count;
    for (var i = 0; i < count; i++) {
        var field = document.fields.getByIndex(i);
        protectedRanges.push(field.interval);
    }
    document.rangePermissions.protectRange(protectedRanges);
    
    Prevent a user/group from editing a range
    richEdit.document.rangePermissions.protectRange([{ start: 0, length: 178}, { start: 325, length: 561}], 'lawyer@somecompany.com');
    richEdit.document.rangePermissions.protectRange([richEdit.document.paragraphs.getByIndex(6).interval], '', 'editors');
    
    Prevent everyone from editing a range

    Use the everyone predefined group to prevent every user from editing the specified range.

    richEdit.document.rangePermissions.protectRange([richEdit.document.paragraphs.getByIndex(10).interval], '', 'everyone');
    // or
    richEdit.document.rangePermissions.protectRange([richEdit.document.paragraphs.getByIndex(10).interval]);
    

    Refer to the following help topic for more information: Document Protection.