Merge branch 'master' into try-tailwind
This commit is contained in:
@@ -14,7 +14,8 @@
|
||||
[com.brunobonacci.mulog :as mu]
|
||||
[datomic.api :as dc]
|
||||
[clj-http.client :as client]
|
||||
[auto-ap.solr :as solr]))
|
||||
[auto-ap.solr :as solr]
|
||||
[clojure.set :as set]))
|
||||
|
||||
(def full-read '[*
|
||||
{:client/square-integration-status [:integration-status/message
|
||||
@@ -149,34 +150,48 @@
|
||||
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
(let [name-like-ids (cond (not (str/blank? (:name-like args)))
|
||||
(set (map (comp #(Long/parseLong %) :id)
|
||||
(solr/query solr/impl "clients"
|
||||
{"query" (format "_text_:(%s*)" (str/upper-case (solr/escape (:name-like args))))
|
||||
"fields" "id"
|
||||
"limit" 300})))
|
||||
|
||||
|
||||
(not (str/blank? (:code args)))
|
||||
(merge-query {:query {:in ['?client-code]
|
||||
:where ['[?e :client/code ?client-code]]}
|
||||
:args [(:code args)]})
|
||||
(not (str/blank? (:code args)))
|
||||
(set (map (comp #(Long/parseLong %) :id)
|
||||
(solr/query solr/impl "clients" {"query" (format "_text_:(%s*)" (str/upper-case (solr/escape (:code args))))
|
||||
"fields" "id"
|
||||
"limit" 300})))
|
||||
|
||||
(not (str/blank? (:name-like args)))
|
||||
(merge-query {:query {:in ['?name-like]
|
||||
:where ['[?e :client/name ?name]
|
||||
'[(clojure.string/includes? ?name ?name-like)]]}
|
||||
:args [(:name-like args)]})
|
||||
:else
|
||||
nil)
|
||||
valid-ids (cond
|
||||
(and name-like-ids (limited-clients (:id args)))
|
||||
(set/intersection name-like-ids (limited-clients (:id args)))
|
||||
|
||||
(limited-clients (:id args))
|
||||
(merge-query {:query {:in ['[?e ...]]
|
||||
:where []}
|
||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||
(limited-clients (:id args))
|
||||
(limited-clients (:id args))
|
||||
|
||||
|
||||
(:sort args) (add-sorter-fields {"name" ['[?e :client/name ?sort-name]]}
|
||||
args)
|
||||
name-like-ids
|
||||
name-like-ids
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :client/name ?sort-default]]}}))]
|
||||
:else
|
||||
nil)
|
||||
|
||||
query (cond-> {:query {:find []
|
||||
:in ['$ ]
|
||||
:where []}
|
||||
:args [db]}
|
||||
valid-ids
|
||||
(merge-query {:query {:in ['[?e ...]]}
|
||||
:args [(set valid-ids)]})
|
||||
|
||||
|
||||
(:sort args) (add-sorter-fields {"name" ['[?e :client/name ?sort-name]]}
|
||||
args)
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e] :where ['[?e :client/name ?sort-default]]}}))]
|
||||
(->> (query2 query)
|
||||
(apply-sort-3 (update args :sort conj {:sort-key "default-2" :asc true}))
|
||||
(apply-pagination args))))
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
(ns auto-ap.datomic.users
|
||||
(:require
|
||||
[auto-ap.datomic :refer [conn]]
|
||||
[datomic.api :as dc]))
|
||||
[datomic.api :as dc]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn add-arg [query name value where & rest]
|
||||
(let [query (-> query
|
||||
@@ -19,27 +20,27 @@
|
||||
(map #(update % :user/role :db/ident))
|
||||
first))
|
||||
|
||||
(defn find-or-insert! [{:keys [:user/provider :user/provider-id] :as new-user}]
|
||||
|
||||
(defn find-or-insert! [{:keys [:user/provider :user/provider-id ] :as new-user}]
|
||||
(let [is-first-user? (not (seq (dc/q [:find '?e
|
||||
:in '$
|
||||
:where '[?e :user/provider]]
|
||||
(dc/db conn))))
|
||||
user (some-> (dc/q [:find '(pull ?e [*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}])
|
||||
:in '$ '?provider '?provider-id
|
||||
:where '[?e :user/provider ?provider]
|
||||
'[?e :user/provider-id ?provider-id]]
|
||||
(dc/db conn) provider provider-id)
|
||||
first
|
||||
first
|
||||
(update :user/role :db/ident))]
|
||||
(if user
|
||||
user
|
||||
(let [new-user-trans @(dc/transact conn [(cond-> new-user
|
||||
true (assoc :db/id "user")
|
||||
is-first-user? (assoc :user/role :user-role/admin))])]
|
||||
(get-by-id (-> new-user-trans :tempids (get "user")))))))
|
||||
user-id (ffirst (dc/q '[:find ?e
|
||||
:in $ ?provider ?provider-id
|
||||
:where [?e :user/provider ?provider]
|
||||
[?e :user/provider-id ?provider-id]]
|
||||
(dc/db conn) provider provider-id))
|
||||
result @(dc/transact conn [[:upsert-entity (cond-> (assoc new-user :db/id (or user-id "user"))
|
||||
(not user-id) (assoc :user/role :user-role/none)
|
||||
is-first-user? (assoc :user/role :user-role/admin))]])
|
||||
user-id (or user-id (get-in result [:tempids "user"]))]
|
||||
(update (dc/pull (dc/db conn)
|
||||
'[*
|
||||
{:user/clients [*]}
|
||||
{:user/role [:db/ident]}]
|
||||
user-id)
|
||||
:user/role :db/ident)))
|
||||
|
||||
(defn raw-graphql [_]
|
||||
(->> (dc/q {:find ['(pull ?e [*
|
||||
|
||||
@@ -236,6 +236,8 @@
|
||||
:user
|
||||
{:fields {:id {:type :id}
|
||||
:name {:type 'String}
|
||||
:profile_image_url {:type 'String}
|
||||
:email {:type 'String}
|
||||
:role {:type :role}
|
||||
:clients {:type '(list :client)}}}
|
||||
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
[clj-http.client :as http]
|
||||
[clj-time.core :as time]
|
||||
[clojure.tools.logging :as log]
|
||||
[config.core :refer [env]]))
|
||||
[config.core :refer [env]]
|
||||
[com.brunobonacci.mulog :as mu]))
|
||||
|
||||
(def google-client-id "264081895820-0nndcfo3pbtqf30sro82vgq5r27h8736.apps.googleusercontent.com")
|
||||
(def google-client-secret "OC-WemHurPXYpuIw5cT-B90g")
|
||||
@@ -30,13 +31,17 @@
|
||||
"grant_type" "authorization_code"}
|
||||
:as :json})
|
||||
:body)
|
||||
|
||||
token (:access_token auth)
|
||||
profile (-> (http/get "https://www.googleapis.com/oauth2/v1/userinfo"
|
||||
{:headers {"Authorization" (str "Bearer " token)} :as :json})
|
||||
:body)
|
||||
_ (mu/log ::got-profile
|
||||
:profile profile)
|
||||
user (users/find-or-insert! {:user/provider "google"
|
||||
:user/provider-id (:id profile)
|
||||
:user/role :user-role/none
|
||||
:user/email (:email profile)
|
||||
:user/profile-image-url (:picture profile)
|
||||
:user/name (:name profile)})
|
||||
auth {:user (:name profile)
|
||||
:exp (time/plus (time/now) (time/days 30))
|
||||
@@ -45,8 +50,8 @@
|
||||
(:user/clients user))
|
||||
:user/role (name (:user/role user))
|
||||
:user/name (:name profile)}
|
||||
]
|
||||
(log/info "authenticated as user" user)
|
||||
_ (mu/log ::logged-in-as
|
||||
:auth auth)]
|
||||
;; TODO - these namespaces are not being transmitted/deserialized properly
|
||||
|
||||
(if (and token user)
|
||||
|
||||
@@ -37,6 +37,8 @@
|
||||
:owns-state {:single ::page}
|
||||
:query-obj {:venia/queries [[:user
|
||||
[:name
|
||||
:profile_image_url
|
||||
:email
|
||||
:id
|
||||
:role
|
||||
[:clients [:id :name]]]]]}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
[grid/header
|
||||
[grid/row {}
|
||||
[grid/header-cell {} "User"]
|
||||
[grid/header-cell {} "Email"]
|
||||
[grid/header-cell {} "Role"]
|
||||
[grid/header-cell {} "Clients"]
|
||||
[grid/header-cell {:style {:width (action-cell-width 1)}} ]]]
|
||||
@@ -36,7 +37,16 @@
|
||||
(for [{:keys [id name role clients] :as c} (:data page)]
|
||||
^{:key (str name "-" id )}
|
||||
[grid/row {:class (:class c) :id id}
|
||||
[grid/cell {} name]
|
||||
[grid/cell {}
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
(when-let [url (:profile-image-url c)]
|
||||
[:div.level-item
|
||||
[:figure.image.is-24x24
|
||||
[:img.is-rounded {:src url
|
||||
:referrer-policy= "no-referrer" }]]])
|
||||
[:div.level-item name]]]]
|
||||
[grid/cell {} (:email c)]
|
||||
[grid/cell {} role]
|
||||
[grid/cell {} (str/join ", " (map :name clients))]
|
||||
[grid/cell {}
|
||||
|
||||
Reference in New Issue
Block a user