How to use the octoprint.server.admin_permission.require 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 OctoPrint / OctoPrint-FirmwareUpdater / tests / test_firmwareupdater.py View on Github external
# -*- coding: utf-8 -*-
import unittest
import mock

import octoprint.server.util.flask
def _restricted_access(func):
	return func
octoprint.server.util.flask.restricted_access = _restricted_access

import octoprint.server
def _require(v):
	def __require(func):
		return func
	return __require
octoprint.server.admin_permission.require = _require

import sarge
import octoprint_firmwareupdater


class TestFlashWithPath(unittest.TestCase):

	@mock.patch('shutil.copyfileobj')
	@mock.patch('__builtin__.open')
	@mock.patch('tempfile.NamedTemporaryFile')
	@mock.patch.object(octoprint_firmwareupdater.FirmwareupdaterPlugin, '_check_avrdude')
	@mock.patch('shutil.copyfileobj')
	@mock.patch('threading.Thread.start')
	@mock.patch('octoprint.plugin.BlueprintPlugin.route')
	@mock.patch('octoprint_firmwareupdater.flask')
	@mock.patch.object(octoprint_firmwareupdater.FirmwareupdaterPlugin, '_send_status')
github AstroPrint / OctoPrint-AstroPrint / octoprint_astroprint / __init__.py View on Github external
	@admin_permission.require(403)
	def getManufacturers(self):
		return self.astroprintCloud.getManufacturer()
github AstroPrint / OctoPrint-AstroPrint / octoprint_astroprint / __init__.py View on Github external
	@admin_permission.require(403)
	def iscameraconnected(self):
		return jsonify({"connected" : True if self.cameraManager.cameraActive else False }), 200, {'ContentType':'application/json'}
github AstroPrint / OctoPrint-AstroPrint / octoprint_astroprint / __init__.py View on Github external
	@admin_permission.require(403)
	def getManufacturerModels(self):
		manufacturerId = request.args.get('manufacturerId', None)
		return self.astroprintCloud.getManufacturerModels(manufacturerId)
github tohara / OctoPrint-BigBoxFirmware / octoprint_bigboxfirmware / __init__.py View on Github external
    @octoprint.plugin.BlueprintPlugin.route("/firmwareprofiles/", methods=["PATCH"])
    @octoprint.server.util.flask.restricted_access
    @octoprint.server.admin_permission.require(403)
    def updateProfile(self, identifier):
        dataFolder = self.get_plugin_data_folder()
        profile_folder = dataFolder + '/profiles'
        
        if not os.path.isdir(profile_folder):
            os.mkdir(profile_folder)
            
        profile_id = flask.request.json['profile']['id']
        
        profile_file = open(profile_folder + '/' + profile_id, 'w+b')
        
        profile_file.write(str(flask.request.json))
        profile_file.flush()
        profile_file.close()
github AstroPrint / OctoPrint-AstroPrint / octoprint_astroprint / __init__.py View on Github external
	@admin_permission.require(403)
	def getPrintFiles(self):
		designId = request.args.get('designId', None)
		return self.astroprintCloud.getPrintFiles(designId)
github AstroPrint / OctoPrint-AstroPrint / octoprint_astroprint / __init__.py View on Github external
	@admin_permission.require(403)
	def checkcamerastatus(self):
		self.cameraManager.checkCameraStatus()
		return jsonify({"connected" : True if self.cameraManager.cameraActive else False }), 200, {'ContentType':'application/json'}
github AstroPrint / OctoPrint-AstroPrint / octoprint_astroprint / __init__.py View on Github external
	@admin_permission.require(403)
	def removefilament(self):
		self._settings.set(['filament'], {'name' : None, 'color' : None})
		self._settings.save()
		self.astroprintCloud.bm.triggerEvent('filamentChanged', {'filament' : {'name' : None, 'color' : None}})
		return jsonify({"Filament removed" : True }), 200, {'ContentType':'application/json'}
github AstroPrint / OctoPrint-AstroPrint / octoprint_astroprint / __init__.py View on Github external
	@admin_permission.require(403)
	def downloadPrintFile(self):
		printFileId = request.json['printFileId']
		printNow = request.json['printNow']
		if self.astroprintCloud.printFile(printFileId, printNow) == "print":
			return jsonify({"state" : "printing"}), 200, {'ContentType':'application/json'}
		if self.astroprintCloud.printFile(printFileId, printNow) == "download":
			return jsonify({"state" : "downloading"}), 200, {'ContentType':'application/json'}
		return jsonify({'error': "Internal server error"}), 500, {'ContentType':'application/json'}
github tohara / OctoPrint-BigBoxFirmware / octoprint_bigboxfirmware / __init__.py View on Github external
    @octoprint.plugin.BlueprintPlugin.route("/updateRepos/", methods=["PATCH"])
    @octoprint.server.util.flask.restricted_access
    @octoprint.server.admin_permission.require(403)
    def updateRepos(self):
       
        repo = flask.request.json['repo']
        repoUrl = repo['repoUrl']
        repoNamePath = self.getRepoNamePath(repoUrl)
        
        self._sendStatus(line= 'Pull changes from remote:' + repoUrl, stream='stdout')
        
        self.execute(['git', 'fetch'], cwd= repoNamePath)
        
        self._sendStatus(line= 'Updating define library', stream='stdout')
        
        gitInfo = self.getGitInfo(repoNamePath)
        
        for branch in gitInfo['branchList']:
            self.execute(['git', 'checkout', '-f', branch], cwd= repoNamePath) # Throw away any changes before pull