Some permission changes & fixes
This commit is contained in:
1 parent
1852578136
commit
5a91b8db48
24 files changed
+362
-247
No files matched your search
@@ -62,6 +62,8 @@ def add_group():
|
||||
|
||||
|
||||
@api.route("/access/groups/<groupname>", methods=["GET"])
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def get_group(groupname):
|
||||
group = groupManager.find_group(groupname)
|
||||
if group is not None:
|
||||
|
||||
@@ -89,7 +89,7 @@ def _create_etag(path, filter, recursive, lm=None):
|
||||
|
||||
|
||||
@api.route("/files", methods=["GET"])
|
||||
@Permissions.FILES_ACCESS.require(403)
|
||||
@Permissions.FILES_LIST.require(403)
|
||||
@with_revalidation_checking(etag_factory=lambda lm=None: _create_etag(request.path,
|
||||
request.values.get("filter", False),
|
||||
request.values.get("recursive", False),
|
||||
@@ -110,7 +110,7 @@ def readGcodeFiles():
|
||||
|
||||
|
||||
@api.route("/files/<string:origin>", methods=["GET"])
|
||||
@Permissions.FILES_ACCESS.require(403)
|
||||
@Permissions.FILES_LIST.require(403)
|
||||
@with_revalidation_checking(etag_factory=lambda lm=None: _create_etag(request.path,
|
||||
request.values.get("filter", False),
|
||||
request.values.get("recursive", False),
|
||||
@@ -260,7 +260,7 @@ def _isBusy(target, path):
|
||||
|
||||
@api.route("/files/<string:target>", methods=["POST"])
|
||||
@restricted_access
|
||||
@Permissions.UPLOAD.require(403)
|
||||
@Permissions.FILES_UPLOAD.require(403)
|
||||
def uploadGcodeFile(target):
|
||||
input_name = "file"
|
||||
input_upload_name = input_name + "." + settings().get(["server", "uploads", "nameSuffix"])
|
||||
@@ -284,7 +284,7 @@ def uploadGcodeFile(target):
|
||||
return make_response("SD card support is disabled", 404)
|
||||
|
||||
sd = target == FileDestinations.SDCARD
|
||||
selectAfterUpload = "select" in request.values.keys() and request.values["select"] in valid_boolean_trues and Permissions.SELECT.can()
|
||||
selectAfterUpload = "select" in request.values.keys() and request.values["select"] in valid_boolean_trues and Permissions.FILES_SELECT.can()
|
||||
printAfterSelect = "print" in request.values.keys() and request.values["print"] in valid_boolean_trues and Permissions.PRINT.can()
|
||||
|
||||
if sd:
|
||||
@@ -456,7 +456,7 @@ def uploadGcodeFile(target):
|
||||
|
||||
|
||||
@api.route("/files/<string:target>/<path:filename>", methods=["GET"])
|
||||
@Permissions.DOWNLOAD.require(403)
|
||||
@Permissions.FILES_DOWNLOAD.require(403)
|
||||
def readGcodeFile(target, filename):
|
||||
if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
|
||||
return make_response("Unknown target: %s" % target, 404)
|
||||
@@ -493,7 +493,7 @@ def gcodeFileCommand(filename, target):
|
||||
return response
|
||||
|
||||
if command == "select":
|
||||
with Permissions.SELECT.require(403):
|
||||
with Permissions.FILES_SELECT.require(403):
|
||||
if not _verifyFileExists(target, filename):
|
||||
return make_response("File not found on '%s': %s" % (target, filename), 404)
|
||||
|
||||
@@ -661,7 +661,7 @@ def gcodeFileCommand(filename, target):
|
||||
return make_response("No analysis possible for {} on {}".format(filename, target), 400)
|
||||
|
||||
elif command == "copy" or command == "move":
|
||||
with Permissions.UPLOAD.require(403):
|
||||
with Permissions.FILES_UPLOAD.require(403):
|
||||
# Copy and move are only possible on local storage
|
||||
if not target in [FileDestinations.LOCAL]:
|
||||
return make_response("Unsupported target for {}: {}".format(command, target), 400)
|
||||
@@ -738,7 +738,7 @@ def gcodeFileCommand(filename, target):
|
||||
|
||||
|
||||
@api.route("/files/<string:target>/<path:filename>", methods=["DELETE"])
|
||||
@Permissions.DELETE.require(403)
|
||||
@Permissions.FILES_DELETE.require(403)
|
||||
@restricted_access
|
||||
def deleteGcodeFile(filename, target):
|
||||
if not _verifyFileExists(target, filename) and not _verifyFolderExists(target, filename):
|
||||
|
||||
@@ -323,6 +323,7 @@ def printerSdCommand():
|
||||
|
||||
|
||||
@api.route("/printer/sd", methods=["GET"])
|
||||
@restricted_access
|
||||
@Permissions.STATUS.require(403)
|
||||
def printerSdState():
|
||||
if not settings().getBoolean(["feature", "sdSupport"]):
|
||||
@@ -396,6 +397,7 @@ def printerCommand():
|
||||
return NO_CONTENT
|
||||
|
||||
@api.route("/printer/command/custom", methods=["GET"])
|
||||
@restricted_access
|
||||
@Permissions.CONTROL.require(403)
|
||||
def getCustomControls():
|
||||
# TODO: document me
|
||||
|
||||
@@ -40,7 +40,8 @@ def _etag(lm=None):
|
||||
@with_revalidation_checking(etag_factory=_etag,
|
||||
lastmodified_factory=_lastmodified,
|
||||
unless=lambda: request.values.get("force", "false") in valid_boolean_trues)
|
||||
@Permissions.PRINTERPROFILES_ACCESS.require(403)
|
||||
@restricted_access
|
||||
@Permissions.CONNECTION.require(403)
|
||||
def printerProfilesList():
|
||||
all_profiles = printerProfileManager.get_all()
|
||||
return jsonify(dict(profiles=_convert_profiles(all_profiles)))
|
||||
@@ -101,6 +102,7 @@ def printerProfilesAdd():
|
||||
return jsonify(dict(profile=_convert_profile(saved_profile)))
|
||||
|
||||
@api.route("/printerprofiles/<string:identifier>", methods=["GET"])
|
||||
@restricted_access
|
||||
@Permissions.CONNECTION.require(403)
|
||||
def printerProfilesGet(identifier):
|
||||
profile = printerProfileManager.get(identifier)
|
||||
|
||||
@@ -11,6 +11,7 @@ from werkzeug.exceptions import BadRequest
|
||||
from octoprint.server import slicingManager
|
||||
from octoprint.server.util.flask import restricted_access, with_revalidation_checking
|
||||
from octoprint.server.api import api, NO_CONTENT
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
from octoprint.settings import settings as s, valid_boolean_trues
|
||||
|
||||
@@ -53,7 +54,7 @@ def _etag(configured, lm=None):
|
||||
hash.update(slicer)
|
||||
hash.update(str(slicer_impl.is_slicer_configured()))
|
||||
hash.update(str(slicer == default_slicer))
|
||||
|
||||
|
||||
hash.update(_DATA_FORMAT_VERSION) # increment version if we change the API format
|
||||
|
||||
return hash.hexdigest()
|
||||
@@ -63,6 +64,7 @@ def _etag(configured, lm=None):
|
||||
@with_revalidation_checking(etag_factory=lambda lm=None: _etag(request.values.get("configured", "false") in valid_boolean_trues, lm=lm),
|
||||
lastmodified_factory=lambda: _lastmodified(request.values.get("configured", "false") in valid_boolean_trues),
|
||||
unless=lambda: request.values.get("force", "false") in valid_boolean_trues)
|
||||
@Permissions.SLICE.require(403)
|
||||
def slicingListAll():
|
||||
from octoprint.filemanager import get_extensions
|
||||
|
||||
@@ -101,6 +103,8 @@ def slicingListAll():
|
||||
return jsonify(result)
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles", methods=["GET"])
|
||||
@restricted_access
|
||||
@Permissions.SLICE.require(403)
|
||||
def slicingListSlicerProfiles(slicer):
|
||||
configured = False
|
||||
if "configured" in request.values and request.values["configured"] in valid_boolean_trues:
|
||||
@@ -112,6 +116,8 @@ def slicingListSlicerProfiles(slicer):
|
||||
return make_response("Unknown slicer {slicer}".format(**locals()), 404)
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles/<string:name>", methods=["GET"])
|
||||
@restricted_access
|
||||
@Permissions.SLICE.require(403)
|
||||
def slicingGetSlicerProfile(slicer, name):
|
||||
try:
|
||||
profile = slicingManager.load_profile(slicer, name, require_configured=False)
|
||||
@@ -126,6 +132,7 @@ def slicingGetSlicerProfile(slicer, name):
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles/<string:name>", methods=["PUT"])
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def slicingAddSlicerProfile(slicer, name):
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
return make_response("Expected content-type JSON", 400)
|
||||
@@ -161,6 +168,7 @@ def slicingAddSlicerProfile(slicer, name):
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles/<string:name>", methods=["PATCH"])
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def slicingPatchSlicerProfile(slicer, name):
|
||||
if not "application/json" in request.headers["Content-Type"]:
|
||||
return make_response("Expected content-type JSON", 400)
|
||||
@@ -204,6 +212,7 @@ def slicingPatchSlicerProfile(slicer, name):
|
||||
|
||||
@api.route("/slicing/<string:slicer>/profiles/<string:name>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def slicingDelSlicerProfile(slicer, name):
|
||||
try:
|
||||
slicingManager.delete_profile(slicer, name)
|
||||
|
||||
@@ -73,10 +73,11 @@ def _etag(unrendered, lm=None):
|
||||
return hash.hexdigest()
|
||||
|
||||
@api.route("/timelapse", methods=["GET"])
|
||||
@restricted_access
|
||||
@with_revalidation_checking(etag_factory=lambda lm=None: _etag(request.values.get("unrendered", "false") in valid_boolean_trues, lm=lm),
|
||||
lastmodified_factory=lambda: _lastmodified(request.values.get("unrendered", "false") in valid_boolean_trues),
|
||||
unless=lambda: request.values.get("force", "false") in valid_boolean_trues)
|
||||
@Permissions.TIMELAPSE.require(403)
|
||||
@Permissions.TIMELAPSE_LIST.require(403)
|
||||
def getTimelapseData():
|
||||
timelapse = octoprint.timelapse.current
|
||||
config = _config_for_timelapse(timelapse)
|
||||
@@ -121,14 +122,15 @@ def getTimelapseData():
|
||||
|
||||
|
||||
@api.route("/timelapse/<filename>", methods=["GET"])
|
||||
@Permissions.TIMELAPSE.require(403)
|
||||
@restricted_access
|
||||
@Permissions.TIMELAPSE_DOWNLOAD.require(403)
|
||||
def downloadTimelapse(filename):
|
||||
return redirect_to_tornado(request, url_for("index") + "downloads/timelapse/" + filename)
|
||||
|
||||
|
||||
@api.route("/timelapse/<filename>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@Permissions.TIMELAPSE_ADMIN.require(403)
|
||||
@Permissions.TIMELAPSE_DELETE.require(403)
|
||||
def deleteTimelapse(filename):
|
||||
if util.is_allowed_file(filename, ["mpg", "mpeg", "mp4", "m4v", "mkv"]):
|
||||
timelapse_folder = settings().getBaseFolder("timelapse")
|
||||
@@ -145,7 +147,7 @@ def deleteTimelapse(filename):
|
||||
|
||||
@api.route("/timelapse/unrendered/<name>", methods=["DELETE"])
|
||||
@restricted_access
|
||||
@Permissions.TIMELAPSE_ADMIN.require(403)
|
||||
@Permissions.TIMELAPSE_DELETE.require(403)
|
||||
def deleteUnrenderedTimelapse(name):
|
||||
octoprint.timelapse.delete_unrendered_timelapse(name)
|
||||
return NO_CONTENT
|
||||
|
||||
@@ -1,86 +1,61 @@
|
||||
# coding=utf-8
|
||||
from __future__ import absolute_import, division, print_function
|
||||
|
||||
from octoprint.util import deprecated
|
||||
from octoprint.server.api import api
|
||||
from octoprint.server.api import api_access as access
|
||||
from octoprint.server.util.flask import restricted_access
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
__author__ = "Gina Häußge <osd@foosel.net>"
|
||||
__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html'
|
||||
__copyright__ = "Copyright (C) 2014 The OctoPrint Project - Released under terms of the AGPLv3 License"
|
||||
|
||||
from octoprint.server.api import api
|
||||
from flask import redirect, url_for
|
||||
|
||||
# NOTE: The redirects here should rather be 308 PERMANENT REDIRECT, however RFC7538 doesn't seem to be supported
|
||||
# by all browsers yet. So we stick to 307 TEMPORARY REDIRECT as defined in RFC7231 although it's definitely not a
|
||||
# temporary redirect we have here.
|
||||
|
||||
@api.route("/users", methods=["GET"])
|
||||
@deprecated("/users has been moved to /access/users")
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def getUsers():
|
||||
return access.get_users()
|
||||
def deprecated_get_users():
|
||||
return redirect(url_for("api.get_users"), code=307)
|
||||
|
||||
|
||||
@api.route("/users", methods=["POST"])
|
||||
@deprecated("/users has been moved to /access/users")
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def addUser():
|
||||
return access.add_user()
|
||||
return redirect(url_for("api.add_user"), code=307)
|
||||
|
||||
|
||||
@api.route("/users/<username>", methods=["GET"])
|
||||
@deprecated("/users/<username> has been moved to /access/users/<username>")
|
||||
@restricted_access
|
||||
def getUser(username):
|
||||
return access.get_user(username)
|
||||
return redirect(url_for("api.get_user", username=username), code=307)
|
||||
|
||||
|
||||
@api.route("/users/<username>", methods=["PUT"])
|
||||
@deprecated("/users/<username> has been moved to /access/users/<username>")
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def updateUser(username):
|
||||
return access.update_user(username)
|
||||
return redirect(url_for("api.update_user", username=username), code=307)
|
||||
|
||||
|
||||
@api.route("/users/<username>", methods=["DELETE"])
|
||||
@deprecated("/users/<username> has been moved to /access/users/<username>")
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
def removeUser(username):
|
||||
return access.remove_user(username)
|
||||
return redirect(url_for("api.remove_user", username=username), code=307)
|
||||
|
||||
|
||||
@api.route("/users/<username>/password", methods=["PUT"])
|
||||
@deprecated("/users/<username> has been moved to /access/users/<username>")
|
||||
@restricted_access
|
||||
def changePasswordForUser(username):
|
||||
return access.change_password_for_user(username)
|
||||
return redirect(url_for("api.change_password_for_user", username=username), code=307)
|
||||
|
||||
|
||||
@api.route("/users/<username>/settings", methods=["GET"])
|
||||
@deprecated("/users/<username>/settings has been moved to /access/users/<username>/settings")
|
||||
@restricted_access
|
||||
def getSettingsForUser(username):
|
||||
return access.get_settings_for_user(username)
|
||||
return redirect(url_for("api.get_settings_for_user", username=username), code=307)
|
||||
|
||||
|
||||
@api.route("/users/<username>/settings", methods=["PATCH"])
|
||||
@deprecated("/users/<username>/settings has been moved to /access/users/<username>/settings")
|
||||
@restricted_access
|
||||
def changeSettingsForUser(username):
|
||||
return access.change_settings_for_user(username)
|
||||
return redirect(url_for("api.change_settings_for_user", username=username), code=307)
|
||||
|
||||
|
||||
@api.route("/users/<username>/apikey", methods=["DELETE"])
|
||||
@deprecated("/users/<username>/apikey has been moved to /access/users/<username>/apikey")
|
||||
@restricted_access
|
||||
def deleteApikeyForUser(username):
|
||||
return access.delete_apikey_for_user(username)
|
||||
return redirect(url_for("api.delete_apikey_for_user", username=username), code=307)
|
||||
|
||||
|
||||
@api.route("/users/<username>/apikey", methods=["POST"])
|
||||
@deprecated("/users/<username>/apikey has been moved to /access/users/<username>/apikey")
|
||||
@restricted_access
|
||||
def generateApikeyForUser(username):
|
||||
return access.generate_apikey_for_user(username)
|
||||
return redirect(url_for("api.generate_apikey_for_user", username=username), code=307)
|
||||
Reference in new issue
Block a user