Skip to content

Commit

Permalink
Merge pull request #2617 from owncloud/new_arch/private_link_accessible
Browse files Browse the repository at this point in the history
Fix private link not accessible when disabling share API
  • Loading branch information
davigonz authored Aug 5, 2019
2 parents 646a27f + 63e74e3 commit 5b4dc17
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ class EditPublicShareTest {
calendar.add(Calendar.DAY_OF_YEAR, 1)
val formatter: DateFormat = SimpleDateFormat("MMM dd, yyyy");
val expirationDate = formatter.format(calendar.time);
val publicLinkExpirationDateInMillis = SimpleDateFormat.getDateInstance().parse(expirationDate).time
val publicLinkExpirationDateInMillis = formatter.parse(expirationDate).time

// 1. Open dialog to edit an existing public share
onView(withId(R.id.editPublicLinkButton)).perform(click())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,18 @@ class ShareFileFragmentTest {
*********************************************** COMMON ***********************************************
******************************************************************************************************/

@Test
fun hideSharesSharingApiDisabled() {
loadShareFileFragment(
capabilities = TestUtil.createCapability(sharingApiEnabled = CapabilityBooleanType.FALSE.value)
)
onView(withId(R.id.shareWithUsersSection))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))

onView(withId(R.id.shareViaLinkSection))
.check(matches(withEffectiveVisibility(ViewMatchers.Visibility.GONE)))
}

private fun getOCFileForTesting(name: String = "default") = OCFile("/Photos").apply {
availableOfflineStatus = OCFile.AvailableOfflineStatus.NOT_AVAILABLE_OFFLINE
fileName = name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

/**
* Filters out the file actions available in a given {@link Menu} for a given {@link OCFile}
* according to the current state of the latest.
* according to the current state of the latest.
*/
public class FileMenuFilter {

Expand All @@ -58,10 +58,10 @@ public class FileMenuFilter {
/**
* Constructor
*
* @param targetFiles List of {@link OCFile} file targets of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile.
* @param cg Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources.
* @param targetFiles List of {@link OCFile} file targets of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile.
* @param cg Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources.
*/
public FileMenuFilter(List<OCFile> targetFiles, Account account, ComponentsGetter cg,
Context context) {
Expand All @@ -74,10 +74,10 @@ public FileMenuFilter(List<OCFile> targetFiles, Account account, ComponentsGette
/**
* Constructor
*
* @param targetFile {@link OCFile} target of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile.
* @param cg Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources.
* @param targetFile {@link OCFile} target of the action to filter in the {@link Menu}.
* @param account ownCloud {@link Account} holding targetFile.
* @param cg Accessor to app components, needed to access synchronization services
* @param context Android {@link Context}, needed to access build setup resources.
*/
public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg,
Context context) {
Expand All @@ -88,7 +88,7 @@ public FileMenuFilter(OCFile targetFile, Account account, ComponentsGetter cg,
* Filters out the file actions available in the passed {@link Menu} taken into account
* the state of the {@link OCFile} held by the filter.
*
* @param menu Options or context menu to filter.
* @param menu Options or context menu to filter.
*/
public void filter(Menu menu, boolean displaySelectAll, boolean displaySelectInverse,
boolean onlyAvailableOffline) {
Expand Down Expand Up @@ -131,14 +131,14 @@ private void hideAll(Menu menu) {

/**
* Performs the real filtering, to be applied in the {@link Menu} by the caller methods.
*
* <p>
* Decides what actions must be shown and hidden.
*
* @param toShow List to save the options that must be shown in the menu.
* @param toHide List to save the options that must be shown in the menu.
* @param toShow List to save the options that must be shown in the menu.
* @param toHide List to save the options that must be shown in the menu.
*/

private void filter(List<Integer> toShow, List <Integer> toHide, boolean displaySelectAll,
private void filter(List<Integer> toShow, List<Integer> toHide, boolean displaySelectAll,
boolean displaySelectInverse, boolean onlyAvailableOffline) {

boolean synchronizing = anyFileSynchronizing();
Expand Down Expand Up @@ -226,16 +226,12 @@ private void filter(List<Integer> toShow, List <Integer> toHide, boolean display
mContext.getResources().getBoolean(R.bool.share_with_users_feature));

RemoteCapability capability = mComponentsGetter.getStorageManager().getCapability(mAccount.name);
boolean shareApiEnabled = capability != null &&
(capability.getFilesSharingApiEnabled().isTrue() ||
capability.getFilesSharingApiEnabled().isUnknown()
);

boolean notAllowResharing = anyFileSharedWithMe() &&
capability != null && capability.getFilesSharingResharing().isFalse();

if ((!shareViaLinkAllowed && !shareWithUsersAllowed) || !isSingleSelection() ||
!shareApiEnabled || notAllowResharing || onlyAvailableOffline) {
notAllowResharing || onlyAvailableOffline) {
toHide.add(R.id.action_share_file);
} else {
toShow.add(R.id.action_share_file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import android.view.ViewGroup
import android.widget.ListView
import android.widget.Toast
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import com.google.android.material.snackbar.Snackbar
import com.owncloud.android.R
Expand All @@ -43,9 +44,9 @@ import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.lib.resources.status.CapabilityBooleanType
import com.owncloud.android.lib.resources.status.OwnCloudVersion
import com.owncloud.android.shares.presentation.ShareUserListAdapter
import com.owncloud.android.shares.domain.OCShare
import com.owncloud.android.shares.presentation.SharePublicLinkListAdapter
import com.owncloud.android.shares.presentation.ShareUserListAdapter
import com.owncloud.android.utils.DisplayUtils
import com.owncloud.android.utils.MimetypeIconUtil
import kotlinx.android.synthetic.main.share_file_layout.*
Expand Down Expand Up @@ -176,11 +177,16 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe
)
}

private val isShareApiEnabled: Boolean
get() = capabilities?.filesSharingApiEnabled == CapabilityBooleanType.TRUE.value ||
capabilities?.filesSharingApiEnabled == CapabilityBooleanType.UNKNOWN.value

/**
* @return 'True' when public share is disabled in the server
*/
private val isPublicShareDisabled: Boolean
get() = capabilities != null && capabilities?.filesSharingPublicEnabled == CapabilityBooleanType.FALSE.value
private val isPublicShareEnabled: Boolean
get() = capabilities?.filesSharingPublicEnabled == CapabilityBooleanType.TRUE.value ||
capabilities?.filesSharingPublicEnabled == CapabilityBooleanType.UNKNOWN.value

/**
* {@inheritDoc}
Expand Down Expand Up @@ -322,13 +328,9 @@ class ShareFileFragment : Fragment(), ShareUserListAdapter.ShareUserAdapterListe
updatePublicLinkButton()

// Update view depending on updated capabilities
if (isPublicShareDisabled) {
shareViaLinkSection.visibility = View.GONE
} else {
shareViaLinkSection.visibility = View.VISIBLE
}

shareViaLinkSection.isGone = isPublicShareDisabled
shareHeaderDivider.isVisible = isShareApiEnabled
shareWithUsersSection.isVisible = isShareApiEnabled
shareViaLinkSection.isVisible = isShareApiEnabled && isPublicShareEnabled
}

/**************************************************************************************************************
Expand Down
2 changes: 1 addition & 1 deletion owncloudApp/src/main/res/layout/edit_share_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<!-- for some reason the divider below is determining the width for the fragment;
so, leave it there, even if it's height is 0dp, we don't really want to see it -->
<View
android:id="@+id/share_header_divider"
android:id="@+id/shareHeaderDivider"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/owncloud_blue"
Expand Down
2 changes: 1 addition & 1 deletion owncloudApp/src/main/res/layout/share_file_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
</RelativeLayout>

<View
android:id="@+id/share_header_divider"
android:id="@+id/shareHeaderDivider"
android:layout_width="match_parent"
android:layout_height="2dp"
android:background="@color/owncloud_blue" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ object TestUtil {
versionString: String = "1.0.0",
versionEdition: String = "1.0.0",
corePollinterval: Int = 0,
sharingApiEnabled: Int = 0,
sharingApiEnabled: Int = 1,
sharingPublicEnabled: Int = 1,
sharingPublicPasswordEnforced: Int = 0,
sharingPublicPasswordEnforcedReadOnly: Int = 0,
Expand Down

0 comments on commit 5b4dc17

Please sign in to comment.