added auditing.

This commit is contained in:
Bryce Covert
2020-08-27 07:24:12 -07:00
parent 6fce14ed6a
commit 183c74f128
13 changed files with 337 additions and 243 deletions

View File

@@ -2,6 +2,7 @@
(:require [auto-ap.utils :refer [default-pagination-size]]
[clj-time.coerce :as coerce]
[datomic.api :as d]
[clojure.tools.logging :as log]
[mount.core :as mount]))
(def uri "datomic:sql://invoices?jdbc:postgresql://database:5432/datomic?user=datomic&password=datomic")
@@ -776,6 +777,7 @@
(update-in [:args] into (get-in query-part-2 [:args]))))
(defn add-sorter-fields [q sort-map args]
(log/info "sort-map" (pr-str sort-map))
(reduce
(fn [q {:keys [sort-key asc]}]
(merge-query q
@@ -803,9 +805,33 @@
(sort comparator results )))
(defn apply-pagination [args results]
(log/info (take 4 results))
{:ids (->> results
(drop (:start args 0))
(take (:count args (or (:per-page args) default-pagination-size)))
(map last))
:count (count results)})
(defn audit-transact-batch [txes id]
(let [batch-id (.toString (java.util.UUID/randomUUID))]
(reduce
(fn [full-tx batch]
(let [batch (conj batch {:db/id "datomic.tx"
:audit/user (str (:user/role id) "-" (:user/name id))
:audit/batch batch-id})
tx-result @(d/transact conn batch)]
(cond-> full-tx
(:tx-data full-tx) (update :tx-data #(into % (:tx-data tx-result)))
(not (:tx-data full-tx)) (assoc :tx-data (vec (:tx-data tx-result)))
(not (:db-before full-tx)) (assoc :db-before (:db-before tx-result))
true (assoc :db-after (:db-after tx-result))
true (update :tempids merge (:tempids tx-result)))))
{}
(partition-all 200 txes))))
(defn audit-transact [txes id]
@(d/transact conn (conj txes {:db/id "datomic.tx"
:audit/user (str (:user/role id) "-" (:user/name id))})))