feat: implement global autoresponder plugin

This commit is contained in:
Marek Miklewicz
2026-06-02 19:19:00 +02:00
commit 6f989af278
62 changed files with 2018 additions and 0 deletions
+24
View File
@@ -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);
};