Permissions for files without a set in Concrete5

The question

Concrete5 community member BlueFractals asked:

In Dashboard > File Manager, is there a way to prevent specific users or group from accessing 'Files in no sets'?

After digging through the advanced permissions I discovered it wasn't possible; permissions are assigned to file sets and not files themselves.

The solution

By hooking into certain events we can seamlessly manage our files which aren't assigned to a set, by adding them to their own set!

  1. If the file does not belong to a set, add it to a new set titled 'Setless' (on_file_add & on_file_removed_from_set)
  2. If file is in multiple sets and 'Setless' is one of them, remove from 'Setless' (on_file_added_to_set)

If you would like to take a closer look at the code or use it on one of your Concrete5 sites, I've made a packaged version on GitHub. View the 5.6 branch if you have a legacy 5.6 site, otherwise the master branch is for 5.7+.

View on GitHub


Update 1: Updated for 5.7+