From bc07ad8f01d733396034d575267cb8cf2460232f Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sun, 24 Jul 2022 08:41:32 -0700 Subject: [PATCH] opened yodlee up. --- .clj-kondo/metosin/malli/config.edn | 2 + resources/sass/bulma.scss | 2 +- src/clj/auto_ap/graphql/yodlee2.clj | 24 +++------ src/clj/auto_ap/routes/ezcater.clj | 1 + src/clj/auto_ap/routes/yodlee2.clj | 16 +++--- src/cljc/auto_ap/client_routes.cljc | 3 +- .../views/components/admin/side_bar.cljs | 5 +- src/cljs/auto_ap/views/main.cljs | 6 +-- .../auto_ap/views/pages/company/side_bar.cljs | 6 ++- .../pages/{admin => company}/yodlee2.cljs | 50 +++++++++---------- .../{admin => company}/yodlee2/form.cljs | 2 +- .../{admin => company}/yodlee2/table.cljs | 42 ++++++++-------- src/cljs/auto_ap/views/pages/reports.cljs | 1 + 13 files changed, 80 insertions(+), 80 deletions(-) create mode 100644 .clj-kondo/metosin/malli/config.edn rename src/cljs/auto_ap/views/pages/{admin => company}/yodlee2.cljs (77%) rename src/cljs/auto_ap/views/pages/{admin => company}/yodlee2/form.cljs (97%) rename src/cljs/auto_ap/views/pages/{admin => company}/yodlee2/table.cljs (79%) diff --git a/.clj-kondo/metosin/malli/config.edn b/.clj-kondo/metosin/malli/config.edn new file mode 100644 index 00000000..0f8b25cc --- /dev/null +++ b/.clj-kondo/metosin/malli/config.edn @@ -0,0 +1,2 @@ +{:lint-as {malli.experimental/defn schema.core/defn} + :linters {:unresolved-symbol {:exclude [(malli.core/=>)]}}} diff --git a/resources/sass/bulma.scss b/resources/sass/bulma.scss index 86f70bd2..26b6a258 100644 --- a/resources/sass/bulma.scss +++ b/resources/sass/bulma.scss @@ -1,4 +1,4 @@ -@charset "utf-8"; +@/charset "utf-8"; /* latin */ @font-face { font-family: 'Calibri'; diff --git a/src/clj/auto_ap/graphql/yodlee2.clj b/src/clj/auto_ap/graphql/yodlee2.clj index e4077169..cfc5877f 100644 --- a/src/clj/auto_ap/graphql/yodlee2.clj +++ b/src/clj/auto_ap/graphql/yodlee2.clj @@ -1,17 +1,9 @@ (ns auto-ap.graphql.yodlee2 - (:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin enum->keyword]] - [auto-ap.datomic.yodlee2 :as d-yodlee2] - [auto-ap.time :refer [parse iso-date]] - [auto-ap.utils :refer [dollars=]] - [datomic.api :as d] - [auto-ap.datomic :refer [uri remove-nils audit-transact conn]] - [clj-time.coerce :as coerce] - [clj-time.core :as time] - [clojure.set :as set] - [clojure.tools.logging :as log])) + (:require + [auto-ap.datomic.yodlee2 :as d-yodlee2] + [auto-ap.graphql.utils :refer [->graphql <-graphql assert-admin]])) (defn get-yodlee-provider-account-page [context args value] - (assert-admin (: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 (map ->graphql yodlee-provider-accounts) @@ -21,9 +13,9 @@ :end (+ (:start args 0) (count yodlee-provider-accounts))})) (defn get-all-yodlee-provider-accounts [context args value] - (assert-admin (:id context)) - (map - ->graphql - (first (d-yodlee2/get-graphql (assoc (<-graphql args) - :count Integer/MAX_VALUE))))) + (let [args (assoc args :id (:id context))] + (map + ->graphql + (first (d-yodlee2/get-graphql (assoc (<-graphql args) + :count Integer/MAX_VALUE)))))) diff --git a/src/clj/auto_ap/routes/ezcater.clj b/src/clj/auto_ap/routes/ezcater.clj index 68620826..d81355aa 100644 --- a/src/clj/auto_ap/routes/ezcater.clj +++ b/src/clj/auto_ap/routes/ezcater.clj @@ -14,6 +14,7 @@ :headers {"Content-Type" "application/json"} :body "{}"}) (POST "/event" request + ;; {"id" "bf3dcf5c-a68f-42d9-9084-049133e03d3d", "parent_type" "Caterer", "parent_id" "91541331-d7ae-4634-9e8b-ccbbcfb2ce70", "entity_type" "Order", "entity_id" "9ab05fee-a9c5-483b-a7f2-14debde4b7a8", "key" "accepted", "occurred_at" "2022-07-21T19:21:07.549Z"} (log/info (str "POST EVENT " (body-string request) request)) {:status 200 :headers {"Content-Type" "application/json"} diff --git a/src/clj/auto_ap/routes/yodlee2.clj b/src/clj/auto_ap/routes/yodlee2.clj index 3d090f3e..16e4a0d4 100644 --- a/src/clj/auto_ap/routes/yodlee2.clj +++ b/src/clj/auto_ap/routes/yodlee2.clj @@ -1,18 +1,20 @@ (ns auto-ap.routes.yodlee2 - (:require - [auto-ap.yodlee.core2 :as yodlee] - [auto-ap.graphql.utils :refer [assert-admin]] + (:require + [auto-ap.datomic :refer [conn]] + [auto-ap.datomic.clients :as d-clients] + [auto-ap.graphql.utils :refer [assert-admin assert-can-see-client]] [auto-ap.routes.utils :refer [wrap-secure]] - [compojure.core :refer [GET POST context defroutes wrap-routes]] - [config.core :refer [env]] + [auto-ap.yodlee.core2 :as yodlee] [clojure.tools.logging :as log] - [auto-ap.datomic.clients :as d-clients])) + [compojure.core :refer [context defroutes GET POST wrap-routes]] + [config.core :refer [env]] + [datomic.api :as d])) (defroutes routes (wrap-routes (context "/yodlee2" [] (GET "/fastlink" {:keys [query-params identity] :as request} - (assert-admin identity) + (assert-can-see-client identity (d/pull (d/db conn) [:db/id] [:client/code (get query-params "client")])) (let [token (if-let [client-id (get query-params "client-id")] (-> client-id diff --git a/src/cljc/auto_ap/client_routes.cljc b/src/cljc/auto_ap/client_routes.cljc index e54bb53b..81881eab 100644 --- a/src/cljc/auto_ap/client_routes.cljc +++ b/src/cljc/auto_ap/client_routes.cljc @@ -16,7 +16,7 @@ "import-batches" :admin-import-batches "vendors" :admin-vendors "excel-import" :admin-excel-import - "yodlee2" :admin-yodlee2} + } "invoices/" {"" :invoices "import" :import-invoices "unpaid" :unpaid-invoices @@ -32,6 +32,7 @@ "excluded" :excluded-transactions} "reports/" {"" :reports} "plaid" :plaid + "yodlee2" :yodlee2 "ledger/" {"" :ledger "profit-and-loss" :profit-and-loss "balance-sheet" :balance-sheet diff --git a/src/cljs/auto_ap/views/components/admin/side_bar.cljs b/src/cljs/auto_ap/views/components/admin/side_bar.cljs index e239dbef..f615777a 100644 --- a/src/cljs/auto_ap/views/components/admin/side_bar.cljs +++ b/src/cljs/auto_ap/views/components/admin/side_bar.cljs @@ -47,10 +47,7 @@ [:span {:class "name"} "Rules"]]] - [:li.menu-item - [:a {:href (bidi/path-for routes/routes :admin-yodlee2), :class (str "item" (active-when ap = :admin-yodlee2))} - [:span {:class "icon icon-saving-bank-1" :style {:font-size "25px"}}] - [:span {:class "name"} "Yodlee 2 Link"]]] + diff --git a/src/cljs/auto_ap/views/main.cljs b/src/cljs/auto_ap/views/main.cljs index c86355d5..6cdb524a 100644 --- a/src/cljs/auto_ap/views/main.cljs +++ b/src/cljs/auto_ap/views/main.cljs @@ -27,7 +27,7 @@ [auto-ap.views.pages.admin.excel-import :refer [admin-excel-import-page]] [auto-ap.views.pages.admin.users :refer [admin-users-page]] [auto-ap.views.pages.admin.import-batches :refer [import-batches-page]] - [auto-ap.views.pages.admin.yodlee2 :as yodlee2] + [auto-ap.views.pages.company.yodlee2 :as yodlee2] [auto-ap.views.pages.company.plaid :as plaid])) (defmulti page (fn [active-page] active-page)) @@ -109,8 +109,8 @@ (defmethod page :admin-import-batches [_] [import-batches-page]) -(defmethod page :admin-yodlee2 [_] - (yodlee2/admin-yodle-provider-accounts-page)) +(defmethod page :yodlee2 [_] + (yodlee2/admin-yodlee-provider-accounts-page)) (defmethod page :plaid [_] (plaid/plaid-page)) diff --git a/src/cljs/auto_ap/views/pages/company/side_bar.cljs b/src/cljs/auto_ap/views/pages/company/side_bar.cljs index ff04cafe..a6d4ff50 100644 --- a/src/cljs/auto_ap/views/pages/company/side_bar.cljs +++ b/src/cljs/auto_ap/views/pages/company/side_bar.cljs @@ -18,4 +18,8 @@ [:li.menu-item [:a {:href (bidi/path-for routes/routes :plaid), :class (str "item" (active-when ap = :plaid))} [:span {:class "icon icon-saving-bank-1" :style {:font-size "25px"}}] - [:span {:class "name"} "Plaid Link"]]]])) + [:span {:class "name"} "Plaid Link"]]] + [:li.menu-item + [:a {:href (bidi/path-for routes/routes :yodlee2), :class (str "item" (active-when ap = :yodlee2))} + [:span {:class "icon icon-saving-bank-1" :style {:font-size "25px"}}] + [:span {:class "name"} "Yodlee Link"]]]])) diff --git a/src/cljs/auto_ap/views/pages/admin/yodlee2.cljs b/src/cljs/auto_ap/views/pages/company/yodlee2.cljs similarity index 77% rename from src/cljs/auto_ap/views/pages/admin/yodlee2.cljs rename to src/cljs/auto_ap/views/pages/company/yodlee2.cljs index 29d27fef..a991eaf3 100644 --- a/src/cljs/auto_ap/views/pages/admin/yodlee2.cljs +++ b/src/cljs/auto_ap/views/pages/company/yodlee2.cljs @@ -1,15 +1,16 @@ -(ns auto-ap.views.pages.admin.yodlee2 +(ns auto-ap.views.pages.company.yodlee2 (:require [auto-ap.effects.forward :as forward] [auto-ap.status :as status] [auto-ap.subs :as subs] - [auto-ap.views.components.admin.side-bar :refer [admin-side-bar]] [auto-ap.views.components.grid :as grid] [auto-ap.views.components.layouts :refer [side-bar-layout]] - [auto-ap.views.pages.admin.yodlee2.table :as table] - [auto-ap.views.utils :refer [dispatch-event]] + [auto-ap.views.pages.company.side-bar :refer [company-side-bar]] + [auto-ap.views.pages.company.yodlee2.table :as table] + [auto-ap.views.utils :refer [dispatch-event with-user]] [re-frame.core :as re-frame] - [reagent.core :as reagent])) + [reagent.core :as reagent] + [vimsical.re-frame.cofx.inject :as inject])) (re-frame/reg-sub ::authentication @@ -27,11 +28,6 @@ (fn [db] (::yodlee-provider-accounts db))) -(re-frame/reg-event-fx - ::params-change - (fn [_ [_ params]] - {:set-uri-params params})) - (re-frame/reg-sub ::page :<- [::params] @@ -42,10 +38,11 @@ (re-frame/reg-event-fx ::data-requested - (fn [{:keys [db]} _] - {:graphql {:token (:user db) + [with-user (re-frame/inject-cofx ::inject/sub [::subs/client])] + (fn [{:keys [user] ::subs/keys [client]} _] + {:graphql {:token user :owns-state {:single ::page} - :query-obj {:venia/queries [[:yodlee-provider-account-page {:client-id (:id @(re-frame/subscribe [::subs/client]))} + :query-obj {:venia/queries [[:yodlee-provider-account-page {:client-id (:id client)} [[:yodlee-provider-accounts [:id :last-updated :status :detailed-status [:client [:id]] [:accounts [:id :name :number :available-balance]]]] @@ -58,20 +55,21 @@ {:dispatch [::data-requested] ::forward/register {:id ::yodlee-account-refreshed :events #{::table/refreshed ::table/provider-account-deleted} - :event-fn (fn [[_ query-result]] + :event-fn (fn [[_ _]] [::data-requested])} :db (dissoc db ::authentication)})) (re-frame/reg-event-fx ::unmounted - (fn [{:keys [db]} _] + (fn [_ _] {::forward/dispose {:id ::yodlee-account-refreshed}})) (re-frame/reg-event-fx ::authenticate-with-yodlee - (fn [{:keys [db]} [_ client]] - {:http {:token (:user db) + [with-user] + (fn [{:keys [user]} [_ client]] + {:http {:token user :method :get :headers {"Content-Type" "application/edn"} :uri (str "/api/yodlee2/fastlink?client=" client) @@ -110,7 +108,6 @@ #js {"fastLinkURL" (:url authentication) "accessToken" (:token authentication) "params" #js { "configName" "Aggregation"}} - "fa-spot") )} [:span [:span.icon [:i.fa.fa-external-link]] " Go to yodlee"]]] @@ -131,11 +128,14 @@ [yodlee-link-button]]) -(defn admin-yodle-provider-accounts-page [] - (reagent/create-class - {:component-will-unmount #(re-frame/dispatch [::unmounted]) - :component-did-mount #(re-frame/dispatch [::mounted]) - :reagent-render (fn [] - [side-bar-layout {:side-bar [admin-side-bar {}] - :main [admin-yodlee-provider-accounts-content]}])})) +(defn admin-yodlee-provider-accounts-page [] + (let [user (re-frame/subscribe [::subs/user])] + (reagent/create-class + {:component-will-unmount #(re-frame/dispatch [::unmounted]) + :component-did-mount #(re-frame/dispatch [::mounted]) + :reagent-render (fn [] + (if (not= "manager" (:user/role @user)) + [side-bar-layout {:side-bar [company-side-bar {}] + :main [admin-yodlee-provider-accounts-content]}] + [:div "Not authorized"]))}))) diff --git a/src/cljs/auto_ap/views/pages/admin/yodlee2/form.cljs b/src/cljs/auto_ap/views/pages/company/yodlee2/form.cljs similarity index 97% rename from src/cljs/auto_ap/views/pages/admin/yodlee2/form.cljs rename to src/cljs/auto_ap/views/pages/company/yodlee2/form.cljs index 0af47b07..89242e14 100644 --- a/src/cljs/auto_ap/views/pages/admin/yodlee2/form.cljs +++ b/src/cljs/auto_ap/views/pages/company/yodlee2/form.cljs @@ -1,4 +1,4 @@ -(ns auto-ap.views.pages.admin.yodlee2.form +(ns auto-ap.views.pages.company.yodlee2.form (:require [auto-ap.views.components.modal :as modal] [re-frame.core :as re-frame] diff --git a/src/cljs/auto_ap/views/pages/admin/yodlee2/table.cljs b/src/cljs/auto_ap/views/pages/company/yodlee2/table.cljs similarity index 79% rename from src/cljs/auto_ap/views/pages/admin/yodlee2/table.cljs rename to src/cljs/auto_ap/views/pages/company/yodlee2/table.cljs index 31d3be3f..9b922be3 100644 --- a/src/cljs/auto_ap/views/pages/admin/yodlee2/table.cljs +++ b/src/cljs/auto_ap/views/pages/company/yodlee2/table.cljs @@ -1,25 +1,24 @@ -(ns auto-ap.views.pages.admin.yodlee2.table +(ns auto-ap.views.pages.company.yodlee2.table (:require [auto-ap.status :as status] [auto-ap.subs :as subs] [auto-ap.views.components.buttons :as buttons] [auto-ap.views.components.grid :as grid] [auto-ap.views.components.modal :as modal] - [auto-ap.views.pages.admin.yodlee2.form :as form] + [auto-ap.views.pages.company.yodlee2.form :as form] [auto-ap.views.utils :refer [->$ action-cell-width date->str with-user dispatch-event]] - [re-frame.core :as re-frame] - [auto-ap.forms :as forms])) + [re-frame.core :as re-frame])) (re-frame/reg-event-fx ::refreshed [with-user ] - (fn [{:keys [user db]} [_ provider-account ]] + (fn [_ _] ;; this is tracked in yodlee main, for refreshing {})) (re-frame/reg-event-fx ::request-refresh [with-user ] - (fn [{:keys [user db]} [_ provider-account client-id ]] + (fn [{:keys [user]} [_ provider-account client-id ]] {:http {:token user :method :post :headers {"Content-Type" "application/edn"} @@ -32,7 +31,7 @@ (re-frame/reg-event-fx ::provider-account-deleted - (fn [{:keys [db]} [_ i result]] + (fn [_ _] {:dispatch [::modal/modal-closed ]})) @@ -52,8 +51,7 @@ (re-frame/reg-event-fx ::delete-provider-account [with-user ] - (fn [{:keys [user db]} [_ provider-account-id ]] - (comment :on-error [::forms/save-error [::delete-provider-account provider-account-id] ]) + (fn [{:keys [user]} [_ provider-account-id ]] {:http {:token user :method :post :owns-state {:single ::delete-provider-account} @@ -67,7 +65,7 @@ (re-frame/reg-event-fx ::delete-requested [with-user] - (fn [{:keys [user db]} [_ account-id]] + (fn [_ [_ account-id]] {:dispatch [::modal/modal-requested {:title "Delete Provider account " :body [:div "Are you sure you want to delete provider account " account-id "?"] @@ -91,7 +89,8 @@ (defn table [{:keys [status page]}] (let [params @(re-frame/subscribe [::params]) statuses @(re-frame/subscribe [::status/multi ::refresh]) - login-statuses @(re-frame/subscribe [::status/multi ::request-login-form])] + login-statuses @(re-frame/subscribe [::status/multi ::request-login-form]) + is-admin? @(re-frame/subscribe [::subs/is-admin?])] [grid/grid {:status status :on-params-change (fn [p] (re-frame/dispatch [::params-changed p])) @@ -121,13 +120,14 @@ ^{:key (:id a)} [:li (:name a) " - " (:number a) [:div.tag (->$ (:available-balance a))]])]] [grid/cell {} - [:div.buttons - [buttons/fa-icon {:event - [::request-login-form (:id c) (:id (:client c))] - :class (status/class-for (get login-statuses (:id c))) - :icon "fa-pencil"}] - [buttons/fa-icon {:event [::request-refresh (:id c) (:id (:client c))] - :class (status/class-for (get statuses (:id c))) - :icon "fa-refresh"}] - [buttons/fa-icon {:event [::delete-requested (:id c)] - :icon "fa-times"}]]]])]]])) + (when is-admin? + [:div.buttons + [buttons/fa-icon {:event + [::request-login-form (:id c) (:id (:client c))] + :class (status/class-for (get login-statuses (:id c))) + :icon "fa-pencil"}] + [buttons/fa-icon {:event [::request-refresh (:id c) (:id (:client c))] + :class (status/class-for (get statuses (:id c))) + :icon "fa-refresh"}] + [buttons/fa-icon {:event [::delete-requested (:id c)] + :icon "fa-times"}]])]])]]])) diff --git a/src/cljs/auto_ap/views/pages/reports.cljs b/src/cljs/auto_ap/views/pages/reports.cljs index d8d4411b..5c3d8b83 100644 --- a/src/cljs/auto_ap/views/pages/reports.cljs +++ b/src/cljs/auto_ap/views/pages/reports.cljs @@ -71,6 +71,7 @@ :component-will-unmount #(re-frame/dispatch [::unmounted]) :reagent-render (fn [] + (println "ROLE" (:user/role @user)) (if (not= "manager" (:user/role @user)) [side-bar-layout {:side-bar [company-side-bar {:data-page ::page}]