mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 04:49:03 -05:00
🎉 Add rpc methods for access tokens
This commit is contained in:
parent
a79d2cf899
commit
bca98f91e4
2 changed files with 30 additions and 1 deletions
|
@ -18,6 +18,12 @@
|
||||||
[app.util.time :as dt]
|
[app.util.time :as dt]
|
||||||
[clojure.spec.alpha :as s]))
|
[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
|
(defn- create-access-token
|
||||||
[{:keys [::conn ::main/props]} profile-id name perms]
|
[{:keys [::conn ::main/props]} profile-id name perms]
|
||||||
(let [created-at (dt/now)
|
(let [created-at (dt/now)
|
||||||
|
@ -58,7 +64,24 @@
|
||||||
(quotes/check-quote! conn
|
(quotes/check-quote! conn
|
||||||
{::quotes/id ::quotes/access-tokens-per-profile
|
{::quotes/id ::quotes/access-tokens-per-profile
|
||||||
::quotes/profile-id profile-id})
|
::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)))
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
(:require
|
(:require
|
||||||
[app.auth]
|
[app.auth]
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
|
[app.common.exceptions :as ex]
|
||||||
[app.common.flags :as flags]
|
[app.common.flags :as flags]
|
||||||
[app.common.pages :as cp]
|
[app.common.pages :as cp]
|
||||||
[app.common.pprint :as pp]
|
[app.common.pprint :as pp]
|
||||||
|
@ -320,6 +321,11 @@
|
||||||
(defn command!
|
(defn command!
|
||||||
[{:keys [::type] :as data}]
|
[{:keys [::type] :as data}]
|
||||||
(let [method-fn (get-in *system* [:app.rpc/methods :commands type])]
|
(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*))
|
;; (app.common.pprint/pprint (:app.rpc/methods *system*))
|
||||||
(try-on! (method-fn (-> data
|
(try-on! (method-fn (-> data
|
||||||
(dissoc ::type)
|
(dissoc ::type)
|
||||||
|
|
Loading…
Add table
Reference in a new issue