diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index 946b9122b..cdc6f1f95 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -228,8 +228,6 @@ :tasks {:sendmail (ig/ref :app.emails/sendmail-handler) :objects-gc (ig/ref :app.tasks.objects-gc/handler) - :delete-object (ig/ref :app.tasks.delete-object/handler) - :delete-profile (ig/ref :app.tasks.delete-profile/handler) :file-media-gc (ig/ref :app.tasks.file-media-gc/handler) :file-xlog-gc (ig/ref :app.tasks.file-xlog-gc/handler) :storage-deleted-gc (ig/ref :app.storage/gc-deleted-task) @@ -257,18 +255,11 @@ {:pool (ig/ref :app.db/pool) :max-age cf/deletion-delay} - :app.tasks.delete-object/handler - {:pool (ig/ref :app.db/pool) - :storage (ig/ref :app.storage/storage)} - :app.tasks.objects-gc/handler {:pool (ig/ref :app.db/pool) :storage (ig/ref :app.storage/storage) :max-age cf/deletion-delay} - :app.tasks.delete-profile/handler - {:pool (ig/ref :app.db/pool)} - :app.tasks.file-media-gc/handler {:pool (ig/ref :app.db/pool) :max-age cf/deletion-delay} diff --git a/backend/src/app/rpc/mutations/fonts.clj b/backend/src/app/rpc/mutations/fonts.clj index 85c604b15..a766265c6 100644 --- a/backend/src/app/rpc/mutations/fonts.clj +++ b/backend/src/app/rpc/mutations/fonts.clj @@ -129,13 +129,6 @@ (db/with-atomic [conn pool] (teams/check-edition-permissions! conn profile-id team-id) - ;; Schedule object deletion - (wrk/submit! {::wrk/task :delete-object - ::wrk/delay cf/deletion-delay - ::wrk/conn conn - :id id - :type :team-font-variant}) - (db/update! conn :team-font-variant {:deleted-at (dt/now)} {:id id :team-id team-id}) diff --git a/backend/src/app/tasks/delete_object.clj b/backend/src/app/tasks/delete_object.clj deleted file mode 100644 index b1b3e701b..000000000 --- a/backend/src/app/tasks/delete_object.clj +++ /dev/null @@ -1,70 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) UXBOX Labs SL - -;; TODO: DEPRECATED -;; Should be removed in the 1.8.x - -(ns app.tasks.delete-object - "Generic task for permanent deletion of objects." - (:require - [app.common.data :as d] - [app.common.spec :as us] - [app.db :as db] - [app.storage :as sto] - [app.util.logging :as l] - [clojure.spec.alpha :as s] - [integrant.core :as ig])) - -(declare handle-deletion) - -(defmethod ig/pre-init-spec ::handler [_] - (s/keys :req-un [::db/pool ::sto/storage])) - -(defmethod ig/init-key ::handler - [_ {:keys [pool] :as cfg}] - (fn [{:keys [props] :as task}] - (us/verify ::props props) - (db/with-atomic [conn pool] - (let [cfg (assoc cfg :conn conn)] - (handle-deletion cfg props))))) - -(s/def ::type ::us/keyword) -(s/def ::id ::us/uuid) -(s/def ::props (s/keys :req-un [::id ::type])) - -(defmulti handle-deletion - (fn [_ props] (:type props))) - -(defmethod handle-deletion :default - [_cfg {:keys [type]}] - (l/warn :hint "no handler found" - :type (d/name type))) - -(defmethod handle-deletion :file - [{:keys [conn]} {:keys [id] :as props}] - (let [sql "delete from file where id=? and deleted_at is not null"] - (db/exec-one! conn [sql id]))) - -(defmethod handle-deletion :project - [{:keys [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 - [{:keys [conn]} {:keys [id] :as props}] - (let [sql "delete from team where id=? and deleted_at is not null"] - (db/exec-one! conn [sql id]))) - -(defmethod handle-deletion :team-font-variant - [{:keys [conn storage]} {:keys [id] :as props}] - (let [font (db/get-by-id conn :team-font-variant id {:check-not-found false}) - storage (assoc storage :conn conn)] - (when (:deleted-at font) - (db/delete! conn :team-font-variant {:id id}) - (some->> (:woff1-file-id font) (sto/del-object storage)) - (some->> (:woff2-file-id font) (sto/del-object storage)) - (some->> (:otf-file-id font) (sto/del-object storage)) - (some->> (:ttf-file-id font) (sto/del-object storage))))) diff --git a/backend/src/app/tasks/delete_profile.clj b/backend/src/app/tasks/delete_profile.clj deleted file mode 100644 index 67a1733df..000000000 --- a/backend/src/app/tasks/delete_profile.clj +++ /dev/null @@ -1,79 +0,0 @@ -;; This Source Code Form is subject to the terms of the Mozilla Public -;; License, v. 2.0. If a copy of the MPL was not distributed with this -;; file, You can obtain one at http://mozilla.org/MPL/2.0/. -;; -;; Copyright (c) UXBOX Labs SL - -(ns app.tasks.delete-profile - "Task for permanent deletion of profiles." - (:require - [app.common.spec :as us] - [app.db :as db] - [app.db.sql :as sql] - [app.util.logging :as l] - [clojure.spec.alpha :as s] - [integrant.core :as ig])) - -;; TODO: DEPRECATED -;; Should be removed in the 1.8.x - -(declare delete-profile-data) - -;; --- INIT - -(defmethod ig/pre-init-spec ::handler [_] - (s/keys :req-un [::db/pool])) - -;; This task is responsible to permanently delete a profile with all -;; the dependent data. As step (1) we delete all owned teams of the -;; profile (that will cause to delete all underlying projects, files, -;; file_media and mark to be deleted storage_object's used by team, -;; profile and files previously deleted. Then, finally as step (2) we -;; proceed to delete the profile row. -;; -;; The storage_objects marked as deleted will be deleted by the -;; corresponding garbage collector task. - -(s/def ::profile-id ::us/uuid) -(s/def ::props (s/keys :req-un [::profile-id])) - -(defmethod ig/init-key ::handler - [_ {:keys [pool] :as cfg}] - (fn [{:keys [props] :as task}] - (us/verify ::props props) - (db/with-atomic [conn pool] - (let [id (:profile-id props) - profile (db/exec-one! conn (sql/select :profile {:id id} {:for-update true}))] - (if (or (:is-demo profile) - (:deleted-at profile)) - (delete-profile-data conn id) - (l/warn :hint "profile does not match constraints for deletion" - :profile-id id)))))) - -;; --- IMPL - -(def ^:private sql:remove-owned-teams - "delete from team - where id in ( - select tpr.team_id - from team_profile_rel as tpr - where tpr.is_owner is true - and tpr.profile_id = ? - )") - -(defn- delete-teams - [conn profile-id] - (db/exec-one! conn [sql:remove-owned-teams profile-id])) - -(defn delete-profile - [conn profile-id] - (db/delete! conn :profile {:id profile-id})) - -(defn- delete-profile-data - [conn profile-id] - (l/debug :action "delete profile" - :profile-id profile-id) - (delete-teams conn profile-id) - (delete-profile conn profile-id) - true) -