cover/Elixir.DaProductAppWeb.MenuManager.html

1 defmodule DaProductAppWeb.MenuManager do
2 @moduledoc """
3 Manages role-based menu access and navigation items.
4 """
5
6 @doc """
7 Returns menu items based on user role and permissions
8 """
9 def get_menu_items(user) do
10
:-(
case user.role.name do
11
:-(
"admin" -> admin_menu_items()
12
:-(
"manager" -> manager_menu_items()
13
:-(
"operator" -> operator_menu_items()
14
:-(
_ -> basic_menu_items()
15 end
16 end
17
18 @doc """
19 Checks if user has access to a specific menu item
20 """
21 def has_access?(user, menu_item) do
22
:-(
menu_items = get_menu_items(user)
23
:-(
Enum.any?(menu_items, fn item -> item.key == menu_item end)
24 end
25
26
:-(
defp admin_menu_items do
27 [
28 %{
29 key: :dashboard,
30 label: "Dashboard",
31 path: "/dashboard",
32 icon: "home",
33 type: :live_view,
34 live_view: DaProductAppWeb.DashboardLive
35 },
36 %{
37 key: :organizations,
38 label: "Organizations",
39 path: "/organizations",
40 icon: "building-office",
41 type: :live_view,
42 live_view: DaProductAppWeb.OrganizationsLive
43 },
44 %{
45 key: :users,
46 label: "Users",
47 path: "/users",
48 icon: "users",
49 type: :live_view,
50 live_view: DaProductAppWeb.UsersLive
51 },
52 %{
53 key: :transactions,
54 label: "Transactions",
55 path: "/transactions",
56 icon: "credit-card",
57 type: :live_view,
58 live_view: DaProductAppWeb.TransactionsLive
59 },
60 %{
61 key: :qr_validations,
62 label: "QR Validations",
63 path: "/qr-validations",
64 icon: "qr-code",
65 type: :live_view,
66 live_view: DaProductAppWeb.QRValidationsLive
67 },
68 %{
69 key: :req_chk_txn,
70 label: "Transaction Checks",
71 path: "/req-chk-txn",
72 icon: "document-check",
73 type: :live_view,
74 live_view: DaProductAppWeb.ReqChkTxnLive
75 },
76 %{
77 key: :req_pay,
78 label: "Payment Requests",
79 path: "/req-pay",
80 icon: "credit-card",
81 type: :live_view,
82 live_view: DaProductAppWeb.ReqPayLive
83 },
84 %{
85 key: :analytics,
86 label: "Analytics",
87 path: "/analytics",
88 icon: "chart-bar",
89 type: :live_view,
90 live_view: DaProductAppWeb.AnalyticsLive
91 },
92 %{
93 key: :international_payments,
94 label: "International Payments",
95 path: "/international-payments",
96 icon: "globe-alt",
97 type: :live_view,
98 live_view: DaProductAppWeb.InternationalPaymentsLive
99 },
100 %{
101 key: :settlements,
102 label: "Settlements",
103 path: "/settlements",
104 icon: "banknotes",
105 type: :live_view,
106 live_view: DaProductAppWeb.SettlementsLive
107 },
108 %{
109 key: :api_docs,
110 label: "API Documentation",
111 path: "/api-docs",
112 icon: "code-bracket",
113 type: :live_view,
114 live_view: DaProductAppWeb.ApiDocsLive
115 },
116 %{
117 key: :settings,
118 label: "Settings",
119 path: "/settings",
120 icon: "cog-6-tooth",
121 type: :live_view,
122 live_view: DaProductAppWeb.SettingsLive
123 }
124 ]
125 end
126
127
:-(
defp manager_menu_items do
128 [
129 %{
130 key: :dashboard,
131 label: "Dashboard",
132 path: "/dashboard",
133 icon: "home",
134 type: :live_view,
135 live_view: DaProductAppWeb.DashboardLive
136 },
137 %{
138 key: :transactions,
139 label: "Transactions",
140 path: "/transactions",
141 icon: "credit-card",
142 type: :live_view,
143 live_view: DaProductAppWeb.TransactionsLive
144 },
145 %{
146 key: :qr_validations,
147 label: "QR Validations",
148 path: "/qr-validations",
149 icon: "qr-code",
150 type: :live_view,
151 live_view: DaProductAppWeb.QRValidationsLive
152 },
153 %{
154 key: :req_chk_txn,
155 label: "Transaction Checks",
156 path: "/req-chk-txn",
157 icon: "document-check",
158 type: :live_view,
159 live_view: DaProductAppWeb.ReqChkTxnLive
160 },
161 %{
162 key: :req_pay,
163 label: "Payment Requests",
164 path: "/req-pay",
165 icon: "credit-card",
166 type: :live_view,
167 live_view: DaProductAppWeb.ReqPayLive
168 },
169 %{
170 key: :analytics,
171 label: "Analytics",
172 path: "/analytics",
173 icon: "chart-bar",
174 type: :live_view,
175 live_view: DaProductAppWeb.AnalyticsLive
176 },
177 %{
178 key: :international_payments,
179 label: "International Payments",
180 path: "/international-payments",
181 icon: "globe-alt",
182 type: :live_view,
183 live_view: DaProductAppWeb.InternationalPaymentsLive
184 },
185 %{
186 key: :settlements,
187 label: "Settlements",
188 path: "/settlements",
189 icon: "banknotes",
190 type: :live_view,
191 live_view: DaProductAppWeb.SettlementsLive
192 }
193 ]
194 end
195
196
:-(
defp operator_menu_items do
197 [
198 %{
199 key: :dashboard,
200 label: "Dashboard",
201 path: "/dashboard",
202 icon: "home",
203 type: :live_view,
204 live_view: DaProductAppWeb.DashboardLive
205 },
206 %{
207 key: :transactions,
208 label: "Transactions",
209 path: "/transactions",
210 icon: "credit-card",
211 type: :live_view,
212 live_view: DaProductAppWeb.TransactionsLive
213 },
214 %{
215 key: :qr_validations,
216 label: "QR Validations",
217 path: "/qr-validations",
218 icon: "qr-code",
219 type: :live_view,
220 live_view: DaProductAppWeb.QrValidationsLive
221 },
222 %{
223 key: :req_chk_txn,
224 label: "Transaction Checks",
225 path: "/req-chk-txn",
226 icon: "document-check",
227 type: :live_view,
228 live_view: DaProductAppWeb.ReqChkTxnLive
229 },
230 %{
231 key: :req_pay,
232 label: "Payment Requests",
233 path: "/req-pay",
234 icon: "credit-card",
235 type: :live_view,
236 live_view: DaProductAppWeb.ReqPayLive
237 }
238 ]
239 end
240
241
:-(
defp basic_menu_items do
242 [
243 %{
244 key: :dashboard,
245 label: "Dashboard",
246 path: "/dashboard",
247 icon: "home",
248 type: :live_view,
249 live_view: DaProductAppWeb.DashboardLive
250 }
251 ]
252 end
253 end
Line Hits Source