graphql mutations are locked by user type.

This commit is contained in:
BC
2018-07-10 22:13:53 -07:00
parent e0ba9395ef
commit 9189c820d7
5 changed files with 26 additions and 11 deletions

View File

@@ -1,5 +1,6 @@
(ns auto-ap.graphql.utils
(:require [clojure.string :as str]
[buddy.auth :refer [throw-unauthorized]]
[clojure.walk :as walk]))
@@ -38,3 +39,16 @@
:else
node))
m))
(defn assert-admin [id]
(when-not (= "admin" (:role id))
(throw-unauthorized)))
(defn can-see-company? [identity company]
(or (= "admin" (:role identity))
((set (:companies identity)) (:id company))))
(defn assert-can-see-company [identity company]
(when-not (can-see-company? identity company)
(throw-unauthorized)))