def dropbox_upload(node_addon, auth, **kwargs): """View for uploading a file from the filebrowser interface. Must return the Rubeus/HGrid representation of the newly added file. """ node = node_addon.owner # Route may or may not have a path path = kwargs.get('path', node_addon.folder) client = get_node_addon_client(node_addon) file_obj = request.files.get('file', None) node = node_addon.owner if path and file_obj and client: filepath = os.path.join(path, file_obj.filename) # Check that user has access to the folder being uploaded to if not is_authorizer(auth, node_addon): abort_if_not_subdir(path, node_addon.folder) metadata = client.put_file(filepath, file_obj) permissions = { 'edit': node.can_edit(auth), 'view': node.can_view(auth) } # Log the event nodelogger = DropboxNodeLogger(node=node, auth=auth, path=filepath) nodelogger.log(NodeLog.FILE_ADDED, save=True) # Return the HGrid-formatted JSON response return metadata_to_hgrid(metadata, node=node, permissions=permissions), http.CREATED raise HTTPError(http.BAD_REQUEST)
def set_user_auth(self, user_settings): """Import a user's Dropbox authentication and create a NodeLog. :param DropboxUserSettings user_settings: The user settings to link. """ self.user_settings = user_settings nodelogger = DropboxNodeLogger(node=self.owner, auth=Auth(user_settings.owner)) nodelogger.log(action="node_authorized", save=True)
def deauthorize(self, auth=None, add_log=True): """Remove user authorization from this node and log the event.""" node = self.owner folder = self.folder self.folder = None self.user_settings = None if add_log: extra = {'folder': folder} nodelogger = DropboxNodeLogger(node=node, auth=auth) nodelogger.log(action="node_deauthorized", extra=extra, save=True)
def dropbox_delete_file(path, auth, node_addon, **kwargs): node = node_addon.owner if path and auth: # Check that user has access to the folder of the file to be deleted if not is_authorizer(auth, node_addon): abort_if_not_subdir(path, node_addon.folder) client = get_node_addon_client(node_addon) client.file_delete(path) # log the event nodelogger = DropboxNodeLogger(node=node, auth=auth, path=path) nodelogger.log(NodeLog.FILE_REMOVED, save=True) return None raise HTTPError(http.BAD_REQUEST)
def set_folder(self, folder, auth): self.folder = folder # Add log to node nodelogger = DropboxNodeLogger(node=self.owner, auth=auth) nodelogger.log(action="folder_selected", save=True)