diff --git a/backend/src/app/loggers/audit.clj b/backend/src/app/loggers/audit.clj index 7d8c7e583..7513f9825 100644 --- a/backend/src/app/loggers/audit.clj +++ b/backend/src/app/loggers/audit.clj @@ -24,19 +24,33 @@ [lambdaisland.uri :as u])) (defn clean-props - "Cleans the params from complex data, only accept strings, numbers and - uuids and removing sensitive data such as :password and related - props." - [params] - (let [params (dissoc params :session-id :password :old-password :token)] - (reduce-kv (fn [params k v] - (cond-> params - (or (string? v) - (uuid? v) - (number? v)) - (assoc k v))) - {} - params))) + [{:keys [profile-id] :as event}] + (letfn [(clean-common [props] + (-> props + (dissoc :session-id) + (dissoc :password) + (dissoc :old-password) + (dissoc :token))) + + (clean-profile-id [props] + (cond-> props + (= profile-id (:profile-id props)) + (dissoc :profile-id))) + + (clean-complex-data [props] + (reduce-kv (fn [props k v] + (cond-> props + (or (string? v) + (uuid? v) + (boolean? v) + (number? v)) + (assoc k v) + + (keyword? v) + (assoc k (name v)))) + {} + props))] + (update event :props #(-> % clean-common clean-profile-id clean-complex-data)))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Collector @@ -52,11 +66,16 @@ (defmethod ig/pre-init-spec ::collector [_] (s/keys :req-un [::db/pool ::wrk/executor ::enabled])) +(def event-xform + (comp + (filter :profile-id) + (map clean-props))) + (defmethod ig/init-key ::collector [_ {:keys [enabled] :as cfg}] (when enabled (l/info :msg "intializing audit collector") - (let [input (a/chan) + (let [input (a/chan 1 event-xform) buffer (aa/batch input {:max-batch-size 100 :max-batch-age (* 5 1000) :init []})] @@ -65,14 +84,17 @@ (l/debug :action "persist-events (batch)" :reason (name type) :count (count events)) - (a/ (assoc cfg :conn conn) (login-or-register params))] (with-meta profile - {:before-complete (annotate-profile-register metrics profile)})))) + {:before-complete (annotate-profile-register metrics profile) + ::audit/props (:props profile) + ::audit/profile-id (:id profile)})))) (defn login-or-register [{:keys [conn] :as cfg} {:keys [email backend] :as params}] @@ -614,7 +618,7 @@ ;; Schedule a complete deletion of profile (wrk/submit! {::wrk/task :delete-profile - ::wrk/dalay cfg/deletion-delay + ::wrk/delay cfg/deletion-delay ::wrk/conn conn :profile-id profile-id}) diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index 73142e4ae..906df6b8d 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -379,9 +379,11 @@ on-success identity}} (meta params)] (->> (rp/mutation :delete-profile {}) (rx/tap on-success) + (rx/delay-at-least 300) + (rx/catch (constantly (rx/of 1))) + (rx/map logged-out) (rx/catch on-error)))))) - ;; --- EVENT: request-profile-recovery (s/def ::request-profile-recovery diff --git a/frontend/src/app/main/ui/settings/delete_account.cljs b/frontend/src/app/main/ui/settings/delete_account.cljs index fe3ef3c59..f26881ddb 100644 --- a/frontend/src/app/main/ui/settings/delete_account.cljs +++ b/frontend/src/app/main/ui/settings/delete_account.cljs @@ -12,7 +12,7 @@ [app.main.store :as st] [app.main.ui.icons :as i] [app.main.ui.messages :as msgs] - [app.util.i18n :as i18n :refer [tr t]] + [app.util.i18n :as i18n :refer [tr]] [app.util.router :as rt] [beicon.core :as rx] [cljs.spec.alpha :as s] @@ -25,42 +25,36 @@ (rx/of (dm/error msg))) (rx/throw error))) -(defn on-success - [x] - (st/emit! (rt/nav :auth-login))) - (mf/defc delete-account-modal {::mf/register modal/components ::mf/register-as :delete-account} [props] - (let [locale (mf/deref i18n/locale) - on-close + (let [on-close (mf/use-callback (st/emitf (modal/hide))) on-accept (mf/use-callback (st/emitf (modal/hide) (du/request-account-deletion - (with-meta {} {:on-error on-error - :on-success on-success}))))] + (with-meta {} {:on-error on-error}))))] [:div.modal-overlay [:div.modal-container.change-email-modal [:div.modal-header [:div.modal-header-title - [:h2 (t locale "modals.delete-account.title")]] + [:h2 (tr "modals.delete-account.title")]] [:div.modal-close-button {:on-click on-close} i/close]] [:div.modal-content [:& msgs/inline-banner {:type :warning - :content (t locale "modals.delete-account.info")}]] + :content (tr "modals.delete-account.info")}]] [:div.modal-footer [:div.action-buttons [:button.btn-warning.btn-large {:on-click on-accept} - (t locale "modals.delete-account.confirm")] + (tr "modals.delete-account.confirm")] [:button.btn-secondary.btn-large {:on-click on-close} - (t locale "modals.delete-account.cancel")]]]]])) + (tr "modals.delete-account.cancel")]]]]]))