Problem with accessing groupfolder ID in my plugin

Hey together,
i have written a small nextcloud plugin for filtering mimetypes based on the files path and it can be configured with a config file ( https://apps.nextcloud.com/apps/files_staticmimecontrol / files_staticmimecontrol/StorageWrapper.php at main 路 Nagold/files_staticmimecontrol 路 GitHub ).
I鈥檓 by no means a php expert and this is my first nextcloud plugin, so most likeley you will be in pain if you analyze my code ( btw: if you can see bad practice or errors, i appreciate any hints!).

The plugin does everything like we imagined and does the job in every situation but one:

When we use a groupfolder and create a subfolder in the groupfolder, then suddenly the path of an uploaded file does not have the __groupfolders/ID prefix in every checkFileAccess call, but only the subfolders name as prefix and therefore the method working in the groupfolders root to match __groupfolders/ID does not work.
Also the mountpoint in this scenario turns to the mount point from a users perspective for example 鈥/user1/files/testgroupfolder/鈥 and not 鈥淿_groupfolders/1/testgroupfolder鈥 as i would expect it.

I have tried to somehow find out how to get to the groupfolder id or path via the objects i have access to, but the debugger shows only 2 places (from point of view of the OCA\FilesStaticmimecontrol\StorageWrapper):

1: $this->storage->storage->storage->OCA\GroupFolders\Mount\GroupFolderStoragefolderId (which i could not manage to access from the code)
2: $this->storage->storage->storage->storage->rootPath (which seems to be either protected or private)

Thanks to get_class($this->storage->storage->storage) i can determinate if the request at that moment depends on a groupfolder object or not, so i just either need to convert the groupfolders name to its id or directly receive the __groupfolders/ path from somewhere, to compare it against my rules.

I would really appreciate any help and any suggestions!
If i did not manage to explain my problem so you can understand it, also let me know.

Thanks in advance,
Alex

can someone suggest anything? :confused:

Hello. I am not yet in the situation, I can help you much but a few comments:

  • You use the OC namespace here. You should not do this. The interface might change anytime.
  • Why is readRules public? Do you need to publish it to some external files? It seems more like an internal method.
  • Do not use \OC
  • I suggest (but this is personal taste) to create a value object with the configuration and fill that during reading the JSON file. That will surface typos more easily.

When looking at the API reference, the addStorageWrapper method might be a way to go.

If I am correct, you want to restrict access to all files with a certain path and mime type. So it is some sort of filtering. Am I correct?

Thanks so much for your reply! :slight_smile:
I initially tried to get rid of the OC Namespace /the \OC calls, but could not manage to get it working like i wanted. But seems i have to invest more time here to understand why.

You are right with the readRules method, it should be protected /private.

And yes, it would be better to make a defined object instead of the json_decode and the array access.

Thanks for pointing those out, i鈥檒l go over that as soon as i have an idea how to fix the actual function of the plugin.

And yes, you are right, we want to restrict the upload of certain mime types in certain paths (with regex rules) from a defined config instead of the database (like files_accesscontrol does). This should work for default files/folders and groupfolders.

The problem we have, like mentioned in the initial post is, that the paths getting into our plugin look different when the groupfolders root folder is used compared to subfolders, and we are not able to 鈥渢ranslate鈥 those paths, to check for the access.

Looking forward to future replys :slight_smile: