1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
CheckFileAccess.php
См. документацию.
1<?php
2
3namespace Bitrix\Im\V2\Controller\Filter;
4
5use Bitrix\Disk\Driver;
6use Bitrix\Disk\File;
7use Bitrix\Disk\Security\DiskSecurityContext;
8use Bitrix\Im\V2\Chat\ChatError;
9use Bitrix\Main\Engine\ActionFilter\Base;
10use Bitrix\Main\Error;
11use Bitrix\Main\Event;
12use Bitrix\Main\EventResult;
13use Bitrix\Main\File\Image;
14
15class CheckFileAccess extends Base
16{
17 private array $path;
18
19 public function __construct(array $path)
20 {
21 parent::__construct();
22 $this->path = $path;
23 }
24
25 public function onBeforeAction(Event $event)
26 {
27 $fileId = $this->extractFileId();
28
29 if (!is_numeric($fileId))
30 {
31 return null;
32 }
33
34 $fileResult = \CFile::GetByID($fileId);
35 $file = (isset($fileResult) && $fileResult) ? $fileResult->Fetch() : null;
36 $info = (new Image($_SERVER["DOCUMENT_ROOT"] . $file['SRC']))->getInfo();
37 if (!$info)
38 {
39 $this->addError(new Error(
40 'Wrong file type',
42 ));
43 return new EventResult(EventResult::ERROR, null, null, $this);
44 }
45
46 $currentUser = $this->getAction()->getCurrentUser();
47 $userId = isset($currentUser) ? $currentUser->getId() : null;
48 $securityContext = new DiskSecurityContext((int)$userId);
49 $parameters = [
50 'filter' => ['FILE_ID' => $fileId],
51 'with' => ['CREATE_USER']
52 ];
53 $parameters = Driver::getInstance()->getRightsManager()->addRightsCheck($securityContext, $parameters, ['ID', 'CREATED_BY']);
54
55 $fileCollection = File::getModelList($parameters);
56 if (!$fileCollection)
57 {
58 $this->addError(new Error(
59 'File is not accessible',
61 ));
62 return new EventResult(EventResult::ERROR, null, null, $this);
63 }
64
65 return null;
66 }
67
68 private function extractFileId()
69 {
70 $arguments = $this->getAction()->getArguments();
71
72 $value = $arguments;
73
74 foreach ($this->path as $key)
75 {
76 if (!is_array($value))
77 {
78 return null;
79 }
80
81 $value = $value[$key] ?? null;
82 }
83
84 return $value;
85 }
86}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
const WRONG_PARAMETER
Определения ChatError.php:12
addError(Error $error)
Определения base.php:80
Определения error.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$_SERVER["DOCUMENT_ROOT"]
Определения cron_frame.php:9
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
Определения Color.php:9
$event
Определения prolog_after.php:141
if(empty($signedUserToken)) $key
Определения quickway.php:257
path
Определения template_copy.php:201