WebDAV: Prevent two-way file sync, default to download #1785

This commit is contained in:
Michael Mayer 2022-03-27 12:49:23 +02:00
parent dda464f28d
commit aaaef5712e
3 changed files with 31 additions and 7 deletions

View file

@ -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')"
></v-checkbox>
</v-flex>
<v-flex xs12 sm6 class="px-2">
@ -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')"
></v-checkbox>
</v-flex>
<v-flex xs12 sm6 class="px-2">
@ -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;

View file

@ -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
}

View file

@ -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)
})
}