diff --git a/frontend/src/dialog/account/edit.vue b/frontend/src/dialog/account/edit.vue index 115321bba..35c623bea 100644 --- a/frontend/src/dialog/account/edit.vue +++ b/frontend/src/dialog/account/edit.vue @@ -150,7 +150,10 @@ :disabled="!model.AccSync || readonly" hide-details color="secondary-dark" + on-icon="radio_button_checked" + off-icon="radio_button_unchecked" :label="$gettext('Download remote files')" + @change="onChangeSync('download')" > @@ -168,7 +171,10 @@ :disabled="!model.AccSync" hide-details color="secondary-dark" + on-icon="radio_button_checked" + off-icon="radio_button_unchecked" :label="$gettext('Upload local files')" + @change="onChangeSync('upload')" > @@ -381,7 +387,14 @@ export default { return result; }, + onChangeSync(dir) { + switch (dir) { + case 'upload': this.model.SyncDownload = !this.model.SyncUpload; break; + default: this.model.SyncUpload = !this.model.SyncDownload; + } + }, onChange() { + this.onChangeSync(); this.paths = [{"abs": "/"}]; this.loading = true; diff --git a/internal/entity/account.go b/internal/entity/account.go index 7780aeece..9896bdb8c 100644 --- a/internal/entity/account.go +++ b/internal/entity/account.go @@ -75,13 +75,18 @@ func (m *Account) SaveForm(form form.Account) error { return err } - if m.AccType != string(remote.ServiceWebDAV) { - // TODO: Only WebDAV supported at the moment + // TODO: Support for other remote services in addition to WebDAV. + if m.AccType != remote.ServiceWebDAV { m.AccShare = false m.AccSync = false } - // Set defaults + // Prevent two-way sync, see https://github.com/photoprism/photoprism/issues/1785 + if m.SyncUpload && m.SyncDownload { + m.SyncUpload = false + } + + // Set defaults. if m.SharePath == "" { m.SharePath = "/" } @@ -90,7 +95,7 @@ func (m *Account) SaveForm(form form.Account) error { m.SyncPath = "/" } - // Refresh after performing changes + // Refresh after performing changes. if m.AccSync && m.SyncStatus == AccountSyncStatusSynced { m.SyncStatus = AccountSyncStatusRefresh } diff --git a/internal/entity/account_test.go b/internal/entity/account_test.go index ccc4fcc21..a2cd702fa 100644 --- a/internal/entity/account_test.go +++ b/internal/entity/account_test.go @@ -53,7 +53,7 @@ func TestAccount_SaveForm(t *testing.T) { t.Run("success", func(t *testing.T) { account := Account{AccName: "Foo", AccOwner: "bar", AccURL: "test.com", AccType: "test", AccKey: "123", AccUser: "testuser", AccPass: "testpass", AccError: "", AccShare: true, AccSync: true, RetryLimit: 4, SharePath: "/home", ShareSize: "500", ShareExpires: 3500, SyncPath: "/sync", - SyncInterval: 5, SyncUpload: true, SyncDownload: false, SyncFilenames: true, SyncRaw: false} + SyncInterval: 5, SyncUpload: true, SyncDownload: true, SyncFilenames: true, SyncRaw: false} accountForm, err := form.NewAccount(account) @@ -66,24 +66,30 @@ func TestAccount_SaveForm(t *testing.T) { t.Fatal(err) } + assert.Equal(t, true, model.SyncDownload) + assert.Equal(t, false, model.SyncUpload) assert.Equal(t, "Foo", model.AccName) assert.Equal(t, "bar", model.AccOwner) assert.Equal(t, "test.com", model.AccURL) - accountUpdate := Account{AccName: "NewName", AccOwner: "NewOwner", AccURL: "new.com"} + accountUpdate := Account{AccName: "NewName", AccOwner: "NewOwner", AccURL: "new.com", SyncUpload: true, SyncDownload: true} UpdateForm, err := form.NewAccount(accountUpdate) + assert.Equal(t, true, UpdateForm.SyncDownload) + assert.Equal(t, true, UpdateForm.SyncUpload) + err = model.SaveForm(UpdateForm) if err != nil { t.Fatal(err) } + assert.Equal(t, true, model.SyncDownload) + assert.Equal(t, false, model.SyncUpload) assert.Equal(t, "NewName", model.AccName) assert.Equal(t, "NewOwner", model.AccOwner) assert.Equal(t, "new.com", model.AccURL) - }) }