🐛 Fix internal error on ws connect on notification with not existing file.

This commit is contained in:
Andrey Antukh 2020-06-10 09:09:54 +02:00
parent 7fb897a7ad
commit bab73cf4eb
2 changed files with 19 additions and 4 deletions

View file

@ -17,21 +17,33 @@
[ring.middleware.keyword-params :refer [wrap-keyword-params]] [ring.middleware.keyword-params :refer [wrap-keyword-params]]
[ring.middleware.params :refer [wrap-params]] [ring.middleware.params :refer [wrap-params]]
[uxbox.common.spec :as us] [uxbox.common.spec :as us]
[uxbox.db :as db]
[uxbox.http.session :refer [wrap-auth]] [uxbox.http.session :refer [wrap-auth]]
[uxbox.services.notifications :as nf])) [uxbox.services.notifications :as nf]))
(s/def ::file-id ::us/uuid) (s/def ::file-id ::us/uuid)
(s/def ::session-id ::us/uuid) (s/def ::session-id ::us/uuid)
(s/def ::websocket-params (s/def ::websocket-params
(s/keys :req-un [::file-id ::session-id])) (s/keys :req-un [::file-id ::session-id]))
(defn websocket (defn websocket
[{:keys [profile-id] :as req}] [{:keys [profile-id] :as req}]
(let [params (us/conform ::websocket-params (:params req)) (let [params (us/conform ::websocket-params (:params req))
params (assoc params :profile-id profile-id)] file (db/get-by-id db/pool :file (:file-id params))
(if profile-id params (assoc params
(nf/websocket params) :profile-id profile-id
{:error {:code 403 :message "Authentication required"}}))) :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 (def handler
(-> websocket (-> websocket

View file

@ -2,6 +2,9 @@
;; License, v. 2.0. If a copy of the MPL was not distributed with this ;; 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/. ;; 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 ;; Copyright (c) 2020 UXBOX Labs SL
(ns uxbox.services.notifications (ns uxbox.services.notifications