From bab73cf4eb0d72a77ecee2b89aa297cb4c9c144f Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Jun 2020 09:09:54 +0200 Subject: [PATCH] :bug: Fix internal error on ws connect on notification with not existing file. --- backend/src/uxbox/http/ws.clj | 20 ++++++++++++++++---- backend/src/uxbox/services/notifications.clj | 3 +++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/src/uxbox/http/ws.clj b/backend/src/uxbox/http/ws.clj index 03017c669..9772814e9 100644 --- a/backend/src/uxbox/http/ws.clj +++ b/backend/src/uxbox/http/ws.clj @@ -17,21 +17,33 @@ [ring.middleware.keyword-params :refer [wrap-keyword-params]] [ring.middleware.params :refer [wrap-params]] [uxbox.common.spec :as us] + [uxbox.db :as db] [uxbox.http.session :refer [wrap-auth]] [uxbox.services.notifications :as nf])) (s/def ::file-id ::us/uuid) (s/def ::session-id ::us/uuid) + (s/def ::websocket-params (s/keys :req-un [::file-id ::session-id])) (defn websocket [{:keys [profile-id] :as req}] (let [params (us/conform ::websocket-params (:params req)) - params (assoc params :profile-id profile-id)] - (if profile-id - (nf/websocket params) - {:error {:code 403 :message "Authentication required"}}))) + file (db/get-by-id db/pool :file (:file-id params)) + params (assoc params + :profile-id profile-id + :file file)] + + (cond + (not profile-id) + {:error {:code 403 :message "Authentication required"}} + + (not file) + {:error {:code 404 :message "File does not exists"}} + + :else + (nf/websocket params)))) (def handler (-> websocket diff --git a/backend/src/uxbox/services/notifications.clj b/backend/src/uxbox/services/notifications.clj index 4c8073870..69b241397 100644 --- a/backend/src/uxbox/services/notifications.clj +++ b/backend/src/uxbox/services/notifications.clj @@ -2,6 +2,9 @@ ;; 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/. ;; +;; This Source Code Form is "Incompatible With Secondary Licenses", as +;; defined by the Mozilla Public License, v. 2.0. +;; ;; Copyright (c) 2020 UXBOX Labs SL (ns uxbox.services.notifications