feat: add logging, marketplace, and admin enhancements
Database & Migrations: - Add application_logs table migration for hybrid cloud logging - Add companies table migration and restructure vendor relationships Logging System: - Implement hybrid logging system (database + file) - Add log_service for centralized log management - Create admin logs page with filtering and viewing capabilities - Add init_log_settings.py script for log configuration - Enhance core logging with database integration Marketplace Integration: - Add marketplace admin page with product management - Create marketplace vendor page with product listings - Implement marketplace.js for both admin and vendor interfaces - Add marketplace integration documentation Admin Enhancements: - Add imports management page and functionality - Create settings page for admin configuration - Add vendor themes management page - Enhance vendor detail and edit pages - Improve code quality dashboard and violation details - Add logs viewing and management - Update icons guide and shared icon system Architecture & Documentation: - Document frontend structure and component architecture - Document models structure and relationships - Add vendor-in-token architecture documentation - Add vendor RBAC (role-based access control) documentation - Document marketplace integration patterns - Update architecture patterns documentation Infrastructure: - Add platform static files structure (css, img, js) - Move architecture_scan.py to proper models location - Update model imports and registrations - Enhance exception handling - Update dependency injection patterns UI/UX: - Improve vendor edit interface - Update admin user interface - Enhance page templates documentation - Add vendor marketplace interface
This commit is contained in:
@@ -134,7 +134,13 @@ class AuthManager:
|
||||
# Authentication successful, return user object
|
||||
return user
|
||||
|
||||
def create_access_token(self, user: User) -> dict[str, Any]:
|
||||
def create_access_token(
|
||||
self,
|
||||
user: User,
|
||||
vendor_id: int | None = None,
|
||||
vendor_code: str | None = None,
|
||||
vendor_role: str | None = None,
|
||||
) -> dict[str, Any]:
|
||||
"""Create a JWT access token for an authenticated user.
|
||||
|
||||
The token includes user identity and role information in the payload.
|
||||
@@ -142,6 +148,9 @@ class AuthManager:
|
||||
|
||||
Args:
|
||||
user (User): Authenticated user object
|
||||
vendor_id (int, optional): Vendor ID if logging into vendor context
|
||||
vendor_code (str, optional): Vendor code if logging into vendor context
|
||||
vendor_role (str, optional): User's role in this vendor (owner, manager, etc.)
|
||||
|
||||
Returns:
|
||||
Dict[str, Any]: Dictionary containing:
|
||||
@@ -163,6 +172,14 @@ class AuthManager:
|
||||
"iat": datetime.now(UTC), # Issued at time (JWT standard claim)
|
||||
}
|
||||
|
||||
# Include vendor information in token if provided (vendor-specific login)
|
||||
if vendor_id is not None:
|
||||
payload["vendor_id"] = vendor_id
|
||||
if vendor_code is not None:
|
||||
payload["vendor_code"] = vendor_code
|
||||
if vendor_role is not None:
|
||||
payload["vendor_role"] = vendor_role
|
||||
|
||||
# Encode the payload into a JWT token
|
||||
token = jwt.encode(payload, self.secret_key, algorithm=self.algorithm)
|
||||
|
||||
@@ -188,6 +205,9 @@ class AuthManager:
|
||||
- username (str): User's username
|
||||
- email (str): User's email address
|
||||
- role (str): User's role (defaults to "user" if not present)
|
||||
- vendor_id (int, optional): Vendor ID if token is vendor-scoped
|
||||
- vendor_code (str, optional): Vendor code if token is vendor-scoped
|
||||
- vendor_role (str, optional): User's role in vendor if vendor-scoped
|
||||
|
||||
Raises:
|
||||
TokenExpiredException: If token has expired
|
||||
@@ -213,7 +233,7 @@ class AuthManager:
|
||||
raise InvalidTokenException("Token missing user identifier")
|
||||
|
||||
# Extract and return user data from token payload
|
||||
return {
|
||||
user_data = {
|
||||
"user_id": int(user_id),
|
||||
"username": payload.get("username"),
|
||||
"email": payload.get("email"),
|
||||
@@ -222,6 +242,16 @@ class AuthManager:
|
||||
), # Default to "user" role if not specified
|
||||
}
|
||||
|
||||
# Include vendor information if present in token
|
||||
if "vendor_id" in payload:
|
||||
user_data["vendor_id"] = payload["vendor_id"]
|
||||
if "vendor_code" in payload:
|
||||
user_data["vendor_code"] = payload["vendor_code"]
|
||||
if "vendor_role" in payload:
|
||||
user_data["vendor_role"] = payload["vendor_role"]
|
||||
|
||||
return user_data
|
||||
|
||||
except jwt.ExpiredSignatureError:
|
||||
# Token has expired (caught by jwt.decode)
|
||||
raise TokenExpiredException()
|
||||
@@ -245,12 +275,15 @@ class AuthManager:
|
||||
Verifies the JWT token from the Authorization header, looks up the user
|
||||
in the database, and ensures the user account is active.
|
||||
|
||||
If the token contains vendor information, attaches it to the user object
|
||||
as dynamic attributes (vendor_id, vendor_code, vendor_role).
|
||||
|
||||
Args:
|
||||
db (Session): SQLAlchemy database session
|
||||
credentials (HTTPAuthorizationCredentials): Bearer token credentials from request
|
||||
|
||||
Returns:
|
||||
User: The authenticated and active user object
|
||||
User: The authenticated and active user object (with vendor attrs if in token)
|
||||
|
||||
Raises:
|
||||
InvalidTokenException: If token verification fails
|
||||
@@ -269,6 +302,15 @@ class AuthManager:
|
||||
if not user.is_active:
|
||||
raise UserNotActiveException()
|
||||
|
||||
# Attach vendor information to user object if present in token
|
||||
# These become dynamic attributes on the user object for this request
|
||||
if "vendor_id" in user_data:
|
||||
user.token_vendor_id = user_data["vendor_id"]
|
||||
if "vendor_code" in user_data:
|
||||
user.token_vendor_code = user_data["vendor_code"]
|
||||
if "vendor_role" in user_data:
|
||||
user.token_vendor_role = user_data["vendor_role"]
|
||||
|
||||
return user
|
||||
|
||||
def require_role(self, required_role: str) -> Callable:
|
||||
|
||||
Reference in New Issue
Block a user