Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions apple/TablePro/Views/Settings/SyncPaneLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ struct SyncPaneLayout: Equatable {
serverPolicies.contains(.passwordsOff) || serverPolicies.contains(.personalSyncOff)
}

// Shows what is in effect, as a setting a profile manages does; the stored choice comes back once the server allows it.
func passwordSwitch(_ settings: SyncSettings) -> Bool {
!passwordsOffOnServer && settings.passwordSwitch(on: settings.provider)
}

// `personal_sync` off holds history too, so it is the one notice then.
static func serverPolicies(_ scopes: [ScopeStatusInfo]) -> [SyncServerPolicy] {
let personal = scopes.first { $0.scope == "personal" }
Expand Down
22 changes: 9 additions & 13 deletions apple/TablePro/Views/Settings/SyncSettingsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct SyncSettingsView: View {
}

if layout.showsCategories {
categoriesSection
categoriesSection(layout)
}
}
.formStyle(.grouped)
Expand Down Expand Up @@ -325,19 +325,19 @@ struct SyncSettingsView: View {
}
}

private var categoriesSection: some View {
private func categoriesSection(_ layout: SyncPaneLayout) -> some View {
Section("What Syncs") {
Toggle(isOn: syncConnections) {
Text("Connections")
Text("Connections set to Local only are left out.")
}
.accessibilityIdentifier("settings-sync-category-connections")

Toggle(isOn: passwords) {
Toggle(isOn: passwords(layout)) {
Text("Passwords")
Text(passwordsDetail)
Text(passwordsDetail(layout))
}
.disabled(!settings.syncConnections || passwordsOffOnServer)
.disabled(!settings.syncConnections || layout.passwordsOffOnServer)
.accessibilityIdentifier("settings-sync-category-passwords")

Toggle("Groups & Tags", isOn: $settings.syncGroupsAndTags)
Expand Down Expand Up @@ -372,12 +372,8 @@ struct SyncSettingsView: View {
}
}

private var passwordsOffOnServer: Bool {
layout.passwordsOffOnServer
}

private var passwordsDetail: String {
if passwordsOffOnServer {
private func passwordsDetail(_ layout: SyncPaneLayout) -> String {
if layout.passwordsOffOnServer {
return String(localized: "Your server does not sync passwords. Each one stays on this Mac.")
}
if settings.provider == .tableproSync {
Expand All @@ -391,10 +387,10 @@ struct SyncSettingsView: View {
}

// iCloud Keychain and TablePro Sync each keep their own switch.
private var passwords: Binding<Bool> {
private func passwords(_ layout: SyncPaneLayout) -> Binding<Bool> {
let settings = $settings
return Binding(
get: { settings.wrappedValue.passwordSwitch(on: settings.wrappedValue.provider) },
get: { layout.passwordSwitch(settings.wrappedValue) },
set: { settings.wrappedValue = settings.wrappedValue.settingPasswords($0, on: settings.wrappedValue.provider) }
)
}
Expand Down
19 changes: 19 additions & 0 deletions apple/TableProTests/Views/Settings/SyncPaneLayoutTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,25 @@ struct SyncPaneLayoutTests {
}
}

@Test("A server that holds passwords back shows the switch off, and the stored choice shows again once it allows them")
func passwordSwitchShowsTheServersHold() {
var settings = SyncSettings.default
settings.provider = .tableproSync
let stored = settings

for hold in [Self.scope("personal", passwords: false), Self.scope("personal", personal: false)] {
let layout = Self.layout(provider: .tableproSync, scopes: [hold])
#expect(layout.passwordsOffOnServer)
#expect(!layout.passwordSwitch(settings))
}
#expect(settings == stored)
#expect(settings.passwordSwitch(on: .tableproSync))

let allowed = Self.layout(provider: .tableproSync, scopes: [Self.scope("personal", passwords: true)])
#expect(allowed.passwordSwitch(settings))
#expect(!allowed.passwordSwitch(settings.settingPasswords(false, on: .tableproSync)))
}

@Test("A personal scope the server keeps read-only is pull-only, as past grace")
func readOnlyScopeIsPullOnly() {
let layout = Self.layout(provider: .tableproSync, scopes: [Self.scope("personal", writable: false)])
Expand Down
7 changes: 7 additions & 0 deletions windows/src/TablePro.App.Model/SyncPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ public sealed record SyncPane(
ServerPolicies.Contains(SyncServerPolicy.PasswordsOff)
|| ServerPolicies.Contains(SyncServerPolicy.PersonalSyncOff);

// Shows what is in effect, as a setting a policy manages does; the stored choice comes back once the server allows it.
public bool PasswordsSwitch(SyncSettings sync)
{
ArgumentNullException.ThrowIfNull(sync);
return sync.Passwords && !PasswordsOffOnServer;
}

public static SyncPane For(SyncPaneInputs inputs)
{
ArgumentNullException.ThrowIfNull(inputs);
Expand Down
17 changes: 14 additions & 3 deletions windows/src/TablePro.App/Views/SettingsView.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ private void LoadSync()
{
var sync = _workbench.Settings.Sync;
SyncConnectionsSwitch.IsOn = sync.Connections;
SyncPasswordsSwitch.IsOn = sync.Passwords;
SyncGroupsSwitch.IsOn = sync.GroupsAndTags;
SyncSavedQueriesSwitch.IsOn = sync.SavedQueries;
SyncTableFavoritesSwitch.IsOn = sync.TableFavorites;
Expand All @@ -46,6 +45,7 @@ private void ShowSync()
host.AccountChoice is not null));
_loading = true;
LoadSync();
SyncPasswordsSwitch.IsOn = pane.PasswordsSwitch(sync);
_loading = false;
SyncProviderTableProSyncItem.IsEnabled = pane.OffersTableProSync;
SyncProviderBox.IsEnabled = !_syncChoosing && !host.IsMoving;
Expand Down Expand Up @@ -348,7 +348,6 @@ private void OnSyncCategoryToggled(object sender, RoutedEventArgs e)
}

var connections = SyncConnectionsSwitch.IsOn;
var passwords = SyncPasswordsSwitch.IsOn;
var groups = SyncGroupsSwitch.IsOn;
var savedQueries = SyncSavedQueriesSwitch.IsOn;
var tableFavorites = SyncTableFavoritesSwitch.IsOn;
Expand All @@ -357,7 +356,6 @@ private void OnSyncCategoryToggled(object sender, RoutedEventArgs e)
{
Sync = (settings.Sync with
{
Passwords = passwords,
GroupsAndTags = groups,
SavedQueries = savedQueries,
TableFavorites = tableFavorites,
Expand All @@ -367,6 +365,19 @@ private void OnSyncCategoryToggled(object sender, RoutedEventArgs e)
ShowSync();
}

// Its own handler: while the server holds passwords the switch shows off, and that is never the person's choice.
private void OnSyncPasswordsToggled(object sender, RoutedEventArgs e)
{
if (_loading)
{
return;
}

var passwords = SyncPasswordsSwitch.IsOn;
_workbench.UpdateSettings(settings => settings with { Sync = settings.Sync with { Passwords = passwords } });
ShowSync();
}

private async void OnSyncNow(object sender, RoutedEventArgs e)
{
_syncingNow = true;
Expand Down
2 changes: 1 addition & 1 deletion windows/src/TablePro.App/Views/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<ToggleSwitch x:Name="SyncConnectionsSwitch" x:Uid="SyncConnectionsSwitch" AutomationProperties.AutomationId="SyncConnectionsSwitch" Toggled="OnSyncCategoryToggled" />
</toolkit:SettingsCard>
<toolkit:SettingsCard x:Uid="SyncPasswordsCard" x:Name="SyncPasswordsCard">
<ToggleSwitch x:Name="SyncPasswordsSwitch" x:Uid="SyncPasswordsSwitch" AutomationProperties.AutomationId="SyncPasswordsSwitch" Toggled="OnSyncCategoryToggled" />
<ToggleSwitch x:Name="SyncPasswordsSwitch" x:Uid="SyncPasswordsSwitch" AutomationProperties.AutomationId="SyncPasswordsSwitch" Toggled="OnSyncPasswordsToggled" />
</toolkit:SettingsCard>
<toolkit:SettingsCard x:Uid="SyncGroupsCard">
<ToggleSwitch x:Name="SyncGroupsSwitch" x:Uid="SyncGroupsSwitch" AutomationProperties.AutomationId="SyncGroupsSwitch" Toggled="OnSyncCategoryToggled" />
Expand Down
27 changes: 27 additions & 0 deletions windows/tests/TablePro.App.Model.Tests/SyncPaneTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,33 @@ public void TheServersSwitchesAreSaidAndPersonalSyncOffIsTheOneNotice()
.OffersTableProSync);
}

[Fact]
public void AServerThatHoldsPasswordsShowsTheSwitchOffAndTheStoredChoiceComesBackOnceItAllowsThem()
{
var sync = new SyncSettings { Provider = SyncProvider.TableProSync };
var stored = sync with { };
var inputs = Inputs(SyncProvider.TableProSync, FeatureAccess.Available, Idle, Approved);

SyncScopeStatus[] holds =
[
new("personal", true, null, false, null),
new("personal", true, false, null, null),
];
foreach (var hold in holds)
{
var held = SyncPane.For(inputs with { Scopes = [hold] });
Assert.True(held.PasswordsOffOnServer);
Assert.False(held.PasswordsSwitch(sync));
}

Assert.Equal(stored, sync);
Assert.True(sync.Passwords);

var allowed = SyncPane.For(inputs with { Scopes = [new SyncScopeStatus("personal", true, null, true, null)] });
Assert.True(allowed.PasswordsSwitch(sync));
Assert.False(allowed.PasswordsSwitch(sync with { Passwords = false }));
}

[Fact]
public void AnotherAccountIsAskedAboutWhileOffToo()
{
Expand Down
Loading