public function getAllTimedAssignmentsForPage() { $db = Loader::db(); $assignments = array(); $r = $db->Execute('select peID, pkID, pdID from PagePermissionAssignments ppa inner join PermissionAccessList pal on ppa.paID = pal.paID where pdID > 0 and cID = ?', array($this->object->getCollectionID())); while ($row = $r->FetchRow()) { $pk = PagePermissionKey::getByID($row['pkID']); $pae = PermissionAccessEntity::getByID($row['peID']); $pd = PermissionDuration::getByID($row['pdID']); $ppc = new PageContentPermissionTimedAssignment(); $ppc->setDurationObject($pd); $ppc->setAccessEntityObject($pae); $ppc->setPermissionKeyObject($pk); $assignments[] = $ppc; } $r = $db->Execute('select arHandle from Areas where cID = ? and arOverrideCollectionPermissions = 1', array($this->object->getCollectionID())); while ($row = $r->FetchRow()) { $r2 = $db->Execute('select peID, pdID, pkID from AreaPermissionAssignments apa inner join PermissionAccessList pal on apa.paID = pal.paID where pdID > 0 and cID = ? and arHandle = ?', array($this->object->getCollectionID(), $row['arHandle'])); while ($row2 = $r2->FetchRow()) { $pk = AreaPermissionKey::getByID($row2['pkID']); $pae = PermissionAccessEntity::getByID($row2['peID']); $area = Area::get($this->getPermissionObject(), $row['arHandle']); $pk->setPermissionObject($area); $pd = PermissionDuration::getByID($row2['pdID']); $ppc = new PageContentPermissionTimedAssignment(); $ppc->setDurationObject($pd); $ppc->setAccessEntityObject($pae); $ppc->setPermissionKeyObject($pk); $assignments[] = $ppc; } } $r = $db->Execute('select peID, cvb.cvID, cvb.bID, pdID, pkID from BlockPermissionAssignments bpa inner join PermissionAccessList pal on bpa.paID = pal.paID inner join CollectionVersionBlocks cvb on cvb.cID = bpa.cID and cvb.cvID = bpa.cvID and cvb.bID = bpa.bID where pdID > 0 and cvb.cID = ? and cvb.cvID = ? and cvb.cbOverrideAreaPermissions = 1', array($this->object->getCollectionID(), $this->object->getVersionID())); while ($row = $r->FetchRow()) { $pk = BlockPermissionKey::getByID($row['pkID']); $pae = PermissionAccessEntity::getByID($row['peID']); $arHandle = $db->GetOne('select arHandle from CollectionVersionBlocks where bID = ? and cvID = ? and cID = ?', array($row['bID'], $row['cvID'], $this->object->getCollectionID())); $b = Block::getByID($row['bID'], $this->object, $arHandle); $pk->setPermissionObject($b); $pd = PermissionDuration::getByID($row['pdID']); $ppc = new PageContentPermissionTimedAssignment(); $ppc->setDurationObject($pd); $ppc->setAccessEntityObject($pae); $ppc->setPermissionKeyObject($pk); $assignments[] = $ppc; } return $assignments; }
if (count($permissionsInherit) == 1) { $permissionsInherit = $permissionsInherit[0]; } else { $permissionsInherit = '-1'; } if (count($permissionsSubpageOverride) == 1) { $permissionsSubpageOverride = $permissionsSubpageOverride[0]; } else { $permissionsSubpageOverride = '-1'; } if ($_REQUEST['subtask'] == 'set' && $permissionsInherit == 'OVERRIDE') { ?> <?php $pk = PagePermissionKey::getByID($_REQUEST['pkID']); $pk->setPermissionObject($pages[0]); $pk->setMultiplePageArray($pages); ?> <?php Loader::element("permission/detail", array('permissionKey' => $pk)); ?> <script type="text/javascript"> var ccm_permissionDialogURL = '<?php echo REL_DIR_FILES_TOOLS_REQUIRED; ?> /pages/permissions?subtask=set<?php echo $cIDStr;
public function assignPermissions($userOrGroup, $permissions = array(), $accessType = PagePermissionKey::ACCESS_TYPE_INCLUDE) { if ($this->cInheritPermissionsFrom != 'OVERRIDE') { $this->setPermissionsToManualOverride(); $this->clearPagePermissions(); } if (is_array($userOrGroup)) { $pe = GroupCombinationPermissionAccessEntity::getOrCreate($userOrGroup); // group combination } else { if ($userOrGroup instanceof User || $userOrGroup instanceof UserInfo) { $pe = UserPermissionAccessEntity::getOrCreate($userOrGroup); } else { // group; $pe = GroupPermissionAccessEntity::getOrCreate($userOrGroup); } } foreach ($permissions as $pkHandle) { $pk = PagePermissionKey::getByHandle($pkHandle); $pk->setPermissionObject($this); $pa = $pk->getPermissionAccessObject(); if (!is_object($pa)) { $pa = PermissionAccess::create($pk); } $pa->addListItem($pe, false, $accessType); $pt = $pk->getPermissionAssignmentObject(); $pt->assignPermissionAccess($pa); $this->loadPermissionAssignments(); } }
private function setPermissions() { /* * This only covers permissions in 5.6+ They changed quite massively at * that revision. Eventually, this package will have other branches for * earlier versions. * * Not everything shown here will work with simple permissions. People * will just be set as able to view or admin, the nuanced stuff about * sub page permissions, etc will not be applied * * First off, we need to set up arrays of what people are allowed to do. */ $viewOnly = array('view_page'); $writePage = array('view_page', 'view_page_versions', 'edit_page_properties', 'edit_page_contents', 'approve_page_versions'); $adminPage = array('edit_page_speed_settings', 'edit_page_permissions', 'edit_page_theme', 'schedule_page_contents_guest_access', 'edit_page_type', 'delete_page', 'preview_page_as_user', 'delete_page_versions', 'move_or_copy_page', 'edit_page_type'); // Now to get the the group that we made for boilerplate $bpGroup = Group::getByName("Boilerplate Admins"); // Then the current user, again, could be anyone $u = new User(); $ui = UserInfo::getByID($u->getUserID()); // and our sample page $bpPage = Page::getByPath('/boilerplate-sample'); if (is_object($bpPage) && is_a($bpPage, "Page")) { // by passing in -1, we are saying that all permissions in the array are // not allowed // // After some more digging, it seems like saying can't view doesn't // work properly. It will hide the page from everyone. If you simply // don't assign any permissions for them at all, then it works properly // I don't get why that is, might be a bug. // // $bpPage->assignPermissions(Group::getByID(GUEST_GROUP_ID), $viewOnly, -1); // $bpPage->assignPermissions(Group::getByID(REGISTERED_GROUP_ID), $viewOnly, -1); $bpPage->assignPermissions(Group::getByID(ADMIN_GROUP_ID), $adminPage); $bpPage->assignPermissions(Group::getByID(ADMIN_GROUP_ID), $writePage); $bpPage->assignPermissions($bpGroup, $writePage); $bpPage->assignPermissions($ui, $writePage); // at this point, our page will let people edit, and others can't even view // in order to allow sub-pages to be added by our admins, we'll need to get // a _bit_ more complicated. // this could probbly be cleaned up a little, to be more efficient // first get the ctID of the page type we want them to be able to add $bpID = CollectionType::getByHandle('boilerplate')->getCollectionTypeID(); // In order to allow the user to add sub pages, we need to do this $bpAdminUserPE = UserPermissionAccessEntity::getOrCreate($ui); $entities[] = $bpAdminUserPE; // lets them add external links $args = array(); $args['allowExternalLinksIncluded'][$bpAdminUserPE->getAccessEntityID()] = 1; // I can't remember why it's "C" or what the other options are... $args['pageTypesIncluded'][$bpAdminUserPE->getAccessEntityID()] = 'C'; // you can repeat this with as many different collection type IDs as you like $args['ctIDInclude'][$bpAdminUserPE->getAccessEntityID()][] = $bpID; // now to allow it for groups $bpAdminPE = GroupPermissionAccessEntity::getOrCreate($bpGroup); $entities[] = $bpAdminPE; $args['allowExternalLinksIncluded'][$bpAdminPE->getAccessEntityID()] = 1; $args['pageTypesIncluded'][$bpAdminPE->getAccessEntityID()] = 'C'; $args['ctIDInclude'][$bpAdminPE->getAccessEntityID()][] = $bpID; // ordinary admins $adminPE = GroupPermissionAccessEntity::getOrCreate(Group::getByID(ADMIN_GROUP_ID)); $entities[] = $adminPE; $args['allowExternalLinksIncluded'][$adminPE->getAccessEntityID()] = 1; $args['pageTypesIncluded'][$adminPE->getAccessEntityID()] = 'C'; $args['ctIDInclude'][$adminPE->getAccessEntityID()][] = $bpID; // and now some crazy voodoo $pk = PagePermissionKey::getByHandle('add_subpage'); $pk->setPermissionObject($bpPage); $pt = $pk->getPermissionAssignmentObject(); $pa = $pk->getPermissionAccessObject(); if (!is_object($pa)) { $pa = PermissionAccess::create($pk); } foreach ($entities as $pe) { $pa->addListItem($pe, false, PagePermissionKey::ACCESS_TYPE_INCLUDE); } $pa->save($args); $pt->assignPermissionAccess($pa); // and now we set it so that sub-pages added under this page // inherit the same permissions $pkr = new ChangeSubpageDefaultsInheritancePageWorkflowRequest(); $pkr->setRequestedPage($bpPage); // if you pass in 0, they will inherit from page type default // permissions in the dashboard. That's what they would do anyway, // if you don't do any of this stuff. $pkr->setPagePermissionsInheritance(1); $pkr->setRequesterUserID($u->getUserID()); $pkr->trigger(); } }
public function assignPermissions($userOrGroup, $permissions = array(), $accessType = FileSetPermissionKey::ACCESS_TYPE_INCLUDE) { $db = Loader::db(); if ($this->fsID > 0) { $db->Execute("update FileSets set fsOverrideGlobalPermissions = 1 where fsID = ?", array($this->fsID)); } if (is_array($userOrGroup)) { $pe = GroupCombinationPermissionAccessEntity::getOrCreate($userOrGroup); // group combination } else { if ($userOrGroup instanceof User || $userOrGroup instanceof UserInfo) { $pe = UserPermissionAccessEntity::getOrCreate($userOrGroup); } else { // group; $pe = GroupPermissionAccessEntity::getOrCreate($userOrGroup); } } foreach ($permissions as $pkHandle) { $pk = PagePermissionKey::getByHandle($pkHandle); $pk->setPermissionObject($this); $pa = $pk->getPermissionAccessObject(); if (!is_object($pa)) { $pa = PermissionAccess::create($pk); } $pa->addListItem($pe, false, $accessType); $pt = $pk->getPermissionAssignmentObject(); $pt->assignPermissionAccess($pa); } }
<? } ?> <? if (!$c->getCollectionPointerID() && !$hasPendingPageApproval) { if (is_object($vo)) { if (!$vo->isApproved() && !$c->isEditMode()) { ?> sbitem = new ccm_statusBarItem(); sbitem.setCSSClass('info'); sbitem.setDescription('<?php echo t("This page is pending approval."); ?> '); <? if ($cp->canApprovePageVersions() && !$c->isCheckedOut()) { $pk = PagePermissionKey::getByHandle('approve_page_versions'); $pk->setPermissionObject($c); $pa = $pk->getPermissionAccessObject(); if (is_object($pa)) { if (count($pa->getWorkflows()) > 0) { $appLabel = t('Submit for Approval'); } } if (!$appLabel) { $appLabel = t('Approve Version'); } ?> btn1 = new ccm_statusBarItemButton(); btn1.setCSSClass('btn-success'); btn1.setLabel('<?php echo $appLabel;