Exemplo n.º 1
0
 public function loadPermissionDurationObject($pdID)
 {
     if ($pdID > 0) {
         $pd = Duration::getByID($pdID);
         $this->duration = $pd;
     }
 }
Exemplo n.º 2
0
 public function validate()
 {
     $u = new User();
     if ($u->isSuperUser()) {
         return true;
     }
     $pae = $this->getPermissionAccessObject();
     if (!is_object($pae)) {
         return false;
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
     $valid = false;
     $list = $this->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_INCLUDE) {
             $valid = true;
         }
         if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_EXCLUDE) {
             $valid = false;
         }
     }
     return $valid;
 }
Exemplo n.º 3
0
 public function getAccessListItems($accessType = PagePermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = array())
 {
     $db = Database::connection();
     $list = parent::getAccessListItems($accessType, $filterEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         $pe = $l->getAccessEntityObject();
         $prow = $db->fetchAssoc('select permission, externalLink from PagePermissionPageTypeAccessList where peID = ? and paID = ?', array($pe->getAccessEntityID(), $l->getPermissionAccessID()));
         if (is_array($prow) && $prow['permission']) {
             $l->setPageTypesAllowedPermission($prow['permission']);
             $l->setAllowExternalLinks($prow['externalLink']);
             $permission = $prow['permission'];
         } elseif ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_INCLUDE) {
             $l->setPageTypesAllowedPermission('A');
             $l->setAllowExternalLinks(1);
         } else {
             $l->setPageTypesAllowedPermission('N');
             $l->setAllowExternalLinks(0);
         }
         if ($permission == 'C') {
             $ptIDs = $db->GetCol('select ptID from PagePermissionPageTypeAccessListCustom where peID = ? and paID = ?', array($pe->getAccessEntityID(), $l->getPermissionAccessID()));
             $l->setPageTypesAllowedArray($ptIDs);
         }
     }
     return $list;
 }
 public function getMyAssignment()
 {
     $u = new User();
     $asl = new AddConversationMessageConversationListItem();
     if ($u->isSuperUser()) {
         $asl->setNewConversationMessageApprovalStatus('A');
         return $asl;
     }
     $pae = $this->getPermissionAccessObject();
     if (!is_object($pae)) {
         $asl->setNewConversationMessageApprovalStatus('U');
         return $asl;
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
     $list = $this->getAccessListItems(UserKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         if ($l->getNewConversationMessageApprovalStatus() == 'U') {
             $asl->setNewConversationMessageApprovalStatus('U');
         }
         if ($l->getNewConversationMessageApprovalStatus() == 'A') {
             $asl->setNewConversationMessageApprovalStatus('A');
         }
     }
     return $asl;
 }
Exemplo n.º 5
0
 protected function getAllowedThemeIDs()
 {
     $u = new User();
     $pae = $this->getPermissionAccessObject();
     if (!is_object($pae)) {
         return array();
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
     $list = $this->getAccessListItems(PageKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     $db = Loader::db();
     $allpThemeIDs = $db->GetCol('select pThemeID from PageThemes order by pThemeID asc');
     $pThemeIDs = array();
     foreach ($list as $l) {
         if ($l->getThemesAllowedPermission() == 'N') {
             $pThemeIDs = array();
         }
         if ($l->getThemesAllowedPermission() == 'C') {
             if ($l->getAccessType() == PageKey::ACCESS_TYPE_EXCLUDE) {
                 $pThemeIDs = array_values(array_diff($pThemeIDs, $l->getThemesAllowedArray()));
             } else {
                 $pThemeIDs = array_unique(array_merge($pThemeIDs, $l->getThemesAllowedArray()));
             }
         }
         if ($l->getThemesAllowedPermission() == 'A') {
             $pThemeIDs = $allpThemeIDs;
         }
     }
     return $pThemeIDs;
 }
Exemplo n.º 6
0
 public function getCurrentlyActiveUsers(WorkflowProgress $wp)
 {
     $paa = $this->getPermissionAccessObject();
     if (!$paa) {
         return array();
     }
     $paa->setWorkflowProgressObject($wp);
     $included = $this->getAccessListItems(self::ACCESS_TYPE_INCLUDE);
     $excluded = $this->getAccessListItems(self::ACCESS_TYPE_EXCLUDE);
     $included = PermissionDuration::filterByActive($included);
     $excluded = PermissionDuration::filterByActive($excluded);
     $users = array();
     $usersExcluded = array();
     foreach ($included as $inc) {
         $pae = $inc->getAccessEntityObject();
         $users = array_merge($users, $pae->getAccessEntityUsers($paa));
     }
     $users = array_unique($users);
     foreach ($excluded as $inc) {
         $pae = $inc->getAccessEntityObject();
         $usersExcluded = array_merge($usersExcluded, $pae->getAccessEntityUsers());
     }
     $users = array_diff($users, $usersExcluded);
     return $users;
 }
 public function getMyAssignment()
 {
     $u = new User();
     $asl = new ViewUserAttributesUserPermissionAssignment();
     if ($u->isSuperUser()) {
         $asl->setAttributesAllowedPermission('A');
         return $asl;
     }
     $pae = $this->getPermissionAccessObject();
     if (!is_object($pae)) {
         return $asl;
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
     $list = $this->getAccessListItems(UserKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         if ($l->getAttributesAllowedPermission() == 'N') {
             $asl->setAttributesAllowedPermission('N');
         }
         if ($l->getAttributesAllowedPermission() == 'C') {
             $asl->setAttributesAllowedPermission('C');
         }
         if ($l->getAttributesAllowedPermission() == 'A') {
             $asl->setAttributesAllowedPermission('A');
         }
     }
     $asl->setAttributesAllowedArray($this->getAllowedAttributeKeyIDs($list));
     return $asl;
 }
Exemplo n.º 8
0
 public function getAccessListItems($accessType = PagePermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = array())
 {
     $db = Loader::db();
     $list = parent::getAccessListItems($accessType, $filterEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         $pe = $l->getAccessEntityObject();
         $prow = $db->GetRow('select permission from PagePermissionThemeAccessList where peID = ? and paID = ?', array($pe->getAccessEntityID(), $l->getPermissionAccessID()));
         if (is_array($prow) && $prow['permission']) {
             $l->setThemesAllowedPermission($prow['permission']);
             $permission = $prow['permission'];
         } else {
             if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_INCLUDE) {
                 $l->setThemesAllowedPermission('A');
             } else {
                 $l->setThemesAllowedPermission('N');
             }
         }
         if ($permission == 'C') {
             $pThemeIDs = $db->GetCol('select pThemeID from PagePermissionThemeAccessListCustom where peID = ? and paID = ?', array($pe->getAccessEntityID(), $l->getPermissionAccessID()));
             $l->setThemesAllowedArray($pThemeIDs);
         }
     }
     return $list;
 }
Exemplo n.º 9
0
 public function getAllowedFileExtensions()
 {
     $u = new User();
     $extensions = array();
     if ($u->isSuperUser()) {
         $extensions = Loader::helper('concrete/file')->getAllowedFileExtensions();
         return $extensions;
     }
     $pae = $this->getPermissionAccessObject();
     if (!is_object($pae)) {
         return array();
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
     $list = $this->getAccessListItems(FileSetKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         if ($l->getFileTypesAllowedPermission() == 'N') {
             $extensions = array();
         }
         if ($l->getFileTypesAllowedPermission() == 'C') {
             $extensions = array_unique(array_merge($extensions, $l->getFileTypesAllowedArray()));
         }
         if ($l->getFileTypesAllowedPermission() == 'A') {
             $extensions = Loader::helper('concrete/file')->getAllowedFileExtensions();
         }
     }
     return $extensions;
 }
 public function getAccessListItems($accessType = PagePermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = array(), $checkCache = true)
 {
     $db = Database::connection();
     $list = parent::getAccessListItems($accessType, $filterEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         /**
          * @var $l NotifyInNotificationCenterNotificationListItem
          */
         $pe = $l->getAccessEntityObject();
         $prow = $db->GetRow('select permission from NotificationPermissionSubscriptionList where peID = ? and paID = ?', array($pe->getAccessEntityID(), $l->getPermissionAccessID()));
         if (is_array($prow) && $prow['permission']) {
             $l->setSubscriptionsAllowedPermission($prow['permission']);
             $permission = $prow['permission'];
             if ($permission == 'C') {
                 $subscriptions = $db->GetCol('select nSubscriptionIdentifier from NotificationPermissionSubscriptionListCustom where peID = ? and paID = ?', array($pe->getAccessEntityID(), $l->getPermissionAccessID()));
                 $l->setSubscriptionsAllowedArray($subscriptions);
             }
         } elseif ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_INCLUDE) {
             $l->setSubscriptionsAllowedPermission('A');
         } else {
             $l->setSubscriptionsAllowedPermission('N');
         }
     }
     return $list;
 }
Exemplo n.º 11
0
 public function handlePageUpdate($event)
 {
     $page = $event->getPageObject();
     $pk = PermissionKey::getByHandle('view_page');
     $pk->setPermissionObject($page);
     $list = $pk->getAccessListItems();
     foreach ($list as $pa) {
         $pae = $pa->getAccessEntityObject();
         if ($pae->getAccessEntityTypeHandle() == 'group') {
             if ($pae->getGroupObject()->getGroupID() == GUEST_GROUP_ID) {
                 $pd = $pa->getPermissionDurationObject();
                 if (!is_object($pd)) {
                     $pd = new PermissionDuration();
                 }
                 $publicDate = strtotime($page->getCollectionDatePublic());
                 $pd->setStartDateAllDay(0);
                 $pd->setEndDateAllDay(0);
                 $pd->setStartDate($dateStart = date('Y-m-d H:i:s', $publicDate));
                 $pd->save();
                 $paa = PermissionAccess::getByID($pa->paID, $pk);
                 $paa->addListItem($pae, $pd, PermissionKey::ACCESS_TYPE_INCLUDE);
             }
         }
     }
 }
 protected function getAllowedBlockTypeIDs()
 {
     $u = new User();
     $pae = $this->getPermissionAccessObject();
     if (!is_object($pae)) {
         return array();
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
     $list = $this->getAccessListItems(AreaKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     $db = Loader::db();
     $btIDs = array();
     if (count($list) > 0) {
         $cache = \Core::make('cache/request');
         $dsh = Loader::helper('concrete/dashboard');
         if ($dsh->inDashboard()) {
             $identifier = 'blocktypeids/all';
         } else {
             $identifier = 'blocktypeids/public';
         }
         $item = $cache->getItem($identifier);
         $allBTIDs = $item->get();
         if ($item->isMiss()) {
             if ($dsh->inDashboard()) {
                 $allBTIDs = $db->GetCol('select btID from BlockTypes');
             } else {
                 $allBTIDs = $db->GetCol('select btID from BlockTypes where btIsInternal = 0');
             }
             $cache->save($item->set($allBTIDs));
         }
         foreach ($list as $l) {
             if ($l->getBlockTypesAllowedPermission() == 'N') {
                 $btIDs = array();
             }
             if ($l->getBlockTypesAllowedPermission() == 'C') {
                 if ($l->getAccessType() == AreaKey::ACCESS_TYPE_EXCLUDE) {
                     $btIDs = array_values(array_diff($btIDs, $l->getBlockTypesAllowedArray()));
                 } else {
                     $btIDs = array_unique(array_merge($btIDs, $l->getBlockTypesAllowedArray()));
                 }
             }
             if ($l->getBlockTypesAllowedPermission() == 'A') {
                 $btIDs = $allBTIDs;
             }
         }
     }
     return $btIDs;
 }
Exemplo n.º 13
0
 public function validateAccessEntities($accessEntities)
 {
     $valid = false;
     $accessEntities = $this->validateAndFilterAccessEntities($accessEntities);
     $list = $this->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_INCLUDE) {
             $valid = true;
         }
         if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_EXCLUDE) {
             $valid = false;
         }
     }
     return $valid;
 }
 public function getAccessListItems($accessType = PagePermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = [], $checkCache = true)
 {
     $db = Database::connection();
     $list = parent::getAccessListItems($accessType, $filterEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         $pe = $l->getAccessEntityObject();
         $prow = $db->fetchAssoc('select permission from PagePermissionThemeAccessList where peID = ? and paID = ?', [$pe->getAccessEntityID(), $l->getPermissionAccessID()]);
         if ($prow && $prow['permission']) {
             $l->setThemesAllowedPermission($prow['permission']);
             $permission = $prow['permission'];
             if ($permission == 'C') {
                 $pThemeIDs = $db->GetCol('select pThemeID from PagePermissionThemeAccessListCustom where peID = ? and paID = ?', [$pe->getAccessEntityID(), $l->getPermissionAccessID()]);
                 $l->setThemesAllowedArray($pThemeIDs);
             }
         } elseif ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_INCLUDE) {
             $l->setThemesAllowedPermission('A');
         } else {
             $l->setThemesAllowedPermission('N');
         }
     }
     return $list;
 }
 public function getAccessListItems($accessType = UserPermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = array())
 {
     $db = Loader::db();
     $list = parent::getAccessListItems($accessType, $filterEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         $pe = $l->getAccessEntityObject();
         $prow = $db->GetRow('select attributePermission, uName, uPassword, uEmail, uAvatar, uTimezone, uDefaultLanguage from UserPermissionEditPropertyAccessList where peID = ? and paID = ?', array($pe->getAccessEntityID(), $this->getPermissionAccessID()));
         if (is_array($prow) && $prow['attributePermission']) {
             $l->setAttributesAllowedPermission($prow['attributePermission']);
             $l->setAllowEditUserName($prow['uName']);
             $l->setAllowEditEmail($prow['uEmail']);
             $l->setAllowEditPassword($prow['uPassword']);
             $l->setAllowEditAvatar($prow['uAvatar']);
             $l->setAllowEditTimezone($prow['uTimezone']);
             $l->setAllowEditDefaultLanguage($prow['uDefaultLanguage']);
             $attributePermission = $prow['attributePermission'];
         } else {
             if ($l->getAccessType() == UserPermissionKey::ACCESS_TYPE_INCLUDE) {
                 $l->setAttributesAllowedPermission('A');
                 $l->setAllowEditUserName(1);
                 $l->setAllowEditEmail(1);
                 $l->setAllowEditPassword(1);
                 $l->setAllowEditAvatar(1);
                 $l->setAllowEditTimezone(1);
                 $l->setAllowEditDefaultLanguage(1);
             } else {
                 $l->setAttributesAllowedPermission('N');
                 $l->setAllowEditUserName(0);
                 $l->setAllowEditEmail(0);
                 $l->setAllowEditPassword(0);
                 $l->setAllowEditAvatar(0);
                 $l->setAllowEditTimezone(0);
                 $l->setAllowEditDefaultLanguage(0);
             }
         }
         if ($attributePermission == 'C') {
             $akIDs = $db->GetCol('select akID from UserPermissionEditPropertyAttributeAccessListCustom where peID = ? and paID = ?', array($pe->getAccessEntityID(), $this->getPermissionAccessID()));
             $l->setAttributesAllowedArray($akIDs);
         }
     }
     return $list;
 }
Exemplo n.º 16
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.º 18
0
 /**
  * @return Duration|null
  */
 public static function createFromRequest()
 {
     $dt = Loader::helper('form/date_time');
     $dateStart = $dt->translate('pdStartDate');
     $dateEnd = $dt->translate('pdEndDate');
     if ($dateStart || $dateEnd) {
         // create a Duration object
         $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']) {
             if ($_POST['pdRepeatPeriod'] == 'daily') {
                 $pd->setRepeatPeriod(Duration::REPEAT_DAILY);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodDaysEvery']);
             } elseif ($_POST['pdRepeatPeriod'] == 'weekly') {
                 $pd->setRepeatPeriod(Duration::REPEAT_WEEKLY);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodWeeksEvery']);
                 $pd->setRepeatPeriodWeekDays($_POST['pdRepeatPeriodWeeksDays']);
             } elseif ($_POST['pdRepeatPeriod'] == 'monthly') {
                 $pd->setRepeatPeriod(Duration::REPEAT_MONTHLY);
                 $repeat_by = $_POST['pdRepeatPeriodMonthsRepeatBy'];
                 $repeat = self::MONTHLY_REPEAT_WEEKLY;
                 switch ($repeat_by) {
                     case 'week':
                         $repeat = self::MONTHLY_REPEAT_WEEKLY;
                         break;
                     case 'month':
                         $repeat = self::MONTHLY_REPEAT_MONTHLY;
                         break;
                     case 'lastweekday':
                         $repeat = self::MONTHLY_REPEAT_LAST_WEEKDAY;
                         $dotw = $_POST['pdRepeatPeriodMonthsRepeatLastDay'] ?: 0;
                         $pd->setRepeatMonthLastWeekday($dotw);
                         break;
                 }
                 $pd->setRepeatMonthBy($repeat);
                 $pd->setRepeatEveryNum($_POST['pdRepeatPeriodMonthsEvery']);
             }
             $pd->setRepeatPeriodEnd($dt->translate('pdEndRepeatDateSpecific'));
         } else {
             $pd->setRepeatPeriod(Duration::REPEAT_NONE);
         }
         $pd->save();
         return $pd;
     } else {
         unset($pd);
     }
     return null;
 }
 public function getAccessListItems($accessType = PagePermissionKey::ACCESS_TYPE_INCLUDE, $filterEntities = array())
 {
     $db = Database::connection();
     $list = parent::getAccessListItems($accessType, $filterEntities);
     $list = PermissionDuration::filterByActive($list);
     foreach ($list as $l) {
         $pe = $l->getAccessEntityObject();
         $prow = $db->GetRow('select attributePermission, name, publicDateTime, uID, description, paths from PagePermissionPropertyAccessList where peID = ? and paID = ?', array($pe->getAccessEntityID(), $l->getPermissionAccessID()));
         $attributePermission = '';
         if (!empty($prow) && $prow['attributePermission']) {
             $l->setAttributesAllowedPermission($prow['attributePermission']);
             $l->setAllowEditName($prow['name']);
             $l->setAllowEditDateTime($prow['publicDateTime']);
             $l->setAllowEditUserID($prow['uID']);
             $l->setAllowEditDescription($prow['description']);
             $l->setAllowEditPaths($prow['paths']);
             $attributePermission = $prow['attributePermission'];
         } elseif ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_INCLUDE) {
             $l->setAttributesAllowedPermission('A');
             $l->setAllowEditName(1);
             $l->setAllowEditDateTime(1);
             $l->setAllowEditUserID(1);
             $l->setAllowEditDescription(1);
             $l->setAllowEditPaths(1);
         } else {
             $l->setAttributesAllowedPermission('N');
             $l->setAllowEditName(0);
             $l->setAllowEditDateTime(0);
             $l->setAllowEditUserID(0);
             $l->setAllowEditDescription(0);
             $l->setAllowEditPaths(0);
         }
         if ($attributePermission == 'C') {
             $akIDs = $db->GetCol('select akID from PagePermissionPropertyAttributeAccessListCustom where peID = ? and paID = ?', array($pe->getAccessEntityID(), $l->getPermissionAccessID()));
             $l->setAttributesAllowedArray($akIDs);
         }
     }
     return $list;
 }
Exemplo n.º 20
0
}
if (!is_object($pae)) {
    $pae = false;
}
$pd = false;
if ($_REQUEST['pdID']) {
    $pd = PermissionDuration::getByID($_REQUEST['pdID']);
}
if (!is_object($pd)) {
    $pd = false;
}
if ($_POST['task'] == 'save_permissions') {
    $js = Loader::helper('json');
    $r = new stdClass();
    if (is_object($pae)) {
        $pd = PermissionDuration::translateFromRequest();
    } else {
        $r->error = true;
        $r->message = t('You must choose who this permission is for.');
    }
    if (!$r->error) {
        $r->peID = $pae->getAccessEntityID();
        if (is_object($pd)) {
            $r->pdID = $pd->getPermissionDurationID();
        } else {
            $r->pdID = 0;
        }
    }
    print $js->encode($r);
    exit;
}
Exemplo n.º 21
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.º 22
0
                    $pa = PermissionAccess::getByID($paID, $pk);
                    if (is_object($pa)) {
                        $pt->assignPermissionAccess($pa);
                    }
                }
            }
        }
    }
    if ($p->canScheduleGuestAccess()) {
        if ($_REQUEST['task'] == 'set_timed_guest_access' && Loader::helper("validation/token")->validate('set_timed_guest_access')) {
            if (!$b->overrideAreaPermissions()) {
                $b->doOverrideAreaPermissions();
            }
            $pk = PermissionKey::getByHandle('view_block');
            $pk->setPermissionObject($b);
            $pa = $pk->getPermissionAccessObject();
            if (!is_object($pa)) {
                $pa = PermissionAccess::create($pk);
            } else {
                if ($pa->isPermissionAccessInUse()) {
                    $pa = $pa->duplicate();
                }
            }
            $pe = GroupPermissionAccessEntity::getOrCreate(Group::getByID(GUEST_GROUP_ID));
            $pd = PermissionDuration::createFromRequest();
            $pa->addListItem($pe, $pd, PermissionKey::ACCESS_TYPE_INCLUDE);
            $pt = $pk->getPermissionAssignmentObject();
            $pt->assignPermissionAccess($pa);
        }
    }
}
Exemplo n.º 23
0
 public function testGenerateMonthlyMonthly()
 {
     $repetition = new Duration();
     $repetition->setRepeatPeriod($repetition::REPEAT_MONTHLY);
     $repetition->setRepeatMonthBy($repetition::MONTHLY_REPEAT_MONTHLY);
     $repetition->setRepeatEveryNum(3);
     $repetition->setStartDate('1/14/2015 1:00:00');
     $repetition->setEndDate('1/14/2015 3:00:00');
     $now = strtotime('2/13/2014');
     $end = strtotime('+5 years', $now);
     $occurrences = $repetition->activeRangesBetween($now, $end);
     $all_active = true;
     foreach ($occurrences as $occurrence) {
         $window = $repetition->getActiveRange($occurrence[0]);
         if (!$window) {
             $all_active = false;
             break;
         }
         if ($window[0] != $occurrence[0] || $window[1] != $occurrence[1]) {
             $all_active = false;
             break;
         }
     }
     $this->assertTrue($all_active, 'EventOccurrenceFactory generated inactive occurrences.');
 }
Exemplo n.º 24
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;
 }
Exemplo n.º 25
0
 public function getMyAssignment()
 {
     $u = new User();
     $asl = new \Concrete\Core\Permission\Access\ListItem\EditUserPropertiesUserListItem();
     $db = Loader::db();
     $allAKIDs = $db->GetCol('select akID from UserAttributeKeys order by akID asc');
     if ($u->isSuperUser()) {
         $asl->setAllowEditUserName(1);
         $asl->setAllowEditEmail(1);
         $asl->setAllowEditPassword(1);
         $asl->setAllowEditAvatar(1);
         $asl->setAllowEditTimezone(1);
         $asl->setAllowEditDefaultLanguage(1);
         $asl->setAttributesAllowedArray($allAKIDs);
         $asl->setAttributesAllowedPermission('A');
         return $asl;
     }
     $pae = $this->getPermissionAccessObject();
     if (!is_object($pae)) {
         return $asl;
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
     $list = $this->getAccessListItems(UserKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     $properties = array();
     $excluded = array();
     $akIDs = array();
     $u = new User();
     foreach ($list as $l) {
         if ($l->allowEditUserName() && !in_array('uName', $excluded)) {
             $asl->setAllowEditUserName(1);
         }
         if ($l->allowEditEmail() && !in_array('uEmail', $excluded)) {
             $asl->setAllowEditEmail(1);
         }
         if ($l->allowEditPassword() && !in_array('uPassword', $excluded)) {
             $asl->setAllowEditPassword(1);
         }
         if ($l->allowEditAvatar() && !in_array('uAvatar', $excluded)) {
             $asl->setAllowEditAvatar(1);
         }
         if ($l->allowEditTimezone() && !in_array('uTimezone', $excluded)) {
             $asl->allowEditTimezone(1);
         }
         if ($l->allowEditDefaultLanguage() && !in_array('uDefaultLanguage', $excluded)) {
             $asl->setAllowEditDefaultLanguage(1);
         }
         if ($l->getAccessType() == UserKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditUserName()) {
             $asl->setAllowEditUserName(0);
             $excluded[] = 'uName';
         }
         if ($l->getAccessType() == UserKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditEmail()) {
             $asl->setAllowEditEmail(0);
             $excluded[] = 'uEmail';
         }
         if ($l->getAccessType() == UserKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditPassword()) {
             $asl->setAllowEditPassword(0);
             $excluded[] = 'uPassword';
         }
         if ($l->getAccessType() == UserKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditAvatar()) {
             $asl->setAllowEditAvatar(0);
             $excluded[] = 'uAvatar';
         }
         if ($l->getAccessType() == UserKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditTimezone()) {
             $asl->setAllowEditTimezone(0);
             $excluded[] = 'uTimezone';
         }
         if ($l->getAccessType() == UserKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditDefaultLanguage()) {
             $asl->setAllowEditDefaultLanguage(0);
             $excluded[] = 'uDefaultLanguage';
         }
         if ($l->getAttributesAllowedPermission() == 'N') {
             $akIDs = array();
             $asl->setAttributesAllowedPermission('N');
         }
         if ($l->getAttributesAllowedPermission() == 'C') {
             $asl->setAttributesAllowedPermission('C');
             if ($l->getAccessType() == UserKey::ACCESS_TYPE_EXCLUDE) {
                 $akIDs = array_values(array_diff($akIDs, $l->getAttributesAllowedArray()));
             } else {
                 $akIDs = array_unique(array_merge($akIDs, $l->getAttributesAllowedArray()));
             }
         }
         if ($l->getAttributesAllowedPermission() == 'A') {
             $akIDs = $allAKIDs;
             $asl->setAttributesAllowedPermission('A');
         }
     }
     $asl->setAttributesAllowedArray($akIDs);
     return $asl;
 }
Exemplo n.º 26
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.º 27
0
 public function getMyAssignment()
 {
     $u = new User();
     $asl = new \Concrete\Core\Permission\Access\ListItem\EditPagePropertiesPageListItem();
     if ($u->isSuperUser()) {
         $asl->setAllowEditName(1);
         $asl->setAllowEditDateTime(1);
         $asl->setAllowEditUserID(1);
         $asl->setAllowEditDescription(1);
         $asl->setAllowEditPaths(1);
         $asl->setAttributesAllowedArray($this->getAllAttributeKeyIDs());
         $asl->setAttributesAllowedPermission('A');
         return $asl;
     }
     $pae = $this->getPermissionAccessObject();
     if (!is_object($pae)) {
         return $asl;
     }
     $accessEntities = $u->getUserAccessEntityObjects();
     $accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
     $list = $pae->getAccessListItems(PageKey::ACCESS_TYPE_ALL, $accessEntities);
     $list = PermissionDuration::filterByActive($list);
     $properties = array();
     $excluded = array();
     $akIDs = array();
     $u = new User();
     if (count($list) > 0) {
         $allAKIDs = $this->getAllAttributeKeyIDs();
     }
     foreach ($list as $l) {
         if ($l->allowEditName() && !in_array('name', $excluded)) {
             $asl->setAllowEditName(1);
         }
         if ($l->allowEditDateTime() && !in_array('date', $excluded)) {
             $asl->setAllowEditDateTime(1);
         }
         if ($l->allowEditUserID() && !in_array('uID', $excluded)) {
             $asl->setAllowEditUserID(1);
         }
         if ($l->allowEditDescription() && !in_array('description', $excluded)) {
             $asl->setAllowEditDescription(1);
         }
         if ($l->allowEditPaths() && !in_array('paths', $excluded)) {
             $asl->setAllowEditPaths(1);
         }
         if ($l->getAccessType() == PageKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditName()) {
             $asl->setAllowEditName(0);
             $excluded[] = 'name';
         }
         if ($l->getAccessType() == PageKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditDateTime()) {
             $asl->setAllowEditDateTime(0);
             $excluded[] = 'date';
         }
         if ($l->getAccessType() == PageKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditUserID()) {
             $asl->setAllowEditUserID(0);
             $excluded[] = 'uID';
         }
         if ($l->getAccessType() == PageKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditDescription()) {
             $asl->setAllowEditDescription(0);
             $excluded[] = 'description';
         }
         if ($l->getAccessType() == PageKey::ACCESS_TYPE_EXCLUDE && !$l->allowEditPaths()) {
             $asl->setAllowEditPaths(0);
             $excluded[] = 'paths';
         }
         if ($l->getAttributesAllowedPermission() == 'N') {
             $akIDs = array();
             $asl->setAttributesAllowedPermission('N');
         }
         if ($l->getAttributesAllowedPermission() == 'C') {
             $asl->setAttributesAllowedPermission('C');
             if ($l->getAccessType() == PageKey::ACCESS_TYPE_EXCLUDE) {
                 $akIDs = array_values(array_diff($akIDs, $l->getAttributesAllowedArray()));
             } else {
                 $akIDs = array_unique(array_merge($akIDs, $l->getAttributesAllowedArray()));
             }
         }
         if ($l->getAttributesAllowedPermission() == 'A') {
             $akIDs = $allAKIDs;
             $asl->setAttributesAllowedPermission('A');
         }
     }
     $asl->setAttributesAllowedArray($akIDs);
     return $asl;
 }