Beispiel #1
0
 /**
  * Helper function checking if param $action is in $grantedActions
  * @param AccessBase\Action $action
  * @param array $grantedActions Array of actions that shall be granted
  * @return GrantResult Allowed if $action is in $grantedActions, NoAccess otherwise
  */
 protected function GrantActions(Action $action, array $grantedActions)
 {
     foreach ($grantedActions as $grantedAction) {
         if ((string) $action == (string) $grantedAction) {
             return GrantResult::Allowed();
         }
     }
     return GrantResult::NoAccess();
 }
Beispiel #2
0
 private function GrantOnUser(BackendAction $action, User $user)
 {
     $allowed = false;
     switch ($action) {
         case BackendAction::Delete():
         case BackendAction::ChangeIsAdmin():
             $allowed = $this->IsAdministrator() && !$this->GetUser()->Equals($user);
             break;
         case BackendAction::AssignGroups():
             $allowed = $this->IsAdministrator() && !$user->GetIsAdmin();
             break;
         case BackendAction::Edit():
         case BackendAction::Read():
             $allowed = $this->IsAdministrator() || $this->GetUser()->Equals($user);
             break;
         case BackendAction::Create():
             $allowed = $this->IsAdministrator();
             break;
     }
     return $allowed ? GrantResult::Allowed() : GrantResult::NoAccess();
 }
Beispiel #3
0
 /**
  * Checks access to an item by its properties and assigned groups
  * @param boolean $guestsOnly True if guests only see the item
  * @param boolean $publish True if item is generally published
  * @param Date $from The start date of publishing
  * @param Date $to The end date of publishing
  * @param Membergroup[] $groups Groups assigned to the item
  * @return GrantResult
  */
 private function GrantByProperties($guestsOnly, $publish, Date $from = null, Date $to = null, array $groups = array())
 {
     if (!PublishDateUtil::IsPublishedNow($publish, $from, $to)) {
         return GrantResult::NoAccess();
     }
     if ($this->GetMember() && $guestsOnly) {
         return GrantResult::NoAccess();
     }
     if (count($groups) == 0) {
         return GrantResult::Allowed();
     }
     if (!$this->GetMember()) {
         return GrantResult::LoginRequired();
     }
     $groupIDs = Membergroup::GetKeyList($groups);
     $memberGroupIDs = Membergroup::GetKeyList($this->Groups());
     return count(array_intersect($groupIDs, $memberGroupIDs)) ? GrantResult::Allowed() : GrantResult::NoAccess();
 }