From 28c30f18b1a804ec06800753e214f016712109ae Mon Sep 17 00:00:00 2001 From: Divyansh Singh <divyanshanandsingh@gmail.com> Date: Fri, 17 Mar 2023 16:32:49 +0530 Subject: [PATCH 1/6] feat: add settings to allow new networks in vorta and show notif when a network is disallowed --- src/vorta/application.py | 16 ++++++++++------ src/vorta/assets/UI/scheduletab.ui | 26 ++++++++++++++++++++------ src/vorta/scheduler.py | 14 +++++++++----- src/vorta/store/connection.py | 2 +- src/vorta/store/migrations.py | 16 ++++++++++++++++ src/vorta/store/models.py | 2 ++ src/vorta/utils.py | 3 ++- src/vorta/views/schedule_tab.py | 12 ++++++++++++ tests/conftest.py | 2 ++ tests/profile_exports/valid.json | 2 ++ 10 files changed, 76 insertions(+), 19 deletions(-) diff --git a/src/vorta/application.py b/src/vorta/application.py index 3c9327db6..aa7c08a3f 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -113,12 +113,16 @@ def create_backup_action(self, profile_id=None): job = BorgCreateJob(msg['cmd'], msg, profile.repo.id) self.jobs_manager.add_job(job) else: - notifier = VortaNotifications.pick() - notifier.deliver( - self.tr('Vorta Backup'), - translate('messages', msg['message']), - level='error', - ) + if not ( + msg['message'] == 'Current Wifi is not allowed.' + and not profile.show_notification_when_network_disallowed + ): + notifier = VortaNotifications.pick() + notifier.deliver( + self.tr('Vorta Backup'), + translate('messages', msg['message']), + level='error', + ) self.backup_progress_event.emit(translate('messages', msg['message'])) return None diff --git a/src/vorta/assets/UI/scheduletab.ui b/src/vorta/assets/UI/scheduletab.ui index 67dbc2c2f..cc6242e35 100644 --- a/src/vorta/assets/UI/scheduletab.ui +++ b/src/vorta/assets/UI/scheduletab.ui @@ -38,8 +38,8 @@ <rect> <x>0</x> <y>0</y> - <width>687</width> - <height>384</height> + <width>898</width> + <height>361</height> </rect> </property> <property name="font"> @@ -520,7 +520,7 @@ <x>0</x> <y>0</y> <width>687</width> - <height>384</height> + <height>378</height> </rect> </property> <attribute name="label"> @@ -530,7 +530,7 @@ <property name="verticalSpacing"> <number>12</number> </property> - <item row="1" column="0"> + <item row="3" column="0"> <layout class="QVBoxLayout" name="verticalLayout_8"> <property name="spacing"> <number>4</number> @@ -567,6 +567,20 @@ </property> </widget> </item> + <item row="1" column="0"> + <widget class="QCheckBox" name="allowNewNetworksCheckBox"> + <property name="text"> + <string>Allow new networks by default</string> + </property> + </widget> + </item> + <item row="2" column="0"> + <widget class="QCheckBox" name="networkDisallowedNotificationCheckBox"> + <property name="text"> + <string>Show notification when a network is disallowed</string> + </property> + </widget> + </item> </layout> </widget> <widget class="QWidget" name="page"> @@ -575,7 +589,7 @@ <x>0</x> <y>0</y> <width>687</width> - <height>384</height> + <height>378</height> </rect> </property> <attribute name="label"> @@ -634,7 +648,7 @@ <x>0</x> <y>0</y> <width>687</width> - <height>384</height> + <height>378</height> </rect> </property> <attribute name="label"> diff --git a/src/vorta/scheduler.py b/src/vorta/scheduler.py index 4cace732c..7c50e9425 100644 --- a/src/vorta/scheduler.py +++ b/src/vorta/scheduler.py @@ -418,11 +418,15 @@ def create_backup(self, profile_id): else: logger.error('Conditions for backup not met. Aborting.') logger.error(msg['message']) - notifier.deliver( - self.tr('Vorta Backup'), - translate('messages', msg['message']), - level='error', - ) + if not ( + msg['message'] == 'Current Wifi is not allowed.' + and not profile.show_notification_when_network_disallowed + ): + notifier.deliver( + self.tr('Vorta Backup'), + translate('messages', msg['message']), + level='error', + ) self.pause(profile_id) def notify(self, result): diff --git a/src/vorta/store/connection.py b/src/vorta/store/connection.py index 72a3461f2..16670efce 100644 --- a/src/vorta/store/connection.py +++ b/src/vorta/store/connection.py @@ -18,7 +18,7 @@ ) from .settings import get_misc_settings -SCHEMA_VERSION = 20 +SCHEMA_VERSION = 21 @signals.post_save(sender=SettingsModel) diff --git a/src/vorta/store/migrations.py b/src/vorta/store/migrations.py index 0db00e9fb..434e88103 100644 --- a/src/vorta/store/migrations.py +++ b/src/vorta/store/migrations.py @@ -226,6 +226,22 @@ def run_migrations(current_schema, db_connection): migrator.add_column(SettingsModel._meta.table_name, 'tooltip', pw.CharField(default='')), ) + if current_schema.version < 21: + _apply_schema_update( + current_schema, + 21, + migrator.add_column( + BackupProfileModel._meta.table_name, + 'allow_new_networks', + pw.BooleanField(default=False), + ), + migrator.add_column( + BackupProfileModel._meta.table_name, + "show_notification_when_network_disallowed", + pw.BooleanField(default=True), + ), + ) + def _apply_schema_update(current_schema, version_after, *operations): with DB.atomic(): diff --git a/src/vorta/store/models.py b/src/vorta/store/models.py index c893764e4..356f296a9 100644 --- a/src/vorta/store/models.py +++ b/src/vorta/store/models.py @@ -95,6 +95,8 @@ class BackupProfileModel(BaseModel): pre_backup_cmd = pw.CharField(default='') post_backup_cmd = pw.CharField(default='') dont_run_on_metered_networks = pw.BooleanField(default=True) + allow_new_networks = pw.BooleanField(default=False) + show_notification_when_network_disallowed = pw.BooleanField(default=True) def refresh(self): return type(self).get(self._pk_expr()) diff --git a/src/vorta/utils.py b/src/vorta/utils.py index 6217fb518..fa2f94fab 100644 --- a/src/vorta/utils.py +++ b/src/vorta/utils.py @@ -322,12 +322,13 @@ def get_sorted_wifis(profile): # Pull networks known to OS and all other backup profiles system_wifis = get_network_status_monitor().get_known_wifis() from_other_profiles = WifiSettingModel.select().where(WifiSettingModel.profile != profile.id).execute() + allow_new_networks = profile.allow_new_networks for wifi in list(from_other_profiles) + system_wifis: db_wifi, created = WifiSettingModel.get_or_create( ssid=wifi.ssid, profile=profile.id, - defaults={'last_connected': wifi.last_connected, 'allowed': True}, + defaults={'last_connected': wifi.last_connected, 'allowed': allow_new_networks}, ) # Update last connected time diff --git a/src/vorta/views/schedule_tab.py b/src/vorta/views/schedule_tab.py index 55837c3fa..95940c7e8 100644 --- a/src/vorta/views/schedule_tab.py +++ b/src/vorta/views/schedule_tab.py @@ -75,6 +75,12 @@ def __init__(self, parent=None): self.meteredNetworksCheckBox.stateChanged.connect( lambda new_val, attr='dont_run_on_metered_networks': self.save_profile_attr(attr, not new_val) ) + self.allowNewNetworksCheckBox.stateChanged.connect( + lambda new_val, attr='allow_new_networks': self.save_profile_attr(attr, new_val) + ) + self.networkDisallowedNotificationCheckBox.stateChanged.connect( + lambda new_val, attr='show_notification_when_network_disallowed': self.save_profile_attr(attr, new_val) + ) self.postBackupCmdLineEdit.textEdited.connect( lambda new_val, attr='post_backup_cmd': self.save_profile_attr(attr, new_val) ) @@ -149,6 +155,12 @@ def populate_from_profile(self): self.meteredNetworksCheckBox.setChecked( QtCore.Qt.Unchecked if profile.dont_run_on_metered_networks else QtCore.Qt.Checked ) + self.allowNewNetworksCheckBox.setChecked( + QtCore.Qt.Checked if profile.allow_new_networks else QtCore.Qt.Unchecked + ) + self.networkDisallowedNotificationCheckBox.setChecked( + QtCore.Qt.Checked if profile.show_notification_when_network_disallowed else QtCore.Qt.Unchecked + ) self.preBackupCmdLineEdit.setText(profile.pre_backup_cmd) self.postBackupCmdLineEdit.setText(profile.post_backup_cmd) diff --git a/tests/conftest.py b/tests/conftest.py index 9350489c2..ee435f3bc 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -78,6 +78,8 @@ def init_db(qapp, qtbot, tmpdir_factory): default_profile.repo = new_repo.id default_profile.dont_run_on_metered_networks = False + default_profile.allow_new_networks = False + default_profile.show_notification_when_network_disallowed = True default_profile.validation_on = False default_profile.save() diff --git a/tests/profile_exports/valid.json b/tests/profile_exports/valid.json index 9b8fe32f4..f0ddf6e9f 100644 --- a/tests/profile_exports/valid.json +++ b/tests/profile_exports/valid.json @@ -36,6 +36,8 @@ "password": "Tr0ub4dor&3", "post_backup_cmd": "", "dont_run_on_metered_networks": true, + "allow_new_networks": false, + "show_notification_when_network_disallowed": true, "SourceFileModel": [ { "dir": "/this/is/a/test/file", From 213ba8c3b561fcb9d143ee47990832923384e32c Mon Sep 17 00:00:00 2001 From: Divyansh Singh <divyanshanandsingh@gmail.com> Date: Fri, 17 Mar 2023 16:40:41 +0530 Subject: [PATCH 2/6] change tests defaults to true --- tests/conftest.py | 2 +- tests/profile_exports/valid.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index ee435f3bc..18d58b450 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -78,7 +78,7 @@ def init_db(qapp, qtbot, tmpdir_factory): default_profile.repo = new_repo.id default_profile.dont_run_on_metered_networks = False - default_profile.allow_new_networks = False + default_profile.allow_new_networks = True default_profile.show_notification_when_network_disallowed = True default_profile.validation_on = False default_profile.save() diff --git a/tests/profile_exports/valid.json b/tests/profile_exports/valid.json index f0ddf6e9f..b14a31772 100644 --- a/tests/profile_exports/valid.json +++ b/tests/profile_exports/valid.json @@ -36,7 +36,7 @@ "password": "Tr0ub4dor&3", "post_backup_cmd": "", "dont_run_on_metered_networks": true, - "allow_new_networks": false, + "allow_new_networks": true, "show_notification_when_network_disallowed": true, "SourceFileModel": [ { From dce04dff3170a6b25bc3b032bf73a502a23ac8a8 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <divyanshanandsingh@gmail.com> Date: Sat, 18 Mar 2023 00:19:29 +0530 Subject: [PATCH 3/6] refactor --- src/vorta/application.py | 5 +---- src/vorta/scheduler.py | 6 +++--- src/vorta/store/migrations.py | 2 +- src/vorta/views/schedule_tab.py | 8 ++------ 4 files changed, 7 insertions(+), 14 deletions(-) diff --git a/src/vorta/application.py b/src/vorta/application.py index aa7c08a3f..d20dff35a 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -113,10 +113,7 @@ def create_backup_action(self, profile_id=None): job = BorgCreateJob(msg['cmd'], msg, profile.repo.id) self.jobs_manager.add_job(job) else: - if not ( - msg['message'] == 'Current Wifi is not allowed.' - and not profile.show_notification_when_network_disallowed - ): + if msg['message'] != 'Current Wifi is not allowed.' or profile.show_notification_when_network_disallowed: notifier = VortaNotifications.pick() notifier.deliver( self.tr('Vorta Backup'), diff --git a/src/vorta/scheduler.py b/src/vorta/scheduler.py index 7c50e9425..1d0d1fed6 100644 --- a/src/vorta/scheduler.py +++ b/src/vorta/scheduler.py @@ -418,9 +418,9 @@ def create_backup(self, profile_id): else: logger.error('Conditions for backup not met. Aborting.') logger.error(msg['message']) - if not ( - msg['message'] == 'Current Wifi is not allowed.' - and not profile.show_notification_when_network_disallowed + if ( + msg['message'] != 'Current Wifi is not allowed.' + or profile.show_notification_when_network_disallowed ): notifier.deliver( self.tr('Vorta Backup'), diff --git a/src/vorta/store/migrations.py b/src/vorta/store/migrations.py index 434e88103..7047c072f 100644 --- a/src/vorta/store/migrations.py +++ b/src/vorta/store/migrations.py @@ -233,7 +233,7 @@ def run_migrations(current_schema, db_connection): migrator.add_column( BackupProfileModel._meta.table_name, 'allow_new_networks', - pw.BooleanField(default=False), + pw.BooleanField(default=True), ), migrator.add_column( BackupProfileModel._meta.table_name, diff --git a/src/vorta/views/schedule_tab.py b/src/vorta/views/schedule_tab.py index 95940c7e8..fefdca441 100644 --- a/src/vorta/views/schedule_tab.py +++ b/src/vorta/views/schedule_tab.py @@ -155,12 +155,8 @@ def populate_from_profile(self): self.meteredNetworksCheckBox.setChecked( QtCore.Qt.Unchecked if profile.dont_run_on_metered_networks else QtCore.Qt.Checked ) - self.allowNewNetworksCheckBox.setChecked( - QtCore.Qt.Checked if profile.allow_new_networks else QtCore.Qt.Unchecked - ) - self.networkDisallowedNotificationCheckBox.setChecked( - QtCore.Qt.Checked if profile.show_notification_when_network_disallowed else QtCore.Qt.Unchecked - ) + self.allowNewNetworksCheckBox.setChecked(profile.allow_new_networks) + self.networkDisallowedNotificationCheckBox.setChecked(profile.show_notification_when_network_disallowed) self.preBackupCmdLineEdit.setText(profile.pre_backup_cmd) self.postBackupCmdLineEdit.setText(profile.post_backup_cmd) From 03b759ec992bc12188cc210f6de04c340d6a2fda Mon Sep 17 00:00:00 2001 From: Divyansh Singh <divyanshanandsingh@gmail.com> Date: Sat, 18 Mar 2023 00:24:37 +0530 Subject: [PATCH 4/6] revert unintended dimension changes --- src/vorta/assets/UI/scheduletab.ui | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/vorta/assets/UI/scheduletab.ui b/src/vorta/assets/UI/scheduletab.ui index cc6242e35..af5a0ecec 100644 --- a/src/vorta/assets/UI/scheduletab.ui +++ b/src/vorta/assets/UI/scheduletab.ui @@ -38,8 +38,8 @@ <rect> <x>0</x> <y>0</y> - <width>898</width> - <height>361</height> + <width>687</width> + <height>384</height> </rect> </property> <property name="font"> @@ -520,7 +520,7 @@ <x>0</x> <y>0</y> <width>687</width> - <height>378</height> + <height>384</height> </rect> </property> <attribute name="label"> @@ -589,7 +589,7 @@ <x>0</x> <y>0</y> <width>687</width> - <height>378</height> + <height>384</height> </rect> </property> <attribute name="label"> @@ -648,7 +648,7 @@ <x>0</x> <y>0</y> <width>687</width> - <height>378</height> + <height>384</height> </rect> </property> <attribute name="label"> From b5811da23a1ab2efe4c2a508549e55d37f8eaef2 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <divyanshanandsingh@gmail.com> Date: Fri, 7 Apr 2023 09:17:45 +0530 Subject: [PATCH 5/6] remove notification setting for disallowed networks --- src/vorta/application.py | 2 +- src/vorta/assets/UI/scheduletab.ui | 21 +++++++-------------- src/vorta/scheduler.py | 5 +---- src/vorta/store/migrations.py | 5 ----- src/vorta/store/models.py | 1 - src/vorta/views/schedule_tab.py | 4 ---- tests/conftest.py | 1 - tests/profile_exports/valid.json | 1 - 8 files changed, 9 insertions(+), 31 deletions(-) diff --git a/src/vorta/application.py b/src/vorta/application.py index b0e9b560d..7b789b27c 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -113,7 +113,7 @@ def create_backup_action(self, profile_id=None): job = BorgCreateJob(msg['cmd'], msg, profile.repo.id) self.jobs_manager.add_job(job) else: - if msg['message'] != 'Current Wifi is not allowed.' or profile.show_notification_when_network_disallowed: + if msg['message'] != 'Current Wifi is not allowed.': notifier = VortaNotifications.pick() notifier.deliver( self.tr('Vorta Backup'), diff --git a/src/vorta/assets/UI/scheduletab.ui b/src/vorta/assets/UI/scheduletab.ui index af5a0ecec..d7c8ea860 100644 --- a/src/vorta/assets/UI/scheduletab.ui +++ b/src/vorta/assets/UI/scheduletab.ui @@ -530,7 +530,7 @@ <property name="verticalSpacing"> <number>12</number> </property> - <item row="3" column="0"> + <item row="2" column="0"> <layout class="QVBoxLayout" name="verticalLayout_8"> <property name="spacing"> <number>4</number> @@ -557,16 +557,6 @@ </item> </layout> </item> - <item row="0" column="0"> - <widget class="QCheckBox" name="meteredNetworksCheckBox"> - <property name="text"> - <string>Run backups over metered networks</string> - </property> - <property name="tristate"> - <bool>false</bool> - </property> - </widget> - </item> <item row="1" column="0"> <widget class="QCheckBox" name="allowNewNetworksCheckBox"> <property name="text"> @@ -574,10 +564,13 @@ </property> </widget> </item> - <item row="2" column="0"> - <widget class="QCheckBox" name="networkDisallowedNotificationCheckBox"> + <item row="0" column="0"> + <widget class="QCheckBox" name="meteredNetworksCheckBox"> <property name="text"> - <string>Show notification when a network is disallowed</string> + <string>Run backups over metered networks</string> + </property> + <property name="tristate"> + <bool>false</bool> </property> </widget> </item> diff --git a/src/vorta/scheduler.py b/src/vorta/scheduler.py index 1d0d1fed6..aeb45ee58 100644 --- a/src/vorta/scheduler.py +++ b/src/vorta/scheduler.py @@ -418,10 +418,7 @@ def create_backup(self, profile_id): else: logger.error('Conditions for backup not met. Aborting.') logger.error(msg['message']) - if ( - msg['message'] != 'Current Wifi is not allowed.' - or profile.show_notification_when_network_disallowed - ): + if msg['message'] != 'Current Wifi is not allowed.': notifier.deliver( self.tr('Vorta Backup'), translate('messages', msg['message']), diff --git a/src/vorta/store/migrations.py b/src/vorta/store/migrations.py index 7047c072f..0078a2b7a 100644 --- a/src/vorta/store/migrations.py +++ b/src/vorta/store/migrations.py @@ -235,11 +235,6 @@ def run_migrations(current_schema, db_connection): 'allow_new_networks', pw.BooleanField(default=True), ), - migrator.add_column( - BackupProfileModel._meta.table_name, - "show_notification_when_network_disallowed", - pw.BooleanField(default=True), - ), ) diff --git a/src/vorta/store/models.py b/src/vorta/store/models.py index 356f296a9..42e4a0871 100644 --- a/src/vorta/store/models.py +++ b/src/vorta/store/models.py @@ -96,7 +96,6 @@ class BackupProfileModel(BaseModel): post_backup_cmd = pw.CharField(default='') dont_run_on_metered_networks = pw.BooleanField(default=True) allow_new_networks = pw.BooleanField(default=False) - show_notification_when_network_disallowed = pw.BooleanField(default=True) def refresh(self): return type(self).get(self._pk_expr()) diff --git a/src/vorta/views/schedule_tab.py b/src/vorta/views/schedule_tab.py index fefdca441..293f0ae18 100644 --- a/src/vorta/views/schedule_tab.py +++ b/src/vorta/views/schedule_tab.py @@ -78,9 +78,6 @@ def __init__(self, parent=None): self.allowNewNetworksCheckBox.stateChanged.connect( lambda new_val, attr='allow_new_networks': self.save_profile_attr(attr, new_val) ) - self.networkDisallowedNotificationCheckBox.stateChanged.connect( - lambda new_val, attr='show_notification_when_network_disallowed': self.save_profile_attr(attr, new_val) - ) self.postBackupCmdLineEdit.textEdited.connect( lambda new_val, attr='post_backup_cmd': self.save_profile_attr(attr, new_val) ) @@ -156,7 +153,6 @@ def populate_from_profile(self): QtCore.Qt.Unchecked if profile.dont_run_on_metered_networks else QtCore.Qt.Checked ) self.allowNewNetworksCheckBox.setChecked(profile.allow_new_networks) - self.networkDisallowedNotificationCheckBox.setChecked(profile.show_notification_when_network_disallowed) self.preBackupCmdLineEdit.setText(profile.pre_backup_cmd) self.postBackupCmdLineEdit.setText(profile.post_backup_cmd) diff --git a/tests/conftest.py b/tests/conftest.py index 18d58b450..afadab4f1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -79,7 +79,6 @@ def init_db(qapp, qtbot, tmpdir_factory): default_profile.repo = new_repo.id default_profile.dont_run_on_metered_networks = False default_profile.allow_new_networks = True - default_profile.show_notification_when_network_disallowed = True default_profile.validation_on = False default_profile.save() diff --git a/tests/profile_exports/valid.json b/tests/profile_exports/valid.json index b14a31772..6f6716a08 100644 --- a/tests/profile_exports/valid.json +++ b/tests/profile_exports/valid.json @@ -37,7 +37,6 @@ "post_backup_cmd": "", "dont_run_on_metered_networks": true, "allow_new_networks": true, - "show_notification_when_network_disallowed": true, "SourceFileModel": [ { "dir": "/this/is/a/test/file", From d934a90e2214beb1d055aa263d86a0c4df49f963 Mon Sep 17 00:00:00 2001 From: Divyansh Singh <divyanshanandsingh@gmail.com> Date: Thu, 13 Apr 2023 12:26:56 +0530 Subject: [PATCH 6/6] wifi notif is not a special notif --- src/vorta/application.py | 13 ++++++------- src/vorta/scheduler.py | 11 +++++------ 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/vorta/application.py b/src/vorta/application.py index 7b789b27c..66f4dcd6a 100644 --- a/src/vorta/application.py +++ b/src/vorta/application.py @@ -113,13 +113,12 @@ def create_backup_action(self, profile_id=None): job = BorgCreateJob(msg['cmd'], msg, profile.repo.id) self.jobs_manager.add_job(job) else: - if msg['message'] != 'Current Wifi is not allowed.': - notifier = VortaNotifications.pick() - notifier.deliver( - self.tr('Vorta Backup'), - translate('messages', msg['message']), - level='error', - ) + notifier = VortaNotifications.pick() + notifier.deliver( + self.tr('Vorta Backup'), + translate('messages', msg['message']), + level='error', + ) self.backup_progress_event.emit(f"[{profile.name}] {translate('messages', msg['message'])}") return None diff --git a/src/vorta/scheduler.py b/src/vorta/scheduler.py index aeb45ee58..4cace732c 100644 --- a/src/vorta/scheduler.py +++ b/src/vorta/scheduler.py @@ -418,12 +418,11 @@ def create_backup(self, profile_id): else: logger.error('Conditions for backup not met. Aborting.') logger.error(msg['message']) - if msg['message'] != 'Current Wifi is not allowed.': - notifier.deliver( - self.tr('Vorta Backup'), - translate('messages', msg['message']), - level='error', - ) + notifier.deliver( + self.tr('Vorta Backup'), + translate('messages', msg['message']), + level='error', + ) self.pause(profile_id) def notify(self, result):