Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/src/components/common/toast/ToastContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const handleRemoveToast = (id: string) => {
position: fixed;
top: 80px;
right: 1.5rem;
z-index: 1000;
z-index: 2000;
pointer-events: none;

@media (max-width: 768px) {
Expand Down
19 changes: 13 additions & 6 deletions frontend/src/components/project/task/AssetThumbnailCell.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<template>
<div class="asset-preview-cell" @mouseenter="onMouseEnter" @mouseleave="onMouseLeave">
<div
class="asset-preview-cell"
:class="{ clickable: isClickable }"
@mouseenter="onMouseEnter"
@mouseleave="onMouseLeave"
>
<div class="asset-thumbnail">
<img
:src="getAssetThumbnailUrl(projectId, task.assetId)"
Expand Down Expand Up @@ -93,6 +98,7 @@ interface Props {
task: TaskTableRow;
projectId: number;
allTasks: TaskTableRow[];
isClickable?: boolean;
}

interface Emits {
Expand Down Expand Up @@ -138,7 +144,7 @@ const onImageError = (event: Event) => {
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
cursor: inherit;
padding: 0.5rem;

.asset-thumbnail {
Expand Down Expand Up @@ -254,15 +260,16 @@ const onImageError = (event: Event) => {
z-index: 1;
}
}

&:hover {
&.clickable { cursor: pointer; }

&.clickable:hover {
.asset-thumbnail {
border-color: var(--color-primary);

.thumbnail-image:not(.loading) {
transform: scale(1.02);
}
}
}
}
</style>
</style>
8 changes: 6 additions & 2 deletions frontend/src/core/workspace/loader/workspaceLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,12 @@ export class WorkspaceLoader {
} else {
logger.warn(`No tasks found for asset ${assetId}`);
}
} catch (taskError) {
} catch (taskError: any) {
logger.error("Failed to fetch tasks:", taskError);
// Propagate access-redirect signals so the store/view can handle navigation + toast
if (taskError?.shouldRedirectToTask || taskError?.shouldRedirectToTaskView) {
throw taskError;
}
}

return result;
Expand Down Expand Up @@ -376,4 +380,4 @@ export class WorkspaceLoader {
}

// Export singleton instance
export const workspaceLoader = new WorkspaceLoader();
export const workspaceLoader = new WorkspaceLoader();
9 changes: 7 additions & 2 deletions frontend/src/layouts/WorkspaceLayout.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
<template>
<div class="workspace-layout">
<slot />


<!-- Global toasts -->
<ToastContainer />

<!-- Teleport target for floating action buttons -->
<div id="fab-container"></div>
</div>
</template>

<script setup lang="ts"></script>
<script setup lang="ts">
import ToastContainer from '@/components/common/toast/ToastContainer.vue';
</script>

<style scoped>
.workspace-layout {
Expand Down
33 changes: 20 additions & 13 deletions frontend/src/services/project/task/taskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,25 +348,32 @@ class TaskService extends BaseProjectService {
this.logger.info(`Fetched task ${taskId} successfully`);
return task;
} catch (error: any) {
// Normalize error fields from transformed ServerError or raw axios error
const status = error?.statusCode ?? error?.status ?? error?.response?.status;
const data = error?.serverResponse ?? error?.data ?? error?.response?.data;

// Handle 409 Task assigned to another user with redirect to alternative task
if (error.status === 409 && error.data?.redirectToTask) {
// Create a special error that contains redirect information
const redirectError = new Error(error.data.message || 'This task is assigned to another user.');
(redirectError as any).redirectToTask = error.data.redirectToTask;
(redirectError as any).alternativeTask = error.data.alternativeTask;
(redirectError as any).toastMessage = error.data.toastMessage;
if (status === 409 && data?.redirectToTask) {
const redirectError = new Error(data.message || 'This task is assigned to another user.');
(redirectError as any).redirectToTask = data.redirectToTask;
(redirectError as any).alternativeTask = data.alternativeTask;
(redirectError as any).toastMessage = data.toastMessage;
throw redirectError;
}

// Handle 404 No tasks available with redirect to task view
if (error.status === 404 && error.data?.redirectToTaskView) {
// Create a special error that contains redirect information
const redirectError = new Error(error.data.message || 'No tasks available for annotation.');
if (status === 404 && data?.redirectToTaskView) {
const redirectError = new Error(data.message || 'No tasks available for annotation.');
(redirectError as any).redirectToTaskView = true;
(redirectError as any).toastMessage = error.data.toastMessage;
(redirectError as any).toastMessage = data.toastMessage;
// Pass through explicit signal for "no tasks available"
const msg = (data?.error || data?.message || '').toString();
const noTasksFromMsg = /no\s*tasks\s*available/i.test(msg);
const noTasksFromCount = typeof data?.availableTasks === 'number' && data.availableTasks === 0;
(redirectError as any).noTasksAvailable = noTasksFromMsg || noTasksFromCount;
throw redirectError;
}

// Re-throw other errors
throw error;
}
Expand Down Expand Up @@ -752,4 +759,4 @@ class TaskService extends BaseProjectService {
}
}

export const taskService = new TaskService();
export const taskService = new TaskService();
5 changes: 4 additions & 1 deletion frontend/src/stores/workspaceStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,10 @@ export const useWorkspaceStore = defineStore("workspace", {
if (error?.shouldRedirectToTaskView) {
const redirectError = new Error(error.error || 'Task access denied');
(redirectError as any).redirectToTaskView = true;
(redirectError as any).toastMessage = error.toastMessage || 'You cannot access this task.';
(redirectError as any).noTasksAvailable = error.noTasksAvailable === true;
(redirectError as any).toastMessage = error.toastMessage || (
error.noTasksAvailable ? 'No tasks available to work on right now.' : 'You cannot access this task.'
);
throw redirectError;
}
// For other task loading errors, log but continue
Expand Down
47 changes: 27 additions & 20 deletions frontend/src/views/AnnotationWorkspace.vue
Original file line number Diff line number Diff line change
Expand Up @@ -421,44 +421,43 @@ onMounted(async () => {
} catch (error: any) {
// Handle redirect to alternative task
if (error?.redirectToTask) {
showToast(
'Task Reassigned',
error.toastMessage || 'This task was assigned to another user. We found you an available task to work on.',
'info',
{ duration: 5000 }
);

// Redirect to the alternative task
const alternativeTaskId = error.redirectToTask;
const alternativeTask = error.alternativeTask;

// Navigate to the alternative task
router.replace({
// Load the alternative task in the workspace first
const targetAssetId = (alternativeTask?.assetId?.toString() || props.assetId);
await workspaceStore.loadAsset(props.projectId, targetAssetId, alternativeTaskId.toString());

// Navigate to the alternative task (update URL without re-mount)
await router.replace({
name: 'AnnotationWorkspace',
params: {
projectId: props.projectId,
assetId: alternativeTask?.assetId?.toString() || props.assetId
assetId: targetAssetId
},
query: {
taskId: alternativeTaskId.toString()
}
});

// Show toast after navigation so it's visible in the new context
showToast(
'Task Reassigned',
error.toastMessage || 'This task was assigned to another user. We found you an available task to work on.',
'info',
{ duration: 7500 }
);
return;
}

// Handle task access errors and redirect to task view
if (error?.redirectToTaskView) {
showToast(
'Access Denied',
error.toastMessage || 'You cannot access this task.',
'error',
{ duration: 5000 }
);

const noTasks = !!error.noTasksAvailable;

// Redirect back to task view
const currentTask = workspaceStore.getCurrentTask;
if (currentTask) {
router.push({
await router.push({
name: 'StageTasks',
params: {
projectId: props.projectId,
Expand All @@ -468,13 +467,21 @@ onMounted(async () => {
});
} else {
// Fallback to project dashboard if no current task context
router.push({
await router.push({
name: 'ProjectDashboard',
params: {
projectId: props.projectId
}
});
}

// Show toast after navigation so it's visible on destination view
showToast(
noTasks ? 'All Tasks Complete' : 'Access Denied',
error.toastMessage || (noTasks ? 'No tasks available to work on right now.' : 'You cannot access this task.'),
noTasks ? 'info' : 'error',
{ duration: 6000 }
);
return;
}

Expand Down
3 changes: 2 additions & 1 deletion frontend/src/views/project/TasksView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
:task="row"
:project-id="projectId"
:all-tasks="tasks"
:is-clickable="row.isClickable"
@preview-show="showPreview"
@preview-hide="hidePreview"
/>
Expand Down Expand Up @@ -1210,4 +1211,4 @@ onMounted(async () => {
padding: 1rem;
}
}
</style>
</style>
85 changes: 49 additions & 36 deletions server/Server/Services/TaskService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,59 +231,72 @@ public async Task<TaskDto> CreateTaskAsync(int projectId, CreateTaskDto createDt
return null;
}

// Validate task assignment before allowing modifications
if (!string.IsNullOrEmpty(updatingUserId))
{
await ValidateTaskAssignmentAsync(taskId, updatingUserId, "UPDATE");
}

// Update the task properties
if (updateDto.Priority.HasValue)
{
existingTask.Priority = updateDto.Priority.Value;
}

// Handle assignment - support both userId and email assignment
if (updateDto.AssignedToEmail != null)
// Determine what type of changes are requested
var isAssignmentChangeRequested = updateDto.AssignedToEmail != null || updateDto.AssignedToUserId != null;
var isNonAssignmentChangeRequested =
updateDto.Priority.HasValue ||
updateDto.DueDate.HasValue ||
updateDto.Status.HasValue ||
updateDto.WorkflowStageId.HasValue ||
updateDto.Metadata != null ||
updateDto.CompletedAt.HasValue ||
updateDto.ArchivedAt.HasValue ||
updateDto.SuspendedAt.HasValue ||
updateDto.DeferredAt.HasValue ||
updateDto.WorkingTimeMs.HasValue;

// Handle assignment changes first (with role-based permission validation)
if (isAssignmentChangeRequested)
{
string? newAssignedUserId;

// Assignment by email - look up the user ID
if (string.IsNullOrEmpty(updateDto.AssignedToEmail))
if (updateDto.AssignedToEmail != null)
{
// Empty email means unassign
newAssignedUserId = null;
// Assignment by email
if (string.IsNullOrEmpty(updateDto.AssignedToEmail))
{
// Empty email means unassign
newAssignedUserId = null;
}
else
{
// Find user by email
var user = await _userManager.FindByEmailAsync(updateDto.AssignedToEmail);
if (user == null)
{
_logger.LogWarning("User not found for assignment email: {Email}", updateDto.AssignedToEmail);
throw new NotFoundException($"User with email '{updateDto.AssignedToEmail}' not found");
}
newAssignedUserId = user.Id;
}
}
else
{
// Find user by email
var user = await _userManager.FindByEmailAsync(updateDto.AssignedToEmail);
if (user == null)
{
_logger.LogWarning("User not found for assignment email: {Email}", updateDto.AssignedToEmail);
throw new NotFoundException($"User with email '{updateDto.AssignedToEmail}' not found");
}
newAssignedUserId = user.Id;
// Assignment by user ID (legacy)
newAssignedUserId = updateDto.AssignedToUserId;
}

// Validate assignment permissions if assignment is changing and updatingUserId is provided
if (existingTask.AssignedToUserId != newAssignedUserId && !string.IsNullOrEmpty(updatingUserId))
{
await ValidateTaskAssignmentPermissionAsync(existingTask.ProjectId, updatingUserId, newAssignedUserId);
await ValidateTaskAssignmentPermissionAsync(existingTask.ProjectId, updatingUserId!, newAssignedUserId);
}

// Apply the assignment change
existingTask.AssignedToUserId = newAssignedUserId;
}
else if (updateDto.AssignedToUserId != null && updateDto.AssignedToUserId != existingTask.AssignedToUserId)

// For non-assignment updates, ensure user is assigned to the task
// (This runs AFTER potential assignment changes so self-assignment is considered)
if (isNonAssignmentChangeRequested && !string.IsNullOrEmpty(updatingUserId))
{
// Validate assignment permissions if updatingUserId is provided
if (!string.IsNullOrEmpty(updatingUserId))
{
await ValidateTaskAssignmentPermissionAsync(existingTask.ProjectId, updatingUserId, updateDto.AssignedToUserId);
}
await ValidateTaskAssignmentAsync(taskId, updatingUserId!, "UPDATE");
}

// Assignment by userId (legacy support) - only update if explicitly provided
existingTask.AssignedToUserId = updateDto.AssignedToUserId;
// Update the task properties
if (updateDto.Priority.HasValue)
{
existingTask.Priority = updateDto.Priority.Value;
}

if (updateDto.Status.HasValue)
Expand Down Expand Up @@ -661,4 +674,4 @@ private async Task<bool> ValidateTaskAssignmentAsync(int taskId, string userId,
}

#endregion
}
}
Loading