Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: settings to allow new networks and show notif when a network is disallowed #1658

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/vorta/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,13 @@ 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 msg['message'] != 'Current Wifi is not allowed.' or profile.show_notification_when_network_disallowed:
diivi marked this conversation as resolved.
Show resolved Hide resolved
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

Expand Down
16 changes: 15 additions & 1 deletion src/vorta/assets/UI/scheduletab.ui
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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">
Expand Down
14 changes: 9 additions & 5 deletions src/vorta/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
msg['message'] != 'Current Wifi is not allowed.'
or 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):
Expand Down
2 changes: 1 addition & 1 deletion src/vorta/store/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
)
from .settings import get_misc_settings

SCHEMA_VERSION = 20
SCHEMA_VERSION = 21


@signals.post_save(sender=SettingsModel)
Expand Down
16 changes: 16 additions & 0 deletions src/vorta/store/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=True),
),
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():
Expand Down
2 changes: 2 additions & 0 deletions src/vorta/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it defaults to False, but in migrations it's True? Suggest to use True everywhere, which is the current behavior.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think yf and I discussed this before (been long so idr exactly where, I tried searching). The new behaviour should not surprise existing users, so the migration changes nothing. But for new users, having this value as false is more beneficial.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found it - #1658 (comment)

show_notification_when_network_disallowed = pw.BooleanField(default=True)

def refresh(self):
return type(self).get(self._pk_expr())
Expand Down
3 changes: 2 additions & 1 deletion src/vorta/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,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
Expand Down
8 changes: 8 additions & 0 deletions src/vorta/views/schedule_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down Expand Up @@ -149,6 +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(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)
Expand Down
2 changes: 2 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = True
default_profile.show_notification_when_network_disallowed = True
default_profile.validation_on = False
default_profile.save()

Expand Down
2 changes: 2 additions & 0 deletions tests/profile_exports/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
"password": "Tr0ub4dor&3",
"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",
Expand Down