mirror of https://github.com/Aidaho12/haproxy-wi
				
				
				
			v8.2.0: Refactor error handlers and clean up unused imports
Replaced inline `get_user_params()` calls with decorators for error handlers, improving readability and consistency. Cleaned up unused imports in multiple files and improved logging messages for better clarity. Simplified `create_db.py` by removing unused ORM fields.pull/424/head
							parent
							
								
									8c300a9f7d
								
							
						
					
					
						commit
						44580ac62a
					
				| 
						 | 
				
			
			@ -1,9 +1,6 @@
 | 
			
		|||
import distro
 | 
			
		||||
 | 
			
		||||
from app.modules.db.db_model import (
 | 
			
		||||
	connect, Setting, Role, User, UserGroups, Groups, Services, RoxyTool, Version, GeoipCodes, migrate, mysql_enable, TextField
 | 
			
		||||
)
 | 
			
		||||
from peewee import IntegerField, SQL
 | 
			
		||||
from app.modules.db.db_model import connect, Setting, Role, User, UserGroups, Groups, Services, RoxyTool, GeoipCodes
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
conn = connect()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
from datetime import datetime
 | 
			
		||||
 | 
			
		||||
from peewee import ForeignKeyField,CharField, DateTimeField, AutoField
 | 
			
		||||
from peewee import ForeignKeyField, CharField, DateTimeField, AutoField, TextField, IntegerField, Model, SQL, FloatField
 | 
			
		||||
from playhouse.migrate import *
 | 
			
		||||
from playhouse.shortcuts import ReconnectMixin
 | 
			
		||||
from playhouse.sqlite_ext import SqliteExtDatabase
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -210,7 +210,7 @@ def keep_action_history(service: str, action: str, server_ip: str, user_id: int,
 | 
			
		|||
		history_sql.insert_action_history(service, action, server_id, user_id, user_ip, server_ip, hostname)
 | 
			
		||||
	except Exception as e:
 | 
			
		||||
		logger.error(
 | 
			
		||||
			f'Cannot save a history',
 | 
			
		||||
			'Cannot save a history',
 | 
			
		||||
			server_ip='Roxy-WI server',
 | 
			
		||||
			exception=e,
 | 
			
		||||
			service=service,
 | 
			
		||||
| 
						 | 
				
			
			@ -228,7 +228,7 @@ def get_dick_permit(**kwargs):
 | 
			
		|||
		else:
 | 
			
		||||
			return servers
 | 
			
		||||
	else:
 | 
			
		||||
		print('Atata!')
 | 
			
		||||
		logging('Roxy-WI server', 'warning: has tried to actions in not his group')
 | 
			
		||||
		return []
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -183,13 +183,12 @@ def register_error_handlers(app):
 | 
			
		|||
        return redirect(url_for('login_page', next=request.full_path))
 | 
			
		||||
 | 
			
		||||
    @app.errorhandler(403)
 | 
			
		||||
    @get_user_params()
 | 
			
		||||
    def forbidden(e):
 | 
			
		||||
        """Handle 403 Forbidden errors."""
 | 
			
		||||
        if 'api' in request.url:
 | 
			
		||||
            return jsonify(ErrorResponse(error=str(e)).model_dump(mode='json')), 403
 | 
			
		||||
 | 
			
		||||
        # Get user parameters for rendering the template
 | 
			
		||||
        get_user_params()
 | 
			
		||||
        kwargs = {
 | 
			
		||||
            'user_params': g.user_params,
 | 
			
		||||
            'title': e,
 | 
			
		||||
| 
						 | 
				
			
			@ -198,13 +197,12 @@ def register_error_handlers(app):
 | 
			
		|||
        return render_template('error.html', **kwargs), 403
 | 
			
		||||
 | 
			
		||||
    @app.errorhandler(404)
 | 
			
		||||
    @get_user_params()
 | 
			
		||||
    def not_found(e):
 | 
			
		||||
        """Handle 404 Not Found errors."""
 | 
			
		||||
        if 'api' in request.url:
 | 
			
		||||
            return jsonify(ErrorResponse(error=str(e)).model_dump(mode='json')), 404
 | 
			
		||||
 | 
			
		||||
        # Get user parameters for rendering the template
 | 
			
		||||
        get_user_params()
 | 
			
		||||
        kwargs = {
 | 
			
		||||
            'user_params': g.user_params,
 | 
			
		||||
            'title': e,
 | 
			
		||||
| 
						 | 
				
			
			@ -228,13 +226,12 @@ def register_error_handlers(app):
 | 
			
		|||
        return jsonify(ErrorResponse(error="Too many requests").model_dump(mode='json')), 429
 | 
			
		||||
 | 
			
		||||
    @app.errorhandler(500)
 | 
			
		||||
    @get_user_params()
 | 
			
		||||
    def internal_server_error(e):
 | 
			
		||||
        """Handle 500 Internal Server Error errors."""
 | 
			
		||||
        if 'api' in request.url:
 | 
			
		||||
            return jsonify(ErrorResponse(error=str(e)).model_dump(mode='json')), 500
 | 
			
		||||
 | 
			
		||||
        # Get user parameters for rendering the template
 | 
			
		||||
        get_user_params()
 | 
			
		||||
        kwargs = {
 | 
			
		||||
            'user_params': g.user_params,
 | 
			
		||||
            'title': e,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue