193 get rid of passing user-id

This commit is contained in:
Ivan Grishaev 2018-02-07 11:33:48 +03:00
parent a0073b295e
commit a61885d5be
3 changed files with 6 additions and 12 deletions

View File

@ -226,18 +226,13 @@
(POST "/" [] (POST "/" []
:auth-rules authenticated? :auth-rules authenticated?
:current-user user :current-user user
:body [body {:user-id s/Int :body [body {(s/optional-key :address) s/Str
(s/optional-key :address) s/Str
(s/optional-key :is_hidden) s/Bool}] (s/optional-key :is_hidden) s/Bool}]
:summary "Updates user's fields." :summary "Updates user's fields."
(let [{:keys [user-id]} body (let [user-id (:id user)
fields (select-keys body [:address :is_hidden])] fields (select-keys body [:address :is_hidden])]
(when-not (= (:id user) user-id)
(log/debugf "User %s tries to update user's %s fields" (:id user) user-id)
(forbidden! (format "Cannot access a user %s" user-id)))
(when (empty? fields) (when (empty? fields)
(bad-request! "No incoming fields were found.")) (bad-request! "No incoming fields were found."))

View File

@ -325,7 +325,7 @@
(reg-event-fx (reg-event-fx
:save-user-fields :save-user-fields
(fn [{:keys [db]} [_ user-id fields]] (fn [{:keys [db]} [_ fields]]
{:dispatch [:set-updating-user] {:dispatch [:set-updating-user]
:http {:method POST :http {:method POST
:url "/api/user" :url "/api/user"
@ -338,7 +338,7 @@
:error :error
(:response %)]) (:response %)])
:finally #(dispatch [:clear-updating-user]) :finally #(dispatch [:clear-updating-user])
:params (merge {:user-id user-id} fields)}})) :params fields}}))
(reg-event-db (reg-event-db

View File

@ -7,7 +7,6 @@
(defn update-address-page [] (defn update-address-page []
(let [db (rf/subscribe [:db]) (let [db (rf/subscribe [:db])
user (rf/subscribe [:user])
updating-user (rf/subscribe [:get-in [:updating-user]]) updating-user (rf/subscribe [:get-in [:updating-user]])
address (r/atom @(rf/subscribe [:get-in [:user :address]])) address (r/atom @(rf/subscribe [:get-in [:user :address]]))
hidden (rf/subscribe [:get-in [:user :is_hidden]])] hidden (rf/subscribe [:get-in [:user :is_hidden]])]
@ -35,7 +34,7 @@
:max-length 42}]])] :max-length 42}]])]
[:button [:button
(merge {:on-click (merge {:on-click
#(rf/dispatch [:save-user-fields (:id @user) {:address @address}]) #(rf/dispatch [:save-user-fields {:address @address}])
:class (str "ui button small update-address-button" :class (str "ui button small update-address-button"
(when @updating-user (when @updating-user
" busy loading"))}) " busy loading"))})
@ -52,6 +51,6 @@
:on-change :on-change
(fn [e] (fn [e]
(let [value (-> e .-target .-checked)] (let [value (-> e .-target .-checked)]
(rf/dispatch [:save-user-fields (:id @user) {:is_hidden value}])))}] (rf/dispatch [:save-user-fields {:is_hidden value}])))}]
[:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]])))) [:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]]]))))