@@ -166,6 +166,7 @@ async function addURLToDB(name, url, email, groups) {
166
166
} )
167
167
} )
168
168
}
169
+
169
170
async function getDataForEmail ( email ) {
170
171
return new Promise ( function ( resolve , reject ) {
171
172
db . serialize ( function ( ) {
@@ -181,6 +182,22 @@ async function getDataForEmail(email) {
181
182
} )
182
183
}
183
184
185
+ async function getAllLinks ( ) {
186
+ return new Promise ( function ( resolve , reject ) {
187
+ db . serialize ( function ( ) {
188
+ const stmt = db . prepare ( "SELECT * FROM urlData" ) ;
189
+ stmt . all ( [ ] , function ( err , data ) {
190
+ if ( err ) {
191
+ reject ( err )
192
+ } else {
193
+ resolve ( data )
194
+ }
195
+ } )
196
+ } )
197
+ } )
198
+ }
199
+
200
+
184
201
async function getDelegatedLinks ( userGroups ) {
185
202
return new Promise ( function ( resolve , reject ) {
186
203
db . serialize ( function ( ) {
@@ -332,12 +349,22 @@ app.use(async (req, res, next) => {
332
349
if ( ! req . user ) { return next ( ) ; }
333
350
req . user . _json . groups = await getUserGroups ( req . user . oid , gat ) ;
334
351
const intserect = validateArray ( config . groups_permitted , req . user . _json . groups ) ;
335
- if ( ! intserect ) {
352
+ const intersect2 = validateArray ( config . admin_groups , req . user . _json . groups )
353
+ if ( ! intserect && ! intersect2 ) {
336
354
return res . status ( 401 ) . redirect ( "/unauthorized" ) ;
337
355
}
338
356
next ( ) ;
339
357
} )
340
358
359
+ app . use ( '/admin/' , async ( req , res , next ) => {
360
+ if ( ! req . user ) { return next ( ) ; }
361
+ req . user . _json . groups = await getUserGroups ( req . user . oid , gat ) ;
362
+ const intersect2 = validateArray ( config . admin_groups , req . user . _json . groups )
363
+ if ( ! intersect2 ) {
364
+ return res . status ( 401 ) . redirect ( "/unauthorized" ) ;
365
+ }
366
+ next ( ) ;
367
+ } )
341
368
// begin business logic
342
369
343
370
app . get ( '/' , async function ( req , res ) {
@@ -426,6 +453,32 @@ app.get('/mylinks', ensureAuthenticated, async function (req, res) {
426
453
} )
427
454
} )
428
455
456
+ app . get ( '/admin/links' , ensureAuthenticated , async function ( req , res ) {
457
+ const email = req . user . _json . preferred_username ;
458
+ const name = req . user . displayName ;
459
+ const userGroups = req . user . _json . groups !== undefined ? req . user . _json . groups : [ ] ;
460
+ let data = await getAllLinks ( ) . catch ( ( ) => { res . status ( 500 ) . render ( '500' , { productName : config . branding . title , logoPath : config . branding . logoPath , copyrightOwner : config . branding . copyrightOwner , statusURL : config . branding . statusURL , } ) ; return } ) ;
461
+ data = data . map ( ( item ) => {
462
+ const d = item ;
463
+ d . url = atob ( d . url ) ;
464
+ d . groups = d . groups . replace ( ',' , "<br />" )
465
+ return d ;
466
+ } )
467
+ res . render ( 'adminlinks' , {
468
+ partials,
469
+ productName : config . branding . title ,
470
+ logoPath : config . branding . logoPath ,
471
+ copyrightOwner : config . branding . copyrightOwner ,
472
+ statusURL : config . branding . statusURL ,
473
+ orgHome : config . branding . orgHome ,
474
+ data,
475
+ name,
476
+ email,
477
+ baseURL,
478
+ productName : config . branding . title
479
+ } )
480
+ } )
481
+
429
482
app . delete ( '/deleteLink' , ensureAuthenticated , async function ( req , res ) {
430
483
const name = req . query . name ;
431
484
removeURLfromDB ( name ) . then ( ( ) => {
0 commit comments