fritzmg / contao-file-access

Contao extension that allows file access restrictions for frontend users.
GNU Lesser General Public License v3.0
8 stars 1 forks source link

Wish: file-access for files outside the DBAFS #6

Closed TB1234 closed 5 years ago

TB1234 commented 5 years ago

Hello,

it would be create if the contao-file-access also works for files which are not in the DBAFS.

I maintain a site with over 700.000 pictures (increasing), which are uploaded via FTP. These files are not included in DBAFS and have to be imported via a manual sync job. For the website the DBAFS is not necessary for these images and these folders could be excluded from the synchronization.

Background: If a permission is set to the parent folder, it would be recursive. This means that the query would exist for the Contao group and an authorization could take effect.

Wish: The delivery of files which are not available in DBAFS, but in the file system below the corresponding file structure which is created in DBAFS. This must be checked accordingly.

Optional: The activation of this function by a flag on the folder, which only then unlocks it. This would also help to reduce the load.

fritzmg commented 5 years ago

Hmm... a quick fix would be the following:

        // Get FilesModel entity
        $filesModel = FilesModel::findOneByPath($file);
+
+       // Dynamically add the file to the DBAFS
+       if (null === $filesModel) {
+           $filesModel = \Contao\Dbafs::addResource($file);
+       }

        // Do not allow files that are not in the database or don't have a parent
        if (null === $filesModel || null === $filesModel->pid) {
            throw new PageNotFoundException();
        }

This would dynamically add the file to the DBAFS. Not sure if this has any negative effects.

TB1234 commented 5 years ago

Hm, ok das scheint mein Problem erst einmal zu lösen. Vielen Dank!

Aktuell sind mir keine Probleme aufgefallen. Ich werde das weiter testen.

fritzmg commented 5 years ago

Yeah I think there shouldn't be any downside to having files added to the Dbafs, even if the parent folder is excluded from the Dbafs sync. And in turn this means that the file access controller is more efficient, because once the file is in the database, less database queries are required (compared to checking the whole file path if any parent folder is in the database).

TB1234 commented 5 years ago

Looks very good. Testresults are here: https://community.contao.org/de/showthread.php?60720-file_access-Dateizugriffsbeschr%C3%A4nkung-%C3%BCber-Frontend-Login&p=501190#post501190

fritzmg commented 5 years ago

Implemented in 3b02124d67cc5577f220bcf80210c97ab957867f