[Web App] Edit files context menu on defined path

I want to edit the context menu, when clicking on the three dots and when right clicking on the folder or file. But only with a defined path, as an example “/s/ShareID?path=%2FFolder”.
“Rename”, “Move or copy”, “Edit locally” and “Leave this share” should be hidden. Visual only.

There are no special requirements that the mentioned functions are possibly executed via a bypass.

Is this possible?
If yes, how?

Inside files/js/fileactions.js I can add if (!folderUrl.includes(excludedPath)) { etc. before any mentioned this.registerAction({.
This solves the problem. Until the next update, then I have to add this again (manually).

Is this the best solution?
Is there a simpler solution?

Are you developing your own app? Then, you have no saying on the content of other apps’ files (like the files app you mentioned).

However, I guess with some js magic it should be possible to hide the entries via css or remove them from DOM. I would discourage this in 99% of all cases, so be sure that your use case is really valid. Also, you will have to somehow detect which entries to hide which will make the app brittle. All in all, not the best solution in the first place.

No, this is only a “design modification” for a single Nextcloud instance.

The code snippets from above also work fine. For the context menu itself.

What I noticed is that drag and drop of folders and files still works (which was to be expected).
Deshlab I would like to block this somewhere else, I just do not know where?

I would doubt it: Every update of the core will overwrite your modifications and also, the core will report the file as tampered as the file signature is no longer valid.

I never asked if it was a good solution. In any case, it is not.

But what other solution is there?
If there is none, then unfortunately it is and remains the best solution :smiley:

You could always add a minimal app that just tweaks a bit with the frontend. That would allow to persist the changes over version updates of the server.

I am thinking in this direction (although tweaking might be needed):
You use jQuery to register a new click action listener (plus right mouse clicks at appropriate locations) on the .fileactions > .action-menu. In the action listener, you check the URL. It it lies within a certain regex, you wait for the next Vue tick (to make all dom changes) and the add the hidden class to the appropriate entries you want hidden.

Would that work?

1 Like

That sounds interesting. I have dealt with it a little, but it was not purposeful.
I have no experience in NC app programming.

Currently I have implemented the above described “files/js/fileactions.js” manupulations solution with a script that creates a backup of the file after each update and manipulates the code.
Before each update the script is executed again and the backup of the file is restored so that there are no errors during the update.

If you have a working solution, maybe stick with it. You would have to either hardcode the path or do some coding in both PHP and JS. You can although have a look at the developer tutorials if there is enough information to get you started.

1 Like