Advanced: Programmatically Setting Permissions on an Object

Any object with permissions can have those permissins set programmatically. Here's an example.

Change Permissions on a File

We can adjust file permissions programmatically. First, we need to enable Advanced Permissions via the dashboard; we can then proceed with some examples.

// override parent folder permissions

// remove Guest access
$pk = PermissionKey::getByHandle('view_file');
$pa = $pk->getPermissionAccessObject();
$pe = GroupPermissionAccessEntity::getOrCreate(UserGroup::getByID(GUEST_GROUP_ID));

// enable access by a group
$g = UserGroup::getByName('VIPs');
if (is_object($g)) {
    $pae = GroupPermissionAccessEntity::getOrCreate($g);
    $pa->addListItem($pae, false, PermissionKey::ACCESS_TYPE_INCLUDE);

// enable access by an individual user
$ui = UserInfo::getByID($uID);
if (is_object($ui)) {
    $pae = UserPermissionAccessEntity::getOrCreate($ui);
    $pa->addListItem($pae, false, PermissionKey::ACCESS_TYPE_INCLUDE);

// apply the the permissions changes
Loading Conversation