0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00

Add import, export and management events to webhooks

This commit is contained in:
Andrey Antukh 2022-12-16 09:26:21 +01:00
parent e25cf13783
commit fa7cf70cee
3 changed files with 24 additions and 14 deletions

View file

@ -15,6 +15,7 @@
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.config :as cf] [app.config :as cf]
[app.db :as db] [app.db :as db]
[app.loggers.webhooks :as-alias webhooks]
[app.media :as media] [app.media :as media]
[app.rpc.commands.files :as files] [app.rpc.commands.files :as files]
[app.rpc.doc :as-alias doc] [app.rpc.doc :as-alias doc]
@ -840,10 +841,10 @@
(defn import! (defn import!
[{:keys [::input] :as cfg}] [{:keys [::input] :as cfg}]
(let [id (uuid/next) (let [id (uuid/next)
ts (dt/now) tp (dt/tpoint)
cs (volatile! nil)] cs (volatile! nil)]
(l/info :hint "import: started" :import-id id)
(try (try
(l/info :hint "start importation" :import-id id)
(binding [*position* (atom 0)] (binding [*position* (atom 0)]
(with-open [^AutoCloseable input (io/input-stream input)] (with-open [^AutoCloseable input (io/input-stream input)]
(read-import! (assoc cfg ::input input)))) (read-import! (assoc cfg ::input input))))
@ -853,10 +854,12 @@
(throw cause)) (throw cause))
(finally (finally
(l/info :hint "importation finished" :import-id id (l/info :hint "import: terminated"
:elapsed (str (inst-ms (dt/diff ts (dt/now))) "ms") :import-id id
:elapsed (dt/format-duration (tp))
:error? (some? @cs) :error? (some? @cs)
:cause @cs))))) :cause @cs
)))))
;; --- Command: export-binfile ;; --- Command: export-binfile
@ -870,7 +873,8 @@
(sv/defmethod ::export-binfile (sv/defmethod ::export-binfile
"Export a penpot file in a binary format." "Export a penpot file in a binary format."
{::doc/added "1.15"} {::doc/added "1.15"
::webhooks/event? true}
[{:keys [pool] :as cfg} {:keys [profile-id file-id include-libraries? embed-assets?] :as params}] [{:keys [pool] :as cfg} {:keys [profile-id file-id include-libraries? embed-assets?] :as params}]
(files/check-read-permissions! pool profile-id file-id) (files/check-read-permissions! pool profile-id file-id)
(let [body (reify yrs/StreamableResponseBody (let [body (reify yrs/StreamableResponseBody
@ -890,7 +894,8 @@
(sv/defmethod ::import-binfile (sv/defmethod ::import-binfile
"Import a penpot file in a binary format." "Import a penpot file in a binary format."
{::doc/added "1.15"} {::doc/added "1.15"
::webhooks/event? true}
[{:keys [pool] :as cfg} {:keys [profile-id project-id file] :as params}] [{:keys [pool] :as cfg} {:keys [profile-id project-id file] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(projects/check-read-permissions! conn profile-id project-id) (projects/check-read-permissions! conn profile-id project-id)

View file

@ -496,8 +496,7 @@
(s/keys :req-un [::profile-id ::id])) (s/keys :req-un [::profile-id ::id]))
(sv/defmethod ::delete-comment (sv/defmethod ::delete-comment
{::doc/added "1.15" {::doc/added "1.15"}
::webhooks/event? true}
[{:keys [pool] :as cfg} {:keys [profile-id id] :as params}] [{:keys [pool] :as cfg} {:keys [profile-id id] :as params}]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(let [comment (db/get-by-id conn :comment id {:for-update true})] (let [comment (db/get-by-id conn :comment id {:for-update true})]

View file

@ -13,6 +13,7 @@
[app.common.spec :as us] [app.common.spec :as us]
[app.common.uuid :as uuid] [app.common.uuid :as uuid]
[app.db :as db] [app.db :as db]
[app.loggers.webhooks :as-alias webhooks]
[app.rpc.commands.binfile :as binfile] [app.rpc.commands.binfile :as binfile]
[app.rpc.commands.files :as files] [app.rpc.commands.files :as files]
[app.rpc.commands.teams :as teams :refer [create-project-role create-project]] [app.rpc.commands.teams :as teams :refer [create-project-role create-project]]
@ -42,7 +43,8 @@
(sv/defmethod ::duplicate-file (sv/defmethod ::duplicate-file
"Duplicate a single file in the same team." "Duplicate a single file in the same team."
{::doc/added "1.16"} {::doc/added "1.16"
::webhooks/event? true}
[{:keys [pool] :as cfg} params] [{:keys [pool] :as cfg} params]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(duplicate-file conn params))) (duplicate-file conn params)))
@ -215,7 +217,8 @@
(sv/defmethod ::duplicate-project (sv/defmethod ::duplicate-project
"Duplicate an entire project with all the files" "Duplicate an entire project with all the files"
{::doc/added "1.16"} {::doc/added "1.16"
::webhooks/event? true}
[{:keys [pool] :as cfg} params] [{:keys [pool] :as cfg} params]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(duplicate-project conn params))) (duplicate-project conn params)))
@ -323,7 +326,8 @@
(sv/defmethod ::move-files (sv/defmethod ::move-files
"Move a set of files from one project to other." "Move a set of files from one project to other."
{::doc/added "1.16"} {::doc/added "1.16"
::webhooks/event? true}
[{:keys [pool] :as cfg} params] [{:keys [pool] :as cfg} params]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(move-files conn params))) (move-files conn params)))
@ -362,7 +366,8 @@
(sv/defmethod ::move-project (sv/defmethod ::move-project
"Move projects between teams." "Move projects between teams."
{::doc/added "1.16"} {::doc/added "1.16"
::webhooks/event? true}
[{:keys [pool] :as cfg} params] [{:keys [pool] :as cfg} params]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(move-project conn params))) (move-project conn params)))
@ -377,7 +382,8 @@
(sv/defmethod ::clone-template (sv/defmethod ::clone-template
"Clone into the specified project the template by its id." "Clone into the specified project the template by its id."
{::doc/added "1.16"} {::doc/added "1.16"
::webhooks/event? true}
[{:keys [pool] :as cfg} params] [{:keys [pool] :as cfg} params]
(db/with-atomic [conn pool] (db/with-atomic [conn pool]
(-> (assoc cfg :conn conn) (-> (assoc cfg :conn conn)