Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
checkpermission.php
1<?php
3
8
9
11{
12 const ERROR_ACCESS_DENIED = 'access_denied';
13
17 private $checkLevel;
18
24 public function __construct($checkLevel = 'auth')
25 {
26 $this->checkLevel = $checkLevel;
27 parent::__construct();
28 }
29
37 public function onBeforeAction(Main\Event $event)
38 {
40 $user = $this->action->getCurrentUser();
41
42 $denied = false;
43 $accessMessage = '';
44 if (!($user instanceof Main\Engine\CurrentUser) || !$user->getId())
45 {
46 $denied = true;
47 $accessMessage = Loc::getMessage('TRANSLATE_FILTER_ERROR_ACCESS_DENIED');
48 }
49
50 if (!$denied)
51 {
52 switch ($this->checkLevel)
53 {
54 case Translate\Permission::SOURCE:
55 if (!Translate\Permission::canEditSource($user))
56 {
57 $denied = true;
58 $accessMessage = Loc::getMessage('TRANSLATE_FILTER_ERROR_WRITING_RIGHTS');
59 }
60 break;
61
62 case Translate\Permission::WRITE:
63 if (!Translate\Permission::canEdit($user))
64 {
65 $denied = true;
66 $accessMessage = Loc::getMessage('TRANSLATE_FILTER_ERROR_WRITING_RIGHTS');
67 }
68 break;
69
70 case Translate\Permission::READ:
71 if (!Translate\Permission::canView($user))
72 {
73 $denied = true;
74 $accessMessage = Loc::getMessage('TRANSLATE_FILTER_ERROR_ACCESS_DENIED');
75 }
76 break;
77 }
78 }
79
80 if ($denied)
81 {
82 Context::getCurrent()->getResponse()->setStatus(401);
83 $this->errorCollection[] = new Main\Error($accessMessage, self::ERROR_ACCESS_DENIED);
84
85 return new Main\EventResult(Main\EventResult::ERROR, null, null, $this);
86 }
87
88 return null;
89 }
90}
static getCurrent()
Definition context.php:241
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static canView($checkUser)
static canEdit($checkUser)
static canEditSource($checkUser)