From 1757e01eca4fdd6db8dbc55633c02bc54cfc1b7d Mon Sep 17 00:00:00 2001 From: "Simon Genin (ges)" Date: Thu, 21 Oct 2021 09:46:30 +0000 Subject: [PATCH] [Add] developer: add js user service closes odoo/documentation#1202 Signed-off-by: Simon Genin (ges@odoo) --- .../javascript/framework_overview.rst | 2 + .../reference/javascript/services.rst | 95 ++++++++++++++++++- 2 files changed, 96 insertions(+), 1 deletion(-) diff --git a/content/developer/reference/javascript/framework_overview.rst b/content/developer/reference/javascript/framework_overview.rst index 2917e1763..a42792807 100644 --- a/content/developer/reference/javascript/framework_overview.rst +++ b/content/developer/reference/javascript/framework_overview.rst @@ -189,6 +189,8 @@ could mean a different thing depending on the situation). not to overuse it! Many problems can be solved in a standard way without modifying the context. +.. _javascript/user-context: + User Context ------------ diff --git a/content/developer/reference/javascript/services.rst b/content/developer/reference/javascript/services.rst index 4912c2d88..95d26cd48 100644 --- a/content/developer/reference/javascript/services.rst +++ b/content/developer/reference/javascript/services.rst @@ -184,4 +184,97 @@ When a rpc fails, then: If it is a network error, then the error description is simply an object ``{type: 'network'}``. When a network error occurs, a notification is displayed and the server is regularly - contacted until it responds. The notification is closed as soon as the server responds. \ No newline at end of file + contacted until it responds. The notification is closed as soon as the server responds. + +The `user` service +================== + +Overview +-------- + +* Technical name: `user` +* Dependencies: `rpc` + +The `user` service provides a bunch of data and a few helper functions concerning +the connected user. + + +API +---- + +.. list-table:: + :widths: 25 25 50 + :header-rows: 1 + + * - Name + - Type + - Description + * - ``context`` + - ``Object`` + - The :ref:`user context` + * - ``db`` + - ``Object`` + - Info about the database + * - ``home_action_id`` + - ``(number | false)`` + - Id of the action used as home for the user + * - ``isAdmin`` + - ``boolean`` + - Whether the user is an admin (group `base.group_erp_manager` or superuser) + * - ``isSystem`` + - ``boolean`` + - Whether the user is part of the system group (`base.group_system`) + * - ``lang`` + - ``string`` + - language used + * - ``name`` + - ``string`` + - Name of the user + * - ``partnerId`` + - ``number`` + - Id of the partner instance of the user + * - ``tz`` + - ``string`` + - The timezone of the user + * - ``userId`` + - ``number`` + - Id of the user + * - ``userName`` + - ``string`` + - Alternative nick name of the user + + +.. js:function:: updateContext(update) + + :param object update: the object to update the context with + + update the :ref:`user context` with the given object. + + .. code-block:: javascript + + userService.updateContext({ isFriend: true }) + +.. js:function:: removeFromContext(key) + + :param string key: the key of the targeted attribute + + remove the value with the given key from the :ref:`user context` + + .. code-block:: js + + userService.removeFromContext("isFriend") + +.. js:function:: hasGroup(group) + + :param string group: the xml_id of the group to look for + + :returns: `Promise` is the user in the group + + check if the user is part of a group + + .. code-block:: js + + const isInSalesGroup = await userService.hasGroup("sale.group_sales") + + +