Skip to content

Commit 2469971

Browse files
authored
DOCSP-35175 Refresh permissions when custom user data changes (#796)
* DOCSP-35175 Refresh permissions when custom user data changes * add link to permssions docs * remaining edits * better example * r=fix formatting * edit * edit * edit * tech edits * tech review comments * title update * shorter title * typo * tech review comments * title change * title change * placement * title
1 parent f951462 commit 2469971

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

source/users/custom-metadata.txt

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,65 @@ Atlas Device SDKs:
390390
- :ref:`Swift SDK <ios-custom-user-data>`
391391
- :ref:`Web SDK <web-access-custom-user-data>`
392392

393+
Best Practices for Modifying Permissions in Custom User Data
394+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
395+
396+
:ref:`Permissions <permissions>` will automatically refresh for a user when you
397+
change their custom user data document. Their :ref:`user session <user-sessions>`
398+
will terminate and then refresh automatically.
399+
400+
For user permissions to refresh automatically, the custom user data
401+
documents should be stored in a normal collection and
402+
not in a :manual:`view </core/views/>` or :manual:`time series </core/timeseries-collections/>` collection.
403+
404+
For permissions to refresh automatically, don't delete a custom user data document.
405+
Rather, unset all the non-ID fields in the document.
406+
407+
.. example::
408+
409+
Consider the following document where the user is assigned read and write
410+
permissions:
411+
412+
.. code-block:: json
413+
:caption: Custom user data document
414+
415+
{
416+
"_id": "63ed2erealobjectid78e526",
417+
"user_id": "63ed2dbe5960df2af7fd216e",
418+
"canRead": true,
419+
"canWrite": true,
420+
}
421+
422+
The ``canRead`` and ``canWrite`` fields can help determine the roles for this document's
423+
collection. For example, the ``canRead`` field is used to determine eligibility
424+
for the following ``readAllRole`` in the ``apply_when`` expression:
425+
426+
.. code-block:: json
427+
:caption: Custom user data document
428+
429+
{
430+
"name": "readAllRole"
431+
"apply_when": {"%%user.custom_data.canRead": true},
432+
...
433+
}
434+
435+
Say you would like to remove the user's document
436+
because they haven't been active for an extended period of time.
437+
First, you need to correctly remove the employee's permissions, by unsetting
438+
the non-ID fields. The document would then look like:
439+
440+
.. code-block:: json
441+
:caption: Correctly updated custom user data document
442+
443+
{
444+
"_id": "63ed2erealobjectid78e526",
445+
"user_id": "63ed2dbe5960df2af7fd216e"
446+
}
447+
448+
Unsetting the non-ID field allows App Services to automatically
449+
refresh the user's permissions according to the roles.
450+
You can now safely delete the document if necessary.
451+
393452
.. _auth-provider-metadata:
394453

395454
Authentication Provider Metadata

0 commit comments

Comments
 (0)