Adds the ability to set up read only users, adds linking filtering

This commit is contained in:
2024-01-03 21:42:30 -08:00
parent 48f70ef93d
commit 810c3aacb2
10 changed files with 192 additions and 63 deletions

View File

@@ -1,6 +1,7 @@
(ns auto-ap.views.components.layouts
(:require
[auto-ap.events :as events]
[auto-ap.permissions :as p]
[auto-ap.forms :as forms]
[auto-ap.forms.builder :as form-builder]
[auto-ap.routes :as routes]
@@ -49,13 +50,20 @@
[:span (:user/name @user)]]
:id ::account}
[:div
[:a {:class "navbar-item"
:href (bidi/path-for auto-ap.ssr-routes/only-routes :company)} "My company"]
[:a.dropdown-item {:on-click (dispatch-event-with-propagation [::vendor-dialog/started {}])} "New Vendor"]
[:a.dropdown-item {:on-click (dispatch-event-with-propagation [::vendor-dialog/edit {}])} "Edit Vendor"]
(when (= "admin" (:user/role @user))
(when (p/can? @user {:subject :my-company-page})
[:a {:class "navbar-item"
:href (bidi/path-for auto-ap.ssr-routes/only-routes :company)} "My company"])
(when (p/can? @user {:subject :vendor
:activity :create})
[:a.dropdown-item {:on-click (dispatch-event-with-propagation [::vendor-dialog/started {}])} "New Vendor"])
(when (p/can? @user {:subject :vendor
:activity :edit})
[:a.dropdown-item {:on-click (dispatch-event-with-propagation [::vendor-dialog/edit {}])} "Edit Vendor"])
(when (p/can? @user {:subject :admin-page})
[:a {:class "navbar-item" :href (bidi/path-for ssr-routes/only-routes :auto-ap.routes.admin/page)} "Administration"])
[:hr {:class "navbar-divider"}]
(when (not= "read-only" (:user/role @user))
[:hr {:class "navbar-divider"}])
[:a.navbar-item {:on-click (fn []
(.removeItem js/localStorage "last-client-id" nil)
(.setItem js/localStorage "last-selected-clients" ":all")
@@ -149,7 +157,6 @@
clients (re-frame/subscribe [::subs/clients])
is-initial-loading @(re-frame/subscribe [::subs/is-initial-loading?])]
[:nav {:class "navbar has-shadow is-fixed-top is-grey"}
[:div {:class "container"}
[:div {:class "navbar-brand"}
[:a {:class "navbar-item", :href "../"}
@@ -164,27 +171,28 @@
(when-not is-initial-loading
[:div.navbar-start
[:a.navbar-item {:class [(active-when ap = :index)]
:href (bidi/path-for routes/routes :index)}
:href (bidi/path-for routes/routes :index)}
"Home" ]
[:a.navbar-item {:class [(active-when ap #{:unpaid-invoices :paid-invoices})]
:href (bidi/path-for routes/routes :unpaid-invoices)}
"Invoices" ]
[:a.navbar-item {:class [(active-when ap = :payments)]
:href (bidi/path-for routes/routes :payments)}
"Payments" ]
(when (= "admin" (:user/role @user))
(when (p/can? @user {:subject :invoice-page})
[:a.navbar-item {:class [(active-when ap #{:unpaid-invoices :paid-invoices})]
:href (bidi/path-for routes/routes :unpaid-invoices)}
"Invoices" ])
(when (p/can? @user {:subject :payment-page})
[:a.navbar-item {:class [(active-when ap = :payments)]
:href (bidi/path-for routes/routes :payments)}
"Payments" ])
(when (p/can? @user {:subject :pos-page})
[:a.navbar-item {:class [(active-when ap = :pos-sales)]
:href (str (bidi/path-for ssr-routes/only-routes :pos-sales) "?date-range=week")}
:href (str (bidi/path-for ssr-routes/only-routes :pos-sales) "?date-range=week")}
"POS" ])
[:a.navbar-item {:class [(active-when ap = :transactions)]
:href (bidi/path-for routes/routes :transactions)}
"Transactions" ]
(when (not= "manager" (:user/role @user))
(when (p/can? @user {:subject :transaction-page})
[:a.navbar-item {:class [(active-when ap = :transactions)]
:href (bidi/path-for routes/routes :transactions)}
"Transactions" ])
(when (p/can? @user {:subject :ledger-page})
[:a.navbar-item {:class [(active-when ap = :ledger)]
:href (bidi/path-for routes/routes :ledger)}
"Ledger" ])])
(when-not is-initial-loading
[:div.navbar-end
(when (> (count @clients) 1)