feat: implement global autoresponder plugin
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
return static function (AppContext $ctx): void {
|
||||
$id = Http::isPost() ? $ctx->post('id') : $ctx->query('id');
|
||||
$rule = $ctx->rules->find($ctx->daUser->username(), $id);
|
||||
if ($rule === null) {
|
||||
$ctx->render('Edit autoresponder', '<div class="alert alert-err">Rule not found</div>');
|
||||
return;
|
||||
}
|
||||
$errors = [];
|
||||
if (Http::isPost()) {
|
||||
try {
|
||||
$ctx->requireCsrf('update:' . $id);
|
||||
$input = normalize_rule_post($_POST);
|
||||
$patch = RuleValidator::validate($input, $ctx->settings);
|
||||
$ctx->rules->update($ctx->daUser->username(), $id, $patch);
|
||||
Http::redirect($ctx->url('index.html', ['status' => 'updated']));
|
||||
} catch (Throwable $e) {
|
||||
$errors[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
$ctx->render('Edit autoresponder', render_rule_form($ctx, 'update', $rule), [], $errors);
|
||||
};
|
||||
Reference in New Issue
Block a user