20 private const NOTIFICATION_CODE =
'HOLD_REST_OVERLOAD';
21 private const OPTION_CODE =
'hold_access_entity';
22 private const MODULE_ID =
'rest';
31 public static function add(
string $type,
string $code) : array
37 $data = static::get();
38 if (!is_array($data[$type]) || !in_array($code, $data[$type]))
40 $data[$type][] = $code;
41 $result[
'success'] = static::set($data);
42 if ($result[
'success'])
44 $url = static::getUrl($type, $code);
52 private static function getUrl(
string $type,
string $code) : string
56 if ($type === static::TYPE_APP)
63 $url = \Bitrix\Rest\Marketplace\Url::getApplicationDetailUrl($app[
'CODE']);
67 $filter[
'=APP_ID'] = $app[
'ID'];
71 elseif ($type === static::TYPE_WEBHOOK)
73 $res = PasswordTable::getList(
84 if ($password = $res->fetch())
86 $filter[
'=PASSWORD_ID'] = $password[
'ID'];
91 $res = IntegrationTable::getList(
101 if ($item = $res->fetch())
103 $url = \Bitrix\Rest\Url\DevOps::getInstance()->getIntegrationEditUrl($item[
'ID'], $item[
'ELEMENT_CODE']);
117 public static function delete(
string $type,
string $code) : array
122 $data = static::get();
123 if (is_array($data[$type]))
125 $key = array_search($code, $data[$type]);
128 if (count($data[$type]) === 1)
134 unset($data[$type][$key]);
136 $result[
'success'] = static::set($data);
150 public static function is(
string $type,
string $code) : bool
152 $list = static::get();
153 return isset($list[$type]) && in_array($code, $list[$type]);
160 public static function reset() : bool
162 return static::set([]);
169 public static function get() : array
171 $option = Option::get(static::MODULE_ID, static::OPTION_CODE,
false);
173 return $option ? Json::decode($option) : [];
181 private static function set(array $data) : bool
185 Option::set(static::MODULE_ID, static::OPTION_CODE, Json::encode($data));
189 Option::delete(static::MODULE_ID, [
'name' => static::OPTION_CODE]);