@@ -69,6 +69,7 @@ class FileMenuFilterIT : AbstractIT() {
6969 every { mockComponentsGetter.operationsServiceBinder } returns mockOperationsServiceBinder
7070 every { mockStorageManager.getFileById(any()) } returns OCFile (" /" )
7171 every { mockStorageManager.getFolderContent(any(), any()) } returns ArrayList <OCFile >()
72+ every { mockStorageManager.isReadOnly(any()) } returns false
7273 every { mockArbitraryDataProvider.getValue(any<User >(), any()) } returns " "
7374 editorUtils = EditorUtils (mockArbitraryDataProvider)
7475 }
@@ -363,6 +364,63 @@ class FileMenuFilterIT : AbstractIT() {
363364 }
364365 }
365366
367+ @Test
368+ fun filter_readOnlyFile_hidesModifyingActions () {
369+ configureCapability(
370+ OCCapability ().apply {
371+ endToEndEncryption = CapabilityBooleanType .TRUE
372+ filesLockingVersion = " 1.0"
373+ }
374+ )
375+
376+ every { mockStorageManager.isReadOnly(any()) } returns true
377+
378+ val file = OCFile (" /readOnly.txt" ).apply {
379+ permissions = FULL_PERMISSIONS
380+ }
381+
382+ launchActivity<TestActivity >().use {
383+ it.onActivity { activity ->
384+ val filterFactory = FileMenuFilter .Factory (mockStorageManager, activity, editorUtils)
385+
386+ val toHide = filterFactory
387+ .newInstance(file, mockComponentsGetter, true , user)
388+ .getToHide(false )
389+
390+ READ_ONLY_HIDDEN_ACTIONS .forEach { action ->
391+ assertTrue(toHide.contains(action))
392+ }
393+ }
394+ }
395+ }
396+
397+ @Test
398+ fun filter_writableFile_keepsModifyingActions () {
399+ configureCapability(
400+ OCCapability ().apply {
401+ filesLockingVersion = " 1.0"
402+ }
403+ )
404+
405+ val file = OCFile (" /writable.txt" ).apply {
406+ permissions = FULL_PERMISSIONS
407+ }
408+
409+ launchActivity<TestActivity >().use {
410+ it.onActivity { activity ->
411+ val filterFactory = FileMenuFilter .Factory (mockStorageManager, activity, editorUtils)
412+
413+ val toHide = filterFactory
414+ .newInstance(file, mockComponentsGetter, true , user)
415+ .getToHide(false )
416+
417+ WRITABLE_VISIBLE_ACTIONS .forEach { action ->
418+ assertFalse(toHide.contains(action))
419+ }
420+ }
421+ }
422+ }
423+
366424 private data class ExpectedLockVisibilities (val lockFile : Boolean , val unlockFile : Boolean )
367425
368426 private fun configureCapability (capability : OCCapability ) {
@@ -398,6 +456,29 @@ class FileMenuFilterIT : AbstractIT() {
398456 }
399457
400458 companion object {
459+ private const val FULL_PERMISSIONS = " RGDNVW"
460+
461+ private val READ_ONLY_HIDDEN_ACTIONS = listOf (
462+ R .id.action_remove_file,
463+ R .id.action_rename_file,
464+ R .id.action_move_or_copy,
465+ R .id.action_edit,
466+ R .id.action_encrypted,
467+ R .id.action_unset_encrypted,
468+ R .id.action_lock_file,
469+ R .id.action_unlock_file,
470+ R .id.action_favorite,
471+ R .id.action_unset_favorite
472+ )
473+
474+ private val WRITABLE_VISIBLE_ACTIONS = listOf (
475+ R .id.action_remove_file,
476+ R .id.action_rename_file,
477+ R .id.action_move_or_copy,
478+ R .id.action_lock_file,
479+ R .id.action_favorite
480+ )
481+
401482 private const val OFFICE_MIMETYPE =
402483 " application/vnd.openxmlformats-officedocument.wordprocessingml.document"
403484
0 commit comments