From 2e438385f3d1e021ba5f4ad922ff8134750247b8 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Feb 2021 16:48:13 +0100 Subject: [PATCH] :sparkles: Increase default deletion delay. --- backend/src/app/config.clj | 4 ++-- backend/src/app/rpc/mutations/demo.clj | 2 +- backend/src/app/rpc/mutations/files.clj | 2 +- backend/src/app/rpc/mutations/profile.clj | 2 +- backend/src/app/rpc/mutations/projects.clj | 21 ++++++------------- backend/src/app/rpc/mutations/teams.clj | 11 +++++++++- .../src/app/rpc/mutations/verify_token.clj | 2 -- backend/src/app/tasks/delete_object.clj | 10 +++++++-- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/backend/src/app/config.clj b/backend/src/app/config.clj index 3a313d4a9..12022af73 100644 --- a/backend/src/app/config.clj +++ b/backend/src/app/config.clj @@ -245,5 +245,5 @@ (def config (read-config env)) (def test-config (read-test-config env)) -(def default-deletion-delay - (dt/duration {:hours 48})) +(def deletion-delay + (dt/duration {:days 7})) diff --git a/backend/src/app/rpc/mutations/demo.clj b/backend/src/app/rpc/mutations/demo.clj index 0461ef13f..c5959f91d 100644 --- a/backend/src/app/rpc/mutations/demo.clj +++ b/backend/src/app/rpc/mutations/demo.clj @@ -52,7 +52,7 @@ ;; Schedule deletion of the demo profile (tasks/submit! conn {:name "delete-profile" - :delay cfg/default-deletion-delay + :delay cfg/deletion-delay :props {:profile-id id}}) {:email email diff --git a/backend/src/app/rpc/mutations/files.clj b/backend/src/app/rpc/mutations/files.clj index 0ccc65c05..9d04afeb2 100644 --- a/backend/src/app/rpc/mutations/files.clj +++ b/backend/src/app/rpc/mutations/files.clj @@ -129,7 +129,7 @@ ;; Schedule object deletion (tasks/submit! conn {:name "delete-object" - :delay cfg/default-deletion-delay + :delay cfg/deletion-delay :props {:id id :type :file}}) (mark-file-deleted conn params))) diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index d897b5ac6..8ee5d7e8f 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -472,7 +472,7 @@ ;; Schedule a complete deletion of profile (tasks/submit! conn {:name "delete-profile" - :delay (dt/duration {:hours 48}) + :delay cfg/deletion-delay :props {:profile-id profile-id}}) (db/update! conn :profile diff --git a/backend/src/app/rpc/mutations/projects.clj b/backend/src/app/rpc/mutations/projects.clj index bb2c4772d..de92bb054 100644 --- a/backend/src/app/rpc/mutations/projects.clj +++ b/backend/src/app/rpc/mutations/projects.clj @@ -16,6 +16,7 @@ [app.rpc.queries.projects :as proj] [app.tasks :as tasks] [app.util.services :as sv] + [app.util.time :as dt] [clojure.spec.alpha :as s])) ;; --- Helpers & Specs @@ -113,8 +114,6 @@ ;; --- Mutation: Delete Project -(declare mark-project-deleted) - (s/def ::delete-project (s/keys :req-un [::id ::profile-id])) @@ -125,18 +124,10 @@ ;; Schedule object deletion (tasks/submit! conn {:name "delete-object" - :delay cfg/default-deletion-delay + :delay cfg/deletion-delay :props {:id id :type :project}}) - (mark-project-deleted conn params))) - -(def ^:private sql:mark-project-deleted - "update project - set deleted_at = clock_timestamp() - where id = ? - returning id") - -(defn mark-project-deleted - [conn {:keys [id] :as params}] - (db/exec! conn [sql:mark-project-deleted id]) - nil) + (db/update! conn :project + {:deleted-at (dt/now)} + {:id id}) + nil)) diff --git a/backend/src/app/rpc/mutations/teams.clj b/backend/src/app/rpc/mutations/teams.clj index 46d3785b9..5abbb4152 100644 --- a/backend/src/app/rpc/mutations/teams.clj +++ b/backend/src/app/rpc/mutations/teams.clj @@ -13,6 +13,7 @@ [app.common.exceptions :as ex] [app.common.spec :as us] [app.common.uuid :as uuid] + [app.config :as cfg] [app.db :as db] [app.emails :as emails] [app.media :as media] @@ -20,6 +21,7 @@ [app.rpc.queries.profile :as profile] [app.rpc.queries.teams :as teams] [app.storage :as sto] + [app.tasks :as tasks] [app.util.services :as sv] [app.util.time :as dt] [clojure.spec.alpha :as s] @@ -133,7 +135,14 @@ (ex/raise :type :validation :code :only-owner-can-delete-team)) - (db/delete! conn :team {:id id}) + ;; Schedule object deletion + (tasks/submit! conn {:name "delete-object" + :delay cfg/deletion-delay + :props {:id id :type :team}}) + + (db/update! conn :team + {:deleted-at (dt/now)} + {:id id}) nil))) diff --git a/backend/src/app/rpc/mutations/verify_token.clj b/backend/src/app/rpc/mutations/verify_token.clj index e1af35591..8f2a7d0f4 100644 --- a/backend/src/app/rpc/mutations/verify_token.clj +++ b/backend/src/app/rpc/mutations/verify_token.clj @@ -7,8 +7,6 @@ ;; ;; Copyright (c) 2020 UXBOX Labs SL -;; TODO: session - (ns app.rpc.mutations.verify-token (:require [app.common.exceptions :as ex] diff --git a/backend/src/app/tasks/delete_object.clj b/backend/src/app/tasks/delete_object.clj index 4d31ff4f9..a65a75b1e 100644 --- a/backend/src/app/tasks/delete_object.clj +++ b/backend/src/app/tasks/delete_object.clj @@ -42,11 +42,12 @@ (db/with-atomic [conn pool] (handle-deletion conn props))) -(defmulti handle-deletion (fn [_ props] (:type props))) +(defmulti handle-deletion + (fn [_ props] (:type props))) (defmethod handle-deletion :default [_conn {:keys [type]}] - (log/warn "no handler found for" type)) + (log/warnf "no handler found for %s" type)) (defmethod handle-deletion :file [conn {:keys [id] :as props}] @@ -57,3 +58,8 @@ [conn {:keys [id] :as props}] (let [sql "delete from project where id=? and deleted_at is not null"] (db/exec-one! conn [sql id]))) + +(defmethod handle-deletion :team + [conn {:keys [id] :as props}] + (let [sql "delete from team where id=? and deleted_at is not null"] + (db/exec-one! conn [sql id])))