-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuser_single.ml
More file actions
363 lines (358 loc) · 12.6 KB
/
user_single.ml
File metadata and controls
363 lines (358 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
type users_tab = Profile | Unikernels | Policy
let tab_style is_active =
if is_active then
"px-6 py-2.5 text-sm font-medium text-primary-50 bg-primary-500 \
rounded-t-lg border-b-0"
else
"px-6 py-2.5 text-sm font-medium text-primary-600 bg-gray-100 \
hover:bg-primary-50 rounded-t-lg transition-colors duration-200"
let policy_row ?(error = "") instance_name policy (user : User_model.user) =
Tyxml_html.(
tr
[
td
~a:
[
a_class
[
"px-6 py-1 whitespace-nowrap text-sm font-medium \
text-gray-800";
];
]
[
txt (Configuration.name_to_str instance_name);
p ~a:[ a_class [ "text-red-500 text-sm" ] ] [ txt error ];
];
td
~a:
[
a_class
[
"px-6 py-1 whitespace-nowrap text-sm font-medium \
text-gray-800";
];
]
[ txt (string_of_int policy.Vmm_core.Policy.unikernels) ];
td
~a:
[
a_class
[
"px-6 py-1 whitespace-normal text-sm font-medium \
text-gray-800";
];
]
[ txt (string_of_int policy.memory ^ " MB") ];
td
~a:
[
a_class
[
"px-6 py-1 whitespace-normal text-sm font-medium \
text-gray-800";
];
]
[ txt (string_of_int (Option.value policy.block ~default:0) ^ " MB") ];
td
~a:
[
a_class
[
"px-6 py-1 whitespace-normal text-sm font-medium \
text-gray-800";
];
]
[
txt
(String.concat ", "
(List.map string_of_int (Vmm_core.IS.elements policy.cpuids)));
];
td
~a:
[
a_class
[
"px-6 py-1 whitespace-normal text-sm font-medium \
text-gray-800";
];
]
[
txt
(String.concat ", "
(List.map string_of_uri
(Vmm_core.String_set.elements policy.bridges)));
];
td
~a:
[
a_class
[
"px-6 py-4 whitespace-nowrap text-sm font-medium \
text-gray-800";
];
]
[
a
~a:
[
a_href
("/admin/u/policy/edit?uuid=" ^ user.uuid ^ "&instance="
^ Configuration.name_to_str instance_name);
a_class
[
"border border-primary-500 hover:bg-primary-700 px-2 \
py-1 text-primary-800 hover:text-primary-50 rounded";
];
]
[ txt "Edit" ];
];
])
let user_profile (user : User_model.user) =
let user_name = Configuration.name_to_str user.name in
Tyxml_html.(
section
~a:[ a_class [ "p-4 bg-gray-50 my-1" ] ]
[
div
~a:[ a_id "account"; a_class [ "max-w-3xl" ] ]
[
div
~a:[ a_class [ "flex-col justify-center text-center" ] ]
[
i ~a:[ a_class [ "fa-solid fa-circle-user text-7xl" ] ] [];
p
~a:[ a_class [ "text-3xl font-semibold uppercase" ] ]
[ txt user_name ];
];
div
~a:[ a_class [ "grid grid-cols-2 my-4" ] ]
[
label [ txt "Email" ];
p
~a:[ a_class [ "rounded border py-2 px-4 w-full" ] ]
[
txt (Emile.to_string user.email);
(match user.email_verified with
| Some _ptime ->
span
[
i ~a:[ a_class [ "fa-solid fa-check" ] ] [];
i ~a:[ a_class [ "text-xs" ] ] [];
]
| None ->
i
~a:[ a_class [ "fa-solid fa-x text-secondary-500" ] ]
[]);
];
label [ txt "Created at" ];
p
~a:[ a_class [ "rounded border py-2 px-4 w-full" ] ]
[ txt (Utils.TimeHelper.string_of_ptime user.created_at) ];
label [ txt "Last Update" ];
p
~a:[ a_class [ "rounded border py-2 px-4 w-full" ] ]
[ txt (Utils.TimeHelper.string_of_ptime user.updated_at) ];
label [ txt "Email verified at" ];
p
~a:[ a_class [ "rounded border py-2 px-4 w-full" ] ]
[
txt
(match user.email_verified with
| None -> "not verified"
| Some t -> Utils.TimeHelper.string_of_ptime t);
];
div
~a:[ a_class [ "flex justify-center space-x-4 my-4" ] ]
[
Utils.button_component
~attribs:[ a_onclick ("deleteUser('" ^ user.uuid ^ "')") ]
~content:(txt "Delete User") ~btn_type:`Danger_full ();
(if user.active then
Utils.button_component
~attribs:
[
a_onclick
("toggleUserActiveStatus('" ^ user.uuid ^ "')");
]
~content:(txt "Deactivate") ~btn_type:`Danger_full ()
else
Utils.button_component
~attribs:
[
a_onclick
("toggleUserActiveStatus('" ^ user.uuid ^ "')");
]
~content:(txt "Activate") ~btn_type:`Primary_full ());
(if user.super_user then
Utils.button_component
~attribs:
[
a_onclick
("toggleUserAdminStatus('" ^ user.uuid ^ "')");
]
~content:(txt "Remove Admin") ~btn_type:`Danger_full ()
else
Utils.button_component
~attribs:
[
a_onclick
("toggleUserAdminStatus('" ^ user.uuid ^ "')");
]
~content:(txt "Make Admin") ~btn_type:`Primary_full ());
];
];
];
])
let user_policy ~empty_policy (user : User_model.user) policies =
Tyxml_html.(
section
~a:[ a_id "policy-table" ]
[
(match policies with
| [] ->
a
~a:
[
a_href ("/admin/u/policy/edit/" ^ user.uuid);
a_class
[
"border border-primary-500 hover:bg-primary-700 px-2 \
py-1 text-primary-800 hover:text-primary-50 rounded";
];
]
[ txt "Add Policy" ]
| policy ->
table
~a:
[ a_class [ "table-auto min-w-full divide-y divide-gray-200" ] ]
~thead:
(thead
[
tr
[
th
~a:
[
a_class
[
"px-6 py-2 text-start text-xs font-bold \
text-primary-600 uppercase";
];
]
[ txt "Albatross instance" ];
th
~a:
[
a_class
[
"px-6 py-2 text-start text-xs font-bold \
text-primary-600 uppercase";
];
]
[ txt "Allowed unikernels" ];
th
~a:
[
a_class
[
"px-6 py-2 text-start text-xs font-bold \
text-primary-600 uppercase";
];
]
[ txt "Allowed Memory" ];
th
~a:
[
a_class
[
"px-6 py-2 text-start text-xs font-bold \
text-primary-600 uppercase";
];
]
[ txt "Allowed Storage" ];
th
~a:
[
a_class
[
"px-6 py-2 text-start text-xs font-bold \
text-primary-600 uppercase";
];
]
[ txt "CPU IDs" ];
th
~a:
[
a_class
[
"px-6 py-2 text-start text-xs font-bold \
text-primary-600 uppercase";
];
]
[ txt "Network Bridges" ];
th
~a:
[
a_class
[
"px-6 py-2 text-start text-xs font-bold \
text-primary-600 uppercase";
];
]
[ txt "Action" ];
];
])
(List.map
(fun (instance_name, policy) ->
match policy with
| Error error ->
policy_row instance_name empty_policy user ~error
| Ok (Some p) -> policy_row instance_name p user
| Ok None -> policy_row instance_name empty_policy user)
policy));
])
let user_single_layout ~active_tab content uuid =
Tyxml_html.(
section
~a:[ a_class [ "col-span-7 p-4 bg-gray-50 my-1" ] ]
[
div
~a:
[
a_class
[
"flex items-center space-x-1 border-b-2 border-primary-500 \
mb-6";
];
]
[
a
~a:
[
a_href ("/admin/user/profile?uuid=" ^ uuid);
a_class [ tab_style (active_tab = Profile) ];
]
[ i ~a:[ a_class [ "fa-solid fa-user mr-2" ] ] []; txt "Account" ];
a
~a:
[
a_href ("/admin/user/unikernels?uuid=" ^ uuid);
a_class [ tab_style (active_tab = Unikernels) ];
]
[
i ~a:[ a_class [ "fa-solid fa-server mr-2" ] ] [];
txt "Unikernels";
];
a
~a:
[
a_href ("/admin/user/policy?uuid=" ^ uuid);
a_class [ tab_style (active_tab = Policy) ];
]
[
i ~a:[ a_class [ "fa-solid fa-gear mr-2" ] ] [];
txt "Resource Policy";
];
];
div ~a:[ a_class [ "my-5" ] ] [ content ];
])