Exemplo n.º 1
0
 public function loadPermissionDurationObject($pdID)
 {
     if ($pdID > 0) {
         $pd = Duration::getByID($pdID);
         $this->duration = $pd;
     }
 }
Exemplo n.º 2
0
<?php

defined('C5_EXECUTE') or die("Access Denied.");
use Concrete\Core\Permission\Access\Entity\Entity as PermissionAccessEntity;
use Concrete\Core\Permission\Duration as PermissionDuration;
$f = File::getByID($_REQUEST['fID']);
if (is_object($f)) {
    $fp = new Permissions($f);
    if ($fp->canEditFilePermissions()) {
        if ($_REQUEST['task'] == 'add_access_entity' && Loader::helper("validation/token")->validate('add_access_entity')) {
            $pk = PermissionKey::getByID($_REQUEST['pkID']);
            $pk->setPermissionObject($f);
            $pa = PermissionAccess::getByID($_REQUEST['paID'], $pk);
            $pe = PermissionAccessEntity::getByID($_REQUEST['peID']);
            $pd = PermissionDuration::getByID($_REQUEST['pdID']);
            $pa->addListItem($pe, $pd, $_REQUEST['accessType']);
        }
        if ($_REQUEST['task'] == 'revert_to_global_file_permissions' && Loader::helper("validation/token")->validate('revert_to_global_file_permissions')) {
            $f->resetPermissions();
        }
        if ($_REQUEST['task'] == 'override_global_file_permissions' && Loader::helper("validation/token")->validate('override_global_file_permissions')) {
            $f->resetPermissions(1);
        }
        if ($_REQUEST['task'] == 'remove_access_entity' && Loader::helper("validation/token")->validate('remove_access_entity')) {
            $pk = PermissionKey::getByID($_REQUEST['pkID']);
            $pk->setPermissionObject($f);
            $pa = PermissionAccess::getByID($_REQUEST['paID'], $pk);
            $pe = PermissionAccessEntity::getByID($_REQUEST['peID']);
            $pa->removeListItem($pe);
        }
        if ($_REQUEST['task'] == 'save_permission' && Loader::helper("validation/token")->validate('save_permission')) {
Exemplo n.º 3
0
 /**
  * Sets up a list to only return items the proper user can access
  */
 public function setupPermissions()
 {
     $u = new User();
     if ($u->isSuperUser() || $this->ignorePermissions) {
         return;
         // super user always sees everything. no need to limit
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $peIDs = array('-1');
     foreach ($accessEntities as $pae) {
         $peIDs[] = $pae->getAccessEntityID();
     }
     $owpae = PageOwnerPermissionAccessEntity::getOrCreate();
     // now we retrieve a list of permission duration object IDs that are attached view_page or view_page_version
     // against any of these access entity objects. We just get'em all.
     $db = Loader::db();
     $activePDIDs = array();
     $vpPKID = $db->GetOne('select pkID from PermissionKeys where pkHandle = ?', array($this->viewPagePermissionKeyHandle));
     /*
     $vpvPKID = $db->GetOne('select pkID from PermissionKeys where pkHandle = \'view_page_versions\'');
     $pdIDs = $db->GetCol("select distinct pdID from PagePermissionAssignments ppa inner join PermissionAccessList pa on ppa.paID = pa.paID where pkID in (?, ?) and pdID > 0", array($vpPKID, $vpvPKID));
     */
     $pdIDs = $db->GetCol("select distinct pdID from PagePermissionAssignments ppa inner join PermissionAccessList pa on ppa.paID = pa.paID where pkID =? and pdID > 0", array($vpPKID));
     if (count($pdIDs) > 0) {
         // then we iterate through all of them and find any that are active RIGHT NOW
         foreach ($pdIDs as $pdID) {
             $pd = PermissionDuration::getByID($pdID);
             if ($pd->isActive()) {
                 $activePDIDs[] = $pd->getPermissionDurationID();
             }
         }
     }
     $activePDIDs[] = 0;
     if ($this->includeAliases) {
         $cInheritPermissionsFromCID = 'if(p2.cID is null, p1.cInheritPermissionsFromCID, p2.cInheritPermissionsFromCID)';
     } else {
         $cInheritPermissionsFromCID = 'p1.cInheritPermissionsFromCID';
     }
     if ($this->displayOnlyApprovedPages) {
         $cvIsApproved = ' and cv.cvIsApproved = 1';
     }
     $uID = 0;
     if ($u->isRegistered()) {
         $uID = $u->getUserID();
     }
     /*
     		$this->filter(false, "((select count(cID) from PagePermissionAssignments ppa1 inner join PermissionAccessList pa1 on ppa1.paID = pa1.paID where ppa1.cID = {$cInheritPermissionsFromCID} and pa1.accessType = " . PermissionKey::ACCESS_TYPE_INCLUDE . " and pa1.pdID in (" . implode(',', $activePDIDs) . ")
     and pa1.peID in (" . implode(',', $peIDs) . ") and (if(pa1.peID = " . $owpae->getAccessEntityID() . " and p1.uID <>" . $uID . ", false, true)) and (ppa1.pkID = " . $vpPKID . $cvIsApproved . " or ppa1.pkID = " . $vpvPKID . ")) > 0
     or (p1.cPointerExternalLink !='' AND p1.cPointerExternalLink IS NOT NULL))");
     		$this->filter(false, "((select count(cID) from PagePermissionAssignments ppaExclude inner join PermissionAccessList paExclude on ppaExclude.paID = paExclude.paID where ppaExclude.cID = {$cInheritPermissionsFromCID} and accessType = " . PermissionKey::ACCESS_TYPE_EXCLUDE . " and pdID in (" . implode(',', $activePDIDs) . ")
     and paExclude.peID in (" . implode(',', $peIDs) . ") and (if(paExclude.peID = " . $owpae->getAccessEntityID() . " and p1.uID <>" . $uID . ", false, true)) and (ppaExclude.pkID = " . $vpPKID . $cvIsApproved . " or ppaExclude.pkID = " . $vpvPKID . ")) = 0)");
     */
     $this->filter(false, "((select count(cID) from PagePermissionAssignments ppa1 inner join PermissionAccessList pa1 on ppa1.paID = pa1.paID where ppa1.cID = {$cInheritPermissionsFromCID} and pa1.accessType = " . PermissionKey::ACCESS_TYPE_INCLUDE . " and pa1.pdID in (" . implode(',', $activePDIDs) . ")\n\t\t\tand pa1.peID in (" . implode(',', $peIDs) . ") and (if(pa1.peID = " . $owpae->getAccessEntityID() . " and p1.uID <>" . $uID . ", false, true)) and (ppa1.pkID = " . $vpPKID . $cvIsApproved . ")) > 0\n\t\t\tor (p1.cPointerExternalLink !='' AND p1.cPointerExternalLink IS NOT NULL))");
     $this->filter(false, "((select count(cID) from PagePermissionAssignments ppaExclude inner join PermissionAccessList paExclude on ppaExclude.paID = paExclude.paID where ppaExclude.cID = {$cInheritPermissionsFromCID} and accessType = " . PermissionKey::ACCESS_TYPE_EXCLUDE . " and pdID in (" . implode(',', $activePDIDs) . ")\n\t\t\tand paExclude.peID in (" . implode(',', $peIDs) . ") and (if(paExclude.peID = " . $owpae->getAccessEntityID() . " and p1.uID <>" . $uID . ", false, true)) and (ppaExclude.pkID = " . $vpPKID . $cvIsApproved . ")) = 0)");
 }
 protected function updatePermissionDurationObjects()
 {
     $db = \Database::get();
     $r = $db->Execute('select pdID from PermissionDurationObjects order by pdID asc');
     while ($row = $r->FetchRow()) {
         $pd = Duration::getByID($row['pdID']);
         if (isset($pd->error)) {
             // this is a legacy object. It was serialized from 5.7.3.1 and earlier and used to extend Object.
             // so we take the old pd* parameters and use them as the basis for the standard parameters.
             $pd->setStartDate($pd->pdStartDate);
             $pd->setEndDate($pd->pdEndDate);
             $pd->setStartDateAllDay((bool) $pd->pdStartDateAllDay);
             $pd->setEndDateAllDay((bool) $pd->pdEndDateAllDay);
             if ($pd->pdRepeatPeriod == 'daily') {
                 $pd->setRepeatPeriod(Duration::REPEAT_DAILY);
             } elseif ($pd->pdRepeatPeriod == 'weekly') {
                 $pd->setRepeatPeriod(Duration::REPEAT_WEEKLY);
             } elseif ($pd->pdRepeatPeriod == 'monthly') {
                 $pd->setRepeatPeriod(Duration::REPEAT_MONTHLY);
             } else {
                 $pd->setRepeatPeriod(Duration::REPEAT_NONE);
             }
             if ($pd->pdRepeatEveryNum) {
                 $pd->setRepeatEveryNum($pd->pdRepeatEveryNum);
             }
             if ($pd->pdRepeatPeriodWeeksDays) {
                 $pd->setRepeatPeriodWeekDays($pd->pdRepeatPeriodWeeksDays);
             }
             if ($pd->pdRepeatPeriodMonthsRepeatBy == 'week') {
                 $pd->setRepeatMonthBy(Duration::MONTHLY_REPEAT_WEEKLY);
             } elseif ($pd->pdRepeatPeriodMonthsRepeatBy == 'month') {
                 $pd->setRepeatMonthBy(Duration::MONTHLY_REPEAT_MONTHLY);
             }
             if ($pd->pdRepeatPeriodEnd) {
                 $pd->setRepeatPeriodEnd($pd->pdRepeatPeriodEnd);
             }
             unset($pd->pdStartDate);
             unset($pd->pdEndDate);
             unset($pd->pdStartDateAllDay);
             unset($pd->pdEndDateAllDay);
             unset($pd->pdRepeatPeriod);
             unset($pd->pdRepeatEveryNum);
             unset($pd->pdRepeatPeriodWeeksDays);
             unset($pd->pdRepeatPeriodMonthsRepeatBy);
             unset($pd->pdRepeatPeriodEnd);
             unset($pd->error);
             $pd->save();
         }
     }
 }
Exemplo n.º 5
0
 public function getAllAssignmentsForPage()
 {
     $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 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 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 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;
 }
Exemplo n.º 6
0
 public static function translateFromRequest()
 {
     $dt = Loader::helper('form/date_time');
     $dateStart = $dt->translate('pdStartDate');
     $dateEnd = $dt->translate('pdEndDate');
     if ($dateStart || $dateEnd) {
         // create a Duration object
         if ($_REQUEST['pdID']) {
             $pd = Duration::getByID($_REQUEST['pdID']);
         } else {
             $pd = new Duration();
         }
         if ($_REQUEST['pdStartDateAllDayActivate']) {
             $pd->setStartDateAllDay(1);
             $dateStart = date('Y-m-d 00:00:00', strtotime($dateStart));
         } else {
             $pd->setStartDateAllDay(0);
         }
         if ($_REQUEST['pdEndDateAllDayActivate']) {
             $pd->setEndDateAllDay(1);
             $dateEnd = date('Y-m-d 23:59:59', strtotime($dateEnd));
         } else {
             $pd->setEndDateAllDay(0);
         }
         $pd->setStartDate($dateStart);
         $pd->setEndDate($dateEnd);
         if ($_POST['pdRepeatPeriod'] && $_POST['pdRepeat']) {
             $pd->setRepeatPeriod($_POST['pdRepeatPeriod']);
             if ($_POST['pdRepeatPeriod'] == 'daily') {
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodDaysEvery']);
             } elseif ($_POST['pdRepeatPeriod'] == 'weekly') {
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodWeeksEvery']);
                 $pd->setRepeatPeriodWeekDays($_POST['pdRepeatPeriodWeeksDays']);
             } elseif ($_POST['pdRepeatPeriod'] == 'monthly') {
                 $pd->setRepeatMonthBy($_POST['pdRepeatPeriodMonthsRepeatBy']);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodMonthsEvery']);
             }
             $pd->setRepeatPeriodEnd($dt->translate('pdEndRepeatDateSpecific'));
         } else {
             $pd->setRepeatPeriod(false);
         }
         $pd->save();
     } else {
         unset($pd);
     }
     return $pd;
 }