<commit_before>(ns cadence.security
  (:require [cemerick.friend :as friend]
            (cemerick.friend [workflows :as workflows]
                             [credentials :as creds])
            [cadence.model.flash :as flash]
            [noir.response :as resp]
            [cadence.model :as model]))

;; Describe user, admin hierarchy.
(derive ::admin ::user)

(def friend-settings
  {:credential-fn (partial creds/bcrypt-credential-fn model/get-user)
   :workflows [(workflows/interactive-form)]
   :login-uri "/login"
   :unauthorized-redirect-uri "/login"
   :default-landing-uri "/"})

(defn wrap-anonymous-only
  "If the user is not anonymous redirect them to his/her profile."
  [handler & message]
  (if (friend/anonymous?)
    handler
    (fn [request]
      (flash/put! :warning message)
      (resp/redirect "/user/profile"))))

(defn admin?
  "Return the role (not nil so its true) that isa? admin."
  ([user] (some #(isa? % ::admin) (:roles user)))
  ([] (admin? (model/get-auth))))<commit_msg>Admin can only be true if someone is logged in.<commit_after>(ns cadence.security
  (:require [cemerick.friend :as friend]
            (cemerick.friend [workflows :as workflows]
                             [credentials :as creds])
            [cadence.model.flash :as flash]
            [noir.response :as resp]
            [cadence.model :as model]))

;; Describe user, admin hierarchy.
(derive ::admin ::user)

(def friend-settings
  {:credential-fn (partial creds/bcrypt-credential-fn model/get-user)
   :workflows [(workflows/interactive-form)]
   :login-uri "/login"
   :unauthorized-redirect-uri "/login"
   :default-landing-uri "/"})

(defn wrap-anonymous-only
  "If the user is not anonymous redirect them to his/her profile."
  [handler & message]
  (if (friend/anonymous?)
    handler
    (fn [request]
      (flash/put! :warning message)
      (resp/redirect "/user/profile"))))

(defn admin?
  "Return the role (not nil so its true) that isa? admin."
  ([user] (some #(isa? % ::admin) (:roles user)))
  ([] (when (model/identity)
        (admin? (model/get-auth)))))
{'fraction_non_alphanumeric': 0.14818355640535372, 'fraction_numerical': 0.0, 'mean_word_length': 2.890334572490706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3361734', 'n_tokens_mistral': 688, 'n_tokens_neox': 673, 'n_words': 186}