diff --git a/backend/src/app/rpc/commands/access_token.clj b/backend/src/app/rpc/commands/access_token.clj index 48a10d128..9abf99c49 100644 --- a/backend/src/app/rpc/commands/access_token.clj +++ b/backend/src/app/rpc/commands/access_token.clj @@ -18,6 +18,12 @@ [app.util.time :as dt] [clojure.spec.alpha :as s])) +(defn- decode-row + [{:keys [perms] :as row}] + (cond-> row + (db/pgarray? perms "text") + (assoc :perms (db/decode-pgarray perms #{})))) + (defn- create-access-token [{:keys [::conn ::main/props]} profile-id name perms] (let [created-at (dt/now) @@ -58,7 +64,24 @@ (quotes/check-quote! conn {::quotes/id ::quotes/access-tokens-per-profile ::quotes/profile-id profile-id}) - (create-access-token cfg profile-id name perms)))) + (-> (create-access-token cfg profile-id name perms) + (decode-row))))) +(s/def ::delete-access-token + (s/keys :req [::rpc/profile-id] + :req-un [::us/id])) +(sv/defmethod ::delete-access-token + {::doc/added "1.18"} + [{:keys [::db/pool]} {:keys [::rpc/profile-id id]}] + (db/delete! pool :access-token {:id id :profile-id profile-id}) + nil) +(s/def ::get-access-tokens + (s/keys :req [::rpc/profile-id])) + +(sv/defmethod ::get-access-tokens + {::doc/added "1.18"} + [{:keys [::db/pool]} {:keys [::rpc/profile-id]}] + (->> (db/query pool :access-token {:profile-id profile-id}) + (mapv decode-row))) diff --git a/backend/test/backend_tests/helpers.clj b/backend/test/backend_tests/helpers.clj index c656d6c74..28d498486 100644 --- a/backend/test/backend_tests/helpers.clj +++ b/backend/test/backend_tests/helpers.clj @@ -8,6 +8,7 @@ (:require [app.auth] [app.common.data :as d] + [app.common.exceptions :as ex] [app.common.flags :as flags] [app.common.pages :as cp] [app.common.pprint :as pp] @@ -320,6 +321,11 @@ (defn command! [{:keys [::type] :as data}] (let [method-fn (get-in *system* [:app.rpc/methods :commands type])] + (when-not method-fn + (ex/raise :type :assertion + :code :rpc-method-not-found + :hint (str/ffmt "rpc method '%' not found" (name type)))) + ;; (app.common.pprint/pprint (:app.rpc/methods *system*)) (try-on! (method-fn (-> data (dissoc ::type)