From 0416082d4d67f109bab8d049fbfb73370b45a9f4 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 28 Feb 2022 12:06:47 +0100 Subject: [PATCH 1/6] :bug: Fix awsns handler, convert it ot async --- backend/src/app/http/awsns.clj | 39 +++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/backend/src/app/http/awsns.clj b/backend/src/app/http/awsns.clj index 11cfe28a8..fdf217db7 100644 --- a/backend/src/app/http/awsns.clj +++ b/backend/src/app/http/awsns.clj @@ -26,25 +26,30 @@ (defmethod ig/init-key ::handler [_ cfg] - (fn [request] - (let [body (parse-json (slurp (:body request))) - mtype (get body "Type")] - (cond - (= mtype "SubscriptionConfirmation") - (let [surl (get body "SubscribeURL") - stopic (get body "TopicArn")] - (l/info :action "subscription received" :topic stopic :url surl) - (http/send! {:uri surl :method :post :timeout 10000})) + (fn [request respond raise] + (try + (let [body (parse-json (slurp (:body request))) + mtype (get body "Type")] + (cond + (= mtype "SubscriptionConfirmation") + (let [surl (get body "SubscribeURL") + stopic (get body "TopicArn")] + (l/info :action "subscription received" :topic stopic :url surl) + (http/send! {:uri surl :method :post :timeout 10000})) - (= mtype "Notification") - (when-let [message (parse-json (get body "Message"))] - (let [notification (parse-notification cfg message)] - (process-report cfg notification))) + (= mtype "Notification") + (when-let [message (parse-json (get body "Message"))] + (let [notification (parse-notification cfg message)] + (process-report cfg notification))) - :else - (l/warn :hint "unexpected data received" - :report (pr-str body))) - {:status 200 :body ""}))) + :else + (l/warn :hint "unexpected data received" + :report (pr-str body)))) + (catch Throwable cause + (l/error :hint "unexpected exception on awsns handler" + :cause cause))) + + (respond {:status 200 :body ""}))) (defn- parse-bounce [data] From dead3138b359274c4b8efd708df4ec60a2d931a5 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 28 Feb 2022 12:07:21 +0100 Subject: [PATCH 2/6] :sparkles: Reduce the size of the default thread pool --- backend/src/app/main.clj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/backend/src/app/main.clj b/backend/src/app/main.clj index b8464c39f..cd3a547f3 100644 --- a/backend/src/app/main.clj +++ b/backend/src/app/main.clj @@ -26,7 +26,7 @@ ;; Default thread pool for IO operations [::default :app.worker/executor] - {:parallelism (cf/get :default-executor-parallelism 120) + {:parallelism (cf/get :default-executor-parallelism 60) :prefix :default} ;; Constrained thread pool. Should only be used from high demand @@ -57,7 +57,6 @@ :app.migrations/all {:main (ig/ref :app.migrations/migrations)} - :app.msgbus/msgbus {:backend (cf/get :msgbus-backend :redis) :redis-uri (cf/get :redis-uri)} From ecd491cd09ee0080918de69cc71ffd7d2437bffe Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 28 Feb 2022 12:07:44 +0100 Subject: [PATCH 3/6] :bug: Don't mark as touched temporal file --- backend/src/app/rpc/mutations/media.clj | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/src/app/rpc/mutations/media.clj b/backend/src/app/rpc/mutations/media.clj index 8cb0bda1d..ed9e8acea 100644 --- a/backend/src/app/rpc/mutations/media.clj +++ b/backend/src/app/rpc/mutations/media.clj @@ -94,7 +94,6 @@ (sto/put-object {:content (sto/content data) :content-type mtype :reference :file-media-object - :touched-at (dt/now) :expired-at (dt/in-future {:minutes 30})})))) ;; NOTE: we use the `on conflict do update` instead of `do nothing` From eb57c2f980a900bf44befddd50d1843f1826a704 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 28 Feb 2022 12:08:05 +0100 Subject: [PATCH 4/6] :lipstick: Cosmetic changes on mutation profile ns --- backend/src/app/rpc/mutations/profile.clj | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/src/app/rpc/mutations/profile.clj b/backend/src/app/rpc/mutations/profile.clj index 944df2fde..4e2d207c8 100644 --- a/backend/src/app/rpc/mutations/profile.clj +++ b/backend/src/app/rpc/mutations/profile.clj @@ -278,7 +278,9 @@ :opt-un [::scope ::invitation-token])) (sv/defmethod ::login - {:auth false ::rlimit/permits (cf/get :rlimit-password)} + {:auth false + ::async/dispatch :default + ::rlimit/permits (cf/get :rlimit-password)} [{:keys [pool session tokens] :as cfg} {:keys [email password] :as params}] (letfn [(check-password [profile password] (when (= (:password profile) "!") From f64b1d3651f206ace2dda62940d68e2f1cf16c6c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 28 Feb 2022 12:08:31 +0100 Subject: [PATCH 5/6] :bug: Properly handle invitations on login --- frontend/src/app/main/data/users.cljs | 56 ++++++++++--------- frontend/src/app/main/ui/auth/login.cljs | 30 +++++++--- frontend/src/app/main/ui/auth/register.cljs | 2 +- .../src/app/main/ui/components/forms.cljs | 1 - 4 files changed, 52 insertions(+), 37 deletions(-) diff --git a/frontend/src/app/main/data/users.cljs b/frontend/src/app/main/data/users.cljs index b4eae4da6..f66c0af21 100644 --- a/frontend/src/app/main/data/users.cljs +++ b/frontend/src/app/main/data/users.cljs @@ -170,13 +170,15 @@ (get-redirect-event)) (rx/observe-on :async))))))) +(s/def ::invitation-token ::us/not-empty-string) (s/def ::login-params - (s/keys :req-un [::email ::password])) + (s/keys :req-un [::email ::password] + :opt-un [::invitation-token])) (declare login-from-register) (defn login - [{:keys [email password] :as data}] + [{:keys [email password invitation-token] :as data}] (us/verify ::login-params data) (ptk/reify ::login ptk/WatchEvent @@ -184,9 +186,10 @@ (let [{:keys [on-error on-success] :or {on-error rx/throw on-success identity}} (meta data) + params {:email email :password password - :scope "webapp"}] + :invitation-token invitation-token}] ;; NOTE: We can't take the profile value from login because ;; there are cases when login is successfull but the cookie is @@ -197,31 +200,32 @@ ;; the returned profile is an NOT authenticated profile, we ;; proceed to logout and show an error message. - (rx/merge - (->> (rp/mutation :login params) - (rx/map fetch-profile) - (rx/catch on-error)) + (->> (rp/mutation :login (d/without-nils params)) + (rx/merge-map (fn [data] + (rx/merge + (rx/of (fetch-profile)) + (->> stream + (rx/filter profile-fetched?) + (rx/take 1) + (rx/map deref) + (rx/filter (complement is-authenticated?)) + (rx/tap on-error) + (rx/map #(ex/raise :type :authentication)) + (rx/observe-on :async)) - (->> stream - (rx/filter profile-fetched?) - (rx/take 1) - (rx/map deref) - (rx/filter (complement is-authenticated?)) - (rx/tap on-error) - (rx/map #(ex/raise :type :authentication)) - (rx/observe-on :async)) + (->> stream + (rx/filter profile-fetched?) + (rx/take 1) + (rx/map deref) + (rx/filter is-authenticated?) + (rx/map (fn [profile] + (with-meta (merge data profile) + {::ev/source "login"}))) + (rx/tap on-success) + (rx/map logged-in) + (rx/observe-on :async))))) + (rx/catch on-error)))))) - (->> stream - (rx/filter profile-fetched?) - (rx/take 1) - (rx/map deref) - (rx/filter is-authenticated?) - (rx/map (fn [profile] - (with-meta profile - {::ev/source "login"}))) - (rx/tap on-success) - (rx/map logged-in) - (rx/observe-on :async))))))) (defn login-from-token [{:keys [profile] :as tdata}] diff --git a/frontend/src/app/main/ui/auth/login.cljs b/frontend/src/app/main/ui/auth/login.cljs index 58d4f97ec..936d5ebb0 100644 --- a/frontend/src/app/main/ui/auth/login.cljs +++ b/frontend/src/app/main/ui/auth/login.cljs @@ -30,9 +30,11 @@ (s/def ::email ::us/email) (s/def ::password ::us/not-empty-string) +(s/def ::invitation-token ::us/not-empty-string) (s/def ::login-form - (s/keys :req-un [::email ::password])) + (s/keys :req-un [::email ::password] + :opt-un [::invitation-token])) (defn- login-with-oauth [event provider params] @@ -62,29 +64,39 @@ (mf/defc login-form [{:keys [params] :as props}] - (let [error (mf/use-state false) - form (fm/use-form :spec ::login-form - :inital {}) + (let [initial (mf/use-memo (mf/deps params) (constantly params)) + + error (mf/use-state false) + form (fm/use-form :spec ::login-form :initial initial) on-error (fn [_] (reset! error (tr "errors.wrong-credentials"))) + on-succes + (fn [data] + (prn "SUCCESS" data) + (when-let [token (:invitation-token data)] + (st/emit! (rt/nav :auth-verify-token {} {:token token})))) + on-submit (mf/use-callback - (mf/deps form) - (fn [_] + (fn [form _event] (reset! error nil) (let [params (with-meta (:clean-data @form) - {:on-error on-error})] + {:on-error on-error + :on-success on-succes})] (st/emit! (du/login params))))) on-submit-ldap (mf/use-callback (mf/deps form) (fn [event] - (let [params (merge (:clean-data @form) params)] - (login-with-ldap event (with-meta params {:on-error on-error})))))] + (reset! error nil) + (let [params (:clean-data @form)] + (login-with-ldap event (with-meta params + {:on-error on-error + :on-success on-succes})))))] [:* (when-let [message @error] diff --git a/frontend/src/app/main/ui/auth/register.cljs b/frontend/src/app/main/ui/auth/register.cljs index c9a2d89a8..84ed3de24 100644 --- a/frontend/src/app/main/ui/auth/register.cljs +++ b/frontend/src/app/main/ui/auth/register.cljs @@ -60,7 +60,7 @@ :email-already-exists (swap! form assoc-in [:errors :email] {:message "errors.email-already-exists"}) - + :email-as-password (swap! form assoc-in [:errors :password] {:message "errors.email-as-password"}) diff --git a/frontend/src/app/main/ui/components/forms.cljs b/frontend/src/app/main/ui/components/forms.cljs index 8d744090b..54022b3fa 100644 --- a/frontend/src/app/main/ui/components/forms.cljs +++ b/frontend/src/app/main/ui/components/forms.cljs @@ -174,7 +174,6 @@ [{:keys [options label form default data-test] :as props :or {default ""}}] (let [input-name (get props :name) - form (or form (mf/use-ctx form-ctx)) value (or (get-in @form [:data input-name]) default) cvalue (d/seek #(= value (:value %)) options) From 1bad233e2f79104a0d1f3e50c11b2c8e26701465 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 28 Feb 2022 12:09:59 +0100 Subject: [PATCH 6/6] :paperclip: Fix linter issues on staging branch --- backend/src/app/http/awsns.clj | 2 +- common/src/app/common/data.cljc | 2 +- common/src/app/common/math.cljc | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/src/app/http/awsns.clj b/backend/src/app/http/awsns.clj index fdf217db7..d4c9eaca4 100644 --- a/backend/src/app/http/awsns.clj +++ b/backend/src/app/http/awsns.clj @@ -26,7 +26,7 @@ (defmethod ig/init-key ::handler [_ cfg] - (fn [request respond raise] + (fn [request respond _] (try (let [body (parse-json (slurp (:body request))) mtype (get body "Type")] diff --git a/common/src/app/common/data.cljc b/common/src/app/common/data.cljc index 9dfba00ad..69e30c6a5 100644 --- a/common/src/app/common/data.cljc +++ b/common/src/app/common/data.cljc @@ -6,7 +6,7 @@ (ns app.common.data "Data manipulation and query helper functions." - (:refer-clojure :exclude [read-string hash-map merge name parse-double group-by]) + (:refer-clojure :exclude [read-string hash-map merge name parse-double group-by iteration]) #?(:cljs (:require-macros [app.common.data])) (:require diff --git a/common/src/app/common/math.cljc b/common/src/app/common/math.cljc index 67a327da8..6b61b3d73 100644 --- a/common/src/app/common/math.cljc +++ b/common/src/app/common/math.cljc @@ -6,6 +6,7 @@ (ns app.common.math "A collection of math utils." + (:refer-clojure :exclude [abs]) #?(:cljs (:require [goog.math :as math])))