Esempio n. 1
0
 public function Validate($reservationSeries)
 {
     if ($this->userSession->IsAdmin) {
         Log::Debug('User is application admin. Skipping check. UserId=%s', $this->userSession->UserId);
         return new ReservationRuleResult(true);
     }
     if ($this->userSession->IsGroupAdmin || $this->userSession->IsResourceAdmin || $this->userSession->IsScheduleAdmin) {
         if ($this->userSession->IsGroupAdmin) {
             $user = $this->userRepository->LoadById($this->userSession->UserId);
             $reservationUser = $this->userRepository->LoadById($reservationSeries->UserId());
             if ($user->IsAdminFor($reservationUser)) {
                 Log::Debug('User is admin for reservation user. Skipping check. UserId=%s', $this->userSession->UserId);
                 return new ReservationRuleResult(true);
             }
         }
         if ($this->userSession->IsResourceAdmin || $this->userSession->IsScheduleAdmin) {
             $user = $this->userRepository->LoadById($this->userSession->UserId);
             $isResourceAdmin = true;
             foreach ($reservationSeries->AllResources() as $resource) {
                 if (!$user->IsResourceAdminFor($resource)) {
                     $isResourceAdmin = false;
                     break;
                 }
             }
             if ($isResourceAdmin) {
                 Log::Debug('User is admin for all resources. Skipping check. UserId=%s', $this->userSession->UserId);
                 return new ReservationRuleResult(true);
             }
         }
     }
     return $this->rule->Validate($reservationSeries);
 }
Esempio n. 2
0
 /**
  * @param ReservationSeries $reservationSeries
  * @return void
  */
 public function Notify($reservationSeries)
 {
     $resourceAdmins = array();
     $applicationAdmins = array();
     $groupAdmins = array();
     if ($this->SendForResourceAdmins($reservationSeries)) {
         $resourceAdmins = $this->userViewRepo->GetResourceAdmins($reservationSeries->ResourceId());
     }
     if ($this->SendForApplicationAdmins($reservationSeries)) {
         $applicationAdmins = $this->userViewRepo->GetApplicationAdmins();
     }
     if ($this->SendForGroupAdmins($reservationSeries)) {
         $groupAdmins = $this->userViewRepo->GetGroupAdmins($reservationSeries->UserId());
     }
     $admins = array_merge($resourceAdmins, $applicationAdmins, $groupAdmins);
     if (count($admins) == 0) {
         // skip if there is nobody to send to
         return;
     }
     $owner = $this->userRepo->LoadById($reservationSeries->UserId());
     $resource = $reservationSeries->Resource();
     $adminIds = array();
     /** @var $admin UserDto */
     foreach ($admins as $admin) {
         $id = $admin->Id();
         if (array_key_exists($id, $adminIds) || $id == $owner->Id()) {
             // only send to each person once
             continue;
         }
         $adminIds[$id] = true;
         $message = $this->GetMessage($admin, $owner, $reservationSeries, $resource);
         ServiceLocator::GetEmailService()->Send($message);
     }
 }
 public function LoadById($groupId)
 {
     $user = $this->userRepository->LoadById($this->userSession->UserId);
     if ($user->IsGroupAdminFor($groupId)) {
         return parent::LoadById($groupId);
     }
     return Group::Null();
 }
Esempio n. 4
0
 /**
  * @param IResource $resource
  * @return bool
  */
 public function ShouldInclude($resource)
 {
     if ($resource->GetStatusId() != ResourceStatus::AVAILABLE) {
         $user = $this->userRepository->LoadById($this->user->UserId);
         return $user->IsResourceAdminFor($resource);
     }
     return true;
 }
Esempio n. 5
0
 /**
  * @param ReservationSeries $reservation
  * @return void
  */
 public function Notify($reservation)
 {
     $owner = $this->_userRepo->LoadById($reservation->UserId());
     if ($this->ShouldSend($owner)) {
         $message = $this->GetMessage($owner, $reservation, $this->_attributeRepo);
         ServiceLocator::GetEmailService()->Send($message);
     } else {
         Log::Debug('Owner does not want these types of email notifications. Email=%s, ReferenceNumber=%s', $owner->EmailAddress(), $reservation->CurrentInstance()->ReferenceNumber());
     }
 }
 /**
  * @param ReservationSeries $reservationSeries
  */
 function Notify($reservationSeries)
 {
     $instance = $reservationSeries->CurrentInstance();
     $owner = $this->userRepository->LoadById($reservationSeries->UserId());
     foreach ($instance->UnchangedParticipants() as $userId) {
         $participant = $this->userRepository->LoadById($userId);
         $message = new ParticipantUpdatedEmail($owner, $participant, $reservationSeries, $this->attributeRepository);
         ServiceLocator::GetEmailService()->Send($message);
     }
 }
Esempio n. 7
0
 public function Activate($activationCode)
 {
     $userId = $this->activationRepository->FindUserIdByCode($activationCode);
     $this->activationRepository->DeleteActivation($activationCode);
     if ($userId != null) {
         $user = $this->userRepository->LoadById($userId);
         $user->Activate();
         $this->userRepository->Update($user);
         return new ActivationResult(true, $user);
     }
     return new ActivationResult(false);
 }
 /**
  * @param ReservationSeries $reservationSeries
  */
 function Notify($reservationSeries)
 {
     $owner = null;
     $instance = $reservationSeries->CurrentInstance();
     foreach ($instance->UnchangedInvitees() as $userId) {
         if ($owner == null) {
             $owner = $this->userRepository->LoadById($reservationSeries->UserId());
         }
         $invitee = $this->userRepository->LoadById($userId);
         $message = new InviteeAddedEmail($owner, $invitee, $reservationSeries, $this->attributeRepository);
         ServiceLocator::GetEmailService()->Send($message);
     }
 }
Esempio n. 9
0
 /**
  * @param ReservationSeries $reservationSeries
  * @return ReservationRuleResult
  */
 public function Validate($reservationSeries)
 {
     $quotas = $this->quotaRepository->LoadAll();
     $user = $this->userRepository->LoadById($reservationSeries->UserId());
     $schedule = $this->scheduleRepository->LoadById($reservationSeries->ScheduleId());
     foreach ($quotas as $quota) {
         if ($quota->ExceedsQuota($reservationSeries, $user, $schedule, $this->reservationViewRepository)) {
             Log::Debug('Quota exceeded. %s', $quota->ToString());
             return new ReservationRuleResult(false, Resources::GetInstance()->GetString('QuotaExceeded'));
         }
     }
     return new ReservationRuleResult();
 }
 public function Add(Schedule $schedule, $copyLayoutFromScheduleId)
 {
     $user = $this->repo->LoadById($this->user->UserId);
     if (!$user->IsInRole(RoleLevel::SCHEDULE_ADMIN)) {
         throw new Exception(sprintf('Schedule Add Failed. User %s does not have admin access.', $this->user->UserId));
     }
     foreach ($user->Groups() as $group) {
         if ($group->IsScheduleAdmin) {
             $schedule->SetAdminGroupId($group->GroupId);
             break;
         }
     }
     parent::Add($schedule, $copyLayoutFromScheduleId);
 }
 /**
  * @param $pageNumber int
  * @param $pageSize int
  * @param $filter ReservationFilter
  * @param $userSession UserSession
  * @return PageableData|ReservationItemView[]
  */
 public function LoadFiltered($pageNumber, $pageSize, $filter, $userSession)
 {
     $user = $this->userRepository->LoadById($userSession->UserId);
     $adminGroups = $user->GetAdminGroups();
     $groupIds = array();
     foreach ($adminGroups as $group) {
         $groupIds[] = $group->GroupId;
     }
     $command = new GetFullGroupReservationListCommand($groupIds);
     if ($filter != null) {
         $command = new FilterCommand($command, $filter->GetFilter());
     }
     $builder = array('ReservationItemView', 'Populate');
     return PageableDataStore::GetList($command, $builder, $pageNumber, $pageSize);
 }
 public function GetList($pageNumber, $pageSize, $sortField = null, $sortDirection = null, $filter = null)
 {
     $user = $this->repo->LoadById($this->user->UserId);
     if (!$user->IsInRole(RoleLevel::SCHEDULE_ADMIN)) {
         return new PageableData();
     }
     $ids = array();
     $filter = new SqlFilterNull();
     foreach ($user->Groups() as $group) {
         if ($group->IsScheduleAdmin) {
             $ids[] = $group->GroupId;
         }
     }
     $filter->_And(new SqlFilterIn(new SqlFilterColumn(TableNames::SCHEDULES_ALIAS, ColumnNames::RESOURCE_ADMIN_GROUP_ID), $ids));
     return parent::GetList($pageNumber, $pageSize, $sortField, $sortDirection, $filter);
 }
Esempio n. 13
0
 public function DisableSubscription()
 {
     $userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
     Log::Debug('Disabling calendar subscription for userId: %s', $userId);
     $user = $this->userRepository->LoadById($userId);
     $user->DisableSubscription();
     $this->userRepository->Update($user);
 }
Esempio n. 14
0
 /**
  * @param UserSession $userSession
  * @param IResource $resource
  * @return bool
  */
 public function CanApproveForResource(UserSession $userSession, IResource $resource)
 {
     if ($userSession->IsAdmin) {
         return true;
     }
     if (!$userSession->IsResourceAdmin) {
         return false;
     }
     $user = $this->userRepository->LoadById($userSession->UserId);
     return $user->IsResourceAdminFor($resource);
 }
Esempio n. 15
0
 public function UpdateUser($userId, $username, $email, $firstName, $lastName, $timezone, $extraAttributes)
 {
     $attributes = new UserAttribute($extraAttributes);
     $user = $this->userRepository->LoadById($userId);
     $user->ChangeName($firstName, $lastName);
     $user->ChangeEmailAddress($email);
     $user->ChangeUsername($username);
     $user->ChangeTimezone($timezone);
     $user->ChangeAttributes($attributes->Get(UserAttribute::Phone), $attributes->Get(UserAttribute::Organization), $attributes->Get(UserAttribute::Position));
     $this->userRepository->Update($user);
 }
Esempio n. 16
0
 public function LoadBlackout($blackoutId, $userId)
 {
     $series = $this->blackoutRepository->LoadByBlackoutId($blackoutId);
     $user = $this->userRepository->LoadById($userId);
     foreach ($series->Resources() as $resource) {
         if (!$user->IsResourceAdminFor($resource)) {
             return null;
         }
     }
     return $series;
 }
 /**
  * @param $resources
  * @return array|BookableResource[]
  */
 private function GetFilteredResources($resources)
 {
     if ($this->user->IsAdmin) {
         return $resources;
     }
     $user = $this->repo->LoadById($this->user->UserId);
     $filteredResources = array();
     /** @var $resource BookableResource */
     foreach ($resources as $resource) {
         if ($user->IsResourceAdminFor($resource)) {
             $filteredResources[] = $resource;
         }
     }
     return $filteredResources;
 }
 public function ForUserAndSchedule($userId, $scheduleId)
 {
     $user = $this->userRepository->LoadById($userId);
     $schedule = $this->scheduleRepository->LoadById($scheduleId);
     return new CalendarSubscriptionDetails($user->GetIsCalendarSubscriptionAllowed(), new CalendarSubscriptionUrl($user->GetPublicId(), $schedule->GetPublicId(), null));
 }
Esempio n. 19
0
 /**
  * @param $currentUser UserSession
  */
 public function PageLoad($currentUser)
 {
     $user = $this->userRepository->LoadById($this->page->GetUserId());
     if ($this->privacyFilter->CanViewUser($currentUser, null, $user->Id())) {
         $this->page->SetCanViewUser(true);
         $attributes = $this->attributeService->GetByCategory(CustomAttributeCategory::USER);
         $this->page->BindAttributes($attributes);
         $this->page->BindUser($user);
     } else {
         $this->page->SetCanViewUser(false);
     }
 }
 /**
  * @param int $userId
  * @return CalendarSubscriptionDetails
  */
 public function ForUser($userId)
 {
     $user = $this->userRepository->LoadById($userId);
     return new CalendarSubscriptionDetails($user->GetIsCalendarSubscriptionAllowed(), new CalendarSubscriptionUrl($user->GetPublicId(), null, null));
 }
Esempio n. 21
0
 /**
  * @return User
  */
 private function GetUser()
 {
     $userId = ServiceLocator::GetServer()->GetUserSession()->UserId;
     return $this->userRepository->LoadById($userId);
 }