diff options
author | Colin Okay <okay@toyful.space> | 2022-02-21 15:55:12 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2022-02-21 15:55:12 -0600 |
commit | e604387cce370cd758e504715075e19f44bd6aca (patch) | |
tree | a031d45e10f0b883eb85f4b2c8f8c660eed9a8e9 /src | |
parent | 5f703c7485cb75b97aefa2be8570a707fda3ba82 (diff) |
flagging and unflagging
Diffstat (limited to 'src')
-rw-r--r-- | src/main.lisp | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/src/main.lisp b/src/main.lisp index 9145a8a..2c5f466 100644 --- a/src/main.lisp +++ b/src/main.lisp @@ -69,8 +69,9 @@ (defun can-invite-p (contributor) "Returns T if the contributor is currently allowed to make more invites." - (with-plist (limit made) (contributor-invites contributor) - (< made limit))) + (or (adminp contributor) + (with-plist (limit made) (contributor-invites contributor) + (< made limit)))) (defclass api-access (db:store-object) ((token @@ -328,12 +329,14 @@ :brief brief :runstyle (or runstyle :auto)))) -(defun flag-oneliner (oneliner &optional contributor) - "Flag a oneliner for review. If locked, ensure that CONTRIBUTOR is an admin. Returns T or NIL." - (when (or (not (lockedp oneliner)) (and contributor (adminp contributor))) - (db:with-transaction () - (setf (flagged-by oneliner) (or contributor :anonymous)) - t))) + +(defun unflag-oneliner (oneliner) + (db:with-transaction () + (setf (flagged-by oneliner) nil))) + +(defun flag-oneliner (oneliner contributor) + (db:with-transaction () + (setf (flagged-by oneliner) contributor))) (defun lock-oneliner (oneliner contributor) "Locks a oneliner. Only admins can lock and unlock." @@ -534,12 +537,15 @@ admin privileges are allowed to perform this action." (apply 'edit-oneliner entry (api-contributor token) (lzb:request-body)) "true") -(defendpoint* :put "/oneliner/:entry a-oneliner-id:/flag" ((token an-api-token)) +(defendpoint* :put "/oneliner/:entry a-oneliner-id:/flag" ((token an-api-token) + (value a-boolean)) (:auth t) "Flag the oneliner for review." (when (and (lockedp entry) (not (adminp (api-contributor token)))) (http-err 403)) - (flag-oneliner entry (api-contributor token)) + (if value + (flag-oneliner entry (api-contributor token)) + (unflag-oneliner entry)) "true") (defendpoint* :get "/oneliners" ((tags a-csl) |