feat(reports): refine exports and restore project access
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
|
||||
from django.utils import timezone
|
||||
from rest_framework.exceptions import ValidationError, PermissionDenied
|
||||
|
||||
from django.utils import timezone
|
||||
from rest_framework.exceptions import ValidationError, PermissionDenied
|
||||
|
||||
from apps.projects.services.access import user_has_project_access
|
||||
from apps.time_entries.models import TimeEntry
|
||||
from apps.time_entries.services.rates import resolve_rate
|
||||
from apps.workspaces.models import Workspace
|
||||
@@ -40,8 +41,10 @@ def create_time_entry(user, workspace_id, start_time, end_time=None, project=Non
|
||||
if start_time and end_time and start_time >= end_time:
|
||||
raise ValidationError({"end_time": "End time must be strictly after start time."})
|
||||
|
||||
if project and project.workspace_id != workspace_id:
|
||||
raise ValidationError({"project": "Project must belong to the same workspace."})
|
||||
if project and project.workspace_id != workspace_id:
|
||||
raise ValidationError({"project": "Project must belong to the same workspace."})
|
||||
if project and not user_has_project_access(user, project):
|
||||
raise ValidationError({"project_id": "Selected project is unavailable."})
|
||||
|
||||
duration = (end_time - start_time) if end_time else None
|
||||
|
||||
@@ -76,9 +79,11 @@ def update_time_entry(entry, **kwargs):
|
||||
Updates an existing time entry, recalculating duration and rates if necessary.
|
||||
"""
|
||||
# Verify Project Workspace if changing
|
||||
project = kwargs.get("project", entry.project)
|
||||
if project and project.workspace_id != entry.workspace_id:
|
||||
raise ValidationError({"project": "Project must belong to the same workspace."})
|
||||
project = kwargs.get("project", entry.project)
|
||||
if project and project.workspace_id != entry.workspace_id:
|
||||
raise ValidationError({"project": "Project must belong to the same workspace."})
|
||||
if project and not user_has_project_access(entry.user, project):
|
||||
raise ValidationError({"project_id": "Selected project is unavailable."})
|
||||
|
||||
start_time = kwargs.get("start_time", entry.start_time)
|
||||
end_time = kwargs.get("end_time", entry.end_time)
|
||||
|
||||
Reference in New Issue
Block a user