From 7317814ce01948e60072c9b25baa39d55d380241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Thu, 23 Jan 2020 13:21:52 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Document=20needed=20permissions?= =?UTF-8?q?=20&=20fix=20some=20stuff?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/api/connection.rst | 4 +- docs/api/files.rst | 18 ++++++-- docs/api/job.rst | 4 +- docs/api/languages.rst | 2 +- docs/api/printer.rst | 60 ++++++++++++++++++++++++--- docs/api/printerprofiles.rst | 24 +++++++++-- docs/api/push.rst | 5 +-- docs/api/settings.rst | 4 +- docs/api/slicing.rst | 64 ++++++++++++++++++++++++++++- docs/api/system.rst | 4 +- docs/api/timelapse.rst | 10 +++-- docs/api/util.rst | 2 +- docs/api/wizard.rst | 2 +- src/octoprint/server/api/files.py | 2 +- src/octoprint/server/api/job.py | 12 ++---- src/octoprint/server/api/printer.py | 1 - 16 files changed, 180 insertions(+), 38 deletions(-) diff --git a/docs/api/connection.rst b/docs/api/connection.rst index 2a0037b9a..97655db9f 100644 --- a/docs/api/connection.rst +++ b/docs/api/connection.rst @@ -16,6 +16,8 @@ Get connection settings Retrieve the current connection settings, including information regarding the available baudrates and serial ports and the current connection state. + Requires the ``STATUS`` permission. + **Example** .. sourcecode:: http @@ -81,7 +83,7 @@ Issue a connection command for the lost acknowledgment should always be properly investigated and removed instead of depending on this "symptom solver". - Requires user rights. + Requires the ``CONNECTION`` permission. **Example Connect Request** diff --git a/docs/api/files.rst b/docs/api/files.rst index 23583d59c..618567df9 100644 --- a/docs/api/files.rst +++ b/docs/api/files.rst @@ -21,6 +21,8 @@ Retrieve all files Returns a :ref:`Retrieve response `. + Requires the ``FILES_LIST`` permission. + **Example 1**: Fetch only the files and folders from the root folder. @@ -250,6 +252,8 @@ Retrieve files from specific location Returns a :ref:`Retrieve response `. + Requires the ``FILES_LIST`` permission. + **Example**: .. sourcecode:: http @@ -327,7 +331,7 @@ Upload file or create folder Returns a :http:statuscode:`201` response with a ``Location`` header set to the management URL of the uploaded file and an :ref:`Upload Response ` as the body upon successful completion. - Requires user rights. + Requires the ``FILES_UPLOAD`` permission. **Example for uploading a file** @@ -504,6 +508,8 @@ Retrieve a specific file's or folder's information On success, a :http:statuscode:`200` is returned, with a :ref:`file information item ` as the response body. + Requires the ``FILES_LIST`` permission. + **Example** .. sourcecode:: http @@ -568,6 +574,8 @@ Issue a file command Upon success, a status code of :http:statuscode:`204` and an empty body is returned. + Requires the ``FILES_SELECT`` permission. + slice Slices an STL file into GCODE. Note that this is an asynchronous operation that will take place in the background after the response has been sent back to the client. Additional parameters are: @@ -598,6 +606,8 @@ Issue a file command Upon success, a status code of :http:statuscode:`202` and a :ref:`sec-api-datamodel-files-fileabridged` in the response body will be returned. + Requires the ``SLICE`` permission. + copy Copies the file or folder to a new ``destination`` on the same ``location``. Additional parameters are: @@ -609,6 +619,8 @@ Issue a file command Upon success, a status code of :http:statuscode:`201` and a :ref:`sec-api-datamodel-files-fileabridged` in the response body will be returned. + Requires the ``FILES_UPLOAD`` permission. + move Moves the file or folder to a new ``destination`` on the same ``location``. Additional parameters are: @@ -622,7 +634,7 @@ Issue a file command Upon success, a status code of :http:statuscode:`201` and a :ref:`sec-api-datamodel-files-fileabridged` in the response body will be returned. - Requires user rights. + Requires the ``FILES_UPLOAD`` permission. **Example Select Request** @@ -773,7 +785,7 @@ Delete file Returns a :http:statuscode:`204` after successful deletion. - Requires user rights. + Requires the ``FILES_DELETE`` permission. **Example Request** diff --git a/docs/api/job.rst b/docs/api/job.rst index 0c43e2b3b..8c0954c39 100644 --- a/docs/api/job.rst +++ b/docs/api/job.rst @@ -57,7 +57,7 @@ Issue a job command Upon success, a status code of :http:statuscode:`204` and an empty body is returned. - Requires user rights. + Requires the ``PRINT`` permission. **Example Start Request** @@ -180,6 +180,8 @@ Retrieve information about the current job Returns a :http:statuscode:`200` with a :ref:`sec-api-job-datamodel-response` in the body. + Requires the ``STATUS`` permission. + **Example** .. sourcecode:: http diff --git a/docs/api/languages.rst b/docs/api/languages.rst index ecb83102a..f9a580500 100644 --- a/docs/api/languages.rst +++ b/docs/api/languages.rst @@ -6,7 +6,7 @@ Languages .. note:: - All language pack management operations require admin rights. + All language pack management operations require the ``SETTINGS`` permission. .. contents:: diff --git a/docs/api/printer.rst b/docs/api/printer.rst index 3fe43aa18..70237c5eb 100644 --- a/docs/api/printer.rst +++ b/docs/api/printer.rst @@ -80,6 +80,8 @@ Retrieve the current printer state Returns a :http:statuscode:`200` with a :ref:`Full State Response ` in the body upon success. + Requires the ``STATUS`` permission. + **Example 1** Include temperature history data, but limit it to two entries. @@ -241,7 +243,7 @@ Issue a print head command Upon success, a status code of :http:statuscode:`204` and an empty body is returned. - Requires user rights. + Requires the ``CONTROL`` permission. **Example Jog Request** @@ -380,7 +382,7 @@ Issue a tool command Upon success, a status code of :http:statuscode:`204` and an empty body is returned. - Requires user rights. + Requires the ``CONTROL`` permission. **Example Target Temperature Request** @@ -555,6 +557,8 @@ Retrieve the current tool state Returns a :http:statuscode:`200` with a Temperature Response in the body upon success. + Requires the ``STATUS`` permission. + .. note:: If you want both tool and bed temperature information at the same time, take a look at :ref:`Retrieve the current printer state `. @@ -645,7 +649,7 @@ Issue a bed command If no heated bed is configured for the currently selected printer profile, the resource will return an :http:statuscode:`409`. - Requires user rights. + Requires the ``CONTROL`` permission. **Example Target Temperature Request** @@ -714,6 +718,8 @@ Retrieve the current bed state If no heated bed is configured for the currently selected printer profile, the resource will return an :http:statuscode:`409`. + Requires the ``STATUS`` permission. + .. note:: If you want tool, bed and chamber temperature information at the same time, take a look at :ref:`Retrieve the current printer state `. @@ -793,7 +799,7 @@ Issue a chamber command If no heated chamber is configured for the currently selected printer profile, the resource will return an :http:statuscode:`409`. - Requires user rights. + Requires the ``CONTROL`` permission. **Example Target Temperature Request** @@ -862,6 +868,8 @@ Retrieve the current chamber state If no heated chamber is configured for the currently selected printer profile, the resource will return an :http:statuscode:`409`. + Requires the ``STATUS`` permission. + .. note:: If you want tool, bed and chamber temperature information at the same time, take a look at :ref:`Retrieve the current printer state `. @@ -944,7 +952,7 @@ Issue an SD command Upon success, a status code of :http:statuscode:`204` and an empty body is returned. - Requires user rights. + Requires the ``CONTROL`` permission. **Example Init Request** @@ -1022,6 +1030,8 @@ Retrieve the current SD state Returns a :http:statuscode:`200` with an :ref:`SD State Response ` in the body upon success. + Requires the ``STATUS`` permission. + **Example** Read the current state of the SD card. @@ -1058,7 +1068,7 @@ Send an arbitrary command to the printer If successful returns a :http:statuscode:`204` and an empty body. - Requires user rights. + Requires the ``CONTROL`` permission. **Example for sending a single command** @@ -1101,6 +1111,26 @@ Send an arbitrary command to the printer :json string commands: List of commands to send to the printer, mutually exclusive with ``command``. :statuscode 204: No error +.. _sec-api-printer-customcontrols: + +Retrieve custom controls +======================== + +.. http:get:: /api/printer/command/custom + + Retrieves the :ref:`custom controls ` as configured in + :ref:`config.yaml `. + + Please refer to the documentation of :ref:`custom controls ` on what + data structure to expect here. + + Returns a :http:statuscode:`200` with an :ref:`Custom Controls Response ` + in the body upon success. + + Requires the ``CONTROL`` permission. + + :statuscode 200: No error + .. _sec-api-printer-datamodel: Data model @@ -1211,3 +1241,21 @@ Arbitrary Command Request - 0..1 - Map of key value pairs - (only if ``script`` is set) additional template variables to provide to the script renderer + +.. _sec-api-printer-datamodel-customcontrols: + +Custom Controls Response +------------------------ + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``controls`` + - 0..n + - List of :ref:`custom controls ` + - A list of custom control definitions as defined in ``config.yaml``. diff --git a/docs/api/printerprofiles.rst b/docs/api/printerprofiles.rst index 9f2f163e2..fc251ea73 100644 --- a/docs/api/printerprofiles.rst +++ b/docs/api/printerprofiles.rst @@ -21,6 +21,8 @@ Retrieve all printer profiles Returns a :http:statuscode:`200` with a list of :ref:`profiles `. + Requires the ``CONNECTION`` permission. + **Example** .. sourcecode:: http @@ -124,6 +126,22 @@ Retrieve all printer profiles } +.. _sec-api-printerprofiles-get: + +Retrieve a single printer profile +================================= + +.. http:get:: /api/printerprofiles/(string:identifier) + + Retrieves an existing single printer profile. + + Returns a :http:statuscode:`200` with a :ref:`profile `. + + Requires the ``CONNECTION`` permission. + + :statuscode 200: No error + :statuscode 404: The profile does not exist + .. _sec-api-printerprofiles-add: Add a new printer profile @@ -143,7 +161,7 @@ Add a new printer profile Returns a :http:statuscode:`200` with the saved profile as property ``profile`` in the JSON body upon success. - Requires admin rights. + Requires the ``SETTINGS`` permission. **Example 1** @@ -314,7 +332,7 @@ Update an existing printer profile Returns a :http:statuscode:`200` with the saved profile as property ``profile`` in the JSON body upon success. - Requires admin rights. + Requires the ``SETTINGS`` permission. **Example** @@ -400,7 +418,7 @@ Remove an existing printer profile Returns a :http:statuscode:`204` an empty body upon success. - Requires admin rights. + Requires the ``SETTINGS`` permission. **Example** diff --git a/docs/api/push.rst b/docs/api/push.rst index 87e40bf5d..515da4aad 100644 --- a/docs/api/push.rst +++ b/docs/api/push.rst @@ -51,9 +51,8 @@ OctoPrint's SockJS socket also accepts two commands from the client to the serve * ``auth`` (since 1.3.10): With the ``auth`` message, clients may associate an existing user session with the socket. That is of special importance to receive - any kind of messages if the bundled :ref:`Forcelogin Plugin ` is enabled - (as it is by default), since it will prevent any kind of status messages to be sent to connected unauthenticated - clients. + any kind of messages, since the permission system will prevent any kind of status messages to be sent to connected + clients lacking the ``STATUS`` permission. The ``auth`` message expects the user id of the user to authenticate followed by ``:`` and a session key to be obtained from the successful payload of a :ref:`(passive or active) login via the API `. diff --git a/docs/api/settings.rst b/docs/api/settings.rst index b4597ef94..ab2b89602 100644 --- a/docs/api/settings.rst +++ b/docs/api/settings.rst @@ -21,6 +21,8 @@ Retrieve current settings The :ref:`data model ` is similar to what can be found in :ref:`config.yaml `, see below for details. + Requires the ``SETTINGS_READ`` permission. + .. _sec-api-settings-save: Save settings @@ -36,7 +38,7 @@ Save settings Returns the currently active settings on success, as part of a :http:statuscode:`200` response. - Requires admin rights. + Requires the ``SETTINGS`` permission. **Example** diff --git a/docs/api/slicing.rst b/docs/api/slicing.rst index c49cb4cd5..7c1ea53f0 100644 --- a/docs/api/slicing.rst +++ b/docs/api/slicing.rst @@ -28,6 +28,8 @@ List All Slicers and Slicing Profiles Returns a :http:statuscode:`200` response with a :ref:`Slicer list ` as the body upon successful completion. + Requires the ``SLICE`` permission. + **Example** .. sourcecode:: http @@ -77,6 +79,8 @@ List Slicing Profiles of a Specific Slicer Returns a :http:statuscode:`200` response with a :ref:`Profile list ` as the body upon successful completion. + Requires the ``SLICE`` permission. + **Example** .. sourcecode:: http @@ -121,6 +125,8 @@ Retrieve Specific Profile Returns a :http:statuscode:`200` response with a :ref:`full Profile ` as the body upon successful completion. + Requires the ``SLICE`` permission. + **Example** .. sourcecode:: http @@ -168,7 +174,7 @@ Add Slicing Profile Returns a :http:statuscode:`201` and an :ref:`abridged Profile ` in the body upon successful completion. - Requires admin rights. + Requires the ``SETTINGS`` permission. **Example** @@ -206,6 +212,31 @@ Add Slicing Profile :statuscode 201: No error :statuscode 404: If the ``slicer`` was unknown to the system. +.. _sec-api-slicing-patch: + +Update Slicing Profile +====================== + +.. http:patch:: /api/slicing/(string:slicer)/profiles/(string:key) + + Updates the slicing profile identified by ``key`` for the slicer ``slicer``. + + Expects a :ref:`profile update request ` as body. + + Returns a :http:statuscode:`201` and an :ref:`abridged Profile ` in the body + upon successful completion. + + Requires the ``SETTINGS`` permission. + + :param slicer: The identifying key of the slicer for which to update the profile + :param key: The identifying key of the profile to update + :json data: New profile overrides to apply + :json displayName: New display name + :json description: New description + :json default: Whether to make the profile default (true) or not (false) for the slicer + :statuscode 200: No error + :statuscode 404: Slicer or profile do not exist + .. _sec-api-slicing-delete: Delete Slicing Profile @@ -216,7 +247,7 @@ Delete Slicing Profile Delete the slicing profile identified by ``key`` for the slicer ``slicer``. If the profile doesn't exist, the request will succeed anyway. - Requires admin rights. + Requires the ``SETTINGS`` permission. :param slicer: The identifying key of the slicer for which to delete the profile :param key: The identifying key of the profile to delete @@ -340,3 +371,32 @@ Profile only the keys differing from the defaults when saving/updating a profile. The keys to be found in here a slicer specific. Will be left out for list responses. +.. _sec-api-slicing-datamodel-profileupdate: + +Profile Update Request +---------------------- + +.. list-table:: + :widths: 15 5 10 30 + :header-rows: 1 + + * - Name + - Multiplicity + - Type + - Description + * - ``data`` + - 0..1 + - Object + - The profile data + * - ``displayName`` + - 0..1 + - ``string`` + - The new display name for the profile + * - ``description`` + - 0..1 + - ``string`` + - The new description for the profile + * - ``default`` + - 0..1 + - ``boolean`` + - Whether to mark the profile as default for the slicer (true) or not (false) diff --git a/docs/api/system.rst b/docs/api/system.rst index c3df02e9a..4dce5dd58 100644 --- a/docs/api/system.rst +++ b/docs/api/system.rst @@ -6,7 +6,7 @@ System .. note:: - All system operations require admin rights. + All system operations require the ``SYSTEM`` permission. .. _sec-api-system-command-list: @@ -20,6 +20,8 @@ List all registered system commands A :http:statuscode:`200` with a :ref:`List all response ` will be returned. + Requires the ``SYSTEM`` permission. + **Example** .. sourcecode:: http diff --git a/docs/api/timelapse.rst b/docs/api/timelapse.rst index 54b3668ec..000a8190f 100644 --- a/docs/api/timelapse.rst +++ b/docs/api/timelapse.rst @@ -18,6 +18,8 @@ Retrieve a list of timelapses and the current config Returns a :ref:`timelapse list ` in the response body. + Requires the ``TIMELAPSE_LIST`` permission. + :param unrendered: If provided and true, also include unrendered timelapses .. _sec-api-timelapse-delete: @@ -29,7 +31,7 @@ Delete a timelapse Delete the timelapse ``filename``. - Requires user rights. + Requires the ``TIMELAPSE_DELETE`` permission. .. _sec-api-timelapse-render: @@ -41,7 +43,7 @@ Issue a command for an unrendered timelapse Current only supports to render the unrendered timelapse ``name`` via the ``render`` command. - Requires user rights. + Requires the ``TIMELAPSE_ADMIN`` permission. :json command: The command to issue, currently only ``render`` is supported @@ -54,7 +56,7 @@ Delete an unrendered timelapse Delete the unrendered timelapse ``name``. - Requires user rights. + Requires the ``TIMELAPSE_DELETE`` permission. .. _sec-api-timelapse-saveconfig: @@ -67,7 +69,7 @@ Change current timelapse config The configuration is expected as the request body. - Requires user rights. + Requires the ``TIMELAPSE_ADMIN`` permission. .. _sec-api-timelapse-datamodel: diff --git a/docs/api/util.rst b/docs/api/util.rst index 48b9e71b9..b4e33a831 100644 --- a/docs/api/util.rst +++ b/docs/api/util.rst @@ -99,7 +99,7 @@ Test paths or URLs The ``server`` command returns :http:statuscode:`200` with a :ref:`Server test result ` when the test could be performed. The status code of the response does NOT reflect the test result! - Requires admin rights. + Requires the ``ADMIN`` permission. **Example 1** diff --git a/docs/api/wizard.rst b/docs/api/wizard.rst index dfbb13801..6a36e3ed5 100644 --- a/docs/api/wizard.rst +++ b/docs/api/wizard.rst @@ -6,7 +6,7 @@ Wizard .. note:: - All wizard operations require either admin rights or the ``firstRun`` flag to be ``true``. + All wizard operations require either the ``ADMIN`` permission or the ``firstRun`` flag to be ``true``. .. contents:: diff --git a/src/octoprint/server/api/files.py b/src/octoprint/server/api/files.py index bf79251ca..d56a9300a 100644 --- a/src/octoprint/server/api/files.py +++ b/src/octoprint/server/api/files.py @@ -471,7 +471,7 @@ def uploadGcodeFile(target): @api.route("/files//", methods=["GET"]) -@Permissions.FILES_DOWNLOAD.require(403) +@Permissions.FILES_LIST.require(403) def readGcodeFile(target, filename): if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]: return make_response("Unknown target: %s" % target, 404) diff --git a/src/octoprint/server/api/job.py b/src/octoprint/server/api/job.py index 070ee26c8..49939ba3d 100644 --- a/src/octoprint/server/api/job.py +++ b/src/octoprint/server/api/job.py @@ -14,7 +14,6 @@ from octoprint.access.permissions import Permissions @api.route("/job", methods=["POST"]) @no_firstrun_access -@Permissions.PRINT.require(403) def controlJob(): if not printer.is_operational(): return make_response("Printer is not operational", 409) @@ -57,13 +56,10 @@ def controlJob(): printer.resume_print(tags=tags, user=user) else: return make_response("Unknown action '{}', allowed values for action parameter are 'pause', 'resume' and 'toggle'".format(action), 400) - - # Safety first, everyone can cancel a print, but log who canceled the print - # to prevent fraudulent use - if command == "cancel": - if not activePrintjob: - return make_response("Printer is neither printing nor paused, 'cancel' command cannot be performed", 409) - printer.cancel_print(tags=tags, user=user) + elif command == "cancel": + if not activePrintjob: + return make_response("Printer is neither printing nor paused, 'cancel' command cannot be performed", 409) + printer.cancel_print(tags=tags, user=user) return NO_CONTENT diff --git a/src/octoprint/server/api/printer.py b/src/octoprint/server/api/printer.py index 0da167d5c..95e23863b 100644 --- a/src/octoprint/server/api/printer.py +++ b/src/octoprint/server/api/printer.py @@ -478,7 +478,6 @@ def printerCommand(): @no_firstrun_access @Permissions.CONTROL.require(403) def getCustomControls(): - # TODO: document me customControls = settings().get(["controls"]) return jsonify(controls=customControls)