feat: enhance project and scenario management with role-based access control
- Implemented role-based access control for project and scenario routes. - Added authorization checks to ensure users have appropriate roles for viewing and managing projects and scenarios. - Introduced utility functions for ensuring project and scenario access based on user roles. - Refactored project and scenario routes to utilize new authorization helpers. - Created initial data seeding script to set up default roles and an admin user. - Added tests for authorization helpers and initial data seeding functionality. - Updated exception handling to include authorization errors.
This commit is contained in:
@@ -57,6 +57,10 @@ class ProjectRepository:
|
||||
raise EntityNotFoundError(f"Project {project_id} not found")
|
||||
return project
|
||||
|
||||
def exists(self, project_id: int) -> bool:
|
||||
stmt = select(Project.id).where(Project.id == project_id).limit(1)
|
||||
return self.session.execute(stmt).scalar_one_or_none() is not None
|
||||
|
||||
def create(self, project: Project) -> Project:
|
||||
self.session.add(project)
|
||||
try:
|
||||
@@ -133,6 +137,10 @@ class ScenarioRepository:
|
||||
raise EntityNotFoundError(f"Scenario {scenario_id} not found")
|
||||
return scenario
|
||||
|
||||
def exists(self, scenario_id: int) -> bool:
|
||||
stmt = select(Scenario.id).where(Scenario.id == scenario_id).limit(1)
|
||||
return self.session.execute(stmt).scalar_one_or_none() is not None
|
||||
|
||||
def create(self, scenario: Scenario) -> Scenario:
|
||||
self.session.add(scenario)
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user