Merge pull request 'feat: 后台身份认证记录支持删除' (#356) from worktree-identity-form-simplify into main
Reviewed-on: CYL/wordpress-theme-aksrt#356
This commit is contained in:
commit
f3e4cdd9cf
4 files changed
+33
No files matched your search
@@ -31,6 +31,7 @@ class UsersMenus {
|
|||||||
add_action('admin_notices', [$this, 'pending_notices']);
|
add_action('admin_notices', [$this, 'pending_notices']);
|
||||||
add_action('admin_post_aksrt_users_send_message', [$this, 'handle_send_message']);
|
add_action('admin_post_aksrt_users_send_message', [$this, 'handle_send_message']);
|
||||||
add_action('admin_post_aksrt_users_review_verify', [$this, 'handle_review_verify']);
|
add_action('admin_post_aksrt_users_review_verify', [$this, 'handle_review_verify']);
|
||||||
|
add_action('admin_post_aksrt_users_delete_verify', [$this, 'handle_delete_verify']);
|
||||||
add_action('admin_post_aksrt_users_update_report', [$this, 'handle_update_report']);
|
add_action('admin_post_aksrt_users_update_report', [$this, 'handle_update_report']);
|
||||||
add_action('admin_post_aksrt_users_add_restriction', [$this, 'handle_add_restriction']);
|
add_action('admin_post_aksrt_users_add_restriction', [$this, 'handle_add_restriction']);
|
||||||
add_action('admin_post_aksrt_users_remove_restriction', [$this, 'handle_remove_restriction']);
|
add_action('admin_post_aksrt_users_remove_restriction', [$this, 'handle_remove_restriction']);
|
||||||
@@ -143,6 +144,7 @@ class UsersMenus {
|
|||||||
'message_sent' => __('消息已发送。', 'aksrt'),
|
'message_sent' => __('消息已发送。', 'aksrt'),
|
||||||
'message_failed' => __('消息发送失败。', 'aksrt'),
|
'message_failed' => __('消息发送失败。', 'aksrt'),
|
||||||
'verify_updated' => __('认证状态已更新。', 'aksrt'),
|
'verify_updated' => __('认证状态已更新。', 'aksrt'),
|
||||||
|
'verify_deleted' => __('认证记录已删除。', 'aksrt'),
|
||||||
'verify_failed' => __('认证审核失败。', 'aksrt'),
|
'verify_failed' => __('认证审核失败。', 'aksrt'),
|
||||||
'report_updated' => __('举报状态已更新。', 'aksrt'),
|
'report_updated' => __('举报状态已更新。', 'aksrt'),
|
||||||
'report_failed' => __('举报更新失败。', 'aksrt'),
|
'report_failed' => __('举报更新失败。', 'aksrt'),
|
||||||
|
|||||||
@@ -176,6 +176,10 @@ trait UsersMenusVerify {
|
|||||||
} else {
|
} else {
|
||||||
echo '<span class="description">' . esc_html__('无需人工操作', 'aksrt') . '</span>';
|
echo '<span class="description">' . esc_html__('无需人工操作', 'aksrt') . '</span>';
|
||||||
}
|
}
|
||||||
|
echo '<form method="post" action="' . esc_url(admin_url('admin-post.php')) . '" style="margin-top:8px;" onsubmit="return confirm(\'' . esc_js(__('确定删除这条身份认证记录?关联事件和人工材料也会删除。', 'aksrt')) . '\');">';
|
||||||
|
echo '<input type="hidden" name="action" value="aksrt_users_delete_verify" /><input type="hidden" name="application_uuid" value="' . esc_attr((string) $row['application_uuid']) . '" />';
|
||||||
|
wp_nonce_field('aksrt_users_delete_verify_' . (string) $row['application_uuid']);
|
||||||
|
echo '<button class="button button-link-delete">' . esc_html__('删除记录', 'aksrt') . '</button></form>';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handle_review_verify(): void {
|
public function handle_review_verify(): void {
|
||||||
@@ -197,6 +201,23 @@ trait UsersMenusVerify {
|
|||||||
$this->redirect('aksrt_user_auth', is_wp_error($result) ? 'verify_failed' : 'verify_updated', $extra);
|
$this->redirect('aksrt_user_auth', is_wp_error($result) ? 'verify_failed' : 'verify_updated', $extra);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function handle_delete_verify(): void {
|
||||||
|
if (!current_user_can('aksrt_review_identity') && !current_user_can(self::CAPABILITY)) {
|
||||||
|
wp_die(esc_html__('权限不足', 'aksrt'));
|
||||||
|
}
|
||||||
|
$uuid = sanitize_text_field((string) wp_unslash($_POST['application_uuid'] ?? ''));
|
||||||
|
check_admin_referer('aksrt_users_delete_verify_' . $uuid);
|
||||||
|
$repo = new \AKSRT\Identity\ApplicationRepository();
|
||||||
|
$application = $repo->find_by_uuid($uuid);
|
||||||
|
if (!$application) {
|
||||||
|
$this->redirect('aksrt_user_auth', 'verify_failed', ['aksrt_verify_error' => __('认证记录不存在', 'aksrt')]);
|
||||||
|
}
|
||||||
|
(new \AKSRT\Identity\EvidenceService())->delete((array) ($application['evidence_ids'] ?? []));
|
||||||
|
(new \AKSRT\Identity\EventRepository())->delete_for_application((int) $application['id']);
|
||||||
|
$deleted = $repo->delete((int) $application['id']);
|
||||||
|
$this->redirect('aksrt_user_auth', $deleted ? 'verify_deleted' : 'verify_failed', $deleted ? [] : ['aksrt_verify_error' => __('认证记录删除失败', 'aksrt')]);
|
||||||
|
}
|
||||||
|
|
||||||
private function get_verify_history(int $user_id): array {
|
private function get_verify_history(int $user_id): array {
|
||||||
return \AKSRT\User\AuthApply::get_review_history($user_id);
|
return \AKSRT\User\AuthApply::get_review_history($user_id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -148,6 +148,11 @@ final class ApplicationRepository {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete(int $id): bool {
|
||||||
|
global $wpdb;
|
||||||
|
return $wpdb->delete($this->table, ['id' => $id], ['%d']) === 1;
|
||||||
|
}
|
||||||
|
|
||||||
/** @return array<string,mixed> */
|
/** @return array<string,mixed> */
|
||||||
private function normalize(array $row): array {
|
private function normalize(array $row): array {
|
||||||
foreach (['id', 'user_id', 'reviewer_id', 'attempt_ordinal', 'retry_count'] as $key) {
|
foreach (['id', 'user_id', 'reviewer_id', 'attempt_ordinal', 'retry_count'] as $key) {
|
||||||
|
|||||||
@@ -51,4 +51,9 @@ final class EventRepository {
|
|||||||
), ARRAY_A);
|
), ARRAY_A);
|
||||||
return is_array($rows) ? $rows : [];
|
return is_array($rows) ? $rows : [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete_for_application(int $application_id): bool {
|
||||||
|
global $wpdb;
|
||||||
|
return $wpdb->delete($this->table, ['application_id' => $application_id], ['%d']) !== false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user