Created
January 3, 2015 05:28
-
-
Save xudifsd/914f9f03bf2dfc966835 to your computer and use it in GitHub Desktop.
ACL checker after optimization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn self-is-active? | |
[{{:keys [uid]} :params :as req}] | |
(when-not (nil? uid) | |
(let [user-id (u/->int uid) | |
user (*get-user-by-id* user-id)] | |
(when-not (nil? user) | |
(not (:inactive user)))))) | |
(defn self-belongs-to-team? | |
[{{:keys [uid subdomain]} :params :as req}] | |
(when-not (nil? uid) | |
(let [user-id (u/->int uid) | |
user (*get-user-by-id* user-id) | |
team (*get-team-by-subdomain* subdomain)] | |
(when-not (some nil? [user team]) | |
(= (:team_id user) (:id team)))))) | |
(defn check-permission [checkers handler] | |
(fn [req] | |
(binding [*get-user-by-id* (memoize users/get-user-by-id) | |
*get-team-by-subdomain* (memoize teams/get-team-by-subdomain)] | |
; loop checkers | |
))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment