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 |
|---|---|---|---|
|
|
— |
Either an ECM model instance (its |
|
|
|
The numeric object type ID. If |
|
|
|
Check for read index data permission ( |
|
|
|
Check for write index data permission ( |
|
|
|
Check for open/execute permission ( |
|
|
|
Check for delete permission ( |
|
|
|
Check for update object permission ( |
|
|
|
ID of the folder or an |
|
|
|
ID of the parent register or an |
|
|
|
Type of the parent register. |
At least one of read, write, execute, delete, or update must be True.
|
3. Access flags
| Flag | Parameter | Description |
|---|---|---|
|
|
Read index data of the object. |
|
|
Write index data of the object. |
|
|
Open or execute the object. |
|
|
Delete the object. |
|
|
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 |
|---|---|---|
|
|
All five permissions granted. |
|
|
Only read and update granted. |
|
|
No permission granted. |
|
|
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 |
|---|---|
|
|
|
|
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
-
check_insert_permission() — May an object be inserted here?
-
delete() — Delete an object
-
insert() — Create a new object