cfmgrv4 init...4

This commit is contained in:
최준흠 2024-10-28 11:37:01 +09:00
parent 356e0376e4
commit b5c44e9ca6
6 changed files with 29 additions and 59 deletions

View File

@ -34,27 +34,12 @@ class AuditLogController extends CloudflareController
} }
return $this->service; 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 private function init(string $action, array $fields = []): void
{ {
$this->action = $action; $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->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->field_options = $this->getFormFieldOptions($this->filter_fields);
$this->batchjob_fields = []; $this->batchjob_fields = [];
} }

View File

@ -27,12 +27,15 @@ ALTER TABLE cloudflareaccount ADD UNIQUE key cloudflareaccount_ibuk_2 (authkey);
6. auditlog용 table추가 6. auditlog용 table추가
CREATE TABLE cloudflareauditlog ( CREATE TABLE cloudflareauditlog (
uid varchar(255) NOT NULL COMMENT 'id', 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 varchar(100) NOT NULL COMMENT 'action->type',
action_info varchar(255) NULL COMMENT 'action->info',
actor varchar(100) NOT NULL COMMENT 'actor->type', actor varchar(100) NOT NULL COMMENT 'actor->type',
interface varchar(100) NULL COMMENT 'interface', interface varchar(100) NULL COMMENT 'interface',
resource_id varchar(100) NOT NULL COMMENT 'resource->id', zone_id varchar(100) NOT NULL COMMENT 'newValueJson->zone_id',
resource_type varchar(50) NOT NULL COMMENT 'resource->type', 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', status varchar(10) NOT NULL COMMENT 'action->result',
updated_at timestamp NULL DEFAULT NULL, updated_at timestamp NULL DEFAULT NULL,
created_at timestamp NOT NULL COMMENT 'when', created_at timestamp NOT NULL COMMENT 'when',

View File

@ -19,20 +19,8 @@ class AuditLogHelper extends MVCHelper
} }
$value = $value ?: DEFAULTS['EMPTY']; $value = $value ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case AuditLogModel::PARENT: case "zone_name":
//기존 작성하던값old($field)가 있으면 그값을 넣고 없으면 부모값이 있으면 넣고 없으면 entiy가 있으면 그값을 넣고 없으면 디폴트값을 넣는다. $form = form_input($field, $value, ["placeholder" => "예)exmaple.com", ...$extras]);
$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]);
break; break;
default: default:
$form = parent::getFieldForm($field, $value, $viewDatas, $extras); $form = parent::getFieldForm($field, $value, $viewDatas, $extras);
@ -44,11 +32,6 @@ class AuditLogHelper extends MVCHelper
{ {
$value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY']; $value = $viewDatas['entity']->$field ?: DEFAULTS['EMPTY'];
switch ($field) { switch ($field) {
case AuditLogModel::PARENT:
$value = " <span class=\"label_auth\">" .
preg_replace("/(\w+)@(.+)/", "$1", $viewDatas['field_options'][$field][$value])
. "</span>";
break;
case AuditLogModel::TITLE: case AuditLogModel::TITLE:
$value = form_label( $value = form_label(
$value, $value,

View File

@ -3,11 +3,14 @@ return [
'title' => "AuditLog정보", 'title' => "AuditLog정보",
'label' => [ 'label' => [
'uid' => "번호", 'uid' => "번호",
'zone_uid' => "도메인", 'action' => "Act",
'action' => "Action", 'action_info' => "ActInfo",
'actor' => "작업자", 'actor' => "작업자",
'interface' => "작업형식", 'interface' => "UI형식",
'zone_id' => "도메인ID",
'zone_name' => "도메인",
'resource_id' => "자원ID", 'resource_id' => "자원ID",
'resource_name' => "자원명",
'resource_type' => "자원형식", 'resource_type' => "자원형식",
'status' => "상태", 'status' => "상태",
'updated_at' => "수정일", 'updated_at' => "수정일",

View File

@ -11,12 +11,11 @@ class AuditLogModel extends CommonModel
const TABLE = "cloudflareauditlog"; const TABLE = "cloudflareauditlog";
const PK = "uid"; const PK = "uid";
const TITLE = "action"; const TITLE = "action";
const PARENT = "zone_uid";
protected $table = self::TABLE; protected $table = self::TABLE;
protected $primaryKey = self::PK; protected $primaryKey = self::PK;
protected $useAutoIncrement = false; protected $useAutoIncrement = false;
protected $returnType = AuditLogEntity::class; //object,array,entity명::class 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; protected $useTimestamps = true;
public function __construct() public function __construct()
@ -34,16 +33,17 @@ class AuditLogModel extends CommonModel
$rule = "required|trim|string"; $rule = "required|trim|string";
$rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : ""; $rule .= $action == "create" ? "|is_unique[{$this->table}.{$field}]" : "";
break; break;
case self::PARENT:
$rule = "required|trim|alpha_numeric";
break;
case self::TITLE: case self::TITLE:
case 'actor': case 'actor':
case 'zone_id':
case 'resource_id': case 'resource_id':
case 'resource_type':
$rule = "required|trim|string"; $rule = "required|trim|string";
break; break;
case 'interface': case 'interface':
case 'action_info':
case 'zone_name':
case 'resource_name':
case 'resource_type':
$rule = "if_exist|trim|string"; $rule = "if_exist|trim|string";
break; break;
case "status": case "status":
@ -75,11 +75,6 @@ class AuditLogModel extends CommonModel
$this->where(self::TITLE, $id); $this->where(self::TITLE, $id);
return $this->getEntity(); return $this->getEntity();
} }
public function getEntitysByParent(ZoneEntity $zone_entity)
{
$this->where(self::PARENT, $zone_entity->getPK());
return $this->getEntitys();
}
//create용 //create용
public function create(array $formDatas = []): AuditLogEntity public function create(array $formDatas = []): AuditLogEntity
{ {

View File

@ -4,8 +4,6 @@ namespace App\Services\Cloudflare;
use App\Entities\Cloudflare\AccountEntity; use App\Entities\Cloudflare\AccountEntity;
use App\Entities\Cloudflare\AuditLogEntity; use App\Entities\Cloudflare\AuditLogEntity;
use App\Entities\Cloudflare\AuthEntity;
use App\Entities\Cloudflare\ZoneEntity;
use App\Models\Cloudflare\AccountModel; use App\Models\Cloudflare\AccountModel;
use App\Models\Cloudflare\AuditLogModel; use App\Models\Cloudflare\AuditLogModel;
use stdClass; use stdClass;
@ -38,12 +36,15 @@ class AuditLogService extends CloudflareService
protected function getArrayByResult(\stdClass $result, array $formDatas = []): array protected function getArrayByResult(\stdClass $result, array $formDatas = []): array
{ {
$formDatas[AuditLogModel::PK] = $result->id; $formDatas[AuditLogModel::PK] = $result->id;
$formDatas[AuditLogModel::PARENT] = $result->newValueJson->zone_id;
$formDatas[AuditLogModel::TITLE] = $result->action->type; $formDatas[AuditLogModel::TITLE] = $result->action->type;
$formDatas['action_info'] = isset($result->action->info) ? $result->action->info : "";
$formDatas['actor'] = $result->actor->type; $formDatas['actor'] = $result->actor->type;
$formDatas['interface'] = $result->interface; $formDatas['interface'] = isset($result->interface) ? $result->interface : "";
$formDatas['resource_id'] = $result->resource->id; $formDatas['zone_id'] = $result->newValueJson->zone_id;
$formDatas['resource_type'] = $result->resource->type; $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['status'] = $result->action->result ? "true" : "false";
$formDatas['updated_at'] = date("Y-m-d H:i:s"); $formDatas['updated_at'] = date("Y-m-d H:i:s");
$formDatas['created_at'] = $result->when; $formDatas['created_at'] = $result->when;