. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
| Server IP : 94.23.64.18 / Your IP :
216.73.216.185 [
Web Server : Apache System : Linux webm005.cluster107.gra.hosting.ovh.net 5.15.167-ovh-vps-grsec-zfs-classid #1 SMP Tue Sep 17 08:14:20 UTC 2024 x86_64 User : villadal ( 6036) PHP Version : 7.4.33 Disable Function : _dyuweyrj4,_dyuweyrj4r,dl Domains : 2 Domains MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : OFF | Pkexec : OFF Directory : /home/villadal/www/old/booked/lib/Application/Admin/ |
Upload File : |
<?php
/**
Copyright 2012-2014 Nick Korbel
This file is part of Booked SchedulerBooked SchedulereIt is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later versBooked SchedulerduleIt is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
alBooked SchedulercheduleIt. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(ROOT_DIR . 'Domain/Access/ResourceRepository.php');
class ResourceAdminResourceRepository extends ResourceRepository
{
/**
* @var IUserRepository
*/
private $repo;
/**
* @var UserSession
*/
private $user;
public function __construct(IUserRepository $repo, UserSession $userSession)
{
$this->repo = $repo;
$this->user = $userSession;
parent::__construct();
}
/**
* @return array|BookableResource[] array of all resources
*/
public function GetResourceList()
{
$resources = parent::GetResourceList();
return $this->GetFilteredResources($resources);
}
public function GetList($pageNumber, $pageSize, $sortField = null, $sortDirection = null, $filter = null)
{
if (!$this->user->IsAdmin)
{
$scheduleAdminGroupIds = array();
$resourceAdminGroupIds = array();
$groups = $this->repo->LoadGroups($this->user->UserId, array(RoleLevel::SCHEDULE_ADMIN, RoleLevel::RESOURCE_ADMIN));
foreach ($groups as $group)
{
if ($group->IsResourceAdmin)
{
$resourceAdminGroupIds[] = $group->GroupId;
}
if ($group->IsScheduleAdmin)
{
$scheduleAdminGroupIds[] = $group->GroupId;
}
}
if ($filter == null)
{
$filter = new SqlFilterNull();
}
$additionalFilter = new SqlFilterIn(new SqlFilterColumn(TableNames::SCHEDULES_ALIAS, ColumnNames::SCHEDULE_ADMIN_GROUP_ID), $scheduleAdminGroupIds);
$filter->_And($additionalFilter->_Or(new SqlFilterIn(new SqlFilterColumn(TableNames::RESOURCES_ALIAS, ColumnNames::RESOURCE_ADMIN_GROUP_ID), $resourceAdminGroupIds)));
}
return parent::GetList($pageNumber, $pageSize, $sortField, $sortDirection, $filter);
}
public function Update(BookableResource $resource)
{
if (!$this->user->IsAdmin)
{
$user = $this->repo->LoadById($this->user->UserId);
if (!$user->IsResourceAdminFor($resource))
{
// if we got to this point, the user does not have the ability to update the resource
throw new Exception(sprintf('Resource Update Failed. User %s does not have admin access to resource %s.', $this->user->UserId, $resource->GetId()));
}
}
parent::Update($resource);
}
public function GetScheduleResources($scheduleId)
{
$resources = parent::GetScheduleResources($scheduleId);
return $this->GetFilteredResources($resources);
}
/**
* @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;
}
}