Skip to content

Commit

Permalink
Hide share option when a file or folder has no reshare permission
Browse files Browse the repository at this point in the history
  • Loading branch information
JuancaG05 committed Mar 29, 2023
1 parent 322eb53 commit 17c1525
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@ public FileMenuFilter(List<OCFile> targetFiles, Account account, ComponentsGette
*/
public void filter(Menu menu, boolean displaySelectAll, boolean displaySelectInverse,
boolean onlyAvailableOffline, boolean sharedByLinkFiles, boolean hasWritePermission,
boolean hasDeletePermission, boolean hasRenamePermission, boolean hasMovePermission) {
boolean hasDeletePermission, boolean hasRenamePermission, boolean hasMovePermission,
boolean hasResharePermission) {
if (mFiles == null || mFiles.size() <= 0) {
hideAll(menu);

Expand All @@ -127,7 +128,7 @@ public void filter(Menu menu, boolean displaySelectAll, boolean displaySelectInv
List<Integer> toHide = new ArrayList<>();

filter(toShow, toHide, displaySelectAll, displaySelectInverse, onlyAvailableOffline, sharedByLinkFiles,
hasDeletePermission, hasRenamePermission, hasMovePermission);
hasDeletePermission, hasRenamePermission, hasMovePermission, hasResharePermission);

MenuItem item;
for (int i : toShow) {
Expand Down Expand Up @@ -175,7 +176,8 @@ private void hideAll(Menu menu) {

private void filter(List<Integer> toShow, List<Integer> toHide, boolean displaySelectAll,
boolean displaySelectInverse, boolean onlyAvailableOffline, boolean sharedByLinkFiles,
boolean hasDeletePermission, boolean hasRenamePermission, boolean hasMovePermission) {
boolean hasDeletePermission, boolean hasRenamePermission, boolean hasMovePermission,
boolean hasResharePermission) {

boolean synchronizing;
if (mFilesSync.isEmpty()) {
Expand Down Expand Up @@ -276,7 +278,7 @@ private void filter(List<Integer> toShow, List<Integer> toHide, boolean displayS
boolean notPersonalSpace = space != null && !space.isPersonal();

if ((!shareViaLinkAllowed && !shareWithUsersAllowed) || !isSingleSelection() ||
notAllowResharing || onlyAvailableOffline || notPersonalSpace) {
notAllowResharing || onlyAvailableOffline || notPersonalSpace || !hasResharePermission) {
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 @@ -212,6 +212,7 @@ class FileDetailsFragment : FileFragment() {
fileDetailsViewModel.getCurrentFile()?.hasDeletePermission == true,
fileDetailsViewModel.getCurrentFile()?.hasRenamePermission == true,
false,
fileDetailsViewModel.getCurrentFile()?.hasResharePermission == true,
)

menu.findItem(R.id.action_see_details)?.apply {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@ class MainFileListFragment : Fragment(),
val hasDeletePermission = checkedFiles.all { it.hasDeletePermission }
val hasRenamePermission = if (checkedCount == 1) checkedFiles.first().hasRenamePermission else false
val hasMovePermission = checkedFiles.all { it.hasMovePermission }
val hasResharePermission = if (checkedCount == 1) checkedFiles.first().hasResharePermission else false

fileMenuFilter.filter(
menu,
Expand All @@ -763,6 +764,7 @@ class MainFileListFragment : Fragment(),
hasDeletePermission,
hasRenamePermission,
hasMovePermission,
hasResharePermission,
)

return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ class PreviewAudioFragment : FileFragment() {
file.hasWritePermission,
file.hasDeletePermission,
file.hasRenamePermission,
false
false,
file.hasResharePermission,
)

// additional restriction for this fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ class PreviewImageFragment : FileFragment() {
file.hasDeletePermission,
file.hasRenamePermission,
false,
file.hasResharePermission,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void onPrepareOptionsMenu(Menu menu) {
);
mf.filter(menu, false, false, false,
false, getFile().getHasWritePermission(), getFile().getHasDeletePermission(),
getFile().getHasRenamePermission(), false);
getFile().getHasRenamePermission(), false, getFile().getHasResharePermission());
}

// additional restriction for this fragment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public void onPrepareOptionsMenu(@NonNull Menu menu) {
);
mf.filter(menu, false, false, false,
false, getFile().getHasWritePermission(), getFile().getHasDeletePermission(),
getFile().getHasRenamePermission(), false);
getFile().getHasRenamePermission(), false, getFile().getHasResharePermission());

// additional restrictions for this fragment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ data class OCFile(
val hasAddSubdirectoriesPermission: Boolean
get() = permissions?.contains(char = 'K', ignoreCase = true) ?: false

/**
* @return 'True' if the file has the 'R' (can reshare) within its group of permissions
*/
val hasResharePermission: Boolean
get() = permissions?.contains(char = 'R', ignoreCase = true) ?: false

/**
* get remote path of parent file
* @return remote path
Expand Down

0 comments on commit 17c1525

Please sign in to comment.