Skip to content

BugFix - Use Correct Download Attribute #15074

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

Closed
wants to merge 5 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

package com.nextcloud.utils

import com.google.gson.Gson
import com.owncloud.android.datamodel.quickPermission.QuickPermissionType
import com.owncloud.android.lib.resources.shares.OCShare
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.lib.resources.shares.attributes.ShareAttributes
import com.owncloud.android.lib.resources.shares.extensions.isAllowDownloadAndSyncEnabled
import com.owncloud.android.lib.resources.shares.extensions.toggleAllowDownloadAndSync
import com.owncloud.android.ui.fragment.util.SharePermissionManager
import junit.framework.TestCase.assertEquals
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.assertTrue
import org.junit.Test

Expand Down Expand Up @@ -252,17 +251,23 @@ class SharePermissionManagerTest {
// region Attributes Tests
@Test
fun testToggleAllowDownloadAndSyncShouldCreateAttributeJsonIfNoneExists() {
val json = SharePermissionManager.toggleAllowDownloadAndSync(true, null)
assertNotNull(json)
val downloadAttribute = ShareAttributes.createDownloadAttributes(true)
val expectedJson = Gson().toJson(listOf(downloadAttribute))
assertEquals(json, expectedJson)
val ocShare = OCShare().apply {
isFolder = true
shareType = ShareType.USER
permissions = 17
}
ocShare.attributes = toggleAllowDownloadAndSync(
ocShare.attributes,
isChecked = true,
useV2DownloadAttributes = false
)
assertTrue(ocShare.isAllowDownloadAndSyncEnabled(false))
}

@Test
fun testIsAllowDownloadAndSyncEnabledShouldReturnFalseIfAttributeIsMissing() {
val share = createShare(OCShare.READ_PERMISSION_FLAG, attributesJson = null)
assertFalse(SharePermissionManager.isAllowDownloadAndSyncEnabled(share))
assertFalse(share.isAllowDownloadAndSyncEnabled(false))
}
// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import com.owncloud.android.datamodel.quickPermission.QuickPermissionType
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.resources.shares.OCShare
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.lib.resources.shares.extensions.isAllowDownloadAndSyncEnabled
import com.owncloud.android.lib.resources.shares.extensions.toggleAllowDownloadAndSync
import com.owncloud.android.lib.resources.status.NextcloudVersion
import com.owncloud.android.lib.resources.status.OCCapability
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.ui.dialog.ExpirationDatePickerDialogFragment
Expand Down Expand Up @@ -629,7 +632,8 @@ class FileDetailsSharingProcessFragment :
}

if (!isPublicShare()) {
shareAllowDownloadAndSyncCheckbox.isChecked = isAllowDownloadAndSyncEnabled(share)
shareAllowDownloadAndSyncCheckbox.isChecked =
share?.isAllowDownloadAndSyncEnabled(useV2DownloadAttributes()) == true
}
}
}
Expand All @@ -652,7 +656,7 @@ class FileDetailsSharingProcessFragment :

if (!isPublicShare()) {
binding.shareAllowDownloadAndSyncCheckbox.setOnCheckedChangeListener { _, isChecked ->
val result = SharePermissionManager.toggleAllowDownloadAndSync(isChecked, share)
val result = toggleAllowDownloadAndSync(share?.attributes, isChecked, useV2DownloadAttributes())
share?.attributes = result
downloadAttribute = result
}
Expand Down Expand Up @@ -899,5 +903,9 @@ class FileDetailsSharingProcessFragment :
(isPublicShare() && capabilities.filesDownloadLimit.isTrue && share?.isFolder == false)

private fun isPublicShare(): Boolean = (shareType == ShareType.PUBLIC_LINK)

private fun useV2DownloadAttributes(): Boolean = capabilities.version
.isNewerOrEqual(NextcloudVersion.nextcloud_30)

// endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ package com.owncloud.android.ui.fragment.util
import com.owncloud.android.datamodel.quickPermission.QuickPermissionType
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.resources.shares.OCShare
import com.owncloud.android.lib.resources.shares.attributes.ShareAttributes
import com.owncloud.android.lib.resources.shares.attributes.ShareAttributesJsonHandler
import com.owncloud.android.lib.resources.shares.attributes.getDownloadAttribute
import com.owncloud.android.ui.fragment.FileDetailsSharingProcessFragment.Companion.TAG

object SharePermissionManager {
Expand Down Expand Up @@ -66,33 +63,6 @@ object SharePermissionManager {
}
// endregion

// region DownloadAttribute
fun toggleAllowDownloadAndSync(isChecked: Boolean, share: OCShare?): String? {
val shareAttributes = getShareAttributes(share)?.toMutableList()
if (shareAttributes == null) {
val downloadAttribute = ShareAttributes.createDownloadAttributes(isChecked)
val updatedShareAttributes = listOf(downloadAttribute)
return ShareAttributesJsonHandler.toJson(updatedShareAttributes)
}

val downloadAttributeIndex = shareAttributes.indexOf(shareAttributes.getDownloadAttribute())
if (downloadAttributeIndex >= 0) {
val updatedAttribute = shareAttributes[downloadAttributeIndex].copy(value = isChecked)
shareAttributes[downloadAttributeIndex] = updatedAttribute
}

return ShareAttributesJsonHandler.toJson(shareAttributes)
}

fun isAllowDownloadAndSyncEnabled(share: OCShare?): Boolean {
return getShareAttributes(share).getDownloadAttribute()?.value == true
}

private fun getShareAttributes(share: OCShare?): List<ShareAttributes>? {
return share?.attributes?.let { ShareAttributesJsonHandler.toList(it) }
}
// endregion

// region Helper Methods
fun canEdit(share: OCShare?): Boolean {
if (share == null) {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*/
buildscript {
ext {
androidLibraryVersion ="0edf15760b8a086ab9969e103c7229dad973efbd"
androidLibraryVersion ="3dbcf59067"
androidCommonLibraryVersion = "0.26.0"
androidPluginVersion = "8.11.0"
androidxMediaVersion = "1.5.1"
Expand Down
40 changes: 40 additions & 0 deletions gradle/verification-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13092,6 +13092,14 @@
<sha256 value="b14de6c6ed598b5b31cb8842b41f1cbb03313bf4bc29eaaa9dfd17f07b6dd8f0" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="3dbcf59067">
<artifact name="android-library-3dbcf59067.aar">
<sha256 value="d10959e216de68719efc582c5698b7e78385a53900672cb024ecc36111be6d2f" origin="Generated by Gradle"/>
</artifact>
<artifact name="android-library-3dbcf59067.module">
<sha256 value="532080a02f0443bef7dc09d3ff484e1b9fa6ba2ca5070a0e7b44b04c4ce7475c" origin="Generated by Gradle"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="3ff8fea794d165afc1b3be698ad04bdee59e37c1">
<artifact name="android-library-3ff8fea794d165afc1b3be698ad04bdee59e37c1.aar">
<sha256 value="43888bc29328b621703ca813bee857853e41af6979aeaa44578beef2477ce314" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand All @@ -13108,6 +13116,14 @@
<sha256 value="cd34092733bea9249fbe600b31e018c7c4c344f4201df45a1c16035338a505ca" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="42c5fbca05">
<artifact name="android-library-42c5fbca05.aar">
<sha256 value="361914f8ec4a86afe93ceeb5af7a2db100acfb7a6d05add8c80e80bfa1d70343" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-42c5fbca05.module">
<sha256 value="2f00698736587390e30f3ffb5ed9e801c1f0e80f1304590488624be969186483" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="451cddeba122ff4d17dc8f88feb2fd7589f77567">
<artifact name="android-library-451cddeba122ff4d17dc8f88feb2fd7589f77567.aar">
<sha256 value="c253a126ca3c32dd5b373ab1c64668e4603305b3113b052fc0fc5e3c833a913c" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down Expand Up @@ -13268,6 +13284,14 @@
<sha256 value="de2e7d2fdde1d6981af8fcd54812dfe510ab7e22bdf8225ed569616b6c1155f4" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="8514831f30">
<artifact name="android-library-8514831f30.aar">
<sha256 value="3306e4c894ae616dbae2579079b23bd07fe8114045e21fb53f198ce675052e06" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-8514831f30.module">
<sha256 value="28848cb53868af301c356100ab5221078475c907b709603545d70e522bc9e78c" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="856c2516c6dd92058535d726ab55f0aef19ee089">
<artifact name="android-library-856c2516c6dd92058535d726ab55f0aef19ee089.aar">
<sha256 value="dc7c01113fc8333aa61ead05bc5058f65857f9d57448b7328f26db24922b6662" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down Expand Up @@ -13380,6 +13404,14 @@
<sha256 value="fb90434eefdf0540aa685dd01c8605c8f65d5a0f44e5713cd65e9f75a0c89038" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="ad5fb9e941">
<artifact name="android-library-ad5fb9e941.aar">
<sha256 value="db7d812133f17806d5f9a5b87cd4591ef5fb5d638705e9f2760f8b0b4f450fa3" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-ad5fb9e941.module">
<sha256 value="f573cab2501e6c04bcfbacdab08ece66e5c35ec36ae2d95681afe47aadadbf4e" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="be43184f87164bd5ec4f1d2ed912665203433321">
<artifact name="android-library-be43184f87164bd5ec4f1d2ed912665203433321.aar">
<sha256 value="7b1c45e5af11857cf1e18d4d4a9347d97b253426f6cad5956c5da058587286a0" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down Expand Up @@ -13484,6 +13516,14 @@
<sha256 value="af2c66e6fa0f282bb91b53849ff2af8aba66ed301269aa9a71783af49a0e99f4" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="e0fb84cbb0">
<artifact name="android-library-e0fb84cbb0.aar">
<sha256 value="195b58450aae3eac4b8f24a8e6bb0e7795ab613a026d1c80cf096ee2df36cbd8" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
<artifact name="android-library-e0fb84cbb0.module">
<sha256 value="548cc8a9156d576dcc46fee694ce3a04eba68c8a5d477796117f806b27c98ed4" origin="Generated by Gradle" reason="Artifact is not signed"/>
</artifact>
</component>
<component group="com.github.nextcloud" name="android-library" version="e77e21da5928674243f5e329f9eaaa3db1b1c09a">
<artifact name="android-library-e77e21da5928674243f5e329f9eaaa3db1b1c09a.aar">
<sha256 value="7026ad9ce3b66726f71b97acd19b6aa104ab38cf0b072ccd624900878e5e48bf" origin="Generated by Gradle" reason="Artifact is not signed"/>
Expand Down
Loading