Skip to content

Commit c716b11

Browse files
Merge pull request #2803 from leper/fix_sync_sharing_disabled
Fix syncing if sharing is disabled server side. Fixes #2733.
2 parents 91b136d + 368275f commit c716b11

File tree

2 files changed

+84
-6
lines changed

2 files changed

+84
-6
lines changed

app/src/main/java/it/niedermann/owncloud/notes/persistence/sync/CapabilitiesDeserializer.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,18 @@ public Capabilities deserialize(JsonElement json, Type typeOfT, JsonDeserializat
7171
response.setFederationShare(outgoing.getAsBoolean());
7272

7373
final var publicObject = filesSharing.getAsJsonObject("public");
74-
final var password = publicObject.getAsJsonObject("password");
75-
final var enforced = password.getAsJsonPrimitive("enforced");
76-
final var askForOptionalPassword = password.getAsJsonPrimitive("askForOptionalPassword");
74+
if (publicObject.has("password")) {
75+
final var password = publicObject.getAsJsonObject("password");
76+
final var enforced = password.getAsJsonPrimitive("enforced");
77+
final var askForOptionalPassword = password.getAsJsonPrimitive("askForOptionalPassword");
78+
79+
response.setPublicPasswordEnforced(enforced.getAsBoolean());
80+
response.setAskForOptionalPassword(askForOptionalPassword.getAsBoolean());
81+
}
82+
7783
final var isReSharingAllowed = filesSharing.getAsJsonPrimitive("resharing");
7884
final var defaultPermission = filesSharing.getAsJsonPrimitive("default_permissions");
79-
8085
response.setDefaultPermission(defaultPermission.getAsInt());
81-
response.setPublicPasswordEnforced(enforced.getAsBoolean());
82-
response.setAskForOptionalPassword(askForOptionalPassword.getAsBoolean());
8386
response.setReSharingAllowed(isReSharingAllowed.getAsBoolean());
8487
}
8588

app/src/test/java/it/niedermann/owncloud/notes/persistence/sync/CapabilitiesDeserializerTest.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,4 +366,79 @@ public void testDirectEditing() {
366366
assertFalse("Wrongly reporting that direct editing is supported", capabilities1.isDirectEditingAvailable());
367367

368368
}
369+
370+
371+
@Test
372+
public void testSharingDisabled() {
373+
//language=json
374+
final String response = "" +
375+
"{" +
376+
" \"version\": {" +
377+
" \"major\": 20," +
378+
" \"minor\": 0," +
379+
" \"micro\": 7," +
380+
" \"string\": \"20.0.7\"," +
381+
" \"edition\": \"\"," +
382+
" \"extendedSupport\": false" +
383+
" }," +
384+
" \"capabilities\": {" +
385+
" \"core\": {" +
386+
" \"pollinterval\": 60," +
387+
" \"webdav-root\": \"remote.php/webdav\"" +
388+
" }," +
389+
" \"notes\": {" +
390+
" \"api_version\": [" +
391+
" \"0.2\"," +
392+
" \"1.1\"" +
393+
" ]," +
394+
" \"version\": \"4.0.4\"" +
395+
" }," +
396+
" \"files_sharing\": {" +
397+
" \"api_enabled\": true," +
398+
" \"public\": {" +
399+
" \"enabled\": false," +
400+
" \"expire_date\": {" +
401+
" \"enabled\": false" +
402+
" }," +
403+
" \"multiple_links\": true," +
404+
" \"expire_date_internal\": {" +
405+
" \"enabled\": false" +
406+
" }," +
407+
" \"send_mail\": false," +
408+
" \"upload\": true," +
409+
" \"upload_files_drop\": true" +
410+
" }," +
411+
" \"resharing\": false," +
412+
" \"user\": {" +
413+
" \"send_mail\": false," +
414+
" \"expire_date\": {" +
415+
" \"enabled\": true" +
416+
" }" +
417+
" }," +
418+
" \"group_sharing\": false," +
419+
" \"group\": {" +
420+
" \"enabled\": true," +
421+
" \"expire_date\": {" +
422+
" \"enabled\": true" +
423+
" }" +
424+
" }," +
425+
" \"default_permissions\": 31," +
426+
" \"federation\": {" +
427+
" \"outgoing\": true," +
428+
" \"incoming\": true," +
429+
" \"expire_date\": {" +
430+
" \"enabled\": true" +
431+
" }" +
432+
" }," +
433+
" \"sharee\": {" +
434+
" \"query_lookup_default\": false" +
435+
" }" +
436+
" }" +
437+
" }" +
438+
"}";
439+
final var capabilities = deserializer.deserialize(JsonParser.parseString(response), null, null);
440+
assertNull(capabilities.getETag());
441+
assertEquals("[\"0.2\",\"1.1\"]", capabilities.getApiVersion());
442+
assertFalse("Wrongly reporting that direct editing is supported", capabilities.isDirectEditingAvailable());
443+
}
369444
}

0 commit comments

Comments
 (0)