Skip to content
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 @@ -21,18 +21,25 @@ import org.junit.Before
import org.junit.Test

class CreateShareRemoteOperationIT : AbstractIT() {
private var ownCloudVersion: OwnCloudVersion? = null

@Before
fun before() {
val result = GetStatusRemoteOperation(context).execute(client)
assertTrue(result.isSuccess)
val data = result.data as ArrayList<Any>
val ownCloudVersion = data[0] as OwnCloudVersion
Assume.assumeTrue(ownCloudVersion.isNewerOrEqual(NextcloudVersion.nextcloud_24))
ownCloudVersion = data[0] as OwnCloudVersion
Assume.assumeTrue(ownCloudVersion?.isNewerOrEqual(NextcloudVersion.nextcloud_24) == true)
}

@Test
fun createShareWithNoteAndAttributes() {
val attributes = listOf(ShareAttributes.createDownloadAttributes(true))
val attributes = listOf(
ShareAttributes.createDownloadAttributes(
true,
ownCloudVersion?.isNewerOrEqual(NextcloudVersion.nextcloud_30) == true
)
)
val note = "Note with attributes"
val path = "/shareWithAttributes/"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,33 @@

package com.owncloud.android.lib.resources.shares.attributes

data class ShareAttributes(
val scope: String,
val key: String,
var value: Boolean
open class ShareAttributes(
open val scope: String,
open val key: String,
open var abstractValue: Boolean
) {
companion object {
const val DOWNLOAD_ATTRIBUTE_KEY = "download"

fun createDownloadAttributes(value: Boolean): ShareAttributes =
ShareAttributes(scope = "permissions", key = DOWNLOAD_ATTRIBUTE_KEY, value = value)
fun createDownloadAttributes(value: Boolean, useV2: Boolean): ShareAttributes =
if (useV2) {
ShareAttributesV2(scope = "permissions", key = DOWNLOAD_ATTRIBUTE_KEY, enabled = value)
} else {
ShareAttributesV1(scope = "permissions", key = DOWNLOAD_ATTRIBUTE_KEY, value = value)
}
}

private data class ShareAttributesV1(
override val scope: String,
override val key: String,
val value: Boolean
) : ShareAttributes(scope, key, value)

private data class ShareAttributesV2(
override val scope: String,
override val key: String,
val enabled: Boolean
) : ShareAttributes(scope, key, enabled)
}

fun List<ShareAttributes>?.getDownloadAttribute(): ShareAttributes? =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ShareAttributesDeserializer : JsonDeserializer<ShareAttributes> {
val jsonObject = json?.asJsonObject
val scope = jsonObject?.get("scope")?.asString ?: ""
val key = jsonObject?.get("key")?.asString ?: ""
val value = (jsonObject.getBoolean("value") ?: jsonObject.getBoolean("enabled")) == true
val value = jsonObject.getBoolean("abstractValue") == true
return ShareAttributes(scope, key, value)
}
}
Loading