0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00

Make profile query work for unauthenticated users.

This commit is contained in:
Andrey Antukh 2020-04-07 16:10:15 +02:00
parent 4465db130d
commit 115ba72572
3 changed files with 43 additions and 41 deletions

View file

@ -17,26 +17,25 @@
[vertx.web :as vw]
[vertx.eventbus :as ve]))
(def mutation-types-hierarchy
(-> (make-hierarchy)
(derive :login ::unauthenticated)
(derive :logout ::unauthenticated)
(derive :register-profile ::unauthenticated)
(derive :request-profile-recovery ::unauthenticated)
(derive :recover-profile ::unauthenticated)
(derive :create-demo-profile ::unauthenticated)))
(def query-types-hierarchy
(make-hierarchy))
(def unauthorized-services
#{:create-demo-profile
:logout
:profile
:recover-profile
:register-profile
:request-profile-recovery
:viewer-bundle
:login})
(defn query-handler
[req]
(let [type (keyword (get-in req [:path-params :type]))
data (merge (:params req)
{::sq/type type
:profile-id (:profile-id req)})]
{::sq/type type})
data (cond-> data
(:profile-id req) (assoc :profile-id (:profile-id req)))]
(if (or (:profile-id req)
(isa? query-types-hierarchy type ::unauthenticated))
(contains? unauthorized-services type))
(-> (sq/handle (with-meta data {:req req}))
(p/then' (fn [result]
{:status 200
@ -51,10 +50,11 @@
data (merge (:params req)
(:body-params req)
(:uploads req)
{::sm/type type
:profile-id (:profile-id req)})]
{::sm/type type})
data (cond-> data
(:profile-id req) (assoc :profile-id (:profile-id req)))]
(if (or (:profile-id req)
(isa? mutation-types-hierarchy type ::unauthenticated))
(contains? unauthorized-services type))
(-> (sm/handle (with-meta data {:req req}))
(p/then' (fn [result]
{:status 200 :body result})))

View file

@ -91,15 +91,6 @@
(db/query-one conn [sql:profile-by-email email]))
;; --- Mutation: Add additional email
;; TODO
;; --- Mutation: Mark email as main email
;; TODO
;; --- Mutation: Verify email (or maybe query?)
;; TODO
;; --- Mutation: Update Profile (own)
(def ^:private sql:update-profile
@ -158,6 +149,7 @@
(update-password conn params)))
;; --- Mutation: Update Photo
(declare upload-photo)

View file

@ -15,6 +15,7 @@
[uxbox.images :as images]
[uxbox.services.queries :as sq]
[uxbox.services.util :as su]
[uxbox.util.uuid :as uuid]
[uxbox.util.blob :as blob]))
;; --- Helpers & Specs
@ -32,11 +33,19 @@
;; --- Query: Profile (own)
(defn retrieve-profile
[conn id]
(let [sql "select * from profile where id=$1 and deleted_at is null"]
(db/query-one db/pool [sql id])))
(declare retrieve-profile)
(declare retrieve-additional-data)
(s/def ::profile
(s/keys :opt-un [::profile-id]))
(sq/defquery ::profile
[{:keys [profile-id] :as params}]
(if profile-id
(db/with-atomic [conn db/pool]
(retrieve-profile conn profile-id))
{:id uuid/zero
:fullname "Anonymous User"}))
;; NOTE: this query make the assumption that union all preserves the
;; order so the first id will always be the team id and the second the
@ -65,18 +74,19 @@
{:default-team-id (:id team)
:default-project-id (:id project)}))))
(s/def ::profile
(s/keys :req-un [::profile-id]))
(defn retrieve-profile-data
[conn id]
(let [sql "select * from profile where id=$1 and deleted_at is null"]
(db/query-one conn [sql id])))
(sq/defquery ::profile
[{:keys [profile-id] :as params}]
(db/with-atomic [conn db/pool]
(p/let [prof (-> (retrieve-profile conn profile-id)
(defn retrieve-profile
[conn id]
(p/let [prof (-> (retrieve-profile-data conn id)
(p/then' su/raise-not-found-if-nil)
(p/then' strip-private-attrs)
(p/then' #(images/resolve-media-uris % [:photo :photo-uri])))
addt (retrieve-additional-data conn profile-id)]
(merge prof addt))))
addt (retrieve-additional-data conn id)]
(merge prof addt)))
;; --- Attrs Helpers