check_permission()

Checks whether the current user has the requested permissions on an object. One DMS.CheckPermission is sent, carrying every requested permission in its Access string.

To check whether an object may be inserted at a location, use check_insert_permission().

1. Signature

  • Sync

  • Async

ecm.dms.check_permission(
    model: _ECMModelBase | int | str,
    object_type_id: int | str | None = None,
    *,
    read: bool = False,
    write: bool = False,
    execute: bool = False,
    delete: bool = False,
    update: bool = False,
    folder_id: int | str | ECMFolderModel | None = None,
    register_id: int | str | ECMRegisterModel | None = None,
    register_type: int | str | None = None,
) -> bool
await ecm.dms.check_permission(
    model: _ECMModelBase | int | str,
    object_type_id: int | str | None = None,
    *,
    read: bool = False,
    write: bool = False,
    execute: bool = False,
    delete: bool = False,
    update: bool = False,
    folder_id: int | str | ECMFolderModel | None = None,
    register_id: int | str | ECMRegisterModel | None = None,
    register_type: int | str | None = None,
) -> bool

2. Parameters

Parameter Type Default Description

model

_ECMModelBase | int | str

 — 

Either an ECM model instance (its id is used) or a plain integer object ID.

object_type_id

int | str | None

None

The numeric object type ID. If None, the type is extracted from the model instance when available, or resolved via get_object_type_by_id() for plain integer IDs.

read

bool

False

Check for read index data permission (R).

write

bool

False

Check for write index data permission (W).

execute

bool

False

Check for open/execute permission (X).

delete

bool

False

Check for delete permission (D).

update

bool

False

Check for update object permission (U).

folder_id

int | str | ECMFolderModel | None

None

ID of the folder or an ECMFolderModel instance for location-based permission checks.

register_id

int | str | ECMRegisterModel | None

None

ID of the parent register or an ECMRegisterModel instance for location-based permission checks.

register_type

int | str | None

None

Type of the parent register. 0 means the object is directly at folder level, -1 means register-independent.

At least one of read, write, execute, delete, or update must be True.

3. Access flags

Flag Parameter Description

R

read

Read index data of the object.

W

write

Write index data of the object.

X

execute

Open or execute the object.

D

delete

Delete the object.

U

update

Update the object (replace files).

All requested flags travel in a single DMS.CheckPermission call. The batch job DMS.CheckPermissions is not used: it expects numbered ObjectType<n> / ObjectList<n> parameters and answers a single-object request with return code 0 and no output at all.

4. How the server reports the verdict

DMS.CheckPermission answers with return code 0 whether the permissions exist or not. The verdict is in its Access output parameter: every granted permission is echoed in place, every denied one is replaced by -.

Sent Access Returned Access Meaning

RWXDU

RWXDU

All five permissions granted.

RWXDU

R---U

Only read and update granted.

RWXDU

-----

No permission granted.

D

-

Delete denied.

A non-zero return code is therefore not the denial channel. An error from the server stays an exception and is never folded into a False.
With an explicit object_type_id the server answers an unknown object ID or a wrong type the same way as a denial: return code 0 and - in every position, so the result is False (measured on enaio 12.0). Only the automatic type resolution raises ECMNotFoundException for an unknown ID. Leave object_type_id out when a missing object must be told apart from a denied one.

5. Return value

True if the user has all requested permissions, False otherwise. An absent or malformed Access output counts as denied, so an unreadable verdict never widens access.

6. Exceptions

Exception Condition

ValueError

model is a model instance with id set to None, none of the permission flags is True, or model is 0 without an object_type_id — object type 0 is a real folder type, not a neutral placeholder, so the insert check needs check_insert_permission().

ECMNotFoundException

object_type_id is None and no object with the given ID exists on the server. With an explicit type the same case returns False, see above.

7. Examples

7.1. Check read permission on a document

  • Sync

  • Async

doc = ecm.dms.get(InvoiceDocument, 12345)
if ecm.dms.check_permission(doc, read=True):
    print("Read access granted")
doc = await ecm.dms.get(InvoiceDocument, 12345)
if await ecm.dms.check_permission(doc, read=True):
    print("Read access granted")

7.2. Check multiple permissions at once

  • Sync

  • Async

if ecm.dms.check_permission(12345, read=True, write=True, delete=True):
    print("Full access")
else:
    print("Restricted access")
if await ecm.dms.check_permission(12345, read=True, write=True, delete=True):
    print("Full access")
else:
    print("Restricted access")

8. See also