@@ -173,7 +173,8 @@ function addNewUser() {
173173 apiUserCreate ( editName . value . trim ( ) )
174174 . then ( data => {
175175 $ ( '#newUserModal' ) . modal ( 'hide' ) ;
176- addRowUser ( data . id , data . name ) ;
176+ addRowUser ( data . id , data . name , data . permissions ) ;
177+ console . log ( data ) ;
177178 } )
178179 . catch ( error => {
179180 if ( error . message == "duplicate" ) {
@@ -190,8 +191,87 @@ function addNewUser() {
190191
191192
192193
194+ const PermissionDefinitions = [
195+ {
196+ key : "UserPermGuestUploads" ,
197+ bit : 1 << 8 ,
198+ icon : "bi bi-box-arrow-in-down" ,
199+ title : "Create file requests" ,
200+ htmlId : userid => `perm_guest_upload_${ userid } ` ,
201+ apiName : "PERM_GUEST_UPLOAD"
202+ } ,
203+ {
204+ key : "UserPermReplaceUploads" ,
205+ bit : 1 << 0 ,
206+ icon : "bi bi-recycle" ,
207+ title : "Replace own uploads" ,
208+ htmlId : userid => `perm_replace_${ userid } ` ,
209+ apiName : "PERM_REPLACE"
210+ } ,
211+ {
212+ key : "UserPermListOtherUploads" ,
213+ bit : 1 << 1 ,
214+ icon : "bi bi-eye" ,
215+ title : "List other uploads" ,
216+ htmlId : userid => `perm_list_${ userid } ` ,
217+ apiName : "PERM_LIST"
218+ } ,
219+ {
220+ key : "UserPermEditOtherUploads" ,
221+ bit : 1 << 2 ,
222+ icon : "bi bi-pencil" ,
223+ title : "Edit other uploads" ,
224+ htmlId : userid => `perm_edit_${ userid } ` ,
225+ apiName : "PERM_EDIT"
226+ } ,
227+ {
228+ key : "UserPermDeleteOtherUploads" ,
229+ bit : 1 << 4 ,
230+ icon : "bi bi-trash3" ,
231+ title : "Delete other uploads" ,
232+ htmlId : userid => `perm_delete_${ userid } ` ,
233+ apiName : "PERM_DELETE"
234+ } ,
235+ {
236+ key : "UserPermReplaceOtherUploads" ,
237+ bit : 1 << 3 ,
238+ icon : "bi bi-arrow-left-right" ,
239+ title : "Replace other uploads" ,
240+ htmlId : userid => `perm_replace_other_${ userid } ` ,
241+ apiName : "PERM_REPLACE_OTHER"
242+ } ,
243+ {
244+ key : "UserPermManageLogs" ,
245+ bit : 1 << 5 ,
246+ icon : "bi bi-card-list" ,
247+ title : "Manage system logs" ,
248+ htmlId : userid => `perm_logs_${ userid } ` ,
249+ apiName : "PERM_LOGS"
250+ } ,
251+ {
252+ key : "UserPermManageUsers" ,
253+ bit : 1 << 7 ,
254+ icon : "bi bi-people" ,
255+ title : "Manage users" ,
256+ htmlId : userid => `perm_users_${ userid } ` ,
257+ apiName : "PERM_USERS"
258+ } ,
259+ {
260+ key : "UserPermManageApiKeys" ,
261+ bit : 1 << 6 ,
262+ icon : "bi bi-sliders2" ,
263+ title : "Manage API keys" ,
264+ htmlId : userid => `perm_api_${ userid } ` ,
265+ apiName : "PERM_API"
266+ }
267+ ] ;
268+
269+ function hasPermission ( userPermissions , permissionBit ) {
270+ return ( userPermissions & permissionBit ) !== 0 ;
271+ }
193272
194- function addRowUser ( userid , name ) {
273+
274+ function addRowUser ( userid , name , permissions ) {
195275
196276 userid = sanitizeUserId ( userid ) ;
197277
@@ -260,23 +340,20 @@ function addRowUser(userid, name) {
260340 cellActions . appendChild ( btnGroup ) ;
261341
262342 // Permissions
263- cellPermissions . innerHTML = `
264- <i id="perm_replace_${ userid } " class="bi bi-recycle perm-notgranted " title="Replace own uploads" onclick='changeUserPermission(${ userid } ,"PERM_REPLACE", "perm_replace_${ userid } ");'></i>
265-
266- <i id="perm_list_${ userid } " class="bi bi-eye perm-notgranted " title="List other uploads" onclick='changeUserPermission(${ userid } ,"PERM_LIST", "perm_list_${ userid } ");'></i>
267-
268- <i id="perm_edit_${ userid } " class="bi bi-pencil perm-notgranted " title="Edit other uploads" onclick='changeUserPermission(${ userid } ,"PERM_EDIT", "perm_edit_${ userid } ");'></i>
269-
270- <i id="perm_delete_${ userid } " class="bi bi-trash3 perm-notgranted " title="Delete other uploads" onclick='changeUserPermission(${ userid } ,"PERM_DELETE", "perm_delete_${ userid } ");'></i>
271-
272- <i id="perm_replace_other_${ userid } " class="bi bi-arrow-left-right perm-notgranted " title="Replace other uploads" onclick='changeUserPermission(${ userid } ,"PERM_REPLACE_OTHER", "perm_replace_other_${ userid } ");'></i>
273-
274- <i id="perm_logs_${ userid } " class="bi bi-card-list perm-notgranted " title="Manage system logs" onclick='changeUserPermission(${ userid } ,"PERM_LOGS", "perm_logs_${ userid } ");'></i>
275-
276- <i id="perm_users_${ userid } " class="bi bi-people perm-notgranted " title="Manage users" onclick='changeUserPermission(${ userid } ,"PERM_USERS", "perm_users_${ userid } ");'></i>
277-
278- <i id="perm_api_${ userid } " class="bi bi-sliders2 perm-notgranted " title="Manage API keys" onclick='changeUserPermission(${ userid } ,"PERM_API", "perm_api_${ userid } ");'></i>` ;
279-
343+ cellPermissions . innerHTML = PermissionDefinitions . map ( perm => {
344+ const granted = hasPermission ( permissions , perm . bit )
345+ ? "perm-granted"
346+ : "perm-notgranted" ;
347+
348+ const id = perm . htmlId ( userid ) ;
349+
350+ return `
351+ <i id="${ id } "
352+ class="${ perm . icon } ${ granted } "
353+ title="${ perm . title } "
354+ onclick='changeUserPermission(${ userid } , "${ perm . apiName } ", "${ id } ")'>
355+ </i>` ;
356+ } ) . join ( "" ) ;
280357
281358 setTimeout ( ( ) => {
282359
0 commit comments