Files
plantillas-proyectos/backend/api/v1/modules/a76/permission_rule_oct/services.py
acazares 52b8fcd434 feat: Implement multi-tenancy support in middleware and security layers
- Enhanced TenantMiddleware to validate tenant information from JWT tokens.
- Added LicenseValidationMiddleware to check tenant licenses before processing requests.
- Updated security utilities to extract tenant information from tokens and validate company access.
- Introduced CompanyStore to manage active company state and handle company switching in the frontend.
- Modified API routes to include company_id in requests for better resource management.
- Improved logging and error handling throughout the middleware and API layers.
- Updated frontend components to reflect changes in company management and selection.
- Added new API route for fetching user's companies with proper authentication handling.
2025-11-11 14:15:31 -06:00

29 lines
905 B
Python

from sqlalchemy.orm import Session
from . import models, dto
class PermissionRuleOctService:
@staticmethod
def get_permission_by_id(db: Session, permission: str):
return (
db.query(models.PermissionRuleOct)
.filter(models.PermissionRuleOct.permission == permission)
.first()
)
@staticmethod
def create_permission(db: Session, permission_data: dto.PermissionRuleOctCreateDTO):
new_permission = models.PermissionRuleOct(**permission_data.dict())
db.add(new_permission)
db.commit()
db.refresh(new_permission)
return new_permission
@staticmethod
def delete_permission(db: Session, permission: str):
permission = PermissionRuleOctService.get_permission_by_id(db, permission)
if permission:
db.delete(permission)
db.commit()
return permission