Listing those Users with View Files access to a File Set
Permalink
Hi,
I want to display a list of users and user groups that have View Files access to a specific File Set.
I have got a list of file sets that the logged in user can access (below), I just need to figure out how to check the access permissions to the file set.
Any ideas?
The purpose of the code is so that I can get a list of users to notify when someone uploads a new file into a file set.
Thanks,
Julian
I want to display a list of users and user groups that have View Files access to a specific File Set.
I have got a list of file sets that the logged in user can access (below), I just need to figure out how to check the access permissions to the file set.
Loader::model('file_set'); $fs = new FileSet(); $fileset_list = $fs->getMySets(); foreach ($fileset_list as $fileset_item){ //get users and groups with View Files access to this file set }
Any ideas?
The purpose of the code is so that I can get a list of users to notify when someone uploads a new file into a file set.
Thanks,
Julian
Perhaps I didn't make myself clear... I want to find ALL of the users and groups that can view files within a particular file set.
An example of what I want to do would be if I was part of a user group called 'Sales Team', and I uploaded a document (through a custom form) into a file set called 'End Of Month Reports'. I want to run some code that finds out who can access the End Of Month Reports file set (this would probably be the Marketing Manager, members of the Finance Team, the Company Directors and the other members of the Sales Team) and notify them by email that a new file has been added for them to go look at.
So, basically all I want at the moment is to list all of the users and user groups that have access to view files within a particular file set.
Does that make sense?
An example of what I want to do would be if I was part of a user group called 'Sales Team', and I uploaded a document (through a custom form) into a file set called 'End Of Month Reports'. I want to run some code that finds out who can access the End Of Month Reports file set (this would probably be the Marketing Manager, members of the Finance Team, the Company Directors and the other members of the Sales Team) and notify them by email that a new file has been added for them to go look at.
So, basically all I want at the moment is to list all of the users and user groups that have access to view files within a particular file set.
Does that make sense?
OK I see, when you grab a Permissions object you can only get the current users permissions.
I would try something like this...
I extrapolated that from the core permissions model.
I would try something like this...
//$users is a list of all users $p = new Permissions($fileset_item); $my_users = new array(); foreach($users as $u) { $permissions = $p->setGroupAccess($fileset_item, $u); if($permissions['canRead'] == FilePermissions::PTYPE_ALL) ADD_TO_LIST; }
I extrapolated that from the core permissions model.
I couldn't get your code to work, but I had a look through the code that is within the dashboard that displays File Set permissions and after a bit of a hack, I came up with this:
What the code does is loop through the file sets that the user has access to (which will change depending on the access rights of whoever is logged in), then within each file set it will find the user groups that have View Files access and loop through the users within that group to display their username and email address. I've also output the ID of each object so I can track things more easily.
It's not exactly an elegant solution, and I'll need to butcher it again to get it to do the whole of what I need, but I hope the code is useful to someone else looking to work with users, user groups and file sets!
$fileset_list = FileSet::getMySets(); foreach ($fileset_list as $fileset_item){ echo "<br />This file set: [" . $fileset_item->getFileSetID() . "] " . $fileset_item->getFileSetName() . "<br />"; $cat = PermissionKeyCategory::getByHandle('file_set'); $permissions = PermissionKey::getList('file_set'); foreach($permissions as $pk) { $pk->setPermissionObject($fileset_item); if ($pk->getPermissionKeyID() == 34){ $pa = $pk->getPermissionAccessObject(); $assignments = array(); $paID = 0; if (is_object($pa)) { $paID = $pa->getPermissionAccessID(); $assignments = $pa->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL); }
Viewing 15 lines of 32 lines. View entire code block.
What the code does is loop through the file sets that the user has access to (which will change depending on the access rights of whoever is logged in), then within each file set it will find the user groups that have View Files access and loop through the users within that group to display their username and email address. I've also output the ID of each object so I can track things more easily.
It's not exactly an elegant solution, and I'll need to butcher it again to get it to do the whole of what I need, but I hope the code is useful to someone else looking to work with users, user groups and file sets!
I wasn't aware that you could set permissions on file sets on an individual file set basis, I think this is an all or none affair.