pref-matrix

Web interface to coordinate preferences
git clone https://git.instinctive.eu/pref-matrix.git
Log | Files | Refs | README | LICENSE

commit 6547f507b2b7bbc377a34b9b56660f2335397a39
parent cd6b51182f09055b460aebd9a66518e54f02e631
Author: Natasha Kerensikova <natgh@instinctive.eu>
Date:   Sat, 27 Jan 2024 10:16:05 +0000

Topics can be closed from web interface
Diffstat:
Msrc/pref-matrix.scm | 18++++++++++++++++++
Mtest/run.sh | 12++++++++++++
Atest/test-4-9b.json | 2++
3 files changed, 32 insertions(+), 0 deletions(-)

diff --git a/src/pref-matrix.scm b/src/pref-matrix.scm @@ -365,6 +365,14 @@ (unless replaying? (generate-topic-json result)) result)))) +(define-traced (close-topic name n) + (let ((tid (topic-id name))) + (if tid + (begin + (exec (sql db "UPDATE topic SET closed=? WHERE id=?") n tid) + tid) + #f))) + (define-traced (new-object topic name) (let ((tid (writable-topic-id topic))) (if (or (not tid) (zero? (string-length name))) @@ -493,6 +501,16 @@ (lambda () (cmd-sleep) . body)) cmd-list))))) +(defcmd close-topic + (let* ((data (read-urlencoded-request-data (current-request))) + (name (alist-ref 'name data eq? #f))) + (if name + (let ((result (with-db (close-topic name 1)))) + (if result + (send-status 'ok) + (send-status 'bad-request "Name not found"))) + (send-status 'bad-request "Missing parameter")))) + (defcmd hide-object (let* ((data (read-urlencoded-request-data (current-request))) (topic (alist-ref 'topic data eq? #f)) diff --git a/test/run.sh b/test/run.sh @@ -209,6 +209,18 @@ check_text test-4-7b.json test-two.json do_post '/new-subject' 200 -d 'topic=one' -d 'name=foo' check_text test-4-7a.json test-one.json check_text test-4-7b.json test-two.json +do_post '/close-topic' 200 -d 'name=one' +check_text test-4-7a.json test-one.json +check_text test-4-7b.json test-two.json +do_post '/set-pref' 200 -d 'topic=two' -d 'sub=foo' -d 'common=5' +check_text test-4-7a.json test-one.json +check_text test-4-9b.json test-two.json +do_post '/set-pref' 200 -d 'topic=one' -d 'sub=foo' -d 'common=5' +check_text test-4-7a.json test-one.json +check_text test-4-9b.json test-two.json +do_post '/new-subject' 409 -d 'topic=one' -d 'name=extra' +check_text test-4-7a.json test-one.json +check_text test-4-9b.json test-two.json kill "${SRV_PID}" trap 'rm -f ${TO_CLEAN}' EXIT diff --git a/test/test-4-9b.json b/test/test-4-9b.json @@ -0,0 +1 @@ +[["common","thing"],{"baz":{"common":5},"foo":{"common":5,"thing":2}}] +\ No newline at end of file