Skip to content

Commit

Permalink
stuff in regards to redirect after login
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaai committed Feb 25, 2020
1 parent 63882a4 commit 13eb063
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion client/leihs-ui
2 changes: 1 addition & 1 deletion server/shared-clj
41 changes: 26 additions & 15 deletions server/src/all/leihs/procurement/authorization.clj
@@ -1,8 +1,12 @@
(ns leihs.procurement.authorization
(:require [clojure.tools.logging :as log]
[leihs.core.core :refer [presence]]
[leihs.core.sign-in.external-authentication.back :as ext-auth]
[leihs.procurement.env :as env]
[leihs.procurement.paths :refer [path]]
[leihs.procurement.permissions.user :as user-perms]
[leihs.procurement.graphql.helpers :as helpers])
[leihs.procurement.graphql.helpers :as helpers]
[ring.util.response :as response])
(:import leihs.procurement.UnauthorizedException))

(defn wrap-ensure-one-of
Expand Down Expand Up @@ -51,27 +55,34 @@
#(check context args value))))

(def skip-authorization-handler-keys
[:attachment
:image
:home ; leads to not-found-handler
:not-found ; leads to not-found-handler
:procurement ; leads to not-found-handler
:sign-in
:status
:upload])
(clojure.set/union #{:attachment
:image
:sign-in
:status
:upload}
ext-auth/skip-authorization-handler-keys))

(defn- skip?
[handler-key]
(some #(= handler-key %) skip-authorization-handler-keys))

(defn wrap-authenticate
[handler]
(fn [request]
(if (or (skip? (:handler-key request)) (:authenticated-entity request))
(handler request)
{:status 401,
:body (helpers/error-as-graphql-object "NOT_AUTHENTICATED"
"Not authenticated!")})))
(fn [{:keys [uri query-string handler-key] :as request}]
(cond
(or (skip? handler-key) (:authenticated-entity request))
(handler request)
(= handler-key :graphql)
{:status 401,
:body (helpers/error-as-graphql-object "NOT_AUTHENTICATED"
"Not authenticated!")}
:else
(response/redirect
(path :sign-in
nil
{:return-to (cond-> uri
(presence query-string)
(str "?" query-string))})))))

(defn wrap-authorize
[handler]
Expand Down
1 change: 0 additions & 1 deletion server/src/all/leihs/procurement/routes.clj
Expand Up @@ -143,7 +143,6 @@
wrap-empty
(wrap-secret-byte-array secret)
datasource/wrap
(wrap-graphiql {:path "/procure/graphiql", :endpoint "/procure/graphql"})
core-routing/wrap-canonicalize-params-maps
wrap-params
wrap-multipart-params
Expand Down
3 changes: 1 addition & 2 deletions spec/shared/common.steps.rb
Expand Up @@ -48,8 +48,7 @@
end

step "I log in with the email :email" do |email|
visit '/'
click_on 'Login'
visit '/sign-in'
within('.ui-form-signin') do
step "I enter '#{email}' in the 'user' field"
find('button[type="submit"]').click
Expand Down

0 comments on commit 13eb063

Please sign in to comment.