def createWorkspace(self, name, description=""): """Uses the instance of workspace manager passed into __init__ to get all the workspaces names and see if they don't clash with the one the user wrote. If everything's fine, it saves the new workspace and returns True. If something went wrong, return False""" if name in self.workspace_manager.getWorkspacesNames(): error_str = "A workspace with name %s already exists" % name faraday_client.model.api.log(error_str, "ERROR") errorDialog(self.window, error_str) creation_ok = False else: faraday_client.model.api.log("Creating workspace '%s'" % name) faraday_client.model.api.devlog("Looking for the delegation class") manager = self.getWorkspaceManager() try: name = manager.createWorkspace(name, description) self.change_workspace(name) creation_ok = True except Exception as e: faraday_client.model.guiapi.notification_center.showDialog( str(e)) creation_ok = False return creation_ok
def on_open_report_button(self, action, param): """What happens when the user clicks the open report button. A dialog will present itself with a combobox to select a plugin. Then a file chooser to select a report. The report will be processed with the selected plugin. """ def select_plugin(): """Creates a simple dialog with a combo box to select a plugin""" plugins_id = self.plugin_manager.plugins() plugins_id = sorted(plugins_id, key=lambda s: s[0].lower()) dialog = Gtk.Dialog("Select plugin", self.window, 0) combo_box = Gtk.ComboBoxText() combo_box.set_wrap_width(3) for plugin_id, plugin in plugins_id: combo_box.append_text(plugin_id) combo_box.show() dialog.vbox.pack_start(combo_box, False, True, 10) dialog.add_button("Cancel", Gtk.ResponseType.DELETE_EVENT) dialog.add_button("OK", Gtk.ResponseType.ACCEPT) response = dialog.run() selected = combo_box.get_active_text() dialog.destroy() return response, selected def on_file_selected(plugin_id, report): """Send the plugin_id and the report file to be processed""" try: self.report_manager.sendReportToPluginById(plugin_id, report) except Unauthorized: self.show_normal_error("You are not authorized to write data " "to this workspace.") plugin_response, plugin_id = select_plugin() while plugin_response == Gtk.ResponseType.ACCEPT and plugin_id is None: # force user to select a plugin if he did not do it errorDialog(self.window, "Please select a plugin to parse your report!") plugin_response, plugin_id = select_plugin() else: if plugin_response == Gtk.ResponseType.ACCEPT: dialog = Gtk.FileChooserDialog( title="Import a report", parent=self.window, action=Gtk.FileChooserAction.OPEN, buttons=("Open", Gtk.ResponseType.ACCEPT, "Cancel", Gtk.ResponseType.CANCEL)) dialog.set_modal(True) res = dialog.run() if res == Gtk.ResponseType.ACCEPT: on_file_selected(plugin_id, dialog.get_filename()) dialog.destroy()
def connect_to_couch(self, server_url, parent=None): """Tries to connect to a CouchDB on a specified Couch URI. Returns the success status of the operation, False for not successful, True for successful """ def certs_ok(server_uri): """Returns True if URI started with https and cert if valid or if URI dind't start with https. False if URI started with https but didn't pass the checkSSL test. """ if server_uri.startswith("https://"): return checkSSL(server_uri) else: return True if parent is None: parent = self.window if not self.serverIO.check_server_url(server_url): errorDialog(parent, "Could not connect to Faraday Server.", ("Are you sure it is running and that you can " "connect to it? \n Make sure your username and " "password are still valid.")) success = False elif server_url.startswith("https://"): if not checkSSL(server_url): errorDialog(self.window, "The SSL certificate validation has failed") success = False else: CONF.setAPIUrl(server_url) CONF.saveConfig() self.reload_workspaces() self.open_last_workspace() success = True self.lost_connection_dialog_raised = False return success
def handle_no_active_workspace(self): """If there's been a problem opening a workspace or for some reason we suddenly find our selves without one, force the user to select one if possible, or if not, to create one. """ def change_flag(widget): self.workspace_dialogs_raised = not self.workspace_dialogs_raised if self.workspace_dialogs_raised: return False if self.serverIO.server_info() is None: # make sure it is not because we're not connected to Couch # there's another whole strategy for that. return False self.workspace_dialogs_raised = True self.ws_sidebar.refresh_sidebar() available_workspaces = self.serverIO.get_workspaces_names() workspace_model = self.ws_sidebar.workspace_model if available_workspaces: dialog = ForceChooseWorkspaceDialog(self.window, workspace_model, self.change_workspace) else: user_info = get_user_info() if user_info['role'] != "admin": def exit(*args, **kwargs): logger.info( "Exit because there are no workspaces found, and user is not admin" ) GObject.idle_add(self.window.destroy) GObject.idle_add(self.on_quit) error_message = "You don't have permissions or no workspace is available.\n" \ "Please contact faraday admin to create a workspace or to assign permissions." dialog = errorDialog(self.window, error_message) dialog.connect("destroy", exit) return else: dialog = ForceNewWorkspaceDialog(self.window, self.createWorkspace, self.workspace_manager, self.ws_sidebar, self.exit_faraday) self.force_new_workspace_dialog = dialog dialog.connect("destroy", change_flag) dialog.show_all()