How to use the octoprint.server.user_permission.can function in OctoPrint

To help you get started, we’ve selected a few OctoPrint examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ziirish / OctoPrint-TuyaSmartplug / octoprint_tuyasmartplug / __init__.py View on Github external
def on_api_command(self, command, data):
		if not user_permission.can():
			from flask import make_response
			return make_response("Insufficient rights", 403)

		if command == 'turnOn':
			self.turn_on("{label}".format(**data))
		elif command == 'turnOff':
			self.turn_off("{label}".format(**data))
		elif command == 'checkStatus':
			self.check_status("{label}".format(**data))
github jneilliii / OctoPrint-TPLinkSmartplug / octoprint_tplinksmartplug / __init__.py View on Github external
def on_api_command(self, command, data):
		if not user_permission.can():
			return flask.make_response("Insufficient rights", 403)

		if command == 'turnOn':
			response = self.turn_on("{ip}".format(**data))
			self._plugin_manager.send_plugin_message(self._identifier, response)
		elif command == 'turnOff':
			response = self.turn_off("{ip}".format(**data))
			self._plugin_manager.send_plugin_message(self._identifier, response)
		elif command == 'checkStatus':
			response = self.check_status("{ip}".format(**data))
		elif command == 'getEnergyData':
			db = sqlite3.connect(self.db_path)
			cursor = db.cursor()
			cursor.execute('''SELECT timestamp, current, power, total, voltage FROM energy_data WHERE ip=? ORDER BY timestamp DESC LIMIT ?,?''', (data["ip"],data["record_offset"],data["record_limit"]))
			response = {'energy_data' : cursor.fetchall()}
			db.close()
github adilinden-oss / octoprint-webcamstreamer / octoprint_webcamstreamer / __init__.py View on Github external
def on_api_command(self, command, data):
        if not user_permission.can():
            from flask import make_response
            return make_response("Insufficient rights", 403)
        
        if command == 'startStream':
            self._logger.info("Start stream command received.")
            self._start_stream()

        if command == 'stopStream':
            self._logger.info("Stop stream command received.")
            self._stop_stream()

        if command == 'checkStream':
            self._logger.info("Checking stream status.")
            self._check_stream()
github jneilliii / OctoPrint-YouTubeLive / octoprint_youtubelive / __init__.py View on Github external
def on_api_command(self, command, data):
		if not user_permission.can():
			from flask import make_response
			return make_response("Insufficient rights", 403)
		
		if command == 'startStream':
			self._logger.info("Start stream command received.")
			self.startStream()

		if command == 'stopStream':
			self._logger.info("Stop stream command received.")
			self.stopStream()

		if command == 'checkStream':
			self._logger.info("Checking stream status.")
			if self.container:
				self._plugin_manager.send_plugin_message(self._identifier, dict(status=True,streaming=True))
			else:
github gdombiak / OctoPrint-OctoPod / octoprint_octopod / __init__.py View on Github external
def on_api_command(self, command, data):
		if not user_permission.can():
			return flask.make_response("Insufficient rights", 403)

		if command == 'updateToken':
			# Convert from ASCII to UTF-8 since somce chars will fail otherwise
			data["deviceName"] = data["deviceName"].encode("utf-8")
			printer_name = data["printerName"] if 'printerName' in data else None
			language_code = data["languageCode"] if 'languageCode' in data else None

			self.update_token("{oldToken}".format(**data), "{newToken}".format(**data), "{deviceName}".format(**data),
							  "{printerID}".format(**data), printer_name, language_code)
		elif command == 'test':
			payload = dict(
				state_id="OPERATIONAL",
				state_string="Operational"
			)
			code = self._job_notifications.send__print_job_notification(self._settings, self._printer, payload,