1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-16 10:59:53 +02:00
Mailu/core/admin/audit.py

48 lines
1.1 KiB
Python
Raw Normal View History

#!/usr/bin/python3
2016-08-29 20:18:00 +02:00
import sys
import tabulate
2021-11-02 17:21:31 +02:00
sys.path[0:0] = ['/app']
import mailu
app = mailu.create_app()
2016-08-29 20:18:00 +02:00
# Known endpoints without permissions
known_missing_permissions = [
'index',
'static', 'bootstrap.static',
'admin.static', 'admin.login'
2016-08-29 20:18:00 +02:00
]
# Compute the permission table
missing_permissions = []
permissions = {}
for endpoint, function in app.view_functions.items():
audit = function.__dict__.get('_audit_permissions')
2016-08-29 20:18:00 +02:00
if audit:
handler, args = audit
if args:
model = args[0].__name__
key = args[1]
else:
model = key = None
permissions[endpoint] = [endpoint, handler.__name__, model, key]
elif endpoint not in known_missing_permissions:
missing_permissions.append(endpoint)
# Display the permissions table
print(tabulate.tabulate([
[route, *permissions[route.endpoint]]
for route in app.url_map.iter_rules() if route.endpoint in permissions
]))
# Warn if any endpoint is missing a permission check
if missing_permissions:
print()
print('The following endpoints are missing permission checks:')
print(','.join(missing_permissions))