Skip to content

Commit 00fa890

Browse files
Merge pull request #2000 from nextcloud/feat/add-e2ee-deletion-calls
feat(e2ee): add deletion functions
2 parents 27d2e50 + 44dc133 commit 00fa890

6 files changed

Lines changed: 144 additions & 67 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.owncloud.android.lib.resources.users
9+
10+
import com.owncloud.android.AbstractIT
11+
import com.owncloud.android.lib.resources.e2ee.DeleteEncryptedFilesRemoteOperation
12+
import junit.framework.TestCase.assertTrue
13+
import org.junit.Test
14+
15+
class DeleteE2ERemoteOperationIT : AbstractIT() {
16+
@Test
17+
fun testDeleteEncryptedFiles() {
18+
val sut = DeleteEncryptedFilesRemoteOperation()
19+
val result = sut.execute(nextcloudClient)
20+
assertTrue(result.isSuccess)
21+
}
22+
23+
@Test
24+
fun testDeletePrivateKey() {
25+
val sut = DeletePrivateKeyRemoteOperation()
26+
val result = sut.execute(nextcloudClient)
27+
assertTrue(result.isSuccess)
28+
}
29+
30+
@Test
31+
fun testDeletePublicKey() {
32+
val sut = DeletePublicKeyRemoteOperation()
33+
val result = sut.execute(nextcloudClient)
34+
assertTrue(result.isSuccess)
35+
}
36+
}

library/src/main/java/com/owncloud/android/lib/resources/assistant/v1/DeleteTaskRemoteOperationV1.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import com.nextcloud.operations.DeleteMethod
1313
import com.owncloud.android.lib.common.operations.RemoteOperation
1414
import com.owncloud.android.lib.common.operations.RemoteOperationResult
1515
import com.owncloud.android.lib.common.utils.Log_OC
16-
import com.owncloud.android.lib.resources.users.DeletePrivateKeyRemoteOperation
1716
import java.io.IOException
1817
import java.net.HttpURLConnection
1918

@@ -42,7 +41,7 @@ class DeleteTaskRemoteOperationV1(
4241
}
4342

4443
companion object {
45-
private val TAG = DeletePrivateKeyRemoteOperation::class.java.simpleName
44+
private val TAG = DeleteTaskRemoteOperationV1::class.java.simpleName
4645
private const val DIRECT_ENDPOINT =
4746
"/ocs/v2.php/textprocessing/task/"
4847
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Alper Ozturk <alper.ozturk@nextcloud.com>
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
8+
package com.owncloud.android.lib.resources.e2ee
9+
10+
import com.nextcloud.common.NextcloudClient
11+
import com.nextcloud.operations.DeleteMethod
12+
import com.owncloud.android.lib.common.operations.RemoteOperation
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import org.apache.commons.httpclient.HttpStatus
16+
17+
class DeleteEncryptedFilesRemoteOperation : RemoteOperation<Unit>() {
18+
@Deprecated("Deprecated in Java")
19+
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
20+
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {
21+
val method =
22+
DeleteMethod(uri = client.baseUri.toString() + ENCRYPTED_FILES_URL, useOcsApiRequestHeader = true)
23+
24+
return try {
25+
val status = client.execute(method)
26+
27+
if (status == HttpStatus.SC_OK) {
28+
RemoteOperationResult<Unit>(true, method)
29+
} else {
30+
RemoteOperationResult<Unit>(false, method).also {
31+
Log_OC.e(
32+
TAG,
33+
"Deleting encrypted files failed: ${method.getResponseBodyAsString()}",
34+
it.exception
35+
)
36+
}
37+
}
38+
} catch (e: Exception) {
39+
RemoteOperationResult<Unit>(e).also {
40+
Log_OC.e(TAG, "Deleting encrypted files failed: ${it.logMessage}", it.exception)
41+
}
42+
} finally {
43+
method.releaseConnection()
44+
}
45+
}
46+
47+
companion object {
48+
private val TAG = DeleteEncryptedFilesRemoteOperation::class.java.simpleName
49+
private const val ENCRYPTED_FILES_URL = "/ocs/v2.php/apps/end_to_end_encryption/api/v1/encrypted-files"
50+
}
51+
}

library/src/main/java/com/owncloud/android/lib/resources/users/DeletePrivateKeyRemoteOperation.kt

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,22 @@ import com.owncloud.android.lib.common.utils.Log_OC
1515
import java.io.IOException
1616
import java.net.HttpURLConnection
1717

18-
/**
19-
* Remote operation performing to delete the private key for an user
20-
*/
21-
class DeletePrivateKeyRemoteOperation : RemoteOperation<Void>() {
22-
/**
23-
* @param client Client object
24-
*/
25-
override fun run(client: NextcloudClient): RemoteOperationResult<Void> {
18+
class DeletePrivateKeyRemoteOperation : RemoteOperation<Unit>() {
19+
@Deprecated("Deprecated in Java")
20+
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
21+
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {
2622
var postMethod: DeleteMethod? = null
27-
var result: RemoteOperationResult<Void>
23+
var result: RemoteOperationResult<Unit>
2824
try {
29-
// remote request
3025
postMethod =
3126
DeleteMethod(
3227
client.baseUri.toString() + PRIVATE_KEY_URL,
3328
true
3429
)
3530
val status = client.execute(postMethod)
36-
result = RemoteOperationResult<Void>(status == HttpURLConnection.HTTP_OK, postMethod)
31+
result = RemoteOperationResult<Unit>(status == HttpURLConnection.HTTP_OK, postMethod)
3732
} catch (e: IOException) {
38-
result = RemoteOperationResult<Void>(e)
33+
result = RemoteOperationResult<Unit>(e)
3934
Log_OC.e(TAG, "Deletion of private key failed: " + result.logMessage, result.exception)
4035
} finally {
4136
postMethod?.releaseConnection()

library/src/main/java/com/owncloud/android/lib/resources/users/DeletePublicKeyRemoteOperation.java

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-FileCopyrightText: 2017 Tobias Kaminsky <tobias@kaminsky.me>
6+
* SPDX-License-Identifier: MIT
7+
*/
8+
package com.owncloud.android.lib.resources.users
9+
10+
import com.nextcloud.common.NextcloudClient
11+
import com.nextcloud.operations.DeleteMethod
12+
import com.owncloud.android.lib.common.operations.RemoteOperation
13+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
14+
import com.owncloud.android.lib.common.utils.Log_OC
15+
import java.net.HttpURLConnection
16+
17+
class DeletePublicKeyRemoteOperation : RemoteOperation<Unit>() {
18+
@Deprecated("Deprecated in Java")
19+
@Suppress("Detekt.TooGenericExceptionCaught", "DEPRECATION")
20+
override fun run(client: NextcloudClient): RemoteOperationResult<Unit> {
21+
var postMethod: DeleteMethod? = null
22+
var result: RemoteOperationResult<Unit>
23+
24+
try {
25+
postMethod = DeleteMethod(client.baseUri.toString() + PUBLIC_KEY_URL, true)
26+
postMethod.addRequestHeader(OCS_API_HEADER, OCS_API_HEADER_VALUE)
27+
28+
val status = client.execute(postMethod)
29+
30+
result = RemoteOperationResult<Unit>(status == HttpURLConnection.HTTP_OK, postMethod)
31+
} catch (e: Exception) {
32+
result = RemoteOperationResult<Unit>(e)
33+
Log_OC.e(
34+
TAG,
35+
"Deletion of public key failed: " + result.getLogMessage(),
36+
result.exception
37+
)
38+
} finally {
39+
postMethod?.releaseConnection()
40+
}
41+
return result
42+
}
43+
44+
companion object {
45+
private val TAG: String = DeletePublicKeyRemoteOperation::class.java.getSimpleName()
46+
private const val PUBLIC_KEY_URL =
47+
"/ocs/v2.php/apps/end_to_end_encryption/api/v1/public-key"
48+
}
49+
}

0 commit comments

Comments
 (0)