def DELETE(self, name=None): try: logging.info("[LayMan][DELETE] %s"% name) params = repr(web.input()) logging.info("[LayMan][DELETE] Parameters: %s ... %s"%\ (str(params)[:500], str(params)[-500:])) if not self.auth.authorised: logging.error("[LayMan][DELETE] Unauthorised") raise AuthError(401, "Authorisation failed. Are you logged-in?") code = 404 # 200, 404... message = "Call not supported: DELETE "+name+" Please check the API doc or report a bug if appropriate." path = [d for d in name.split(os.path.sep) if d] if len(name) > 0: if path[0] != "fileman" and not self.auth.canDelete(): logging.error("[LayMan][DELETE] Only admin can DELETE") raise AuthError(401, "Authorisation failed. Only Administrator can delete") # /fileman/file.shp" if path[0] == "fileman": from fileman import FileMan fm = FileMan() fileName = name[8:] (code, message) = fm.deleteFile(self._getTargetFile(path[-1])) # /user/<username> elif path[0] == "user" and len(path) == 2: userName = path[1] from userprefs import UserPrefs up = UserPrefs(config) (code, message) = up.deleteUser(userName) # /layed/<layer> elif path[0] == "layed" and len(path) == 2: from layed import LayEd le = LayEd() layerName = path[1] inpt = web.input(usergroup=None) deleteTable = True if "deleteTable" in inpt: if inpt["deleteTable"].lower() == "false": deleteTable = False gsWorkspace = self.auth.getGSWorkspace(inpt.usergroup) dbSchema = self.auth.getDBSchema(inpt.usergroup) logging.info("[LayMan][DELETE] Delete layer '%s'"% layerName ) logging.info("[LayMan][DELETE] Delete from workspace '%s'"% gsWorkspace) (code, message) = le.deleteLayer(gsWorkspace, layerName, dbSchema, deleteTable) # /publish/<layer> elif path[0] == "publish" and len(path) == 2: from layed import LayEd le = LayEd() layerName = path[1] inpt = web.input() if not "schema" in inpt: raise LaymanError( 400, "'schema' parameter missing") gsWorkspace = self.auth.getGSWorkspace(inpt.schema) dbSchema = self.auth.getDBSchema(inpt.schema) logging.info("[LayMan][DELETE] Delete layer '%s'"% layerName ) logging.info("[LayMan][DELETE] Delete from workspace '%s'"% gsWorkspace) (code, message) = le.deleteLayer(gsWorkspace, layerName, dbSchema, deleteTable=False) success = self._setReturnCode(code) retval = self._jsonReply(code, message, success) return retval except LaymanError as le: return self._handleLaymanError(le) except Exception as e: return self._handleException(e)
def DELETE(self, name=None): try: logging.info("[LayMan][DELETE] %s"% name) params = repr(web.input()) logging.info("[LayMan][DELETE] Parameters: %s ... %s"%\ (str(params)[:500], str(params)[-500:])) if not self.auth.authorised: logging.error("[LayMan][DELETE] Unauthorised") raise AuthError(401, "Authorisation failed. Are you logged-in?") code = 404 # 200, 404... message = "Call not supported: DELETE "+name+" Please check the API doc or report a bug if appropriate." path = [d for d in name.split(os.path.sep) if d] if len(name) > 0: # /files/<user>/file.shp" if path[0] == "files" and len(path) == 3: from fileman import FileMan fm = FileMan() # Everyone can DELETE only his/her own files userName = self.auth.getUserName() if userName != path[1]: logging.error("[LayMan][DELETE] %s is not authorized to delete files of %s"% (userName, path[1])) raise AuthError(401, "Sorry, you are not authorized to delete files of %s"% path[1]) (code, message) = fm.deleteFile(self._getTargetFile(path[-1])) # /user/<username> elif path[0] == "user" and len(path) == 2: userName = path[1] from userprefs import UserPrefs up = UserPrefs(config) (code, message) = up.deleteUser(userName) # /layers/<group>/<layer> # was /layed/<layer> elif path[0] == "layers" and len(path) == 3: from layed import LayEd le = LayEd() # Check authorization for the given group checkRole = self.auth.getRole(path[1]) if checkRole["roleName"] != path[1]: logging.error("[LayMan][DELETE] Not authorized to DELETE layer from %s group"% path[1]) raise AuthError(401, "Sorry, you are not authorized to delete layer from %s group"% path[1]) gsWorkspace = self.auth.getGSWorkspace(path[1]) dbSchema = self.auth.getDBSchema(path[1]) logging.info("[LayMan][DELETE] Delete layer '%s'"% path[2] ) logging.info("[LayMan][DELETE] Delete from workspace '%s'"% gsWorkspace) # Delete layer only (code, message) = le.deleteLayer(gsWorkspace, path[2], dbSchema, deleteTable=False) # /datalayers/<group>/<layer> elif path[0] == "datalayers" and len(path) == 3: from layed import LayEd le = LayEd() # Check authorization for the given group checkRole = self.auth.getRole(path[1]) if checkRole["roleName"] != path[1]: logging.error("[LayMan][DELETE] Not authorized to DELETE layer from %s group"% path[1]) raise AuthError(401, "Sorry, you are not authorized to delete layer from %s group"% path[1]) gsWorkspace = self.auth.getGSWorkspace(path[1]) dbSchema = self.auth.getDBSchema(path[1]) logging.info("[LayMan][DELETE] Delete layer and data '%s'"% path[2] ) logging.info("[LayMan][DELETE] Delete from workspace '%s'"% gsWorkspace) # Delete layer and data (code, message) = le.deleteLayer(gsWorkspace, path[2], dbSchema, deleteTable=True) success = self._setReturnCode(code) retval = self._jsonReply(code, message, success) return retval except LaymanError as le: return self._handleLaymanError(le) except Exception as e: return self._handleException(e)