Back to Devexpress

RangePermissionCollection Class

aspnetcore-js-devexpress-dot-richedit-e6e203ea.md

latest7.8 KB
Original Source

RangePermissionCollection Class

A collection of RangePermission objects.

Declaration

ts
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

count

getByIndex(index)

Inheritance

Collection<T> RangePermissionCollection

Methods

create(interval) Method

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

Declaration

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

Parameters

NameTypeDescription
intervalIInterval

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

TypeDescription
RangePermission

The newly created range permission.

|

Remarks

Allow a user/group to edit a range.
js
richEdit.document.rangePermissions.create({ start: 0, length: richEdit.document.paragraphs.getByIndex(5).interval.end}, '[email protected]');
richEdit.document.rangePermissions.create(richEdit.document.paragraphs.getByIndex(6).interval, '', 'editors');
Allow a user/group to edit the entire document.
js
richEdit.document.rangePermissions.create(richEdit.document.interval, '[email protected]');
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.

js
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

ts
find(
    options: IRangePermissionSearchOptions
): RangePermission[]

Parameters

NameTypeDescription
optionsIRangePermissionSearchOptions

An object that specifies range permission options.

|

Returns

TypeDescription
RangePermission[]

An array of range permissions.

|

Remarks

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

isAllowEdit(position) Method

Indicates whether the specified range can be edited.

Declaration

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

Parameters

NameTypeDescription
positionnumberIInterval

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

|

Returns

TypeDescription
boolean

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

|

Remarks

js
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

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

Parameters

NameTypeDescription
intervalsIInterval[]

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

TypeDescription
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.

js
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.

js
// 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
js
richEdit.document.rangePermissions.protectRange([{ start: 0, length: 178}, { start: 325, length: 561}], '[email protected]');
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.

js
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.