Multiple clients=no show for non-admins
This commit is contained in:
@@ -6,12 +6,12 @@
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.graphql.checks :as gq-checks]
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql
|
||||
<-graphql
|
||||
:refer [<-graphql
|
||||
assert-admin
|
||||
assert-can-see-client
|
||||
assert-power-user
|
||||
enum->keyword]]
|
||||
enum->keyword]
|
||||
:as u]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as time]
|
||||
@@ -20,6 +20,13 @@
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
[datomic.api :as d]))
|
||||
|
||||
(defn ->graphql [invoice user ]
|
||||
(if (= "admin" (:user/role user))
|
||||
(u/->graphql invoice)
|
||||
(u/->graphql (if (:invoice/source-url-admin-only invoice)
|
||||
(dissoc invoice :invoice/source-url)
|
||||
invoice))))
|
||||
|
||||
(defn get-invoice-page [context args _]
|
||||
|
||||
(let [args (assoc args :id (:id context))
|
||||
@@ -28,7 +35,7 @@
|
||||
(<-graphql)
|
||||
(update :status enum->keyword "invoice-status")
|
||||
(d-invoices/get-graphql))]
|
||||
[{:invoices (map ->graphql invoices)
|
||||
[{:invoices (mapv #(->graphql % (:id context)) invoices)
|
||||
:outstanding outstanding
|
||||
:total invoice-count
|
||||
:count (count invoices)
|
||||
@@ -38,7 +45,7 @@
|
||||
(defn get-all-invoices [context args _]
|
||||
(assert-admin (:id context))
|
||||
(map
|
||||
->graphql
|
||||
u/->graphql
|
||||
(first (d-invoices/get-graphql (assoc (<-graphql args)
|
||||
:count Integer/MAX_VALUE)))))
|
||||
|
||||
@@ -147,7 +154,7 @@
|
||||
|
||||
(let [transaction-result (audit-transact [(add-invoice-transaction in)] (:id context))]
|
||||
(-> (d-invoices/get-by-id (get-in transaction-result [:tempids "invoice"]))
|
||||
(->graphql))))
|
||||
(->graphql (:id context)))))
|
||||
|
||||
(defn assert-bank-account-belongs [client-id bank-account-id]
|
||||
(when-not ((set (map :db/id (:client/bank-accounts (d-clients/get-by-id client-id)))) bank-account-id)
|
||||
@@ -166,7 +173,7 @@
|
||||
bank-account-id
|
||||
type
|
||||
(:id context))
|
||||
->graphql)))
|
||||
u/->graphql)))
|
||||
|
||||
(defn edit-invoice [context {{:keys [id due invoice_number total date expense_accounts scheduled_payment] :as in} :invoice} _]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
@@ -196,7 +203,7 @@
|
||||
(map (fn [d] [:db/retract id :invoice/expense-accounts d]) deleted))
|
||||
(:id context))
|
||||
(-> (d-invoices/get-by-id id)
|
||||
(->graphql))))
|
||||
(->graphql (:id context)))))
|
||||
|
||||
(defn void-invoice [context {id :invoice_id} _]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
@@ -210,7 +217,7 @@
|
||||
(:invoice/expense-accounts invoice))}]
|
||||
(:id context))
|
||||
|
||||
(-> (d-invoices/get-by-id id) (->graphql))))
|
||||
(-> (d-invoices/get-by-id id) (->graphql (:id context)))))
|
||||
|
||||
(defn unvoid-invoice [context {id :invoice_id} _]
|
||||
(let [invoice (d-invoices/get-by-id id)
|
||||
@@ -239,7 +246,7 @@
|
||||
(:id context))
|
||||
|
||||
(-> (d-invoices/get-by-id id)
|
||||
(->graphql))))
|
||||
(->graphql (:id context)))))
|
||||
|
||||
(defn unautopay-invoice [context {id :invoice_id} _]
|
||||
(let [invoice (d/entity (d/db conn) id)
|
||||
@@ -251,7 +258,7 @@
|
||||
(:id context))
|
||||
|
||||
(-> (d-invoices/get-by-id id)
|
||||
(->graphql))))
|
||||
(->graphql (:id context)))))
|
||||
|
||||
(defn edit-expense-accounts [context args _]
|
||||
(assert-can-see-client (:id context) (:db/id (:invoice/client (d-invoices/get-by-id (:invoice_id args)))))
|
||||
@@ -268,27 +275,28 @@
|
||||
(map (fn [d] [:db/retract invoice-id :invoice/expense-accounts d]) deleted))
|
||||
(:id context))
|
||||
(->graphql
|
||||
(d-invoices/get-by-id (:invoice_id args)))))
|
||||
(d-invoices/get-by-id (:invoice_id args))
|
||||
(:id context))))
|
||||
|
||||
(def objects
|
||||
{:invoice
|
||||
{:fields {:id {:type :id}
|
||||
:original_id {:type 'Int}
|
||||
:client_identifier {:type 'String}
|
||||
:total {:type 'String}
|
||||
:source_url {:type 'String}
|
||||
:outstanding_balance {:type 'String}
|
||||
:invoice_number {:type 'String}
|
||||
:status {:type 'String}
|
||||
:expense_accounts {:type '(list :invoices_expense_accounts)}
|
||||
:similarity {:type 'Float}
|
||||
:date {:type :iso_date}
|
||||
:due {:type :iso_date}
|
||||
:client_id {:type 'Int}
|
||||
:payments {:type '(list :invoice_payment)}
|
||||
:vendor {:type :vendor}
|
||||
:client {:type :client}
|
||||
:scheduled_payment {:type :iso_date}}}
|
||||
{:fields {:id {:type :id}
|
||||
:original_id {:type 'Int}
|
||||
:client_identifier {:type 'String}
|
||||
:total {:type 'String}
|
||||
:source_url {:type 'String}
|
||||
:outstanding_balance {:type 'String}
|
||||
:invoice_number {:type 'String}
|
||||
:status {:type 'String}
|
||||
:expense_accounts {:type '(list :invoices_expense_accounts)}
|
||||
:similarity {:type 'Float}
|
||||
:date {:type :iso_date}
|
||||
:due {:type :iso_date}
|
||||
:client_id {:type 'Int}
|
||||
:payments {:type '(list :invoice_payment)}
|
||||
:vendor {:type :vendor}
|
||||
:client {:type :client}
|
||||
:scheduled_payment {:type :iso_date}}}
|
||||
|
||||
:invoices_expense_accounts
|
||||
{:fields {:id {:type :id}
|
||||
|
||||
Reference in New Issue
Block a user