Move all domain folders from src/AKSRT/{Domain} to src/{Domain}; remap
Composer PSR-4 "AKSRT\\": "src/"; update audit script + README + ADR
paths; remove dead tools/build-psr4-map.php (scanned deleted inc/classes).
83 lines
2.8 KiB
PHP
83 lines
2.8 KiB
PHP
<?php
|
|
/**
|
|
* @package AKSRT
|
|
*/
|
|
|
|
namespace AKSRT\Admin;
|
|
|
|
defined('ABSPATH') || exit;
|
|
|
|
trait UserControllerRestrictionOperations {
|
|
|
|
public function get_user_restrictions(\WP_REST_Request $request): \WP_REST_Response {
|
|
$user_id = (int) $request->get_param('user_id');
|
|
$user = get_userdata($user_id);
|
|
if (!$user) {
|
|
return $this->error('用户不存在', 404);
|
|
}
|
|
|
|
if (!class_exists('\AKSRT\User\Restriction')) {
|
|
return $this->success(['data' => ['restrictions' => []]]);
|
|
}
|
|
|
|
$restrictions = \AKSRT\User\Restriction::get_instance()->get_user_restrictions($user_id, false);
|
|
return $this->success(['data' => ['restrictions' => $restrictions]]);
|
|
}
|
|
|
|
public function add_user_restriction(\WP_REST_Request $request): \WP_REST_Response {
|
|
$user_id = (int) $request->get_param('user_id');
|
|
$user = get_userdata($user_id);
|
|
if (!$user) {
|
|
return $this->error('用户不存在', 404);
|
|
}
|
|
|
|
$params = $request->get_json_params() ?? [];
|
|
$type = sanitize_key((string) ($params['type'] ?? ''));
|
|
$reason = sanitize_textarea_field((string) ($params['reason'] ?? ''));
|
|
$scope = sanitize_key((string) ($params['scope'] ?? 'global'));
|
|
$expires_at = sanitize_text_field((string) ($params['expires_at'] ?? ''));
|
|
|
|
if (!$type) {
|
|
return $this->error('请选择限制类型');
|
|
}
|
|
|
|
if (!class_exists('\AKSRT\User\Restriction')) {
|
|
return $this->error('限制系统未启用', 501);
|
|
}
|
|
|
|
$result = \AKSRT\User\Restriction::get_instance()->restrict(
|
|
$user_id, $type, $reason, $scope, $expires_at, get_current_user_id()
|
|
);
|
|
|
|
if (!$result['success']) {
|
|
return $this->error($result['message']);
|
|
}
|
|
|
|
return $this->success(['message' => '限制已添加', 'data' => $result]);
|
|
}
|
|
|
|
public function remove_user_restriction(\WP_REST_Request $request): \WP_REST_Response {
|
|
$restriction_id = (int) $request->get_param('id');
|
|
|
|
if (!class_exists('\AKSRT\User\Restriction')) {
|
|
return $this->error('限制系统未启用', 501);
|
|
}
|
|
|
|
$result = \AKSRT\User\Restriction::get_instance()->remove_restriction($restriction_id);
|
|
if (!$result) {
|
|
return $this->error('移除失败', 500);
|
|
}
|
|
|
|
return $this->success(['message' => '限制已移除']);
|
|
}
|
|
|
|
public function get_restriction_stats(\WP_REST_Request $request): \WP_REST_Response {
|
|
if (!class_exists('\AKSRT\User\Restriction')) {
|
|
return $this->success(['data' => ['total' => 0, 'active' => 0, 'banned' => 0]]);
|
|
}
|
|
|
|
$stats = \AKSRT\User\Restriction::get_instance()->get_stats();
|
|
return $this->success(['data' => $stats]);
|
|
}
|
|
}
|