User management and module improvements

- Added daily_mirror module to permissions system
- Fixed user module management - updates now work correctly
- Implemented dashboard module filtering based on user permissions
- Fixed warehouse create_locations page (config parser and delete)
- Implemented POST-Redirect-GET pattern to prevent duplicate entries
- Added application license system with validation middleware
- Cleaned up debug logging code
- Improved user module selection with fetch API instead of form submit
This commit is contained in:
ske087
2025-11-29 14:16:36 +02:00
parent 3e314332a7
commit 7912885046
9 changed files with 355 additions and 69 deletions

View File

@@ -20,6 +20,55 @@ def create_app():
# Add 'now' function to Jinja2 globals
app.jinja_env.globals['now'] = datetime.now
# Add license check middleware
@app.before_request
def check_license_middleware():
from flask import session, request, redirect, url_for, flash, render_template
import os
import json
from datetime import datetime
# Skip license check for static files, login page, and superadmin users
if request.endpoint and (
request.endpoint == 'static' or
request.endpoint == 'main.login' or
request.path.startswith('/static/')
):
return None
# Skip if user is not logged in (will be redirected to login by other means)
if 'user' not in session:
return None
# Skip license check for superadmin
if session.get('role') == 'superadmin':
return None
# Check license validity
license_path = os.path.join(app.instance_path, 'app_license.json')
if not os.path.exists(license_path):
session.clear()
flash('⚠️ Application License Missing - Please contact your superadmin to generate a license key.', 'danger')
return redirect(url_for('main.login'))
try:
with open(license_path, 'r') as f:
license_data = json.load(f)
valid_until = datetime.strptime(license_data['valid_until'], '%Y-%m-%d')
if datetime.utcnow().date() > valid_until.date():
session.clear()
flash(f'⚠️ Application License Expired on {license_data["valid_until"]} - Please contact your superadmin to renew the license.', 'danger')
return redirect(url_for('main.login'))
except Exception as e:
session.clear()
flash('⚠️ License Validation Error - Please contact your superadmin.', 'danger')
return redirect(url_for('main.login'))
return None
# Initialize automatic backup scheduler
from app.backup_scheduler import init_backup_scheduler
init_backup_scheduler(app)