diff --git a/backend/src/app/http/handlers.clj b/backend/src/app/http/handlers.clj index f49e6da45..1f887fea3 100644 --- a/backend/src/app/http/handlers.clj +++ b/backend/src/app/http/handlers.clj @@ -34,8 +34,7 @@ {::sq/type type}) data (cond-> data (:profile-id req) (assoc :profile-id (:profile-id req)))] - (if (or (:profile-id req) - (contains? unauthorized-services type)) + (if (or (:profile-id req) (contains? unauthorized-services type)) {:status 200 :body (sq/handle (with-meta data {:req req}))} {:status 403 @@ -51,18 +50,14 @@ {::sm/type type}) data (cond-> data (:profile-id req) (assoc :profile-id (:profile-id req)))] - (if (or (:profile-id req) - (contains? unauthorized-services type)) - (let [body (sm/handle (with-meta data {:req req}))] - (if (= type :delete-profile) - (do - (some-> (session/extract-auth-token req) - (session/delete)) - {:status 204 - :cookies (session/cookies "" {:max-age -1}) - :body ""}) - {:status 200 - :body body})) + (if (or (:profile-id req) (contains? unauthorized-services type)) + (let [result (sm/handle (with-meta data {:req req})) + mdata (meta result) + resp {:status (if (nil? (seq result)) 204 200) + :body result}] + (cond->> resp + (:transform-response mdata) ((:transform-response mdata) req))) + {:status 403 :body {:type :authentication :code :unauthorized}}))) diff --git a/backend/src/app/http/session.clj b/backend/src/app/http/session.clj index be3384364..75fe605b5 100644 --- a/backend/src/app/http/session.clj +++ b/backend/src/app/http/session.clj @@ -7,6 +7,8 @@ ;; ;; Copyright (c) 2020 UXBOX Labs SL +;; TODO: move to services. + (ns app.http.session (:require [app.db :as db] diff --git a/backend/src/app/services/mutations/profile.clj b/backend/src/app/services/mutations/profile.clj index ee8217979..6ce7a878d 100644 --- a/backend/src/app/services/mutations/profile.clj +++ b/backend/src/app/services/mutations/profile.clj @@ -18,6 +18,7 @@ [app.emails :as emails] [app.media :as media] [app.media-storage :as mst] + [app.http.session :as session] [app.services.mutations :as sm] [app.services.mutations.media :as media-mutations] [app.services.mutations.projects :as projects] @@ -473,7 +474,14 @@ (db/update! conn :profile {:deleted-at (dt/now)} {:id profile-id}) - nil)) + + (with-meta {} + {:transform-response + (fn [request response] + (some-> (session/extract-auth-token request) + (session/delete)) + (assoc response + :cookies (session/cookies "" {:max-age -1})))}))) (def ^:private sql:teams-ownership-check "with teams as (