Add a unioned permission objects, this mostly is used for the api GET methods
This commit is contained in:
1 parent
15c8bd7d6d
commit
281eb346a5
4 files changed
+23
-9
No files matched your search
@@ -202,6 +202,15 @@ class PermissionManager(object):
|
||||
else self.find_permission(permission["name"]) if isinstance(permission, dict) \
|
||||
else self.find_permission(permission)
|
||||
|
||||
def unionPermissions(name, *args):
|
||||
if len(args) == 0:
|
||||
return None
|
||||
|
||||
permission = OctoPrintPermission(name, "", *args[0].needs)
|
||||
for p in args[1:]:
|
||||
permission = permission.union(p)
|
||||
|
||||
return permission
|
||||
|
||||
class Permissions:
|
||||
class PluginPermissionMetaclass(type):
|
||||
@@ -267,7 +276,12 @@ class Permissions:
|
||||
#USER = variable_deprecated("This variable is only for migration and is deprecated already, don't use it!", since="now")(OctoPrintPermission("User", "Migrated User permission class, deprecated", *reduce(or_, map(lambda p: p.needs, USER_ARRAY))))
|
||||
################################################################################
|
||||
|
||||
FILE_PERMISSION = Permission(*UPLOAD.needs.union(DOWNLOAD.needs).union(DELETE.needs).union(SELECT.needs).union(PRINT.needs).union(SLICE.needs))
|
||||
|
||||
CONTROL_ACCESS = unionPermissions("Control Access", CONTROL, WEBCAM)
|
||||
CONNECTION_ACCESS = unionPermissions("Connection Access", CONNECTION, STATUS)
|
||||
FILES_ACCESS = unionPermissions("Files Access", UPLOAD, DOWNLOAD, DELETE, SELECT, PRINT, SLICE)
|
||||
PRINTERPROFILES_ACCESS = unionPermissions("Printerprofiles Access", CONNECTION, SETTINGS)
|
||||
TIMELAPSE_ACCESS = unionPermissions("Timelapse Access", TIMELAPSE, TIMELAPSE_ADMIN)
|
||||
|
||||
@classmethod
|
||||
def initialize(cls):
|
||||
|
||||
@@ -14,7 +14,7 @@ from octoprint.server.util.flask import restricted_access, get_json_command_from
|
||||
from octoprint.access.permissions import Permissions
|
||||
|
||||
@api.route("/connection", methods=["GET"])
|
||||
@Permissions.STATUS.require(403)
|
||||
@Permissions.CONNECTION_ACCESS.require(403)
|
||||
def connectionState():
|
||||
state, port, baudrate, printer_profile = printer.get_current_connection()
|
||||
current = {
|
||||
|
||||
@@ -85,7 +85,7 @@ def _create_etag(path, filter, recursive, lm=None):
|
||||
|
||||
|
||||
@api.route("/files", methods=["GET"])
|
||||
@Permissions.FILE_PERMISSION.require(403)
|
||||
@Permissions.FILES_ACCESS.require(403)
|
||||
@with_revalidation_checking(etag_factory=lambda lm=None: _create_etag(request.path,
|
||||
request.values.get("filter", False),
|
||||
request.values.get("recursive", False),
|
||||
@@ -106,7 +106,7 @@ def readGcodeFiles():
|
||||
|
||||
|
||||
@api.route("/files/<string:origin>", methods=["GET"])
|
||||
@Permissions.FILE_PERMISSION.require(403)
|
||||
@Permissions.FILES_ACCESS.require(403)
|
||||
@with_revalidation_checking(etag_factory=lambda lm=None: _create_etag(request.path,
|
||||
request.values.get("filter", False),
|
||||
request.values.get("recursive", False),
|
||||
@@ -279,8 +279,8 @@ 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
|
||||
printAfterSelect = "print" in request.values.keys() and request.values["print"] in valid_boolean_trues
|
||||
selectAfterUpload = "select" in request.values.keys() and request.values["select"] in valid_boolean_trues and Permissions.SELECT.can()
|
||||
printAfterSelect = "print" in request.values.keys() and request.values["print"] in valid_boolean_trues and Permissions.PRINT.can()
|
||||
|
||||
if sd:
|
||||
# validate that all preconditions for SD upload are met before attempting it
|
||||
@@ -462,7 +462,7 @@ def readGcodeFile(target, filename):
|
||||
|
||||
@api.route("/files/<string:target>/<path:filename>", methods=["POST"])
|
||||
@restricted_access
|
||||
@Permissions.FILE_PERMISSION.require(403)
|
||||
@Permissions.FILES_ACCESS.require(403)
|
||||
def gcodeFileCommand(filename, target):
|
||||
if not target in [FileDestinations.LOCAL, FileDestinations.SDCARD]:
|
||||
return make_response("Unknown target: %s" % target, 404)
|
||||
|
||||
@@ -24,7 +24,6 @@ from octoprint.access.permissions import Permissions
|
||||
def _lastmodified():
|
||||
return printerProfileManager.last_modified
|
||||
|
||||
|
||||
def _etag(lm=None):
|
||||
if lm is None:
|
||||
lm = _lastmodified()
|
||||
@@ -41,7 +40,7 @@ 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.SETTINGS.require(403)
|
||||
@Permissions.PRINTERPROFILES_ACCESS.require(403)
|
||||
def printerProfilesList():
|
||||
all_profiles = printerProfileManager.get_all()
|
||||
return jsonify(dict(profiles=_convert_profiles(all_profiles)))
|
||||
@@ -102,6 +101,7 @@ def printerProfilesAdd():
|
||||
return jsonify(dict(profile=_convert_profile(saved_profile)))
|
||||
|
||||
@api.route("/printerprofiles/<string:identifier>", methods=["GET"])
|
||||
@Permissions.CONNECTION.require(403)
|
||||
def printerProfilesGet(identifier):
|
||||
profile = printerProfileManager.get(identifier)
|
||||
if profile is None:
|
||||
|
||||
Reference in new issue
Block a user