Makes multiple client selection somewhat possible via graphql.
This commit is contained in:
15
notes.txt
15
notes.txt
@@ -1 +1,16 @@
|
|||||||
4. Maybe make dark mode persist
|
4. Maybe make dark mode persist
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# Implement multi
|
||||||
|
# test headers->clients
|
||||||
|
# Still use single client in subs, but have it only be set if a single on is selected
|
||||||
|
X Pass X-Clients header as :all :mine [id-1, id-2, id-3]
|
||||||
|
X Use X-Clients instead of client filter
|
||||||
|
# Remove the client specific filter from each graphql
|
||||||
|
# Test with single client user, all client user, admin, etc
|
||||||
|
# Synchronize with the backend for SSR, set in session, but hydrate to real clients in middleware
|
||||||
|
# Ensure that client selection still resets everything
|
||||||
|
# maybe set it up so that changing assignments works automatically without having to log out or in
|
||||||
|
# figure out how to not make this require a whole login
|
||||||
|
# bulk-code-transactions
|
||||||
|
|||||||
@@ -40,15 +40,13 @@
|
|||||||
([db args]
|
([db args]
|
||||||
(let [check-number-like (try (Long/parseLong (:check-number-like args)) (catch Exception _ nil))
|
(let [check-number-like (try (Long/parseLong (:check-number-like args)) (catch Exception _ nil))
|
||||||
query (if (:exact-match-id args)
|
query (if (:exact-match-id args)
|
||||||
(cond-> {:query {:find '[?e]
|
{:query {:find '[?e]
|
||||||
:in '[$ ?e]
|
:in '[$ ?e [?c ...]]
|
||||||
:where '[[?e :payment/client ?c]]}
|
:where '[[?e :payment/client ?c]]}
|
||||||
:args [db
|
:args [db
|
||||||
(:exact-match-id args)]}
|
(:exact-match-id args)
|
||||||
(limited-clients (:id args))
|
(map :db/id (:clients args))]
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
}
|
||||||
:where ['[?e :payment/client ?xx]]}
|
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
|
||||||
(cond-> {:query {:find []
|
(cond-> {:query {:find []
|
||||||
:in ['$]
|
:in ['$]
|
||||||
:where []}
|
:where []}
|
||||||
@@ -69,10 +67,10 @@
|
|||||||
:where []}
|
:where []}
|
||||||
:args [(:exact-match-id args)]})
|
:args [(:exact-match-id args)]})
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(seq (:clients args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :payment/client ?xx]]}
|
:where ['[?e :payment/client ?xx]]}
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
:args [(map :db/id (:clients args))]})
|
||||||
|
|
||||||
|
|
||||||
(:client-id args)
|
(:client-id args)
|
||||||
|
|||||||
@@ -165,18 +165,20 @@
|
|||||||
|
|
||||||
:else
|
:else
|
||||||
nil)
|
nil)
|
||||||
valid-ids (cond
|
matching-ids (cond
|
||||||
(and name-like-ids (limited-clients (:id args)))
|
(and name-like-ids (limited-clients (:id args)))
|
||||||
(set/intersection name-like-ids (limited-clients (:id args)))
|
(set/intersection name-like-ids (limited-clients (:id args)))
|
||||||
|
|
||||||
(limited-clients (:id args))
|
|
||||||
(limited-clients (:id args))
|
|
||||||
|
|
||||||
name-like-ids
|
name-like-ids
|
||||||
name-like-ids
|
name-like-ids
|
||||||
|
|
||||||
:else
|
:else
|
||||||
nil)
|
nil)
|
||||||
|
valid-ids (if matching-ids
|
||||||
|
(set/intersection (set (map :db/id (:clients args)))
|
||||||
|
matching-ids)
|
||||||
|
(set (map :db/id (:clients args))))
|
||||||
|
|
||||||
|
|
||||||
query (cond-> {:query {:find []
|
query (cond-> {:query {:find []
|
||||||
:in ['$ ]
|
:in ['$ ]
|
||||||
|
|||||||
@@ -38,10 +38,10 @@
|
|||||||
"fee" ['[?e :expected-deposit/fee ?sort-fee]]}
|
"fee" ['[?e :expected-deposit/fee ?sort-fee]]}
|
||||||
args)
|
args)
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(seq (:clients args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :expected-deposit/client ?xx]]}
|
:where ['[?e :expected-deposit/client ?xx]]}
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
:args [(set (map :db/id (:clients args)))]})
|
||||||
|
|
||||||
(:exact-match-id args)
|
(:exact-match-id args)
|
||||||
(merge-query {:query {:in ['?e]
|
(merge-query {:query {:in ['?e]
|
||||||
|
|||||||
@@ -49,24 +49,21 @@
|
|||||||
([db args]
|
([db args]
|
||||||
(let [query
|
(let [query
|
||||||
(if (:exact-match-id args)
|
(if (:exact-match-id args)
|
||||||
(cond-> {:query {:find '[?e]
|
{:query {:find '[?e]
|
||||||
:in '[$ ?e]
|
:in '[$ ?e [?c ...]]
|
||||||
:where '[[?e :invoice/client ?c]]}
|
:where '[[?e :invoice/client ?c]]}
|
||||||
:args [db
|
:args [db
|
||||||
(:exact-match-id args)]}
|
(:exact-match-id args)
|
||||||
(limited-clients (:id args))
|
(map :db/id (:clients args))]}
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
|
||||||
:where ['[?e :invoice/client ?xx]]}
|
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
|
||||||
(cond-> {:query {:find []
|
(cond-> {:query {:find []
|
||||||
:in ['$]
|
:in ['$]
|
||||||
:where ['[?e :invoice/client]]}
|
:where ['[?e :invoice/client]]}
|
||||||
:args [db]}
|
:args [db]}
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(seq (:clients args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :invoice/client ?xx]]}
|
:where ['[?e :invoice/client ?xx]]}
|
||||||
:args [ (set (map :db/id (limited-clients (:id args))))]})
|
:args [ (map :db/id (:clients args))]})
|
||||||
(:client-id args)
|
(:client-id args)
|
||||||
(merge-query {:query {:in ['?client-id]
|
(merge-query {:query {:in ['?client-id]
|
||||||
:where ['[?e :invoice/client ?client-id]]}
|
:where ['[?e :invoice/client ?client-id]]}
|
||||||
@@ -87,14 +84,14 @@
|
|||||||
(string? (:original-id args)) Long/parseLong )]})
|
(string? (:original-id args)) Long/parseLong )]})
|
||||||
|
|
||||||
(:start (:date-range args)) (merge-query {:query {:in '[?start-date]
|
(:start (:date-range args)) (merge-query {:query {:in '[?start-date]
|
||||||
:where ['[?e :invoice/date ?date]
|
:where ['[?e :invoice/date ?date]
|
||||||
'[(>= ?date ?start-date)]]}
|
'[(>= ?date ?start-date)]]}
|
||||||
:args [(coerce/to-date (:start (:date-range args)))]})
|
:args [(coerce/to-date (:start (:date-range args)))]})
|
||||||
|
|
||||||
(:end (:date-range args)) (merge-query {:query {:in '[?end-date]
|
(:end (:date-range args)) (merge-query {:query {:in '[?end-date]
|
||||||
:where ['[?e :invoice/date ?date]
|
:where ['[?e :invoice/date ?date]
|
||||||
'[(<= ?date ?end-date)]]}
|
'[(<= ?date ?end-date)]]}
|
||||||
:args [(coerce/to-date (:end (:date-range args)))]})
|
:args [(coerce/to-date (:end (:date-range args)))]})
|
||||||
|
|
||||||
(:start (:due-range args)) (merge-query {:query {:in '[?start-due]
|
(:start (:due-range args)) (merge-query {:query {:in '[?start-due]
|
||||||
:where ['[?e :invoice/due ?due]
|
:where ['[?e :invoice/due ?due]
|
||||||
|
|||||||
@@ -16,24 +16,21 @@
|
|||||||
(defn raw-graphql-ids [db args]
|
(defn raw-graphql-ids [db args]
|
||||||
(let [query
|
(let [query
|
||||||
(if (:exact-match-id args)
|
(if (:exact-match-id args)
|
||||||
(cond-> {:query {:find '[?e]
|
{:query {:find '[?e]
|
||||||
:in '[$ ?e]
|
:in '[$ ?e [?c ...]]
|
||||||
:where '[[?e :journal-entry/client ?c]]}
|
:where '[[?e :journal-entry/client ?c]]}
|
||||||
:args [db
|
:args [db
|
||||||
(:exact-match-id args)]}
|
(:exact-match-id args)
|
||||||
(limited-clients (:id args))
|
(map :db/id (:clients args))]}
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
|
||||||
:where ['[?e :journal-entry/client ?xx]]}
|
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
|
||||||
(cond-> {:query {:find []
|
(cond-> {:query {:find []
|
||||||
:in ['$ ]
|
:in ['$ ]
|
||||||
:where []}
|
:where []}
|
||||||
:args [db]}
|
:args [db]}
|
||||||
|
|
||||||
(:client-id args)
|
(seq (:clients args))
|
||||||
(merge-query {:query {:in ['?client-id]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :journal-entry/client ?client-id]]}
|
:where ['[?e :journal-entry/client ?xx]]}
|
||||||
:args [(:client-id args)]})
|
:args [(set (map :db/id (:clients args)))]})
|
||||||
|
|
||||||
(:only-external args)
|
(:only-external args)
|
||||||
(merge-query {:query {:where ['(not [?e :journal-entry/original-entity ])]}})
|
(merge-query {:query {:where ['(not [?e :journal-entry/original-entity ])]}})
|
||||||
@@ -86,7 +83,7 @@
|
|||||||
'[(>= ?c ?from-numeric-code)]
|
'[(>= ?c ?from-numeric-code)]
|
||||||
'[(<= ?c ?to-numeric-code)]]}
|
'[(<= ?c ?to-numeric-code)]]}
|
||||||
:args [(vec (for [{:keys [from to]} (:numeric-code args)]
|
:args [(vec (for [{:keys [from to]} (:numeric-code args)]
|
||||||
[(or from 0) (or to 99999)]))]})
|
[(or from 0) (or to 99999)]))]})
|
||||||
|
|
||||||
|
|
||||||
(:amount-gte args)
|
(:amount-gte args)
|
||||||
@@ -127,10 +124,10 @@
|
|||||||
:where ['[?e :journal-entry/client ?xx]]}
|
:where ['[?e :journal-entry/client ?xx]]}
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
:args [(set (map :db/id (limited-clients (:id args))))]})
|
||||||
(:sort args) (add-sorter-fields {"client" ['[?e :journal-entry/client ?c]
|
(:sort args) (add-sorter-fields {"client" ['[?e :journal-entry/client ?c]
|
||||||
'[?c :client/name ?sort-client]]
|
'[?c :client/name ?sort-client]]
|
||||||
"date" ['[?e :journal-entry/date ?sort-date]]
|
"date" ['[?e :journal-entry/date ?sort-date]]
|
||||||
"vendor" ['[?e :journal-entry/vendor ?v]
|
"vendor" ['[?e :journal-entry/vendor ?v]
|
||||||
'[?v :vendor/name ?sort-vendor]]
|
'[?v :vendor/name ?sort-vendor]]
|
||||||
"amount" ['[?e :journal-entry/amount ?sort-amount]]
|
"amount" ['[?e :journal-entry/amount ?sort-amount]]
|
||||||
"external-id" ['[?e :journal-entry/external-id ?sort-external-id]]
|
"external-id" ['[?e :journal-entry/external-id ?sort-external-id]]
|
||||||
"source" ['[?e :journal-entry/source ?sort-source]]}
|
"source" ['[?e :journal-entry/source ?sort-source]]}
|
||||||
|
|||||||
@@ -21,10 +21,10 @@
|
|||||||
:args [db]}
|
:args [db]}
|
||||||
|
|
||||||
|
|
||||||
(:client-id args)
|
(seq (:clients args))
|
||||||
(merge-query {:query {:in ['?client-id]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :report/client ?client-id]]}
|
:where ['[?e :report/client ?xx]]}
|
||||||
:args [(:client-id args)]})
|
:args [(set (map :db/id (:clients args)))]})
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(limited-clients (:id args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
{:charge/processor [:db/ident]} {:expected-deposit/_charges [:db/id]}]}])
|
{:charge/processor [:db/ident]} {:expected-deposit/_charges [:db/id]}]}])
|
||||||
|
|
||||||
(defn raw-graphql-ids [db args]
|
(defn raw-graphql-ids [db args]
|
||||||
(let [visible-clients (visible-clients (:id args))
|
(let [visible-clients (set (map :db/id (:clients args)))
|
||||||
selected-clients (->> (cond
|
selected-clients (->> (cond
|
||||||
(:client-id args)
|
(:client-id args)
|
||||||
(set/intersection #{(:client-id args)}
|
(set/intersection #{(:client-id args)}
|
||||||
|
|||||||
@@ -50,15 +50,10 @@
|
|||||||
"amount-gte" ['[?e :transaction-rule/amount-gte ?sort-amount-gte]]}
|
"amount-gte" ['[?e :transaction-rule/amount-gte ?sort-amount-gte]]}
|
||||||
args)
|
args)
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(seq (:clients args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :transaction-rule/client ?xx]]}
|
:where ['[?e :transaction-rule/client ?xx]]}
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
:args [(set (map :db/id (:clients args)))]})
|
||||||
|
|
||||||
(:client-id args)
|
|
||||||
(merge-query {:query {:in ['?client-id]
|
|
||||||
:where ['[?e :transaction-rule/client ?client-id]]}
|
|
||||||
:args [(:client-id args)]})
|
|
||||||
|
|
||||||
(:vendor-id args)
|
(:vendor-id args)
|
||||||
(merge-query {:query {:in ['?vendor-id]
|
(merge-query {:query {:in ['?vendor-id]
|
||||||
|
|||||||
@@ -45,14 +45,11 @@
|
|||||||
query
|
query
|
||||||
(if (:exact-match-id args)
|
(if (:exact-match-id args)
|
||||||
(cond-> {:query {:find '[?e]
|
(cond-> {:query {:find '[?e]
|
||||||
:in '[$ ?e]
|
:in '[$ ?e [?c ...]]
|
||||||
:where '[[?e :transaction/client ?c]]}
|
:where '[[?e :transaction/client ?c]]}
|
||||||
:args [db
|
:args [db
|
||||||
(:exact-match-id args)]}
|
(:exact-match-id args)
|
||||||
(limited-clients (:id args))
|
(map :db/id (:clients args))]})
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
|
||||||
:where ['[?e :transaction/client ?xx]]}
|
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]}))
|
|
||||||
(cond-> {:query {:find []
|
(cond-> {:query {:find []
|
||||||
:in ['$ ]
|
:in ['$ ]
|
||||||
:where []}
|
:where []}
|
||||||
@@ -62,10 +59,10 @@
|
|||||||
(merge-query {:query {:in '[[?e ...]]}
|
(merge-query {:query {:in '[[?e ...]]}
|
||||||
:args [potential-duplicates]})
|
:args [potential-duplicates]})
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(seq (:clients args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :transaction/client ?xx]]}
|
:where ['[?e :transaction/client ?xx]]}
|
||||||
:args [(set (map :db/id (limited-clients (:id args))))]})
|
:args [(set (map :db/id (:clients args)))]})
|
||||||
|
|
||||||
(:bank-account-id args)
|
(:bank-account-id args)
|
||||||
(merge-query {:query {:in ['?bank-account-id]
|
(merge-query {:query {:in ['?bank-account-id]
|
||||||
|
|||||||
@@ -23,10 +23,10 @@
|
|||||||
:where ['[?e :yodlee-provider-account/id]]}
|
:where ['[?e :yodlee-provider-account/id]]}
|
||||||
:args [db]}
|
:args [db]}
|
||||||
|
|
||||||
(limited-clients (:id args))
|
(seq (:clients args))
|
||||||
(merge-query {:query {:in ['[?xx ...]]
|
(merge-query {:query {:in ['[?xx ...]]
|
||||||
:where ['[?e :yodlee-provider-account/client ?xx]]}
|
:where ['[?e :yodlee-provider-account/client ?xx]]}
|
||||||
:args [ (set (map :db/id (limited-clients (:id args))))]})
|
:args [(set (map :db/id (:clients args)))]})
|
||||||
|
|
||||||
(:client-id args)
|
(:client-id args)
|
||||||
(merge-query {:query {:in ['?client-id]
|
(merge-query {:query {:in ['?client-id]
|
||||||
|
|||||||
@@ -862,7 +862,9 @@
|
|||||||
(lc/with-context {:query q}
|
(lc/with-context {:query q}
|
||||||
(log/info "executing query name" (query-name q))
|
(log/info "executing query name" (query-name q))
|
||||||
(try
|
(try
|
||||||
(let [[result time] (time-it (simplify (execute schema q v {:id id})))]
|
(let [[result time] (time-it (simplify (execute schema q (dissoc v
|
||||||
|
:clients) {:id id
|
||||||
|
:clients (:clients v)})))]
|
||||||
(info-event "Query completed"
|
(info-event "Query completed"
|
||||||
{:time (:time time)
|
{:time (:time time)
|
||||||
:errors (seq (:errors result))})
|
:errors (seq (:errors result))})
|
||||||
|
|||||||
@@ -433,7 +433,7 @@
|
|||||||
(let [[payments checks-count] (d-checks/get-graphql (-> args
|
(let [[payments checks-count] (d-checks/get-graphql (-> args
|
||||||
:filters
|
:filters
|
||||||
(<-graphql)
|
(<-graphql)
|
||||||
(assoc :id (:id context))
|
(assoc :clients (:clients context))
|
||||||
(update :payment-type enum->keyword "payment-type")
|
(update :payment-type enum->keyword "payment-type")
|
||||||
(update :status enum->keyword "payment-status")))]
|
(update :status enum->keyword "payment-status")))]
|
||||||
|
|
||||||
@@ -557,10 +557,10 @@
|
|||||||
|
|
||||||
(defn void-payments [context args _]
|
(defn void-payments [context args _]
|
||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :clients (:clients context))
|
||||||
ids (some-> args
|
ids (some-> args
|
||||||
:filters
|
:filters
|
||||||
(assoc :id (:id context))
|
(assoc :clients (:clients context))
|
||||||
(<-graphql)
|
(<-graphql)
|
||||||
(update :payment-type enum->keyword "payment-type")
|
(update :payment-type enum->keyword "payment-type")
|
||||||
(update :status enum->keyword "payment-status")
|
(update :status enum->keyword "payment-status")
|
||||||
|
|||||||
@@ -221,7 +221,7 @@
|
|||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[clients clients-count] (d-clients/get-graphql-page (assoc (<-graphql (:filters args))
|
[clients clients-count] (d-clients/get-graphql-page (assoc (<-graphql (:filters args))
|
||||||
:id (:id context)))
|
:clients (:clients context)))
|
||||||
clients (->> clients
|
clients (->> clients
|
||||||
|
|
||||||
(map (fn [c]
|
(map (fn [c]
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
(first (d-expected-deposit/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
|
(first (d-expected-deposit/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE)))))
|
||||||
|
|
||||||
(defn get-expected-deposit-page [context args _]
|
(defn get-expected-deposit-page [context args _]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :clients (:clients context))
|
||||||
[expected-deposits expected-deposit-count] (d-expected-deposit/get-graphql (<-graphql args))
|
[expected-deposits expected-deposit-count] (d-expected-deposit/get-graphql (<-graphql args))
|
||||||
expected-deposits (map status->graphql expected-deposits)]
|
expected-deposits (map status->graphql expected-deposits)]
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[invoices invoice-count outstanding total-amount] (-> args
|
[invoices invoice-count outstanding total-amount] (-> args
|
||||||
:filters
|
:filters
|
||||||
(assoc :id (:id context))
|
(assoc :clients (:clients context))
|
||||||
(<-graphql)
|
(<-graphql)
|
||||||
(update :status enum->keyword "invoice-status")
|
(update :status enum->keyword "invoice-status")
|
||||||
(d-invoices/get-graphql))]
|
(d-invoices/get-graphql))]
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
(defn get-ledger-page [context args _]
|
(defn get-ledger-page [context args _]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[journal-entries journal-entries-count] (l/get-graphql (assoc (<-graphql (:filters args))
|
[journal-entries journal-entries-count] (l/get-graphql (assoc (<-graphql (:filters args))
|
||||||
:id (:id context)))
|
:clients (:clients context)))
|
||||||
|
|
||||||
journal-entries (mapv
|
journal-entries (mapv
|
||||||
(fn [je]
|
(fn [je]
|
||||||
@@ -316,7 +316,7 @@
|
|||||||
|
|
||||||
(defn delete-external-ledger [context args _]
|
(defn delete-external-ledger [context args _]
|
||||||
(let [_ (assert-admin (:id context))
|
(let [_ (assert-admin (:id context))
|
||||||
args (assoc args :id (:id context))
|
args (assoc args :clients (:clients context))
|
||||||
ids (some-> (:filters args)
|
ids (some-> (:filters args)
|
||||||
(assoc :only-external true)
|
(assoc :only-external true)
|
||||||
(<-graphql)
|
(<-graphql)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
(defn get-report-page [context args _]
|
(defn get-report-page [context args _]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[reports reports-count] (r/get-graphql (assoc (<-graphql (:filters args))
|
[reports reports-count] (r/get-graphql (assoc (<-graphql (:filters args))
|
||||||
:id (:id context)))]
|
:clients (:clients context)))]
|
||||||
(result->page reports reports-count :reports (:filters args)))
|
(result->page reports reports-count :reports (:filters args)))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
[auto-ap.graphql.utils :refer [attach-tracing-resolvers]]))
|
[auto-ap.graphql.utils :refer [attach-tracing-resolvers]]))
|
||||||
|
|
||||||
(defn get-sales-orders-page [context args _]
|
(defn get-sales-orders-page [context args _]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :clients (:clients context))
|
||||||
[sales-orders sales-orders-count {:keys [total tax]}] (d-sales-orders2/get-graphql (<-graphql args))]
|
[sales-orders sales-orders-count {:keys [total tax]}] (d-sales-orders2/get-graphql (<-graphql args))]
|
||||||
(assoc (result->page sales-orders sales-orders-count :sales_orders args)
|
(assoc (result->page sales-orders sales-orders-count :sales_orders args)
|
||||||
:sales_order_total total
|
:sales_order_total total
|
||||||
|
|||||||
@@ -20,7 +20,7 @@
|
|||||||
[iol-ion.tx :refer [random-tempid]]))
|
[iol-ion.tx :refer [random-tempid]]))
|
||||||
|
|
||||||
(defn get-transaction-rule-page [context args _]
|
(defn get-transaction-rule-page [context args _]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :clients (:clients context))
|
||||||
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
||||||
(result->page (->> journal-entries
|
(result->page (->> journal-entries
|
||||||
(map (ident->enum-f :transaction-rule/transaction-approval-status)))
|
(map (ident->enum-f :transaction-rule/transaction-approval-status)))
|
||||||
|
|||||||
@@ -52,7 +52,8 @@
|
|||||||
{:validation-error "In order to select potential duplicates, you must filter your view more."})))))
|
{:validation-error "In order to select potential duplicates, you must filter your view more."})))))
|
||||||
|
|
||||||
(defn get-transaction-page [context args _]
|
(defn get-transaction-page [context args _]
|
||||||
(let [args (assoc (:filters args) :id (:id context))
|
(let [args (assoc (:filters args)
|
||||||
|
:clients (:clients context))
|
||||||
_ (assert-filtered-enough args)
|
_ (assert-filtered-enough args)
|
||||||
[transactions transactions-count] (d-transactions/get-graphql (update (<-graphql args) :approval-status enum->keyword "transaction-approval-status"))
|
[transactions transactions-count] (d-transactions/get-graphql (update (<-graphql args) :approval-status enum->keyword "transaction-approval-status"))
|
||||||
transactions (map ->graphql (map approval-status->graphql transactions))]
|
transactions (map ->graphql (map approval-status->graphql transactions))]
|
||||||
@@ -85,7 +86,7 @@
|
|||||||
(map first)))
|
(map first)))
|
||||||
(defn bulk-change-status [context args _]
|
(defn bulk-change-status [context args _]
|
||||||
(let [_ (assert-admin (:id context))
|
(let [_ (assert-admin (:id context))
|
||||||
args (assoc args :id (:id context))
|
args (assoc args :clients (:clients context))
|
||||||
all-ids (->> (get-ids-matching-filters args)
|
all-ids (->> (get-ids-matching-filters args)
|
||||||
all-ids-not-locked)]
|
all-ids-not-locked)]
|
||||||
|
|
||||||
@@ -137,10 +138,11 @@
|
|||||||
|
|
||||||
(defn bulk-code-transactions [context args _]
|
(defn bulk-code-transactions [context args _]
|
||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(when-not (:client_id args)
|
(when-not (seq (:client_id args))
|
||||||
(throw (ex-info "Client is required"
|
(throw (ex-info "Client is required"
|
||||||
{:validation-error "client is required"})))
|
{:validation-error "client is required"})))
|
||||||
(let [args (assoc args :id (:id context))
|
;; TODO FIX THIS TO WORK WITH MULTIPLE
|
||||||
|
(let [args (assoc args :clients (:clients context))
|
||||||
locations (pull-attr (dc/db conn)
|
locations (pull-attr (dc/db conn)
|
||||||
:client/locations
|
:client/locations
|
||||||
(:client_id args))
|
(:client_id args))
|
||||||
@@ -184,7 +186,7 @@
|
|||||||
|
|
||||||
(defn delete-transactions [context args _]
|
(defn delete-transactions [context args _]
|
||||||
(let [_ (assert-admin (:id context))
|
(let [_ (assert-admin (:id context))
|
||||||
args (assoc args :id (:id context))
|
args (assoc args :clients (:clients context))
|
||||||
all-ids (all-ids-not-locked (get-ids-matching-filters args))
|
all-ids (all-ids-not-locked (get-ids-matching-filters args))
|
||||||
db (dc/db conn)]
|
db (dc/db conn)]
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
|
|
||||||
(defn get-yodlee-provider-account-page [context args _]
|
(defn get-yodlee-provider-account-page [context args _]
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
[yodlee-provider-accounts cnt] (d-yodlee2/get-graphql (<-graphql (assoc args :id (:id context))))]
|
[yodlee-provider-accounts cnt] (d-yodlee2/get-graphql (<-graphql (assoc args :clients (:clients context))))]
|
||||||
{:yodlee_provider_accounts (map ->graphql yodlee-provider-accounts)
|
{:yodlee_provider_accounts (map ->graphql yodlee-provider-accounts)
|
||||||
:total cnt
|
:total cnt
|
||||||
:count (count yodlee-provider-accounts)
|
:count (count yodlee-provider-accounts)
|
||||||
|
|||||||
@@ -1,10 +1,47 @@
|
|||||||
(ns auto-ap.routes.graphql
|
(ns auto-ap.routes.graphql
|
||||||
(:require [auto-ap.routes.utils :refer [wrap-secure]]
|
(:require
|
||||||
[auto-ap.graphql :as ql]
|
[auto-ap.datomic :refer [conn pull-many]]
|
||||||
[auto-ap.logging :refer [warn-event]]
|
[auto-ap.datomic.clients :as d-clients]
|
||||||
[buddy.auth :refer [throw-unauthorized]]
|
[auto-ap.graphql :as ql]
|
||||||
[clojure.edn :as edn]
|
[auto-ap.graphql.utils :refer [limited-clients]]
|
||||||
[clojure.tools.logging :as log]))
|
[auto-ap.logging :refer [warn-event]]
|
||||||
|
[auto-ap.routes.utils :refer [wrap-secure]]
|
||||||
|
[buddy.auth :refer [throw-unauthorized]]
|
||||||
|
[clojure.edn :as edn]
|
||||||
|
[clojure.set :as set]
|
||||||
|
[clojure.tools.logging :as log]
|
||||||
|
[datomic.api :as dc]))
|
||||||
|
|
||||||
|
(defn headers->clients [identity headers]
|
||||||
|
(let [x-clients (clojure.edn/read-string (get headers "x-clients"))
|
||||||
|
ideal-ids (set (cond
|
||||||
|
(or (= :all x-clients)
|
||||||
|
(nil? x-clients))
|
||||||
|
(->> (dc/q '[:find ?c
|
||||||
|
:where [?c :client/code]]
|
||||||
|
(dc/db conn))
|
||||||
|
(map first))
|
||||||
|
|
||||||
|
(= :mine x-clients)
|
||||||
|
(map :db/id (:user/clients identity))
|
||||||
|
|
||||||
|
(seq x-clients)
|
||||||
|
x-clients))
|
||||||
|
_ (println "X-CLIENSTT" x-clients)
|
||||||
|
_ (println "IDEAL" ideal-ids)
|
||||||
|
_ (println "LIMITS" (limited-clients identity))
|
||||||
|
limited-clients (some->> (limited-clients identity)
|
||||||
|
(map :db/id )
|
||||||
|
set)
|
||||||
|
|
||||||
|
client-ids (if (set? limited-clients)
|
||||||
|
(set/intersection ideal-ids
|
||||||
|
limited-clients)
|
||||||
|
ideal-ids)]
|
||||||
|
(pull-many (dc/db conn)
|
||||||
|
d-clients/full-read
|
||||||
|
client-ids)))
|
||||||
|
|
||||||
(defn handle-graphql [{:keys [request-method query-params] :as r}]
|
(defn handle-graphql [{:keys [request-method query-params] :as r}]
|
||||||
(when (= "none" (:user/role (:identity r)))
|
(when (= "none" (:user/role (:identity r)))
|
||||||
(throw-unauthorized))
|
(throw-unauthorized))
|
||||||
@@ -13,8 +50,11 @@
|
|||||||
(let [variables (some-> (query-params "variables")
|
(let [variables (some-> (query-params "variables")
|
||||||
edn/read-string)
|
edn/read-string)
|
||||||
body (some-> r :body slurp)]
|
body (some-> r :body slurp)]
|
||||||
|
|
||||||
{:status 200
|
{:status 200
|
||||||
:body (pr-str (ql/query (:identity r) (if (= request-method :get) (query-params "query") body) variables ))
|
:body (pr-str (ql/query (:identity r) (if (= request-method :get) (query-params "query") body) (assoc variables
|
||||||
|
:clients
|
||||||
|
(headers->clients (:identity r) (:headers r))) ))
|
||||||
:headers {"Content-Type" "application/edn"}})
|
:headers {"Content-Type" "application/edn"}})
|
||||||
(catch Throwable e
|
(catch Throwable e
|
||||||
(log/info "here we are " (.getCause e))
|
(log/info "here we are " (.getCause e))
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
(ns auto-ap.ssr.company-dropdown
|
(ns auto-ap.ssr.company-dropdown
|
||||||
(:require
|
(:require
|
||||||
[auto-ap.datomic :refer [conn pull-many]]
|
[auto-ap.datomic :refer [conn pull-many]]
|
||||||
[auto-ap.graphql.utils :refer [assert-can-see-client cleanse-query]]
|
[auto-ap.graphql.utils
|
||||||
|
:refer [assert-can-see-client cleanse-query is-admin?]]
|
||||||
[auto-ap.solr :as solr]
|
[auto-ap.solr :as solr]
|
||||||
[auto-ap.ssr-routes :as ssr-routes]
|
[auto-ap.ssr-routes :as ssr-routes]
|
||||||
[auto-ap.ssr.svg :as svg]
|
[auto-ap.ssr.svg :as svg]
|
||||||
@@ -125,18 +126,48 @@ function initCompanyDropdown() {
|
|||||||
")]]])
|
")]]])
|
||||||
|
|
||||||
(defn active-client [{:keys [identity params] :as request}]
|
(defn active-client [{:keys [identity params] :as request}]
|
||||||
(let [client-id (some-> (or (:search-client params) (get params "search-client")) not-empty Long/parseLong)]
|
(let [client-search (or (:search-client params)
|
||||||
(println (format "HERE CLIENT ID '%s'" client-id))
|
(get params "search-client"))
|
||||||
|
client-id (try (some-> client-search
|
||||||
|
(not-empty )
|
||||||
|
Long/parseLong)
|
||||||
|
(catch Exception _
|
||||||
|
nil))]
|
||||||
(when client-id
|
(when client-id
|
||||||
(assert-can-see-client identity client-id))
|
(assert-can-see-client identity client-id))
|
||||||
(let [new-session (assoc (:session request) :client
|
|
||||||
|
(let [new-session (assoc (:session request)
|
||||||
|
|
||||||
|
:client
|
||||||
(when client-id
|
(when client-id
|
||||||
(dc/pull (dc/db conn) [:db/id :client/name :client/code] client-id)))]
|
(dc/pull (dc/db conn) [:db/id :client/name :client/code] client-id))
|
||||||
|
|
||||||
|
:clients
|
||||||
|
(cond (int? client-id)
|
||||||
|
[(dc/pull (dc/db conn) [:db/id :client/name :client/code] client-id)]
|
||||||
|
|
||||||
|
(= ":mine" client-search)
|
||||||
|
(->> (dc/q '[:find (pull ?c [:db/id :client/name :client/code])
|
||||||
|
:in $ ?u
|
||||||
|
:where [?u :user/clients ?c]]
|
||||||
|
(dc/db conn)
|
||||||
|
(:db/id identity))
|
||||||
|
(map first))
|
||||||
|
|
||||||
|
(and (or (empty? client-search)
|
||||||
|
(= ":all" client-search))
|
||||||
|
(is-admin? identity))
|
||||||
|
(->> (dc/q '[:find (pull ?c [:db/id :client/name :client/code])
|
||||||
|
:in $ ?u
|
||||||
|
:where [?c :client/code]]
|
||||||
|
(dc/db conn)
|
||||||
|
(:db/id identity))
|
||||||
|
(map first))))]
|
||||||
(assoc
|
(assoc
|
||||||
(html-response
|
(html-response
|
||||||
(dropdown {:client (:client new-session)
|
(dropdown {:client (:client new-session)
|
||||||
:identity identity}))
|
:identity identity}))
|
||||||
:session
|
:session
|
||||||
new-session
|
new-session
|
||||||
:headers
|
:headers
|
||||||
{"hx-trigger" "clientSelected"}))))
|
{"hx-trigger" "clientSelected"}))))
|
||||||
|
|||||||
@@ -85,6 +85,7 @@
|
|||||||
(let [headers (if token
|
(let [headers (if token
|
||||||
(assoc headers "Authorization" (str "Token " token))
|
(assoc headers "Authorization" (str "Token " token))
|
||||||
headers)
|
headers)
|
||||||
|
headers (assoc headers "x-clients" (pr-str (:selected-clients @re-frame.db/app-db)))
|
||||||
response (<! (http/request {:method method
|
response (<! (http/request {:method method
|
||||||
:body body
|
:body body
|
||||||
:headers headers
|
:headers headers
|
||||||
@@ -155,7 +156,7 @@
|
|||||||
|
|
||||||
(re-frame/reg-fx
|
(re-frame/reg-fx
|
||||||
:graphql
|
:graphql
|
||||||
(fn [{:keys [query on-success on-error token variables query-obj owns-state]}]
|
(fn [{:keys [query on-success on-error token variables query-obj owns-state db]}]
|
||||||
(go
|
(go
|
||||||
(when (:multi owns-state)
|
(when (:multi owns-state)
|
||||||
(re-frame/dispatch-sync [::status/loading-multi (:multi owns-state) (:which owns-state)]))
|
(re-frame/dispatch-sync [::status/loading-multi (:multi owns-state) (:which owns-state)]))
|
||||||
@@ -165,6 +166,7 @@
|
|||||||
(let [headers (if token
|
(let [headers (if token
|
||||||
{"Authorization" (str "Token " token)}
|
{"Authorization" (str "Token " token)}
|
||||||
{})
|
{})
|
||||||
|
headers (assoc headers "x-clients" (pr-str (:selected-clients @re-frame.db/app-db)))
|
||||||
on-success (if (fn? on-success)
|
on-success (if (fn? on-success)
|
||||||
on-success
|
on-success
|
||||||
(fn [result]
|
(fn [result]
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
[goog.crypt.base64 :as b64]
|
[goog.crypt.base64 :as b64]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[auto-ap.ssr-routes :as ssr-routes]
|
[auto-ap.ssr-routes :as ssr-routes]
|
||||||
[cemerick.url :as url]))
|
[cemerick.url :as url]
|
||||||
|
[auto-ap.subs :as subs]))
|
||||||
|
|
||||||
(defn jwt->data [token]
|
(defn jwt->data [token]
|
||||||
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
|
(js->clj (.parse js/JSON (b64/decodeString (second (str/split token #"\." ))))))
|
||||||
@@ -127,15 +128,36 @@
|
|||||||
::swap-client
|
::swap-client
|
||||||
[with-user]
|
[with-user]
|
||||||
(fn [{:keys [db user]} [_ client]]
|
(fn [{:keys [db user]} [_ client]]
|
||||||
(.setItem js/localStorage "last-client-id" (:id client))
|
(let [client-identifier (or (:id client) client)]
|
||||||
{:db (assoc db :client (:id client))
|
(when (:id client)
|
||||||
:http {:token user
|
(.setItem js/localStorage "last-client-id" (:id client)))
|
||||||
:method :put
|
(.setItem js/localStorage "last-selected-clients"
|
||||||
:uri (str (bidi/path-for ssr-routes/only-routes
|
(condp = client-identifier
|
||||||
:active-client
|
:all
|
||||||
:request-method :put)
|
:all
|
||||||
"?"
|
|
||||||
(url/map->query {:search-client (:id client)}))}}))
|
:mine
|
||||||
|
:mine
|
||||||
|
|
||||||
|
(pr-str [(js/parseInt (:id client))])))
|
||||||
|
|
||||||
|
{:db (assoc db :client (:id client)
|
||||||
|
:selected-clients
|
||||||
|
(condp = client-identifier
|
||||||
|
:all
|
||||||
|
:all
|
||||||
|
|
||||||
|
:mine
|
||||||
|
:mine
|
||||||
|
|
||||||
|
[(js/parseInt (:id client))]))
|
||||||
|
:http {:token user
|
||||||
|
:method :put
|
||||||
|
:uri (str (bidi/path-for ssr-routes/only-routes
|
||||||
|
:active-client
|
||||||
|
:request-method :put)
|
||||||
|
"?"
|
||||||
|
(url/map->query {:search-client client-identifier}))}})))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::set-active-route
|
::set-active-route
|
||||||
|
|||||||
@@ -23,6 +23,28 @@
|
|||||||
(when (:user db)
|
(when (:user db)
|
||||||
(sort-by :name (vals (:clients db))))))
|
(sort-by :name (vals (:clients db))))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::selected-clients
|
||||||
|
(fn [db]
|
||||||
|
(let [selected-clients (:selected-clients db)]
|
||||||
|
(cond (= :mine selected-clients)
|
||||||
|
(sort-by :name
|
||||||
|
(:user/clients (parse-jwt (:user db))))
|
||||||
|
|
||||||
|
(or (and (sequential? selected-clients)
|
||||||
|
(empty? selected-clients))
|
||||||
|
(= :all selected-clients)
|
||||||
|
(nil? selected-clients))
|
||||||
|
(sort-by :name
|
||||||
|
(vals
|
||||||
|
(:clients db)))
|
||||||
|
|
||||||
|
(sequential? selected-clients)
|
||||||
|
selected-clients
|
||||||
|
|
||||||
|
:else
|
||||||
|
nil))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::client-refs
|
::client-refs
|
||||||
:<- [::clients]
|
:<- [::clients]
|
||||||
|
|||||||
@@ -93,17 +93,29 @@
|
|||||||
|
|
||||||
(defn client-dropdown []
|
(defn client-dropdown []
|
||||||
(let [client (re-frame/subscribe [::subs/client])
|
(let [client (re-frame/subscribe [::subs/client])
|
||||||
matching-clients @(re-frame/subscribe [::matching-clients])]
|
clients @(re-frame/subscribe [::subs/selected-clients])
|
||||||
|
matching-clients @(re-frame/subscribe [::matching-clients])
|
||||||
|
user (re-frame/subscribe [::subs/user])]
|
||||||
|
|
||||||
[navbar-drop-down {:header (str "Company: " (if @client (:name @client)
|
[navbar-drop-down {:header (str "Company: " (cond @client
|
||||||
"All"))
|
(:name @client)
|
||||||
:id ::select-client}
|
|
||||||
|
:else
|
||||||
|
(str (count (or clients [])) " Clients")))
|
||||||
|
:id ::select-client}
|
||||||
[:div
|
[:div
|
||||||
[:a {:class "navbar-item"
|
[:a {:class "navbar-item"
|
||||||
:on-click (fn []
|
:on-click (fn []
|
||||||
(re-frame/dispatch [::events/toggle-menu ::select-client])
|
(re-frame/dispatch [::events/toggle-menu ::select-client])
|
||||||
(re-frame/dispatch [::forms/form-closing ::client-search])
|
(re-frame/dispatch [::forms/form-closing ::client-search])
|
||||||
(re-frame/dispatch [::events/swap-client nil]))} "All" ]
|
(re-frame/dispatch [::events/swap-client :all]))} "All" ]
|
||||||
|
(when (= "admin" (:user/role @user))
|
||||||
|
[:a {:class "navbar-item"
|
||||||
|
:on-click (fn []
|
||||||
|
(re-frame/dispatch [::events/toggle-menu ::select-client])
|
||||||
|
(re-frame/dispatch [::forms/form-closing ::client-search])
|
||||||
|
(re-frame/dispatch [::events/swap-client :mine]))} "Mine" ])
|
||||||
|
|
||||||
[:hr {:class "navbar-divider"}]
|
[:hr {:class "navbar-divider"}]
|
||||||
[form-builder/builder {:id ::client-search
|
[form-builder/builder {:id ::client-search
|
||||||
:submit-event [::client-searched]}
|
:submit-event [::client-searched]}
|
||||||
|
|||||||
@@ -75,17 +75,18 @@
|
|||||||
[:admin "Admin"]]
|
[:admin "Admin"]]
|
||||||
:allow-nil? false
|
:allow-nil? false
|
||||||
:keywordize? true}]]
|
:keywordize? true}]]
|
||||||
(when (#{:user :manager :power_user} (:role data))
|
[form-builder/field-v2 {:field :clients}
|
||||||
[form-builder/field-v2 {:field :clients}
|
(if (= :admin (:role data))
|
||||||
"Client"
|
"Client Assignments"
|
||||||
[com/multi-field-v2 {:template [[form-builder/raw-field-v2 {:field :client}
|
"Client")
|
||||||
[com/entity-typeahead
|
[com/multi-field-v2 {:template [[form-builder/raw-field-v2 {:field :client}
|
||||||
{:entities clients
|
[com/entity-typeahead
|
||||||
:entity->text :name
|
{:entities clients
|
||||||
:style {:width "13em"}}]]]
|
:entity->text :name
|
||||||
:key-fn :id
|
:style {:width "13em"}}]]]
|
||||||
:schema [:sequential client-schema]
|
:key-fn :id
|
||||||
:new-text "Grant access to client"}]])
|
:schema [:sequential client-schema]
|
||||||
|
:new-text "Grant access to client"}]]
|
||||||
|
|
||||||
[form-builder/hidden-submit-button]]]))
|
[form-builder/hidden-submit-button]]]))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user