def handle_named_version(self): if verify_user_token(self.mscolab_server_url, self.token): version_name, completed = QtWidgets.QInputDialog.getText( self, 'Version Name Dialog', 'Enter version name:') if completed is True: if len(version_name) > 255 or len(version_name) == 0: show_popup( self, "Error", "Version name length has to be between 1 and 255") return selected_item = self.changes.currentItem() res = self.request_set_version_name(version_name, selected_item.id) if res.text != "False": res = res.json() if res["success"] is True: item_text = selected_item.text().split('\n')[-1] new_text = f"{version_name}\n{item_text}" selected_item.setText(new_text) selected_item.version_name = version_name self.deleteVersionNameBtn.setVisible(True) else: show_popup(self, "Error", res["message"]) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id)
def send_message(self): """ send message through connection """ if self.attachment is None: reply_id = -1 if self.active_message_reply is not None: reply_id = self.active_message_reply.id message_text = self.messageText.toPlainText() if message_text == "": return message_text = message_text.strip() self.conn.send_message(message_text, self.op_id, reply_id) else: files = {"file": open(self.attachment, 'rb')} data = { "token": self.token, "op_id": self.op_id, "message_type": int(self.attachment_type) } url = url_join(self.mscolab_server_url, 'message_attachment') try: requests.post(url, data=data, files=files) except requests.exceptions.ConnectionError: show_popup(self, "Error", "File size too large") self.send_message_state()
def import_permissions(self): if verify_user_token(self.mscolab_server_url, self.token): import_op_id = self.importPermissionsCB.currentData( QtCore.Qt.UserRole) data = { "token": self.token, "current_op_id": self.op_id, "import_op_id": import_op_id } url = url_join(self.mscolab_server_url, 'import_permissions') res = requests.post(url, data=data) if res.text != "False": res = res.json() if res["success"]: self.load_import_operations() self.load_users_without_permission() self.load_users_with_permission() else: show_popup(self, "Error", res["message"]) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id)
def export_config(self): invalid, dummy = self.validate_data() if invalid: show_popup( self, "Invalid values detected", "Please correct the invalid values (keys colored in red) to be able to save." ) self.statusbar.showMessage( "Please correct the values and try exporting") return False if self.json_model.serialize() == default_options: msg = """Since the current configuration matches the default configuration, \ only an empty json file would be exported.\nDo you still want to continue?""" ret = QtWidgets.QMessageBox.warning( self, self.tr("Mission Support System"), self.tr(msg), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if ret == QtWidgets.QMessageBox.No: return path = get_save_filename(self, "Export configuration", "msui_settings", "JSON files (*.json)") if path: self._save_to_path(path)
def add_selected_users(self): if verify_user_token(self.mscolab_server_url, self.token): selected_userids = self.get_selected_userids( self.addUsersTable, self.addUsers) if len(selected_userids) == 0: return selected_access_level = str(self.addUsersPermission.currentText()) data = { "token": self.token, "op_id": self.op_id, "selected_userids": json.dumps(selected_userids), "selected_access_level": selected_access_level } url = url_join(self.mscolab_server_url, "add_bulk_permissions") res = requests.post(url, data=data) if res.text != "False": res = res.json() if res["success"]: # TODO: Do we need a success popup? self.load_import_operations() self.load_users_without_permission() self.load_users_with_permission() else: show_popup(self, "Error", res["message"]) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id)
def load_users_with_permission(self): if verify_user_token(self.mscolab_server_url, self.token): self.modifyUsers = [] data = {"token": self.token, "op_id": self.op_id} url = url_join(self.mscolab_server_url, "users_with_permission") res = requests.get(url, data=data) if res.text != "False": res = res.json() if res["success"]: self.modifyUsers = res["users"] self.populate_table(self.modifyUsersTable, self.modifyUsers) text_filter = self.modifyUsersSearch.text() permission_filter = str( self.modifyUsersPermissionFilter.currentText()) self.apply_filters(self.modifyUsersTable, text_filter, permission_filter) else: show_popup(self, "Error", res["message"]) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id)
def save_config(self): invalid, dummy = self.validate_data() if invalid: show_popup( self, "Invalid values detected", "Please correct the invalid values (keys colored in red) to be able to save." ) self.statusbar.showMessage( "Please correct the values and try saving again") return False if dummy and self.check_modified(): ret = QtWidgets.QMessageBox.warning( self, self.tr("Dummy values detected"), self. tr("Dummy values detected (keys colored in gray.)\n" "Since they are dummy values you might face issues later on while working." "\n\nDo you still want to continue to save?"), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if ret == QtWidgets.QMessageBox.No: self.statusbar.showMessage( "Please correct the values and try saving") return False if self.check_modified(): if self.restart_on_save: ret = QtWidgets.QMessageBox.warning( self, self.tr("Mission Support System"), self. tr("Do you want to restart the application?\n" "(This is necessary to apply changes)\n\n" "Please note that clicking 'No' will not save the current configuration" ), QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if ret == QtWidgets.QMessageBox.Yes: logging.debug( f"saving config file to: {self.path} and restarting MSS" ) self._save_to_path(self.path) self.restartApplication.emit() self.restart_on_save = False self.close() else: return self.restart_on_save = True logging.debug(f"saving config file to: {self.path}") self._save_to_path(self.path) else: self.statusbar.showMessage("No values changed") return True
def handle_permissions_updated(self, u_id): if verify_user_token(self.mscolab_server_url, self.token): if self.user["id"] == u_id: return show_popup( self, 'Alert', 'The permissions for this operation were updated! The window is going to refresh.', 1) self.load_import_operations() self.load_users_without_permission() self.load_users_with_permission() else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id)
def load_users(self): # load users to side-tab here # make request to get users data = {"token": self.token, "op_id": self.op_id} url = url_join(self.mscolab_server_url, 'authorized_users') r = requests.get(url, data=data) if r.text != "False": self.collaboratorsList.clear() users = r.json()["users"] for user in users: item = QtWidgets.QListWidgetItem( f'{user["username"]} - {user["access_level"]}', parent=self.collaboratorsList) self.collaboratorsList.addItem(item) else: show_popup(self, "Error", "Session expired, new login required")
def handle_message_search(self, start_index, end_index, step=1): text = self.searchMessageLineEdit.text() if text == "": return for row in range(start_index, end_index, step): item = self.messageList.item(row) message_widget = self.messageList.itemWidget(item) if message_widget.message_type in (MessageType.TEXT, MessageType.DOCUMENT): if text.lower() in message_widget.message_text.lower(): self.messageList.scrollToItem( item, QtWidgets.QAbstractItemView.PositionAtCenter) item.setSelected(True) self.current_search_index = row return if self.current_search_index is None: show_popup(self, "Alert", "No message found!", 1)
def import_config(self): file_path = get_open_filename( self, "Import config", "", ";;".join(["JSON Files (*.json)", "All Files (*.*)"])) if not file_path: return # load data from selected file dir_name, file_name = fs.path.split(file_path) with fs.open_fs(dir_name) as _fs: if _fs.exists(file_name): file_content = _fs.readtext(file_name) try: json_file_data = json.loads( file_content, object_pairs_hook=dict_raise_on_duplicates_empty) except json.JSONDecodeError as e: show_popup(self, "Error while loading file", e) logging.error(f"Error while loading json file {e}") return except ValueError as e: show_popup(self, "Invalid keys detected", e) logging.error(f"Error while loading json file {e}") return if json_file_data: json_model_data = self.json_model.serialize() options = merge_dict(copy.deepcopy(json_model_data), json_file_data) if options == json_model_data: self.statusbar.showMessage("No option with new values found") return # replace existing data with new data self.json_model.init(options, editable_keys=True, editable_values=True) self.view.setColumnWidth(0, self.view.width() // 2) self.set_noneditable_items(QtCore.QModelIndex()) self.update_view() self.statusbar.showMessage("Successfully imported config") logging.debug("Imported new config data from file") else: self.statusbar.showMessage("No data found in the file") logging.debug("No data found in the file, using existing settings")
def load_all_messages(self): # empty messages and reload from server data = { "token": self.token, "op_id": self.op_id, "timestamp": datetime.datetime(1970, 1, 1).strftime("%Y-%m-%d, %H:%M:%S") } # returns an array of messages url = url_join(self.mscolab_server_url, "messages") res = requests.get(url, data=data) if res.text != "False": res = res.json() messages = res["messages"] # clear message box for message in messages: self.render_new_message(message, scroll=False) self.messageList.scrollToBottom() else: show_popup(self, "Error", "Session expired, new login required")
def handle_delete_version_name(self): if verify_user_token(self.mscolab_server_url, self.token): selected_item = self.changes.currentItem() res = self.request_set_version_name(None, selected_item.id) if res.text != "False": res = res.json() if res["success"] is True: # Remove item if the filter is set to Named version if self.versionFilterCB.currentIndex() == 0: self.changes.takeItem(self.changes.currentRow()) # Remove name from item else: item_text = selected_item.text().split('\n')[-1] selected_item.setText(item_text) selected_item.version_name = None self.deleteVersionNameBtn.setVisible(False) else: show_popup(self, "Error", res["message"]) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id) else: # this triggers disconnect self.conn.signal_reload.emit(self.op_id)