Set standalone attribute to 'auto' if new class syntax is used in module.xml

- 새로 추가된 클래스 문법 사용시 standalone 속성 기본값은 true가 아닌 auto로 지정

- standalone 속성의 의미는 아래와 같음
  - true: 항상 접근 허용 (기존 방식으로 선언한 액션의 기본값)
  - false: mid가 소속 모듈과 일치하거나, admin 모듈인 경우에만 접근 허용
  - auto: module 또는 mid가 소속 모듈과 일치하거나, admin 모듈인 경우에만 접근 허용
    (즉, false와 비슷하지만 exec_json 함수 등에서 module+act로 호출하는 경우에는
    mid가 없더라도 module만 일치하면 호출할 수 있도록 허용하여 개발 편의를 높임)

- 단, global_route 속성이 있는 경우 standalone 속성 기본값은 true임
  (전역 짧은주소는 mid 없이 호출될 수밖에 없으므로)
This commit is contained in:
Kijin Sung 2021-04-20 21:45:21 +09:00
parent f98964467c
commit 741a714abd
3 changed files with 38 additions and 9 deletions

View file

@ -80,9 +80,9 @@ class ModuleActionParser extends BaseParser
{
// Parse permissions.
$action_name = trim($action['name']);
$action_type = trim($action['type']);
$action_class = trim($action['class']);
$permission = trim($action['permission']);
$action_type = trim($action['type'] ?? '');
$action_class = trim($action['class'] ?? '');
$permission = trim($action['permission'] ?? '');
$permission_info = (object)['target' => '', 'check_var' => '', 'check_type' => ''];
if ($permission)
{
@ -101,18 +101,17 @@ class ModuleActionParser extends BaseParser
{
$methods = ['POST'];
}
/*
elseif ($action_type === 'view' || starts_with('disp', $action_name))
elseif ($action_class && starts_with('disp', $action_name))
{
$methods = ['GET'];
}
*/
else
{
$methods = ['GET', 'POST'];
}
// Parse routes.
$global_route = (trim($action['global_route']) ?: trim($action['global-route'])) === 'true' ? 'true' : 'false';
$route_attr = trim($action['route']);
$route_tags = $action->route ?: [];
$route_arg = [];
@ -136,6 +135,28 @@ class ModuleActionParser extends BaseParser
}
}
// Parse the standalone attribute.
if ($global_route === 'true')
{
$standalone = 'true';
}
elseif ($action_class)
{
$standalone = trim($action['standalone']);
if (!$standalone || !in_array($standalone, ['true', 'false', 'auto']))
{
$standalone = 'auto';
}
}
else
{
$standalone = trim($action['standalone']);
if (!$standalone || !in_array($standalone, ['true', 'false', 'auto']))
{
$standalone = 'true';
}
}
// Automatically determine the type for custom classes.
if ($action_class && !$action_type)
{
@ -162,10 +183,10 @@ class ModuleActionParser extends BaseParser
$action_info->ruleset = trim($action['ruleset']);
$action_info->method = implode('|', $methods);
$action_info->route = $route_arg;
$action_info->standalone = trim($action['standalone']) === 'false' ? 'false' : 'true';
$action_info->standalone = $standalone;
$action_info->check_csrf = (trim($action['check_csrf']) ?: trim($action['check-csrf'])) === 'false' ? 'false' : 'true';
$action_info->meta_noindex = (trim($action['meta_noindex']) ?: trim($action['meta-noindex'])) === 'true' ? 'true' : 'false';
$action_info->global_route = (trim($action['global_route']) ?: trim($action['global-route'])) === 'true' ? 'true' : 'false';
$action_info->global_route = $global_route;
$info->action->{$action_name} = $action_info;
// Set the menu name and index settings.