cfmgrv4 init...4
This commit is contained in:
parent
356e0376e4
commit
b5c44e9ca6
@ -34,27 +34,12 @@ class AuditLogController extends CloudflareController
|
||||
}
|
||||
return $this->service;
|
||||
}
|
||||
protected function getFormFieldOption(string $field, array $options = []): array
|
||||
{
|
||||
switch ($field) {
|
||||
case $this->getModel()::PARENT:
|
||||
// $this->getZoneModel()->where('status', 'active');
|
||||
$options[$field] = $this->getZoneModel()->getFormFieldOption($field);
|
||||
// echo $this->getAccountModel()->getLastQuery();
|
||||
// dd($options);
|
||||
break;
|
||||
default:
|
||||
$options = parent::getFormFieldOption($field, $options);
|
||||
break;
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
private function init(string $action, array $fields = []): void
|
||||
{
|
||||
$this->action = $action;
|
||||
$this->fields = count($fields) ? $fields : [$this->getModel()::PARENT, $this->getModel()::TITLE, 'actor', 'interface', 'resource_id', 'resource_type', 'status', 'updated_at', 'created_at'];
|
||||
$this->fields = count($fields) ? $fields : [$this->getModel()::TITLE, 'actor', 'interface', 'zone_name', 'resource_type', 'resource_name', 'status', 'updated_at', 'created_at'];
|
||||
$this->field_rules = $this->getModel()->getFieldRules($this->action, $this->fields);
|
||||
$this->filter_fields = [$this->getModel()::PARENT, 'status'];
|
||||
$this->filter_fields = ['status'];
|
||||
$this->field_options = $this->getFormFieldOptions($this->filter_fields);
|
||||
$this->batchjob_fields = [];
|
||||
}
|
||||
|
||||
@ -27,12 +27,15 @@ ALTER TABLE cloudflareaccount ADD UNIQUE key cloudflareaccount_ibuk_2 (authkey);
|
||||
6. auditlog용 table추가
|
||||
CREATE TABLE cloudflareauditlog (
|
||||
uid varchar(255) NOT NULL COMMENT 'id',
|
||||
zone_uid varchar(100) NOT NULL COMMENT 'newValueJson->zone_id',
|
||||
action varchar(100) NOT NULL COMMENT 'action->type',
|
||||
action_info varchar(255) NULL COMMENT 'action->info',
|
||||
actor varchar(100) NOT NULL COMMENT 'actor->type',
|
||||
interface varchar(100) NULL COMMENT 'interface',
|
||||
resource_id varchar(100) NOT NULL COMMENT 'resource->id',
|
||||
resource_type varchar(50) NOT NULL COMMENT 'resource->type',
|
||||
zone_id varchar(100) NOT NULL COMMENT 'newValueJson->zone_id',
|
||||
zone_name varchar(100) NULL COMMENT 'newValueJson->zone_name',
|
||||
resource_id varchar(100) NOT NULL COMMENT 'newValueJson->id',
|
||||
resource_name varchar(100) NULL COMMENT 'newValueJson->name',
|
||||
resource_type varchar(50) NULL COMMENT 'newValueJson->type',
|
||||
status varchar(10) NOT NULL COMMENT 'action->result',
|
||||
updated_at timestamp NULL DEFAULT NULL,
|
||||
created_at timestamp NOT NULL COMMENT 'when',
|
||||
|
||||
@ -19,20 +19,8 @@ class AuditLogHelper extends MVCHelper
|
||||
}
|
||||
$value = $value ?: DEFAULTS['EMPTY'];
|
||||
switch ($field) {
|
||||
case AuditLogModel::PARENT:
|
||||
//기존 작성하던값old($field)가 있으면 그값을 넣고 없으면 부모값이 있으면 넣고 없으면 entiy가 있으면 그값을 넣고 없으면 디폴트값을 넣는다.
|
||||
$value = $value ?: (isset($viewDatas[$field]) ? $viewDatas[$field] : (isset($viewDatas['entity']) ? $viewDatas['entity']->getParent() : DEFAULTS['EMPTY']));
|
||||
|
||||
$extra_class = isset($extras['class']) ? 'select-field ' . $extras['class'] : 'select-field';
|
||||
$form = form_dropdown($field, [
|
||||
"" => lang($viewDatas['class_path'] . '.label.' . $field) . ' 선택',
|
||||
] + $viewDatas['field_options'][$field], $value, [
|
||||
'class' => $extra_class,
|
||||
...array_diff_key($extras, ['class' => ''])
|
||||
]);
|
||||
break;
|
||||
case AuditLogModel::TITLE:
|
||||
$form = form_input($field, $value, ["placeholder" => "예)test@exmaple.com", ...$extras]);
|
||||
case "zone_name":
|
||||
$form = form_input($field, $value, ["placeholder" => "예)exmaple.com", ...$extras]);
|
||||
break;
|
||||
default:
|
||||
$form = parent::getFieldForm($field, $value, $viewDatas, $extras);
|
||||
@ -44,11 +32,6 @@ class AuditLogHelper extends MVCHelper
|
||||
{
|
||||
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
|
||||
switch ($field) {
|
||||
case AuditLogModel::PARENT:
|
||||
$value = " <span class=\"label_auth\">" .
|
||||
preg_replace("/(\w+)@(.+)/", "$1", $viewDatas['field_options'][$field][$value])
|
||||
. "</span>";
|
||||
break;
|
||||
case AuditLogModel::TITLE:
|
||||
$value = form_label(
|
||||
$value,
|
||||
|
||||
@ -3,11 +3,14 @@ return [
|
||||
'title' => "AuditLog정보",
|
||||
'label' => [
|
||||
'uid' => "번호",
|
||||
'zone_uid' => "도메인",
|
||||
'action' => "Action",
|
||||
'action' => "Act",
|
||||
'action_info' => "ActInfo",
|
||||
'actor' => "작업자",
|
||||
'interface' => "작업형식",
|
||||
'interface' => "UI형식",
|
||||
'zone_id' => "도메인ID",
|
||||
'zone_name' => "도메인",
|
||||
'resource_id' => "자원ID",
|
||||
'resource_name' => "자원명",
|
||||
'resource_type' => "자원형식",
|
||||
'status' => "상태",
|
||||
'updated_at' => "수정일",
|
||||
|
||||
@ -11,12 +11,11 @@ class AuditLogModel extends CommonModel
|
||||
const TABLE = "cloudflareauditlog";
|
||||
const PK = "uid";
|
||||
const TITLE = "action";
|
||||
const PARENT = "zone_uid";
|
||||
protected $table = self::TABLE;
|
||||
protected $primaryKey = self::PK;
|
||||
protected $useAutoIncrement = false;
|
||||
protected $returnType = AuditLogEntity::class; //object,array,entity명::class
|
||||
protected $allowedFields = [self::PK, self::PARENT, self::TITLE, 'actor', 'interface', 'resource_id', 'resource_type', 'status', 'updated_at', 'created_at'];
|
||||
protected $allowedFields = [self::PK, self::TITLE, 'action_info', 'actor', 'interface', 'zone_id', 'zone_name', 'resource_id', 'resource_name', 'resource_type', 'status', 'updated_at', 'created_at'];
|
||||
protected $useTimestamps = true;
|
||||
|
||||
public function __construct()
|
||||
@ -34,16 +33,17 @@ class AuditLogModel extends CommonModel
|
||||
$rule = "required|trim|string";
|
||||
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
|
||||
break;
|
||||
case self::PARENT:
|
||||
$rule = "required|trim|alpha_numeric";
|
||||
break;
|
||||
case self::TITLE:
|
||||
case 'actor':
|
||||
case 'zone_id':
|
||||
case 'resource_id':
|
||||
case 'resource_type':
|
||||
$rule = "required|trim|string";
|
||||
break;
|
||||
case 'interface':
|
||||
case 'action_info':
|
||||
case 'zone_name':
|
||||
case 'resource_name':
|
||||
case 'resource_type':
|
||||
$rule = "if_exist|trim|string";
|
||||
break;
|
||||
case "status":
|
||||
@ -75,11 +75,6 @@ class AuditLogModel extends CommonModel
|
||||
$this->where(self::TITLE, $id);
|
||||
return $this->getEntity();
|
||||
}
|
||||
public function getEntitysByParent(ZoneEntity $zone_entity)
|
||||
{
|
||||
$this->where(self::PARENT, $zone_entity->getPK());
|
||||
return $this->getEntitys();
|
||||
}
|
||||
//create용
|
||||
public function create(array $formDatas = []): AuditLogEntity
|
||||
{
|
||||
|
||||
@ -4,8 +4,6 @@ namespace App\Services\Cloudflare;
|
||||
|
||||
use App\Entities\Cloudflare\AccountEntity;
|
||||
use App\Entities\Cloudflare\AuditLogEntity;
|
||||
use App\Entities\Cloudflare\AuthEntity;
|
||||
use App\Entities\Cloudflare\ZoneEntity;
|
||||
use App\Models\Cloudflare\AccountModel;
|
||||
use App\Models\Cloudflare\AuditLogModel;
|
||||
use stdClass;
|
||||
@ -38,12 +36,15 @@ class AuditLogService extends CloudflareService
|
||||
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
|
||||
{
|
||||
$formDatas[AuditLogModel::PK] = $result->id;
|
||||
$formDatas[AuditLogModel::PARENT] = $result->newValueJson->zone_id;
|
||||
$formDatas[AuditLogModel::TITLE] = $result->action->type;
|
||||
$formDatas['action_info'] = isset($result->action->info) ? $result->action->info : "";
|
||||
$formDatas['actor'] = $result->actor->type;
|
||||
$formDatas['interface'] = $result->interface;
|
||||
$formDatas['resource_id'] = $result->resource->id;
|
||||
$formDatas['resource_type'] = $result->resource->type;
|
||||
$formDatas['interface'] = isset($result->interface) ? $result->interface : "";
|
||||
$formDatas['zone_id'] = $result->newValueJson->zone_id;
|
||||
$formDatas['zone_name'] = isset($result->newValueJson->zone_name) ? $result->newValueJson->zone_name : "";
|
||||
$formDatas['resource_id'] = $result->newValueJson->id;
|
||||
$formDatas['resource_name'] = isset($result->newValueJson->name) ? $result->newValueJson->name : "";
|
||||
$formDatas['resource_type'] = $result->newValueJson->type ? $result->newValueJson->type : "";
|
||||
$formDatas['status'] = $result->action->result ? "true" : "false";
|
||||
$formDatas['updated_at'] = date("Y-m-d H:i:s");
|
||||
$formDatas['created_at'] = $result->when;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user