Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2020-09-08 06:59:37 +02:00
parent 4dfefee31a
commit 01f27dd08c
No known key found for this signature in database
GPG key ID: 0E00D4D47D0C5AF7
11 changed files with 170 additions and 61 deletions

View file

@ -58,6 +58,7 @@ import androidx.test.runner.lifecycle.Stage;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static com.owncloud.android.lib.common.accounts.AccountUtils.Constants.KEY_USER_ID;
import static org.junit.Assert.assertTrue;
@ -96,7 +97,7 @@ public abstract class AbstractIT {
Account temp = new Account("test@https://server.com", MainApp.getAccountType(targetContext));
platformAccountManager.addAccountExplicitly(temp, "password", null);
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_OC_BASE_URL, "https://server.com");
platformAccountManager.setUserData(temp, AccountUtils.Constants.KEY_USER_ID, "test");
platformAccountManager.setUserData(temp, KEY_USER_ID, "test");
final UserAccountManager userAccountManager = UserAccountManagerImpl.fromContext(targetContext);
account = userAccountManager.getAccountByName("test@https://server.com");
@ -381,4 +382,8 @@ public abstract class AbstractIT {
return name;
}
public static String getUserId(User user) {
return AccountManager.get(targetContext).getUserData(user.toPlatformAccount(), KEY_USER_ID);
}
}

View file

@ -34,6 +34,8 @@ import com.owncloud.android.lib.resources.shares.OCShare
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.utils.ScreenshotTest
import org.junit.After
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Rule
import org.junit.Test
@ -43,7 +45,7 @@ class FileDetailSharingFragmentIT : AbstractIT() {
val testActivityRule = IntentsTestRule(TestActivity::class.java, true, false)
@get:Rule
val permissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
val permissionRule: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.WRITE_EXTERNAL_STORAGE)
lateinit var file: OCFile
lateinit var folder: OCFile
@ -67,8 +69,6 @@ class FileDetailSharingFragmentIT : AbstractIT() {
@Test
@ScreenshotTest
fun listShares_file_none() {
// todo search hint is not shown!?
show(file)
}
@ -87,6 +87,8 @@ class FileDetailSharingFragmentIT : AbstractIT() {
remoteId = 1
shareType = ShareType.USER
sharedWithDisplayName = "Admin"
permissions = OCShare.MAXIMUM_PERMISSIONS_FOR_FILE
userId = getUserId(user)
activity.storageManager.saveShare(this)
}
@ -94,6 +96,8 @@ class FileDetailSharingFragmentIT : AbstractIT() {
remoteId = 2
shareType = ShareType.GROUP
sharedWithDisplayName = "Group"
permissions = OCShare.MAXIMUM_PERMISSIONS_FOR_FILE
userId = getUserId(user)
activity.storageManager.saveShare(this)
}
@ -101,6 +105,7 @@ class FileDetailSharingFragmentIT : AbstractIT() {
remoteId = 3
shareType = ShareType.EMAIL
sharedWithDisplayName = "admin@nextcloud.server.com"
userId = getUserId(user)
activity.storageManager.saveShare(this)
}
@ -122,6 +127,8 @@ class FileDetailSharingFragmentIT : AbstractIT() {
remoteId = 6
shareType = ShareType.FEDERATED
sharedWithDisplayName = "admin@nextcloud.remoteserver.com"
permissions = OCShare.FEDERATED_PERMISSIONS_FOR_FILE
userId = getUserId(user)
activity.storageManager.saveShare(this)
}
@ -129,6 +136,8 @@ class FileDetailSharingFragmentIT : AbstractIT() {
remoteId = 7
shareType = ShareType.CIRCLE
sharedWithDisplayName = "Private circle"
permissions = OCShare.SHARE_PERMISSION_FLAG
userId = getUserId(user)
activity.storageManager.saveShare(this)
}
@ -136,6 +145,8 @@ class FileDetailSharingFragmentIT : AbstractIT() {
remoteId = 8
shareType = ShareType.ROOM
sharedWithDisplayName = "Meeting"
permissions = OCShare.SHARE_PERMISSION_FLAG
userId = getUserId(user)
activity.storageManager.saveShare(this)
}
@ -143,28 +154,152 @@ class FileDetailSharingFragmentIT : AbstractIT() {
}
private fun show(file: OCFile) {
val fragment = FileDetailSharingFragment.newInstance(file, user);
val fragment = FileDetailSharingFragment.newInstance(file, user)
activity.addFragment(fragment)
waitForIdleSync()
screenshot(activity)
longSleep()
}
@Test
fun publicLink_optionMenu() {
val sut = FileDetailSharingFragment()
val sut = FileDetailSharingFragment.newInstance(file, user)
activity.addFragment(sut)
shortSleep()
sut.refreshCapabilitiesFromDB()
val overflowMenuShareLink = ImageView(targetContext)
val popup = PopupMenu(targetContext, overflowMenuShareLink)
popup.inflate(R.menu.fragment_file_detail_sharing_public_link)
val publicShare = OCShare()
val publicShare = OCShare().apply {
isFolder = true
shareType = ShareType.PUBLIC_LINK
permissions = OCShare.READ_PERMISSION_FLAG
}
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
// TODO check all options
// check if items are visible
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isVisible)
assertTrue(popup.menu.findItem(R.id.action_password).isVisible)
assertTrue(popup.menu.findItem(R.id.action_share_expiration_date).isVisible)
assertTrue(popup.menu.findItem(R.id.action_share_send_link).isVisible)
assertTrue(popup.menu.findItem(R.id.action_share_send_note).isVisible)
assertTrue(popup.menu.findItem(R.id.action_edit_label).isVisible)
assertTrue(popup.menu.findItem(R.id.action_unshare).isVisible)
assertTrue(popup.menu.findItem(R.id.action_add_another_public_share_link).isVisible)
assertTrue(popup.menu.findItem(R.id.link_share_read_only).isChecked)
assertFalse(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isChecked)
assertFalse(popup.menu.findItem(R.id.link_share_file_drop).isChecked)
publicShare.permissions = OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertFalse(popup.menu.findItem(R.id.link_share_read_only).isChecked)
assertTrue(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isChecked)
assertFalse(popup.menu.findItem(R.id.link_share_file_drop).isChecked)
// TODO
// publicShare.permissions = OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER
// sut.prepareLinkOptionsMenu(popup.menu, publicShare)
// assertFalse(popup.menu.findItem(R.id.link_share_read_only).isChecked)
// assertFalse(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isChecked)
// assertTrue(popup.menu.findItem(R.id.link_share_file_drop).isChecked)
// password protection
publicShare.shareWith = "someValue"
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.action_password).title ==
targetContext.getString(R.string.share_password_title))
publicShare.shareWith = ""
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.action_password).title ==
targetContext.getString(R.string.share_no_password_title))
// hide download
publicShare.isHideFileDownload = true
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
publicShare.isHideFileDownload = false
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertFalse(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
// TODO expires
// publicShare.expirationDate = 1582019340000
// sut.prepareLinkOptionsMenu(popup.menu, publicShare)
// assertTrue(popup.menu.findItem(R.id.action_share_expiration_date).title.startsWith(
// targetContext.getString(R.string.share_expiration_date_label)))
publicShare.expirationDate = 0
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.action_share_expiration_date).title ==
targetContext.getString(R.string.share_no_expiration_date_label))
// file
publicShare.isFolder = false
publicShare.permissions = OCShare.READ_PERMISSION_FLAG
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
// check if items are visible
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isVisible)
assertTrue(popup.menu.findItem(R.id.action_password).isVisible)
assertTrue(popup.menu.findItem(R.id.action_share_expiration_date).isVisible)
assertTrue(popup.menu.findItem(R.id.action_share_send_link).isVisible)
assertTrue(popup.menu.findItem(R.id.action_share_send_note).isVisible)
assertTrue(popup.menu.findItem(R.id.action_edit_label).isVisible)
assertTrue(popup.menu.findItem(R.id.action_unshare).isVisible)
assertTrue(popup.menu.findItem(R.id.action_add_another_public_share_link).isVisible)
assertFalse(popup.menu.findItem(R.id.link_share_read_only).isVisible)
assertFalse(popup.menu.findItem(R.id.link_share_allow_upload_and_editing).isVisible)
assertFalse(popup.menu.findItem(R.id.link_share_file_drop).isVisible)
assertTrue(popup.menu.findItem(R.id.allow_editing).isVisible)
// allow editing
assertFalse(popup.menu.findItem(R.id.allow_editing).isChecked)
publicShare.permissions = OCShare.UPDATE_PERMISSION_FLAG
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.allow_editing).isChecked)
// hide download
publicShare.isHideFileDownload = true
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
publicShare.isHideFileDownload = false
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertFalse(popup.menu.findItem(R.id.action_hide_file_download).isChecked)
// password protection
publicShare.isPasswordProtected = true
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.action_password).title ==
targetContext.getString(R.string.share_password_title))
publicShare.isPasswordProtected = false
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertFalse(popup.menu.findItem(R.id.action_password).isChecked)
assertTrue(popup.menu.findItem(R.id.action_password).title ==
targetContext.getString(R.string.share_no_password_title))
// expires
publicShare.expirationDate = 1582019340
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.action_share_expiration_date).title.startsWith(
targetContext.getString(R.string.share_expiration_date_label)))
publicShare.expirationDate = 0
sut.prepareLinkOptionsMenu(popup.menu, publicShare)
assertTrue(popup.menu.findItem(R.id.action_password).title ==
targetContext.getString(R.string.share_no_expiration_date_label))
// TODO check all options
// scenarios: public link, email, …, both for file/folder
}

View file

@ -32,6 +32,8 @@ import com.owncloud.android.datamodel.FileDataStorageManager
import com.owncloud.android.datamodel.OCFile
import com.owncloud.android.files.services.FileDownloader
import com.owncloud.android.files.services.FileUploader
import com.owncloud.android.lib.resources.status.OCCapability
import com.owncloud.android.lib.resources.status.OwnCloudVersion
import com.owncloud.android.services.OperationsService
import com.owncloud.android.ui.activity.FileActivity
import com.owncloud.android.ui.activity.OnEnforceableRefreshListener
@ -101,6 +103,12 @@ class TestActivity :
override fun getStorageManager(): FileDataStorageManager {
if (!this::storage.isInitialized) {
storage = FileDataStorageManager(account, contentResolver)
val capability = OCCapability().apply {
versionMayor = OwnCloudVersion.nextcloud_15.getMajorVersionNumber()
}
storage.saveCapabilities(capability)
}
return storage

View file

@ -39,7 +39,6 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
*/
private boolean publicUpload;
private Boolean hideFileDownload;
private Boolean videoVerification;
private long expirationDateInMillis;
private long shareId;
private String label;
@ -104,8 +103,4 @@ public class UpdateShareViaLinkOperation extends SyncOperation {
public void setLabel(String label) {
this.label = label;
}
public void setVideoVerification(Boolean enabled) {
this.videoVerification = enabled;
}
}

View file

@ -554,11 +554,6 @@ public class OperationsService extends Service {
false);
updateLinkOperation.setHideFileDownload(hideFileDownload);
boolean videoVerificationEnabled =
operationIntent.getBooleanExtra(EXTRA_SHARE_VIDEO_VERIFICATION, false);
updateLinkOperation.setVideoVerification(videoVerificationEnabled);
if (operationIntent.hasExtra(EXTRA_SHARE_PUBLIC_UPLOAD)) {
updateLinkOperation.setPublicUpload(true);
}

View file

@ -899,8 +899,8 @@ public abstract class FileActivity extends DrawerActivity
if (getFile().isSharedWithMe()) {
return OCShare.READ_PERMISSION_FLAG; // minimum permissions
} else if (ShareType.FEDERATED.equals(shareType)) {
return getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9 :
OCShare.FEDERATED_PERMISSIONS_FOR_FILE_AFTER_OC9;
return getFile().isFolder() ? OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER :
OCShare.FEDERATED_PERMISSIONS_FOR_FILE;
} else {
return getFile().isFolder() ? OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER :
OCShare.MAXIMUM_PERMISSIONS_FOR_FILE;

View file

@ -80,6 +80,8 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import static com.owncloud.android.lib.resources.shares.OCShare.MAXIMUM_PERMISSIONS_FOR_FOLDER;
public class FileDetailSharingFragment extends Fragment implements ShareeListAdapterListener,
DisplayUtils.AvatarGenerationListener,
Injectable {
@ -387,6 +389,12 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
MenuItem readOnly = menu.findItem(R.id.link_share_read_only);
MenuItem uploadAndEditing = menu.findItem(R.id.link_share_allow_upload_and_editing);
MenuItem fileDrop = menu.findItem(R.id.link_share_file_drop);
if ((publicShare.getPermissions() & MAXIMUM_PERMISSIONS_FOR_FOLDER) == MAXIMUM_PERMISSIONS_FOR_FOLDER) {
uploadAndEditing.setChecked(true);
} else if ((publicShare.getPermissions() & OCShare.READ_PERMISSION_FLAG) == 1) {
readOnly.setChecked(true);
}
} else {
menu.setGroupVisible(R.id.folder_permission, false);
menu.findItem(R.id.allow_editing).setVisible(true);
@ -405,20 +413,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
res);
menu.findItem(R.id.action_share_send_note).setVisible(capabilities.getVersion().isNoteOnShareSupported());
// TODO move to separate PR
MenuItem videoVerification = menu.findItem(R.id.link_share_video_verification);
// if (videoVerification != null) {
// videoVerification.setChecked(publicShare.isSendPasswordByTalk());
// -When enabling it:
// -If it is for a mail share, you must always set a new password (which is also different from the previous one)
// -If it is for a link share, you only need to set a new password if the share didn't have one yet (but you can repeat the previous password)
// -When disabling it:
// -If it is for a mail share, you must always set a new password (which is also different from the previous one)
// -If it is for a link share, you do not need to set a new password
// }
}
private boolean userOptionsItemSelected(Menu menu,
@ -514,10 +508,6 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
case R.id.action_unshare:
fileOperationsHelper.unshareShare(file, publicShare);
return true;
case R.id.link_share_video_verification:
item.setChecked(!item.isChecked());
fileOperationsHelper.setVideoVerificationToPublicShare(publicShare, item.isChecked());
return true;
default:
return super.onOptionsItemSelected(item);
}
@ -601,12 +591,11 @@ public class FileDetailSharingFragment extends Fragment implements ShareeListAda
/**
* Get public link from the DB to fill in the "Share link" section in the UI.
* <p>
* Takes into account server capabilities before reading database.
*/
public void refreshSharesFromDB() {
// TODO check if this is not called too often
ShareeListAdapter adapter = ((ShareeListAdapter) binding.sharesList.getAdapter());
ShareeListAdapter adapter = (ShareeListAdapter) binding.sharesList.getAdapter();
adapter.getShares().clear();
// to show share with users/groups info

View file

@ -717,7 +717,7 @@ public class FileOperationsHelper {
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS, OCShare.CREATE_PERMISSION_FLAG);
} else {
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_PERMISSIONS,
OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER_AFTER_OC9);
OCShare.FEDERATED_PERMISSIONS_FOR_FOLDER);
}
queueShareIntent(updateShareIntent);
@ -733,16 +733,6 @@ public class FileOperationsHelper {
queueShareIntent(updateShareIntent);
}
public void setVideoVerificationToPublicShare(OCShare share, boolean videoVerificationEnabled) {
Intent updateShareIntent = new Intent(fileActivity, OperationsService.class);
updateShareIntent.setAction(OperationsService.ACTION_UPDATE_PUBLIC_SHARE);
updateShareIntent.putExtra(OperationsService.EXTRA_ACCOUNT, fileActivity.getAccount());
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_ID, share.getId());
updateShareIntent.putExtra(OperationsService.EXTRA_SHARE_VIDEO_VERIFICATION, videoVerificationEnabled);
queueShareIntent(updateShareIntent);
}
public void updateNoteToShare(OCShare share, String note) {
Intent updateShareIntent = new Intent(fileActivity, OperationsService.class);
updateShareIntent.setAction(OperationsService.ACTION_UPDATE_SHARE_NOTE);

View file

@ -23,7 +23,6 @@
android:id="@+id/detail_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:orientation="vertical">
<LinearLayout
@ -184,7 +183,7 @@
<androidx.viewpager.widget.ViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="fill_parent" />
android:layout_height="match_parent" />
<include layout="@layout/empty_list" />
</LinearLayout>

View file

@ -97,7 +97,6 @@
android:dividerHeight="1dp"
android:id="@+id/sharesList"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_marginBottom="72dp" />
android:layout_width="match_parent" />
</LinearLayout>

View file

@ -50,12 +50,6 @@
android:showAsAction="never"
android:title="@string/share_via_link_menu_password_label"
app:showAsAction="never" />
<item
android:id="@+id/link_share_video_verification"
android:checkable="true"
android:showAsAction="never"
android:title="@string/link_share_video_verification"
app:showAsAction="never" />
<item
android:id="@+id/action_share_expiration_date"
android:showAsAction="never"