From b1b9329614870dfd7bb92b867181899ffccb2d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 24 Jan 2020 13:05:06 +0100 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=20Move=20/api/access/user=20to=20/api?= =?UTF-8?q?/currentuser?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update documentation accordingly. See also #3418 --- docs/api/access.rst | 264 +-------------------------- docs/api/datamodel.rst | 170 +++++++++++++++++ docs/api/general.rst | 76 +++++--- src/octoprint/server/api/__init__.py | 7 + src/octoprint/server/api/access.py | 20 -- 5 files changed, 227 insertions(+), 310 deletions(-) diff --git a/docs/api/access.rst b/docs/api/access.rst index 10d223d22..061d9fb00 100644 --- a/docs/api/access.rst +++ b/docs/api/access.rst @@ -6,67 +6,6 @@ Access control .. contents:: -.. _sec-api-access-user: - -Current user -============ - -.. _sec-api-access-user-info: - -Get current user ----------------- - -.. http:get:: /api/access/user - - Retrieves information about the current user. - - Will return a :http:statuscode:`200` with a :ref:`current user object ` - as body. - - :status 200: No error - -.. _sec-api-access-user-name: - -Get current user's name ------------------------ - -.. http:get:: /api/access/user/name - - Retrieves the name of the current user. - - Will return a :http:statuscode:`200` with a :ref:`current user object ` - with only the ``name`` field as body. - - :status 200: No error - -.. _sec-api-access-user-permissions: - -List current user's permissions -------------------------------- - -.. http:get:: /api/access/user/permissions - - Retrieves the effective permissions assigned to the current user. - - Will return a :http:statuscode:`200` with a :ref:`permission list ` - as body. - - :status 200: No error - -.. _sec-api-access-user-groups: - -List current user's groups --------------------------- - -.. http:get:: /api/access/user/groups - - Retrieves the groups assigned to the current user. - - Will return a :http:statuscode:`200` with a :ref:`current user object ` - as body. - - :status 200: No error - .. _sec-api-access-permissions: Permissions @@ -389,32 +328,6 @@ Delete a user's api key Data model ========== -.. _sec-api-access-datamodel-currentuser: - -Current user ------------- - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``name`` - - 1 - - string - - The id of the current user. Unset if guest. - * - ``permissions`` - - 0..n - - List of :ref:`permission records ` - - The effective list of permissions assigned to the user - * - ``groups`` - - 0..n - - List of :ref:`permission records ` - - The list of groups assigned to the user - .. _sec-api-access-datamodel-permissions: Permissions @@ -435,48 +348,10 @@ Permission list response - Description * - ``permissions`` - 0..n - - List of :ref:`permission records ` + - List of :ref:`permission records ` - The list of permissions -.. _sec-api-access-datamodel-permissions-permissionrecord: - -Permission record -~~~~~~~~~~~~~~~~~ - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``key`` - - 1 - - string - - The permission's identifier - * - ``name`` - - 1 - - string - - The permission's name - * - ``dangerous`` - - 1 - - boolean - - Whether the permission should be considered dangerous due to a high reponsibility (true) or not (false). - * - ``default_groups`` - - 1 - - List of string - - List of group identifiers for which this permission is enabled by default - * - ``description`` - - 1 - - string - - Human readable description of the permission - * - ``needs`` - - 1 - - :ref:`Needs object ` - - Needs assigned to the permission - .. _sec-api-access-datamodel-groups: Groups @@ -497,64 +372,9 @@ Group list response - Description * - ``groups`` - 0..n - - List of :ref:`group records ` + - List of :ref:`group records ` - The list of groups -.. _sec-api-access-datamodel-groups-grouprecord: - -Group record -~~~~~~~~~~~~ - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``key`` - - 1 - - string - - The group's identifier - * - ``name`` - - 1 - - string - - The group's name - * - ``description`` - - 1 - - string - - A human readable description of the group - * - ``permissions`` - - 0..n - - List of :ref:`Permissions ` - - The list of permissions assigned to the group (note: this does not include implicit permissions inherited from - subgroups). - * - ``subgroups`` - - 0..n - - List of :ref:`Groups ` - - Subgroups assigned to the group - * - ``needs`` - - 1 - - :ref:`Needs object ` - - Effective needs of the group - * - ``default`` - - 1 - - boolean - - Whether this is a default group (true) or not (false) - * - ``removable`` - - 1 - - boolean - - Whether this group can be removed (true) or not (false) - * - ``changeable`` - - 1 - - boolean - - Whether this group can be modified (true) or not (false) - * - ``toggleable`` - - 1 - - boolean - - Whether this group can be assigned to users or other groups (true) or not (false) - .. _sec-api-access-datamodel-groups-addgrouprequest: Group registration request @@ -644,59 +464,9 @@ User list response - Description * - ``users`` - 0..n - - List of :ref:`user records ` + - List of :ref:`user records ` - The list of users -.. _sec-api-access-datamodel-users-userrecord: - -User record -~~~~~~~~~~~ - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``name`` - - 1 - - string - - The user's name - * - ``active`` - - 1 - - bool - - Whether the user's account is active (true) or not (false) - * - ``user`` - - 1 - - bool - - Whether the user has user rights. Should always be true. Deprecated as of 1.4.0, use the ``users`` group instead. - * - ``admin`` - - 1 - - bool - - Whether the user has admin rights (true) or not (false). Deprecated as of 1.4.0, use the ``admins`` group instead. - * - ``apikey`` - - 0..1 - - string - - The user's personal API key - * - ``settings`` - - 1 - - object - - The user's personal settings, might be an empty object. - * - ``groups`` - - 1..n - - List of string - - Groups assigned to the user - * - ``needs`` - - 1 - - :ref:`Needs object ` - - Effective needs of the user - * - ``permissions`` - - 0..n - - List of :ref:`Permissions ` - - The list of permissions assigned to the user (note: this does not include implicit permissions inherit from groups). - .. _sec-api-access-datamodel-users-adduserrequest: User registration request @@ -757,31 +527,3 @@ User update request - 0..n - List of string - A list of identifiers of permissions to assign to the user - -.. _sec-api-access-datamodel-general: - -General -------- - -.. _sec-api-access-datamodel-general-needs: - -Needs -~~~~~ - -.. list-table:: - :widths: 15 5 10 30 - :header-rows: 1 - - * - Name - - Multiplicity - - Type - - Description - * - ``role`` - - 0..1 - - List of string - - List of ``role`` needs - * - ``group`` - - 0..1 - - List of string - - List of ``group`` needs - diff --git a/docs/api/datamodel.rst b/docs/api/datamodel.rst index 2af4f727f..4f9803e73 100644 --- a/docs/api/datamodel.rst +++ b/docs/api/datamodel.rst @@ -480,3 +480,173 @@ References - URL - The model from which this file was generated (e.g. an STL, currently not used). Never present for folders. + +.. _sec-api-datamodel-access: + +Access control +============== + +.. _sec-api-datamodel-access-users: + +User record +----------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``name`` + - 1 + - string + - The user's name + * - ``active`` + - 1 + - bool + - Whether the user's account is active (true) or not (false) + * - ``user`` + - 1 + - bool + - Whether the user has user rights. Should always be true. Deprecated as of 1.4.0, use the ``users`` group instead. + * - ``admin`` + - 1 + - bool + - Whether the user has admin rights (true) or not (false). Deprecated as of 1.4.0, use the ``admins`` group instead. + * - ``apikey`` + - 0..1 + - string + - The user's personal API key + * - ``settings`` + - 1 + - object + - The user's personal settings, might be an empty object. + * - ``groups`` + - 1..n + - List of string + - Groups assigned to the user + * - ``needs`` + - 1 + - :ref:`Needs object ` + - Effective needs of the user + * - ``permissions`` + - 0..n + - List of :ref:`Permissions ` + - The list of permissions assigned to the user (note: this does not include implicit permissions inherit from groups). + +.. _sec-api-datamodel-access-permissions: + +Permission record +----------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``key`` + - 1 + - string + - The permission's identifier + * - ``name`` + - 1 + - string + - The permission's name + * - ``dangerous`` + - 1 + - boolean + - Whether the permission should be considered dangerous due to a high reponsibility (true) or not (false). + * - ``default_groups`` + - 1 + - List of string + - List of group identifiers for which this permission is enabled by default + * - ``description`` + - 1 + - string + - Human readable description of the permission + * - ``needs`` + - 1 + - :ref:`Needs object ` + - Needs assigned to the permission + +.. _sec-api-datamodel-access-groups: + +Group record +------------ + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``key`` + - 1 + - string + - The group's identifier + * - ``name`` + - 1 + - string + - The group's name + * - ``description`` + - 1 + - string + - A human readable description of the group + * - ``permissions`` + - 0..n + - List of :ref:`Permissions ` + - The list of permissions assigned to the group (note: this does not include implicit permissions inherited from + subgroups). + * - ``subgroups`` + - 0..n + - List of :ref:`Groups ` + - Subgroups assigned to the group + * - ``needs`` + - 1 + - :ref:`Needs object ` + - Effective needs of the group + * - ``default`` + - 1 + - boolean + - Whether this is a default group (true) or not (false) + * - ``removable`` + - 1 + - boolean + - Whether this group can be removed (true) or not (false) + * - ``changeable`` + - 1 + - boolean + - Whether this group can be modified (true) or not (false) + * - ``toggleable`` + - 1 + - boolean + - Whether this group can be assigned to users or other groups (true) or not (false) + +.. _sec-api-datamodel-access-needs: + +Needs +----- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``role`` + - 0..1 + - List of string + - List of ``role`` needs + * - ``group`` + - 0..1 + - List of string + - List of ``group`` needs diff --git a/docs/api/general.rst b/docs/api/general.rst index 47e46aa32..6ad073009 100644 --- a/docs/api/general.rst +++ b/docs/api/general.rst @@ -180,6 +180,20 @@ Logout :status 204: No error +.. _sec-api-general-currentuser: + +Current User +============ + +.. http:get:: /api/access/currentuser + + Retrieves information about the current user. + + Will return a :http:statuscode:`200` with a :ref:`current user object ` + as body. + + :status 200: No error + .. _sec-api-general-datamodel: Data model @@ -190,6 +204,30 @@ Data model Login response -------------- +The Login response is a :ref:`user record ` extended by the following fields: + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``session`` + - 1 + - string + - The session key, can be used to authenticate with the ``auth`` message on the :ref:`push API `. + * - ``_is_external_client`` + - 1 + - boolean + - Whether the client that made the request got detected as external from the local network or not. + +.. _sec-api-general-datamodel-currentuser: + +Current user +------------ + .. list-table:: :widths: 15 5 10 30 :header-rows: 1 @@ -201,32 +239,12 @@ Login response * - ``name`` - 1 - string - - the user's name/id - * - ``active`` - - 1 - - boolean - - Whether the user's account is active or not - * - ``admin`` - - 1 - - boolean - - Whether the user has admin rights or not - * - ``user`` - - 1 - - boolean - - Whether the user has user rights or not (always ``true``) - * - ``apikey`` - - 1 - - string or None - - The user's API key, if set - * - ``settings`` - - 1 - - dict - - The user's settings, if any - * - ``session`` - - 1 - - string - - The session key, can be used to authenticate with the ``auth`` message on the :ref:`push API `. - * - ``_is_external_client`` - - 1 - - boolean - - Whether the client that made the request got detected as external from the local network or not. + - The id of the current user. Unset if guest. + * - ``permissions`` + - 0..n + - List of :ref:`permission records ` + - The effective list of permissions assigned to the user + * - ``groups`` + - 0..n + - List of :ref:`permission records ` + - The list of groups assigned to the user diff --git a/src/octoprint/server/api/__init__.py b/src/octoprint/server/api/__init__.py index e2d55759e..5b66a6379 100644 --- a/src/octoprint/server/api/__init__.py +++ b/src/octoprint/server/api/__init__.py @@ -289,6 +289,13 @@ def _logout(user): octoprint.server.userManager.logout_user(user) +@api.route("/currentuser", methods=["GET"]) +def get_current_user(): + return jsonify(name=current_user.get_name(), + permissions=[permission.key for permission in current_user.effective_permissions], + groups=[group.key for group in current_user.groups]) + + #~~ Test utils diff --git a/src/octoprint/server/api/access.py b/src/octoprint/server/api/access.py index c2dcb9216..807003d19 100644 --- a/src/octoprint/server/api/access.py +++ b/src/octoprint/server/api/access.py @@ -17,26 +17,6 @@ from octoprint.server.api import api, valid_boolean_trues from octoprint.server.util.flask import no_firstrun_access from octoprint.access.permissions import Permissions -#~~ current user - -@api.route("/access/user", methods=["GET"]) -def get_current_user(): - return jsonify(name=current_user.get_name(), - permissions=[permission.key for permission in current_user.effective_permissions], - groups=[group.key for group in current_user.groups]) - -@api.route("/access/user/name", methods=["GET"]) -def get_current_user_name(): - return jsonify(name=current_user.get_name()) - -@api.route("/access/user/permissions", methods=["GET"]) -def get_current_user_permissions(): - return jsonify(permissions=[permission.key for permission in current_user.effective_permissions]) - -@api.route("/access/user/groups", methods=["GET"]) -def get_current_user_groups(): - return jsonify(groups=[group.key for group in current_user.groups]) - #~~ permission api @api.route("/access/permissions", methods=["GET"])