Added additional Permissions in the bundled Plugins
This commit is contained in:
1 parent
1c07974f6c
commit
83ed6a4297
3 files changed
+42
-16
No files matched your search
@@ -32,6 +32,18 @@ import dateutil.parser
|
||||
import time
|
||||
import threading
|
||||
|
||||
|
||||
# Access permissions hook
|
||||
|
||||
def additional_permissions(components):
|
||||
return [
|
||||
dict(name="Manage Plugins", description=gettext("Allows to use the plugin manager to manage plugins"),
|
||||
roles=["manage_plugins"]),
|
||||
dict(name="Upload Archive", description=gettext("Allows to install plugins through an archive"),
|
||||
roles=["manage_plugins", "upload_archive"])
|
||||
|
||||
]
|
||||
|
||||
class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
octoprint.plugin.TemplatePlugin,
|
||||
octoprint.plugin.AssetPlugin,
|
||||
@@ -164,7 +176,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/upload_archive", methods=["POST"])
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
@Permissions.PLUGIN_PLUGINMANAGER_UPLOAD_ARCHIVE.require(403)
|
||||
def upload_archive(self):
|
||||
import flask
|
||||
|
||||
@@ -210,7 +222,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
}
|
||||
|
||||
def on_api_get(self, request):
|
||||
if not Permissions.SETTINGS.can():
|
||||
if not Permissions.PLUGIN_PLUGINMANAGER_MANAGE_PLUGINS.can():
|
||||
return make_response("Insufficient rights", 403)
|
||||
|
||||
from octoprint.server import safe_mode
|
||||
@@ -261,7 +273,7 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
unless=lambda: refresh_repository or refresh_notices)(view)()
|
||||
|
||||
def on_api_command(self, command, data):
|
||||
if not Permissions.SETTINGS.can():
|
||||
if not Permissions.PLUGIN_PLUGINMANAGER_MANAGE_PLUGINS.can():
|
||||
return make_response("Insufficient rights", 403)
|
||||
|
||||
if self._printer.is_printing() or self._printer.is_paused():
|
||||
@@ -980,6 +992,8 @@ class PluginManagerPlugin(octoprint.plugin.SimpleApiPlugin,
|
||||
versions=notification.get("versions", []),
|
||||
important=notification.get("important", False))
|
||||
|
||||
|
||||
|
||||
__plugin_name__ = "Plugin Manager"
|
||||
__plugin_author__ = "Gina Häußge"
|
||||
__plugin_url__ = "http://docs.octoprint.org/en/master/bundledplugins/pluginmanager.html"
|
||||
@@ -993,5 +1007,6 @@ def __plugin_load__():
|
||||
global __plugin_hooks__
|
||||
__plugin_hooks__ = {
|
||||
"octoprint.server.http.bodysize": __plugin_implementation__.increase_upload_bodysize,
|
||||
"octoprint.ui.web.templatetypes": __plugin_implementation__.get_template_types
|
||||
"octoprint.ui.web.templatetypes": __plugin_implementation__.get_template_types,
|
||||
"octoprint.access.permissions": additional_permissions
|
||||
}
|
||||
@@ -27,8 +27,16 @@ from octoprint.util import dict_merge, to_unicode
|
||||
import octoprint.settings
|
||||
|
||||
|
||||
##~~ Plugin
|
||||
# Access permissions hook
|
||||
|
||||
def additional_permissions(components):
|
||||
return [
|
||||
dict(name="Check", description=gettext("Allows to check for software updates"), roles=["check"]),
|
||||
dict(name="Perform", description=gettext("Allows to perform a software updates"), roles=["perform"]),
|
||||
dict(asCombined=True, name="Access", permissions=["Check", "Perform"])
|
||||
]
|
||||
|
||||
##~~ Plugin
|
||||
|
||||
class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
octoprint.plugin.SettingsPlugin,
|
||||
@@ -457,6 +465,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/check", methods=["GET"])
|
||||
@restricted_access
|
||||
@Permissions.PLUGIN_SOFTWAREUPDATE_CHECK.require(403)
|
||||
def check_for_update(self):
|
||||
if "check" in flask.request.values:
|
||||
check_targets = map(lambda x: x.strip(), flask.request.values["check"].split(","))
|
||||
@@ -518,7 +527,7 @@ class SoftwareUpdatePlugin(octoprint.plugin.BlueprintPlugin,
|
||||
|
||||
@octoprint.plugin.BlueprintPlugin.route("/update", methods=["POST"])
|
||||
@restricted_access
|
||||
@Permissions.SETTINGS.require(403)
|
||||
@Permissions.PLUGIN_SOFTWAREUPDATE_PERFORM.require(403)
|
||||
def perform_update(self):
|
||||
if self._printer.is_printing() or self._printer.is_paused():
|
||||
# do not update while a print job is running
|
||||
@@ -1077,7 +1086,8 @@ def __plugin_load__():
|
||||
|
||||
global __plugin_hooks__
|
||||
__plugin_hooks__ = {
|
||||
"octoprint.cli.commands": cli.commands
|
||||
"octoprint.cli.commands": cli.commands,
|
||||
"octoprint.access.permissions": additional_permissions
|
||||
}
|
||||
|
||||
|
||||
@@ -158,7 +158,9 @@ $(function() {
|
||||
});
|
||||
|
||||
self.onUserLoggedIn = function() {
|
||||
self.performCheck();
|
||||
if (self.loginState.hasPermission(self.access.permissions.PLUGIN_SOFTWAREUPDATE_CHECK)) {
|
||||
self.performCheck();
|
||||
}
|
||||
};
|
||||
|
||||
self.onUserLoggedOut = function() {
|
||||
@@ -311,7 +313,7 @@ $(function() {
|
||||
}
|
||||
}
|
||||
|
||||
if (!self.loginState.isAdmin() && !self.settings.settings.plugins.softwareupdate.notify_users()) return;
|
||||
if (!self.loginState.hasPermission(self.access.permissions.PLUGIN_SOFTWAREUPDATE_PERFORM) && !self.settings.settings.plugins.softwareupdate.notify_users()) return;
|
||||
|
||||
if (data.status == "updateAvailable" || data.status == "updatePossible") {
|
||||
var text = "<div class='softwareupdate_notification'>" + gettext("There are updates available for the following components:");
|
||||
@@ -330,7 +332,7 @@ $(function() {
|
||||
|
||||
text += "<p><small>" + gettext("Those components marked with <i class=\"fa fa-check\"></i> can be updated directly.") + "</small></p>";
|
||||
|
||||
if (!self.loginState.isAdmin()) {
|
||||
if (!self.loginState.hasPermission(self.access.permissions.PLUGIN_SOFTWAREUPDATE_PERFORM)) {
|
||||
text += "<p><small>" + gettext("To have updates applied, get in touch with an administrator of this OctoPrint instance.") + "</small></p>";
|
||||
}
|
||||
|
||||
@@ -344,7 +346,7 @@ $(function() {
|
||||
var eventListeners = {};
|
||||
|
||||
var singleButtonNotify = false;
|
||||
if (data.status == "updatePossible" && self.loginState.isAdmin()) {
|
||||
if (data.status == "updatePossible" && self.loginState.hasPermission(self.access.permissions.PLUGIN_SOFTWAREUPDATE_PERFORM)) {
|
||||
// if update is possible and user is admin, add action buttons for ignore and update
|
||||
options["confirm"] = {
|
||||
confirm: true,
|
||||
@@ -406,8 +408,7 @@ $(function() {
|
||||
};
|
||||
|
||||
self.performCheck = function(showIfNothingNew, force, ignoreSeen) {
|
||||
|
||||
if (!self.loginState.hasPermission(self.access.permissions.SETTINGS) && !self.settings.settings.plugins.softwareupdate.notify_users()) return;
|
||||
if (!self.loginState.hasPermission(self.access.permissions.PLUGIN_SOFTWAREUPDATE_CHECK) && !self.settings.settings.plugins.softwareupdate.notify_users()) return;
|
||||
|
||||
self.checking(true);
|
||||
OctoPrint.plugins.softwareupdate.check(force)
|
||||
@@ -467,7 +468,7 @@ $(function() {
|
||||
};
|
||||
|
||||
self.performUpdate = function(force, items) {
|
||||
if (!self.loginState.isAdmin()) return;
|
||||
if (!self.loginState.hasPermission(self.access.permissions.PLUGIN_SOFTWAREUPDATE_PERFORM)) return;
|
||||
|
||||
self.updateInProgress = true;
|
||||
|
||||
@@ -503,7 +504,7 @@ $(function() {
|
||||
};
|
||||
|
||||
self.update = function(force) {
|
||||
if (self.updateInProgress || !self.loginState.hasPermission(self.access.permissions.SETTINGS)) {
|
||||
if (self.updateInProgress || !self.loginState.hasPermission(self.access.permissions.PLUGIN_SOFTWAREUPDATE_PERFORM)) {
|
||||
self._updateClicked = false;
|
||||
return;
|
||||
}
|
||||
@@ -533,7 +534,7 @@ $(function() {
|
||||
};
|
||||
|
||||
self._showWorkingDialog = function(title) {
|
||||
if (!self.loginState.hasPermission(self.access.permissions.SETTINGS)) {
|
||||
if (!self.loginState.hasPermission(self.access.permissions.PLUGIN_SOFTWAREUPDATE_PERFORM)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user