Skip to content

Commit d4d1e3c

Browse files
Merge pull request #1967 from nextcloud/editTags
Delete Tags
2 parents 2bed5ee + 34f714c commit d4d1e3c

3 files changed

Lines changed: 123 additions & 1 deletion

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
package com.owncloud.android.lib.resources.tags
8+
9+
import com.nextcloud.test.RandomStringGenerator
10+
import com.owncloud.android.AbstractIT
11+
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
12+
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
13+
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation
14+
import com.owncloud.android.lib.resources.files.model.RemoteFile
15+
import com.owncloud.android.lib.resources.status.NextcloudVersion
16+
import junit.framework.TestCase.assertEquals
17+
import junit.framework.TestCase.assertTrue
18+
import org.junit.Test
19+
20+
class DeleteTagRemoteOperationIT : AbstractIT() {
21+
companion object {
22+
const val TAG_LENGTH = 10
23+
}
24+
25+
@Test
26+
fun deleteTag() {
27+
testOnlyOnServer(NextcloudVersion.nextcloud_31)
28+
29+
// create a folder
30+
val folder = "/deleteTagFolder/"
31+
assertTrue(CreateFolderRemoteOperation(folder, true).execute(client).isSuccess)
32+
val folderMetadata = ReadFileRemoteOperation(folder).execute(client)
33+
val fileId = (folderMetadata.data[0] as RemoteFile).localId
34+
35+
// create a tag
36+
val tagName = RandomStringGenerator.make(TAG_LENGTH)
37+
assertTrue(
38+
CreateTagRemoteOperation(tagName)
39+
.execute(nextcloudClient)
40+
.isSuccess
41+
)
42+
43+
// find the created tag
44+
val tagsResult = GetTagsRemoteOperation().execute(client)
45+
assertTrue(tagsResult.isSuccess)
46+
val tag = tagsResult.resultData.find { it.name == tagName }
47+
assertTrue(tag != null)
48+
49+
// assign the tag to the folder
50+
assertTrue(
51+
PutTagRemoteOperation(tag!!.id, fileId)
52+
.execute(nextcloudClient)
53+
.isSuccess
54+
)
55+
56+
// verify the tag is on the folder
57+
var rootMetadata = ReadFolderRemoteOperation("/").execute(client)
58+
var folderTags =
59+
(rootMetadata.data as ArrayList<RemoteFile>)
60+
.find { it.remotePath == folder }
61+
?.tags
62+
assertEquals(1, folderTags?.size)
63+
assertEquals(tagName, folderTags?.first()?.name)
64+
65+
// delete the tag from the folder
66+
assertTrue(
67+
DeleteTagRemoteOperation(tag.id, fileId)
68+
.execute(nextcloudClient)
69+
.isSuccess
70+
)
71+
72+
// verify the tag is no longer on the folder
73+
rootMetadata = ReadFolderRemoteOperation("/").execute(client)
74+
folderTags =
75+
(rootMetadata.data as ArrayList<RemoteFile>)
76+
.find { it.remotePath == folder }
77+
?.tags
78+
assertTrue(folderTags.isNullOrEmpty())
79+
}
80+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
package com.owncloud.android.lib.resources.tags
8+
9+
import com.nextcloud.common.NextcloudClient
10+
import com.nextcloud.operations.DeleteMethod
11+
import com.owncloud.android.lib.common.operations.RemoteOperation
12+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
13+
import org.apache.commons.httpclient.HttpStatus
14+
15+
class DeleteTagRemoteOperation(
16+
val id: String,
17+
val fileId: Long
18+
) : RemoteOperation<Void>() {
19+
override fun run(client: NextcloudClient): RemoteOperationResult<Void> {
20+
val deleteMethod =
21+
DeleteMethod(
22+
client.baseUri.toString() + TAG_URL + fileId + "/" + id,
23+
true
24+
)
25+
26+
val status = deleteMethod.execute(client)
27+
28+
return if (status == HttpStatus.SC_NO_CONTENT) {
29+
RemoteOperationResult<Void>(true, deleteMethod)
30+
} else {
31+
RemoteOperationResult<Void>(false, deleteMethod)
32+
}
33+
}
34+
35+
companion object {
36+
const val TAG_URL = "/remote.php/dav/systemtags-relations/files/"
37+
}
38+
}

library/src/main/java/com/owncloud/android/lib/resources/tags/Tag.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
*/
88
package com.owncloud.android.lib.resources.tags
99

10+
import android.os.Parcelable
11+
import kotlinx.parcelize.Parcelize
12+
13+
@Parcelize
1014
data class Tag(
1115
val id: String,
1216
val name: String,
1317
val color: String?
14-
)
18+
) : Parcelable

0 commit comments

Comments
 (0)