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 13 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
9 changes: 8 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="2" column="0">
<layout class="QVBoxLayout" name="verticalLayout_8">
<property name="spacing">
<number>4</number>
Expand All @@ -557,6 +557,13 @@
</item>
</layout>
</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="0" column="0">
<widget class="QCheckBox" name="meteredNetworksCheckBox">
<property name="text">
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 @@ -21,7 +21,7 @@
)
from .settings import get_misc_settings

SCHEMA_VERSION = 20
SCHEMA_VERSION = 21


@signals.post_save(sender=SettingsModel)
Expand Down
11 changes: 11 additions & 0 deletions src/vorta/store/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,17 @@ 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),
),
)


def _apply_schema_update(current_schema, version_after, *operations):
with DB.atomic():
Expand Down
1 change: 1 addition & 0 deletions src/vorta/store/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ 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)


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 @@ -321,12 +321,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
4 changes: 4 additions & 0 deletions src/vorta/views/schedule_tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ 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.postBackupCmdLineEdit.textEdited.connect(
lambda new_val, attr='post_backup_cmd': self.save_profile_attr(attr, new_val)
)
Expand Down Expand Up @@ -157,6 +160,7 @@ def populate_from_profile(self):
self.missedBackupsCheckBox.setCheckState(
QtCore.Qt.CheckState.Checked if profile.schedule_make_up_missed else QtCore.Qt.CheckState.Unchecked
)
self.allowNewNetworksCheckBox.setChecked(profile.allow_new_networks)
self.meteredNetworksCheckBox.setChecked(False if profile.dont_run_on_metered_networks else True)

self.preBackupCmdLineEdit.setText(profile.pre_backup_cmd)
Expand Down
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 = True
default_profile.validation_on = False
default_profile.save()

Expand Down
1 change: 1 addition & 0 deletions tests/profile_exports/valid.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"password": "Tr0ub4dor&3",
"post_backup_cmd": "",
"dont_run_on_metered_networks": true,
"allow_new_networks": true,
"SourceFileModel": [
{
"dir": "/this/is/a/test/file",
Expand Down