Skip to content

Commit

Permalink
Merge pull request #4472 from owncloud/technical/rely_on_resharing_ca…
Browse files Browse the repository at this point in the history
…pability_ocis

[TECHNICAL] Rely on `resharing` capability
  • Loading branch information
jesmrec committed Sep 24, 2024
2 parents fc9b417 + 22457f4 commit fd4b375
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 5 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ownCloud admins and users.

## Summary

* Bugfix - Rely on `resharing` capability: [#4397](https://github.com/owncloud/android/issues/4397)
* Bugfix - Shares in non-root are updated correctly: [#4432](https://github.com/owncloud/android/issues/4432)
* Bugfix - List filtering not working after rotating device: [#4441](https://github.com/owncloud/android/issues/4441)
* Bugfix - The color of some elements is set up correctly: [#4442](https://github.com/owncloud/android/issues/4442)
Expand All @@ -45,6 +46,16 @@ ownCloud admins and users.

## Details

* Bugfix - Rely on `resharing` capability: [#4397](https://github.com/owncloud/android/issues/4397)

The request to create a new share has been fixed so that it only includes the
share permission by default when the resharing capability is true, and the "can
share" switch in the edition view of private shares is now only shown when
resharing is true.

https://github.com/owncloud/android/issues/4397
https://github.com/owncloud/android/pull/4472

* Bugfix - Shares in non-root are updated correctly: [#4432](https://github.com/owncloud/android/issues/4432)

The items of the "Share" view are updated instantly when create/edit a link or
Expand Down
8 changes: 8 additions & 0 deletions changelog/unreleased/4472
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Rely on `resharing` capability

The request to create a new share has been fixed so that it only includes the share permission
by default when the resharing capability is true, and the "can share" switch in the edition view
of private shares is now only shown when resharing is true.

https://github.com/owncloud/android/issues/4397
https://github.com/owncloud/android/pull/4472
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class EditPrivateShareFragmentTest {
@Before
fun setUp() {
every { shareViewModel.privateShare } returns privateShareAsLiveData
every { shareViewModel.isResharingAllowed() } returns true

stopKoin()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ val viewModelModule = module {
viewModel { (accountName: String) -> CapabilityViewModel(accountName, get(), get(), get()) }
viewModel { (action: PasscodeAction) -> PassCodeViewModel(get(), get(), action) }
viewModel { (filePath: String, accountName: String) ->
ShareViewModel(filePath, accountName, get(), get(), get(), get(), get(), get(), get(), get(), get())
ShareViewModel(filePath, accountName, get(), get(), get(), get(), get(), get(), get(), get(), get(), get())
}
viewModel { (initialFolderToDisplay: OCFile, fileListOption: FileListOption) ->
MainFileListViewModel(get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), get(), initialFolderToDisplay, fileListOption)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ class ReleaseNotesViewModel(
subtitle = R.string.release_notes_4_3_0_subtitle_accessibility_improvements,
type = ReleaseNoteType.ENHANCEMENT
),
ReleaseNote(
title = R.string.release_notes_4_4_0_title_resharing_capability,
subtitle = R.string.release_notes_4_4_0_subtitle_resharing_capability,
type = ReleaseNoteType.ENHANCEMENT
),
ReleaseNote(
title = R.string.release_notes_bugfixes_title,
subtitle = R.string.release_notes_bugfixes_subtitle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*
* Copyright (C) 2024 ownCloud GmbH.
*
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
Expand Down Expand Up @@ -167,7 +166,7 @@ class ShareActivity : FileActivity(), ShareFragmentListener {
// check if the Share is FERERATED
val isFederated = ShareType.FEDERATED == shareType

return when {
val permissions = when {
file.isSharedWithMe -> RemoteShare.READ_PERMISSION_FLAG // minimum permissions
isFederated ->
if (file.isFolder) {
Expand All @@ -182,6 +181,8 @@ class ShareActivity : FileActivity(), ShareFragmentListener {
RemoteShare.MAXIMUM_PERMISSIONS_FOR_FILE
}
}

return if (shareViewModel.isResharingAllowed()) permissions else permissions - RemoteShare.SHARE_PERMISSION_FLAG
}

private fun observePrivateShareEdition() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* ownCloud Android client application
*
* @author David González Verdugo
* Copyright (C) 2020 ownCloud GmbH.
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand All @@ -22,6 +24,9 @@ package com.owncloud.android.presentation.sharing
import androidx.lifecycle.LiveData
import androidx.lifecycle.MediatorLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.owncloud.android.domain.capabilities.model.OCCapability
import com.owncloud.android.domain.capabilities.usecases.GetStoredCapabilitiesUseCase
import com.owncloud.android.domain.sharing.shares.model.OCShare
import com.owncloud.android.domain.sharing.shares.model.ShareType
import com.owncloud.android.domain.sharing.shares.usecases.CreatePrivateShareAsyncUseCase
Expand All @@ -37,6 +42,7 @@ import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResult
import com.owncloud.android.extensions.ViewModelExt.runUseCaseWithResultAndUseCachedData
import com.owncloud.android.presentation.common.UIResult
import com.owncloud.android.providers.CoroutinesDispatcherProvider
import kotlinx.coroutines.launch

/**
* View Model to keep a reference to the share repository and an up-to-date list of a shares
Expand All @@ -52,6 +58,7 @@ class ShareViewModel(
private val createPublicShareUseCase: CreatePublicShareAsyncUseCase,
private val editPublicShareUseCase: EditPublicShareAsyncUseCase,
private val deletePublicShareUseCase: DeleteShareAsyncUseCase,
private val getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase,
private val coroutineDispatcherProvider: CoroutinesDispatcherProvider
) : ViewModel() {

Expand All @@ -62,12 +69,22 @@ class ShareViewModel(
GetSharesAsLiveDataUseCase.Params(filePath = filePath, accountName = accountName)
)

private var capabilities: OCCapability? = null

init {
_shares.addSource(sharesLiveData) { shares ->
_shares.postValue(Event(UIResult.Success(shares)))
}

refreshSharesFromNetwork()

viewModelScope.launch(coroutineDispatcherProvider.io) {
capabilities = getStoredCapabilitiesUseCase(
GetStoredCapabilitiesUseCase.Params(
accountName = accountName
)
)
}
}

fun refreshSharesFromNetwork() = runUseCaseWithResultAndUseCachedData(
Expand Down Expand Up @@ -98,6 +115,8 @@ class ShareViewModel(
postSuccess = false
)

fun isResharingAllowed() = capabilities?.filesSharingResharing?.isTrue ?: false

/******************************************************************************************************
******************************************* PRIVATE SHARES *******************************************
******************************************************************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
* @author David A. Velasco
* @author Christian Schabesberger
* @author David González Verdugo
* Copyright (C) 2020 ownCloud GmbH.
* @author Juan Carlos Garrote Gascón
*
* Copyright (C) 2024 ownCloud GmbH.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
Expand Down Expand Up @@ -165,6 +167,7 @@ class EditPrivateShareFragment : DialogFragment() {

val sharePermissions = share!!.permissions

binding.canShareSwitch.isVisible = shareViewModel.isResharingAllowed()
binding.canShareSwitch.isChecked = sharePermissions and RemoteShare.SHARE_PERMISSION_FLAG > 0

val anyUpdatePermission = RemoteShare.CREATE_PERMISSION_FLAG or
Expand Down
2 changes: 2 additions & 0 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,8 @@
<string name="release_notes_4_3_0_subtitle_accessibility_improvements">Some improvements to make the application more accessible</string>
<string name="release_notes_4_4_0_title_improved_from_original_folder_auto_upload">Auto uploads more consistent</string>
<string name="release_notes_4_4_0_subtitle_improved_from_original_folder_auto_upload">Added some mechanisms over retries to improve reliability</string>
<string name="release_notes_4_4_0_title_resharing_capability">Improvements in private shares</string>
<string name="release_notes_4_4_0_subtitle_resharing_capability">The \"can share\" option is now only shown when editing a private share if the user is able to edit it</string>
<string name="release_notes_bugfixes_title">Minor bugfixes</string>
<string name="release_notes_bugfixes_subtitle">Some bugs were fixed to improve experience in the app</string>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package com.owncloud.android.presentation.viewmodels.sharing
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.lifecycle.MutableLiveData
import com.owncloud.android.domain.UseCaseResult
import com.owncloud.android.domain.capabilities.usecases.GetStoredCapabilitiesUseCase
import com.owncloud.android.domain.sharing.shares.model.OCShare
import com.owncloud.android.domain.sharing.shares.usecases.CreatePrivateShareAsyncUseCase
import com.owncloud.android.domain.sharing.shares.usecases.CreatePublicShareAsyncUseCase
Expand Down Expand Up @@ -74,6 +75,7 @@ class ShareViewModelTest {
private lateinit var createPublicShareAsyncUseCase: CreatePublicShareAsyncUseCase
private lateinit var editPublicShareAsyncUseCase: EditPublicShareAsyncUseCase
private lateinit var deletePublicShareAsyncUseCase: DeleteShareAsyncUseCase
private lateinit var getStoredCapabilitiesUseCase: GetStoredCapabilitiesUseCase
private lateinit var ocContextProvider: ContextProvider

private val filePath = "/Photos/image.jpg"
Expand Down Expand Up @@ -130,6 +132,7 @@ class ShareViewModelTest {
createPublicShareAsyncUseCase = spyk(mockkClass(CreatePublicShareAsyncUseCase::class))
editPublicShareAsyncUseCase = spyk(mockkClass(EditPublicShareAsyncUseCase::class))
deletePublicShareAsyncUseCase = spyk(mockkClass(DeleteShareAsyncUseCase::class))
getStoredCapabilitiesUseCase = spyk(mockkClass(GetStoredCapabilitiesUseCase::class))

every { getSharesAsLiveDataUseCase(any()) } returns sharesLiveData
every { getShareAsLiveDataUseCase(any()) } returns privateShareLiveData
Expand All @@ -147,6 +150,7 @@ class ShareViewModelTest {
createPublicShareAsyncUseCase,
editPublicShareAsyncUseCase,
deletePublicShareAsyncUseCase,
getStoredCapabilitiesUseCase,
coroutineDispatcherProvider
)
}
Expand Down

0 comments on commit fd4b375

Please sign in to comment.