Files
wmantly e9b808d1c2 Add cross-app super admin group; rename Executive page to Overview
- app_super_admin is a new cross-app LDAP group (also recognized by proxy
  and jump-host) that grants full admin here regardless of app_sso_admin
  membership: bypassed centrally in utils/permission.js's byGroup, folded
  into GET /api/user/me's isAdmin flag, and added to nav/forceLogin gates
  alongside app_sso_admin.
- Renamed the Executive page to Overview (route, view, API path
  /api/metrics/overview, nav label, docs), keeping /executive as a 301
  redirect alongside the existing /admin, /notifications, /dashboard
  legacy redirects.
2026-07-30 11:56:58 -04:00

45 lines
1.6 KiB
JavaScript

'use strict';
const router = require('express').Router();
const permission = require('../utils/permission');
const metrics = require('../utils/metrics');
// /api/metrics/overview
router.get('/overview', async (req, res, next) => {
try {
await permission.byGroup(req.user, ['app_sso_admin']);
const topIps = await metrics.getTopN('metrics:failed_ips', 7, 5);
const topUsers = await metrics.getTopN('metrics:failed_users', 7, 5);
const topServices = await metrics.getTopN('metrics:service_usage', 7, 5);
res.json({ results: { ips: topIps, users: topUsers, services: topServices } });
} catch(e) {
next(e);
}
});
// /api/metrics/user/:uid
router.get('/user/:uid', async (req, res, next) => {
try {
// Can only view if admin or self
if (req.user.uid !== req.params.uid) {
await permission.byGroup(req.user, ['app_sso_admin']);
}
// Failed logins for user is hard if we didn't track it by user, but wait, we did! metrics:failed_users:YYYY-MM-DD
// However, we didn't track failed IPs per user. We tracked failed_users as a sorted set.
// To get the user's failures, we just query their score from the union.
// Wait, for services we have user_service_usage:<uid>:<date>. No, in metrics.js I wrote:
// `metrics:user_service_usage:${username}:${date}`
const topServices = await metrics.getTopN('metrics:user_service_usage', 7, 5, req.params.uid);
res.json({ results: { services: topServices } });
} catch(e) {
next(e);
}
});
module.exports = router;