adding power user role.

This commit is contained in:
2021-01-26 09:52:28 -08:00
parent 20634e73ef
commit 7eeb1737ab
7 changed files with 42 additions and 17 deletions

View File

@@ -167,7 +167,7 @@
:requires [:auto-ap/add-hidden-to-vendor]}
#_#_:auto-ap/convert-invoices {:txes-fn `add-general-ledger/convert-invoices
:requires [:auto-ap/convert-vendors]}
:auto-ap/add-yodlee-merchant2 {:txes add-general-ledger/add-yodlee-merchant :requires [:auto-ap/convert-vendors]}
:auto-ap/add-yodlee-merchant2 {:txes add-general-ledger/add-yodlee-merchant }
:auto-ap/add-external-id-to-ledger {:txes add-general-ledger/add-external-id-to-ledger :requires [:auto-ap/add-yodlee-merchant2]}
:auto-ap/add-exclude-to-transaction {:txes add-general-ledger/add-exclude-to-transaction :requires [:auto-ap/add-external-id-to-ledger]}
:auto-ap/add-client-identifier2 {:txes add-client-identifier :requires [:auto-ap/make-every-account-visible]}
@@ -176,7 +176,7 @@
;; should not be needed.
#_#_:auto-ap/convert-transactions {:txes-fn `add-general-ledger/convert-transactions :requires [:auto-ap/add-bank-account-locations]}
:auto-ap/add-exclude-to-invoice {:txes add-general-ledger/add-exclude-to-invoice :requires [:auto-ap/convert-transactions]}
:auto-ap/add-exclude-to-invoice {:txes add-general-ledger/add-exclude-to-invoice }
:auto-ap/add-terms {:txes [[{:db/ident :vendor/terms
:db/doc "How many days till you pay"
:db/valueType :db.type/long
@@ -331,7 +331,9 @@
{:db/ident :vendor-schedule-payment-dom/dom
:db/doc "What day of the month"
:db/valueType :db.type/long
:db/cardinality :db.cardinality/one}]]}}
:db/cardinality :db.cardinality/one}]]}
:auto-ap/add-power-user-schema {:txes [[{:db/ident :user-role/power-user}]]}}
sales/norms-map
clients/norms-map

View File

@@ -13,6 +13,7 @@
[->graphql
<-graphql
assert-admin
assert-power-user
assert-can-see-client
enum->keyword
ident->enum-f
@@ -84,8 +85,10 @@
{:message (str "Succesfully deleted " (count all-ids) " transactions.")}))
(defn get-potential-autopay-invoices-matches [context args value]
(assert-admin (:id context))
(let [transaction (d-transactions/get-by-id (:transaction_id args))]
(assert-power-user (:id context))
(let [transaction (d-transactions/get-by-id (:transaction_id args))
_ (assert-can-see-client (:id context) (:transaction/client transaction) )]
(let [matches-set (import/match-transaction-to-unfulfilled-autopayments (:transaction/amount transaction)
(:db/id (:transaction/client transaction)))]
@@ -94,8 +97,9 @@
(d-invoices/get-by-id invoice-id)))))))
(defn get-potential-unpaid-invoices-matches [context args value]
(assert-admin (:id context))
(let [transaction (d-transactions/get-by-id (:transaction_id args))]
(assert-power-user (:id context))
(let [transaction (d-transactions/get-by-id (:transaction_id args))
_ (assert-can-see-client (:id context) (:transaction/client transaction) )]
(let [matches-set (import/match-transaction-to-unpaid-invoices (:transaction/amount transaction)
(:db/id (:transaction/client transaction)))]
@@ -104,7 +108,8 @@
(d-invoices/get-by-id invoice-id)))))))
(defn unlink-transaction [context args value]
(let [_ (assert-admin (:id context))
(let [_ (assert-power-user (:id context))
args (assoc args :id (:id context))
transaction-id (:transaction_id args)
transaction (d/pull (d/db conn)
@@ -113,9 +118,11 @@
:transaction/location
:transaction/vendor
:transaction/accounts
:transaction/client [:db/id]
{:transaction/payment [{:payment/status [:db/ident]} :db/id]} ]
transaction-id)
_ (assert-can-see-client (:id context) (:transaction/client transaction) )
_ (log/info "Unlinking" transaction)
payment (-> transaction :transaction/payment )
is-autopay-payment? (some->> (doto (d/query {:query {:find ['?sp]
@@ -296,7 +303,7 @@
->graphql))
(defn match-transaction-autopay-invoices [context {:keys [transaction_id autopay_invoice_ids]} value]
(let [_ (assert-admin (:id context))
(let [_ (assert-power-user (:id context))
transaction (d-transactions/get-by-id transaction_id)
_ (assert-can-see-client (:id context) (:transaction/client transaction) )
db (d/db conn)
@@ -334,7 +341,7 @@
->graphql)))
(defn match-transaction-unpaid-invoices [context {:keys [transaction_id unpaid_invoice_ids]} value]
(let [_ (assert-admin (:id context))
(let [_ (assert-power-user (:id context))
transaction (d-transactions/get-by-id transaction_id)
_ (assert-can-see-client (:id context) (:transaction/client transaction) )
db (d/db conn)

View File

@@ -5,6 +5,7 @@
(def role->datomic-role {":none" :user-role/none
":admin" :user-role/admin
":power_user" :user-role/power-user
":manager" :user-role/manager
":user" :user-role/user})

View File

@@ -51,6 +51,11 @@
(log/warn "user " id " not an admin!")
(throw-unauthorized)))
(defn assert-power-user [id]
(when-not (#{"power-user" "admin"} (:user/role id))
(log/warn "user " id " not an power-user!")
(throw-unauthorized)))
(defn can-see-client? [identity client]
(when (not client)
(log/warn "WARNING - permission checking for null client"))
@@ -72,7 +77,7 @@
(= (:user/role id) "admin")
nil
(#{"manager" "user"} (:user/role id))
(#{"manager" "user" "power-user"} (:user/role id))
(:user/clients id [])))
(defn result->page [results result-count key args]