diff --git a/backend/src/app/rpc/commands/binfile.clj b/backend/src/app/rpc/commands/binfile.clj index c9cf634b4..798966ed1 100644 --- a/backend/src/app/rpc/commands/binfile.clj +++ b/backend/src/app/rpc/commands/binfile.clj @@ -15,10 +15,12 @@ [app.common.uuid :as uuid] [app.config :as cf] [app.db :as db] + [app.loggers.audit :as-alias audit] [app.loggers.webhooks :as-alias webhooks] [app.media :as media] [app.rpc.commands.files :as files] [app.rpc.doc :as-alias doc] + [app.rpc.helpers :as rph] [app.rpc.queries.projects :as projects] [app.storage :as sto] [app.storage.tmp :as tmp] @@ -899,7 +901,9 @@ [{:keys [pool] :as cfg} {:keys [profile-id project-id file] :as params}] (db/with-atomic [conn pool] (projects/check-read-permissions! conn profile-id project-id) - (import! (assoc cfg - ::input (:path file) - ::project-id project-id - ::ignore-index-errors? true)))) + (let [ids (import! (assoc cfg + ::input (:path file) + ::project-id project-id + ::ignore-index-errors? true))] + (rph/with-meta ids + {::audit/props {:file nil :file-ids ids}})))) diff --git a/backend/src/app/rpc/commands/files.clj b/backend/src/app/rpc/commands/files.clj index 98518feb9..e2c012439 100644 --- a/backend/src/app/rpc/commands/files.clj +++ b/backend/src/app/rpc/commands/files.clj @@ -17,6 +17,7 @@ [app.common.types.shape-tree :as ctt] [app.db :as db] [app.db.sql :as sql] + [app.loggers.audit :as-alias audit] [app.loggers.webhooks :as-alias webhooks] [app.rpc.commands.files.thumbnails :as-alias thumbs] [app.rpc.commands.teams :as teams] @@ -753,11 +754,10 @@ (defn rename-file [conn {:keys [id name] :as params}] - (-> (db/update! conn :file - {:name name - :modified-at (dt/now)} - {:id id}) - (select-keys [:id :name :created-at :modified-at]))) + (db/update! conn :file + {:name name + :modified-at (dt/now)} + {:id id})) (s/def ::rename-file (s/keys :req-un [::profile-id ::name ::id])) @@ -768,8 +768,12 @@ [{:keys [pool] :as cfg} {:keys [id profile-id] :as params}] (db/with-atomic [conn pool] (check-edition-permissions! conn profile-id id) - (rename-file conn params))) - + (let [file (rename-file conn params)] + (rph/with-meta + (select-keys file [:id :name :created-at :modified-at]) + {::audit/props {:project-id (:project-id file) + :created-at (:created-at file) + :modified-at (:modified-at file)}})))) ;; --- MUTATION COMMAND: set-file-shared @@ -779,10 +783,9 @@ (defn set-file-shared [conn {:keys [id is-shared] :as params}] - (-> (db/update! conn :file - {:is-shared is-shared} - {:id id}) - (select-keys [:id :name :is-shared]))) + (db/update! conn :file + {:is-shared is-shared} + {:id id})) (defn absorb-library "Find all files using a shared library, and absorb all library assets @@ -816,8 +819,13 @@ (when-not is-shared (absorb-library conn params) (unlink-files conn params)) - (set-file-shared conn params))) + (let [file (set-file-shared conn params)] + (rph/with-meta + (select-keys file [:id :name :is-shared]) + {::audit/props {:name (:name file) + :project-id (:project-id file) + :is-shared (:is-shared file)}})))) ;; --- MUTATION COMMAND: delete-file @@ -825,8 +833,7 @@ [conn {:keys [id] :as params}] (db/update! conn :file {:deleted-at (dt/now)} - {:id id}) - nil) + {:id id})) (s/def ::delete-file (s/keys :req-un [::id ::profile-id])) @@ -838,7 +845,12 @@ (db/with-atomic [conn pool] (check-edition-permissions! conn profile-id id) (absorb-library conn params) - (mark-file-deleted conn params))) + (let [file (mark-file-deleted conn params)] + (rph/with-meta (rph/wrap) + {::audit/props {:project-id (:project-id file) + :name (:name file) + :created-at (:created-at file) + :modified-at (:modified-at file)}})))) ;; --- MUTATION COMMAND: link-file-to-library diff --git a/backend/src/app/rpc/mutations/projects.clj b/backend/src/app/rpc/mutations/projects.clj index 95fbb5da9..db5c18529 100644 --- a/backend/src/app/rpc/mutations/projects.clj +++ b/backend/src/app/rpc/mutations/projects.clj @@ -122,4 +122,7 @@ {:deleted-at (dt/now)} {:id id :is-default false})] (rph/with-meta (rph/wrap) - {::audit/props {:team-id (:team-id project)}})))) + {::audit/props {:team-id (:team-id project) + :name (:name project) + :created-at (:created-at project) + :modified-at (:modified-at project)}})))) diff --git a/common/src/app/common/transit.cljc b/common/src/app/common/transit.cljc index ad0ba80d1..9d698cd3a 100644 --- a/common/src/app/common/transit.cljc +++ b/common/src/app/common/transit.cljc @@ -14,6 +14,7 @@ [lambdaisland.uri :as luri] [linked.core :as lk] [linked.set :as lks] + #?(:clj [datoteka.fs :as fs]) #?(:cljs ["luxon" :as lxn])) #?(:clj (:import @@ -22,6 +23,7 @@ java.io.ByteArrayInputStream java.io.ByteArrayOutputStream java.io.File + java.nio.file.Path java.time.Duration java.time.Instant java.time.OffsetDateTime @@ -102,11 +104,15 @@ ;; --- HANDLERS (add-handlers! - #?(:clj - {:id "file" - :class File - :wfn str - :rfn identity}) + #?@(:clj + [{:id "file" + :class File + :wfn str + :rfn identity} + {:id "path" + :class Path + :wfn str + :rfn fs/path}]) #?(:cljs {:id "n"