|
| 1 | +/** |
| 2 | + * ownCloud Android client application |
| 3 | + * |
| 4 | + * @author Jorge Aguado Recio |
| 5 | + * |
| 6 | + * Copyright (C) 2026 ownCloud GmbH. |
| 7 | + * |
| 8 | + * This program is free software: you can redistribute it and/or modify |
| 9 | + * it under the terms of the GNU General Public License version 2, |
| 10 | + * as published by the Free Software Foundation. |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + */ |
| 20 | + |
| 21 | +package com.owncloud.android.lib.resources.links |
| 22 | + |
| 23 | +import com.owncloud.android.lib.common.OwnCloudClient |
| 24 | +import com.owncloud.android.lib.common.http.HttpConstants |
| 25 | +import com.owncloud.android.lib.common.http.methods.nonwebdav.DeleteMethod |
| 26 | +import com.owncloud.android.lib.common.operations.RemoteOperation |
| 27 | +import com.owncloud.android.lib.common.operations.RemoteOperationResult |
| 28 | +import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode |
| 29 | +import timber.log.Timber |
| 30 | +import java.net.URL |
| 31 | + |
| 32 | +class RemoveRemoteLinkOperation( |
| 33 | + private val spaceId: String, |
| 34 | + private val linkId: String |
| 35 | +): RemoteOperation<Unit>() { |
| 36 | + override fun run(client: OwnCloudClient): RemoteOperationResult<Unit> { |
| 37 | + var result: RemoteOperationResult<Unit> |
| 38 | + try { |
| 39 | + val uriBuilder = client.baseUri.buildUpon().apply { |
| 40 | + appendEncodedPath(GRAPH_API_SPACES_PATH) |
| 41 | + appendEncodedPath(spaceId) |
| 42 | + appendEncodedPath(GRAPH_API_ROOT_PERMISSIONS_PATH) |
| 43 | + appendEncodedPath(linkId) |
| 44 | + } |
| 45 | + |
| 46 | + val deleteMethod = DeleteMethod(URL(uriBuilder.build().toString())) |
| 47 | + |
| 48 | + val status = client.executeHttpMethod(deleteMethod) |
| 49 | + |
| 50 | + val response = deleteMethod.getResponseBodyAsString() |
| 51 | + |
| 52 | + if (status == HttpConstants.HTTP_NO_CONTENT) { |
| 53 | + Timber.d("Successful response: $response") |
| 54 | + result = RemoteOperationResult(ResultCode.OK) |
| 55 | + } else { |
| 56 | + result = RemoteOperationResult(deleteMethod) |
| 57 | + Timber.e("Failed response while removing a space public link; status code: $status, response: $response") |
| 58 | + } |
| 59 | + } catch (e: Exception) { |
| 60 | + result = RemoteOperationResult(e) |
| 61 | + Timber.e(e, "Exception while removing a space public link") |
| 62 | + } |
| 63 | + return result |
| 64 | + } |
| 65 | + |
| 66 | + companion object { |
| 67 | + private const val GRAPH_API_SPACES_PATH = "graph/v1beta1/drives/" |
| 68 | + private const val GRAPH_API_ROOT_PERMISSIONS_PATH = "root/permissions" |
| 69 | + } |
| 70 | +} |
0 commit comments