@endora-commerce/mod-tasks 0.0.0-stage → 0.109.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +61 -2
- package/dist/admin/api.d.ts +121 -0
- package/dist/admin/api.d.ts.map +1 -0
- package/dist/admin/api.js +262 -0
- package/dist/admin/api.js.map +1 -0
- package/dist/admin/components/AssigneePicker.d.ts +36 -0
- package/dist/admin/components/AssigneePicker.d.ts.map +1 -0
- package/dist/admin/components/AssigneePicker.js +64 -0
- package/dist/admin/components/AssigneePicker.js.map +1 -0
- package/dist/admin/components/BoardCardFieldsEditor.d.ts +23 -0
- package/dist/admin/components/BoardCardFieldsEditor.d.ts.map +1 -0
- package/dist/admin/components/BoardCardFieldsEditor.js +138 -0
- package/dist/admin/components/BoardCardFieldsEditor.js.map +1 -0
- package/dist/admin/components/ContextLabel.d.ts +13 -0
- package/dist/admin/components/ContextLabel.d.ts.map +1 -0
- package/dist/admin/components/ContextLabel.js +18 -0
- package/dist/admin/components/ContextLabel.js.map +1 -0
- package/dist/admin/components/ContextSection.d.ts +27 -0
- package/dist/admin/components/ContextSection.d.ts.map +1 -0
- package/dist/admin/components/ContextSection.js +60 -0
- package/dist/admin/components/ContextSection.js.map +1 -0
- package/dist/admin/components/DigestControl.d.ts +15 -0
- package/dist/admin/components/DigestControl.d.ts.map +1 -0
- package/dist/admin/components/DigestControl.js +102 -0
- package/dist/admin/components/DigestControl.js.map +1 -0
- package/dist/admin/components/LinkedRecordsSection.d.ts +25 -0
- package/dist/admin/components/LinkedRecordsSection.d.ts.map +1 -0
- package/dist/admin/components/LinkedRecordsSection.js +93 -0
- package/dist/admin/components/LinkedRecordsSection.js.map +1 -0
- package/dist/admin/components/LookupPicker.d.ts +26 -0
- package/dist/admin/components/LookupPicker.d.ts.map +1 -0
- package/dist/admin/components/LookupPicker.js +42 -0
- package/dist/admin/components/LookupPicker.js.map +1 -0
- package/dist/admin/components/RelatedTasksSection.d.ts +19 -0
- package/dist/admin/components/RelatedTasksSection.d.ts.map +1 -0
- package/dist/admin/components/RelatedTasksSection.js +64 -0
- package/dist/admin/components/RelatedTasksSection.js.map +1 -0
- package/dist/admin/components/RemindersSection.d.ts +22 -0
- package/dist/admin/components/RemindersSection.d.ts.map +1 -0
- package/dist/admin/components/RemindersSection.js +107 -0
- package/dist/admin/components/RemindersSection.js.map +1 -0
- package/dist/admin/components/StatusBadge.d.ts +13 -0
- package/dist/admin/components/StatusBadge.d.ts.map +1 -0
- package/dist/admin/components/StatusBadge.js +12 -0
- package/dist/admin/components/StatusBadge.js.map +1 -0
- package/dist/admin/components/SubtasksSection.d.ts +25 -0
- package/dist/admin/components/SubtasksSection.d.ts.map +1 -0
- package/dist/admin/components/SubtasksSection.js +76 -0
- package/dist/admin/components/SubtasksSection.js.map +1 -0
- package/dist/admin/components/TaskAttachments.d.ts +24 -0
- package/dist/admin/components/TaskAttachments.d.ts.map +1 -0
- package/dist/admin/components/TaskAttachments.js +135 -0
- package/dist/admin/components/TaskAttachments.js.map +1 -0
- package/dist/admin/components/TaskBoard.d.ts +44 -0
- package/dist/admin/components/TaskBoard.d.ts.map +1 -0
- package/dist/admin/components/TaskBoard.js +295 -0
- package/dist/admin/components/TaskBoard.js.map +1 -0
- package/dist/admin/components/TaskCard.d.ts +14 -0
- package/dist/admin/components/TaskCard.d.ts.map +1 -0
- package/dist/admin/components/TaskCard.js +125 -0
- package/dist/admin/components/TaskCard.js.map +1 -0
- package/dist/admin/components/TaskComments.d.ts +18 -0
- package/dist/admin/components/TaskComments.d.ts.map +1 -0
- package/dist/admin/components/TaskComments.js +58 -0
- package/dist/admin/components/TaskComments.js.map +1 -0
- package/dist/admin/components/TaskCustomFields.d.ts +15 -0
- package/dist/admin/components/TaskCustomFields.d.ts.map +1 -0
- package/dist/admin/components/TaskCustomFields.js +66 -0
- package/dist/admin/components/TaskCustomFields.js.map +1 -0
- package/dist/admin/components/TaskFieldInputs.d.ts +47 -0
- package/dist/admin/components/TaskFieldInputs.d.ts.map +1 -0
- package/dist/admin/components/TaskFieldInputs.js +79 -0
- package/dist/admin/components/TaskFieldInputs.js.map +1 -0
- package/dist/admin/components/TaskFilters.d.ts +34 -0
- package/dist/admin/components/TaskFilters.d.ts.map +1 -0
- package/dist/admin/components/TaskFilters.js +100 -0
- package/dist/admin/components/TaskFilters.js.map +1 -0
- package/dist/admin/components/TaskMarkers.d.ts +13 -0
- package/dist/admin/components/TaskMarkers.d.ts.map +1 -0
- package/dist/admin/components/TaskMarkers.js +20 -0
- package/dist/admin/components/TaskMarkers.js.map +1 -0
- package/dist/admin/components/TaskPicker.d.ts +21 -0
- package/dist/admin/components/TaskPicker.d.ts.map +1 -0
- package/dist/admin/components/TaskPicker.js +56 -0
- package/dist/admin/components/TaskPicker.js.map +1 -0
- package/dist/admin/components/ViewModeToggle.d.ts +12 -0
- package/dist/admin/components/ViewModeToggle.d.ts.map +1 -0
- package/dist/admin/components/ViewModeToggle.js +18 -0
- package/dist/admin/components/ViewModeToggle.js.map +1 -0
- package/dist/admin/components/priorities/TaskPriorityDeleteDialog.d.ts +20 -0
- package/dist/admin/components/priorities/TaskPriorityDeleteDialog.d.ts.map +1 -0
- package/dist/admin/components/priorities/TaskPriorityDeleteDialog.js +59 -0
- package/dist/admin/components/priorities/TaskPriorityDeleteDialog.js.map +1 -0
- package/dist/admin/components/priorities/TaskPriorityDialog.d.ts +29 -0
- package/dist/admin/components/priorities/TaskPriorityDialog.d.ts.map +1 -0
- package/dist/admin/components/priorities/TaskPriorityDialog.js +88 -0
- package/dist/admin/components/priorities/TaskPriorityDialog.js.map +1 -0
- package/dist/admin/components/tags/TaskTagDeleteDialog.d.ts +16 -0
- package/dist/admin/components/tags/TaskTagDeleteDialog.d.ts.map +1 -0
- package/dist/admin/components/tags/TaskTagDeleteDialog.js +34 -0
- package/dist/admin/components/tags/TaskTagDeleteDialog.js.map +1 -0
- package/dist/admin/components/tags/TaskTagDialog.d.ts +27 -0
- package/dist/admin/components/tags/TaskTagDialog.d.ts.map +1 -0
- package/dist/admin/components/tags/TaskTagDialog.js +60 -0
- package/dist/admin/components/tags/TaskTagDialog.js.map +1 -0
- package/dist/admin/components/task-columns.d.ts +5 -0
- package/dist/admin/components/task-columns.d.ts.map +1 -0
- package/dist/admin/components/task-columns.js +72 -0
- package/dist/admin/components/task-columns.js.map +1 -0
- package/dist/admin/components/workflow/TaskStatusDeleteDialog.d.ts +21 -0
- package/dist/admin/components/workflow/TaskStatusDeleteDialog.d.ts.map +1 -0
- package/dist/admin/components/workflow/TaskStatusDeleteDialog.js +63 -0
- package/dist/admin/components/workflow/TaskStatusDeleteDialog.js.map +1 -0
- package/dist/admin/components/workflow/TaskStatusDialog.d.ts +32 -0
- package/dist/admin/components/workflow/TaskStatusDialog.d.ts.map +1 -0
- package/dist/admin/components/workflow/TaskStatusDialog.js +102 -0
- package/dist/admin/components/workflow/TaskStatusDialog.js.map +1 -0
- package/dist/admin/components/workflow/TaskStatusesTable.d.ts +20 -0
- package/dist/admin/components/workflow/TaskStatusesTable.d.ts.map +1 -0
- package/dist/admin/components/workflow/TaskStatusesTable.js +25 -0
- package/dist/admin/components/workflow/TaskStatusesTable.js.map +1 -0
- package/dist/admin/index.d.ts +20 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +121 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/lib/current-admin.d.ts +6 -0
- package/dist/admin/lib/current-admin.d.ts.map +1 -0
- package/dist/admin/lib/current-admin.js +11 -0
- package/dist/admin/lib/current-admin.js.map +1 -0
- package/dist/admin/lib/labels.d.ts +30 -0
- package/dist/admin/lib/labels.d.ts.map +1 -0
- package/dist/admin/lib/labels.js +76 -0
- package/dist/admin/lib/labels.js.map +1 -0
- package/dist/admin/lib/references.d.ts +16 -0
- package/dist/admin/lib/references.d.ts.map +1 -0
- package/dist/admin/lib/references.js +53 -0
- package/dist/admin/lib/references.js.map +1 -0
- package/dist/admin/lib/settings-paths.d.ts +10 -0
- package/dist/admin/lib/settings-paths.d.ts.map +1 -0
- package/dist/admin/lib/settings-paths.js +10 -0
- package/dist/admin/lib/settings-paths.js.map +1 -0
- package/dist/admin/lib/task-filters.d.ts +69 -0
- package/dist/admin/lib/task-filters.d.ts.map +1 -0
- package/dist/admin/lib/task-filters.js +180 -0
- package/dist/admin/lib/task-filters.js.map +1 -0
- package/dist/admin/lib/use-editor-focus.d.ts +25 -0
- package/dist/admin/lib/use-editor-focus.d.ts.map +1 -0
- package/dist/admin/lib/use-editor-focus.js +54 -0
- package/dist/admin/lib/use-editor-focus.js.map +1 -0
- package/dist/admin/lib/use-task-vocabulary.d.ts +15 -0
- package/dist/admin/lib/use-task-vocabulary.d.ts.map +1 -0
- package/dist/admin/lib/use-task-vocabulary.js +26 -0
- package/dist/admin/lib/use-task-vocabulary.js.map +1 -0
- package/dist/admin/pages/MyTasksPage.d.ts +17 -0
- package/dist/admin/pages/MyTasksPage.d.ts.map +1 -0
- package/dist/admin/pages/MyTasksPage.js +96 -0
- package/dist/admin/pages/MyTasksPage.js.map +1 -0
- package/dist/admin/pages/TaskCreate.d.ts +34 -0
- package/dist/admin/pages/TaskCreate.d.ts.map +1 -0
- package/dist/admin/pages/TaskCreate.js +146 -0
- package/dist/admin/pages/TaskCreate.js.map +1 -0
- package/dist/admin/pages/TaskDetail.d.ts +33 -0
- package/dist/admin/pages/TaskDetail.d.ts.map +1 -0
- package/dist/admin/pages/TaskDetail.js +431 -0
- package/dist/admin/pages/TaskDetail.js.map +1 -0
- package/dist/admin/pages/TasksPage.d.ts +21 -0
- package/dist/admin/pages/TasksPage.d.ts.map +1 -0
- package/dist/admin/pages/TasksPage.js +145 -0
- package/dist/admin/pages/TasksPage.js.map +1 -0
- package/dist/admin/pages/settings/TaskGeneralSettingsPage.d.ts +13 -0
- package/dist/admin/pages/settings/TaskGeneralSettingsPage.d.ts.map +1 -0
- package/dist/admin/pages/settings/TaskGeneralSettingsPage.js +75 -0
- package/dist/admin/pages/settings/TaskGeneralSettingsPage.js.map +1 -0
- package/dist/admin/pages/settings/TaskPrioritiesPage.d.ts +16 -0
- package/dist/admin/pages/settings/TaskPrioritiesPage.d.ts.map +1 -0
- package/dist/admin/pages/settings/TaskPrioritiesPage.js +75 -0
- package/dist/admin/pages/settings/TaskPrioritiesPage.js.map +1 -0
- package/dist/admin/pages/settings/TaskTagsPage.d.ts +16 -0
- package/dist/admin/pages/settings/TaskTagsPage.d.ts.map +1 -0
- package/dist/admin/pages/settings/TaskTagsPage.js +68 -0
- package/dist/admin/pages/settings/TaskTagsPage.js.map +1 -0
- package/dist/admin/pages/settings/TaskWorkflowPage.d.ts +22 -0
- package/dist/admin/pages/settings/TaskWorkflowPage.d.ts.map +1 -0
- package/dist/admin/pages/settings/TaskWorkflowPage.js +110 -0
- package/dist/admin/pages/settings/TaskWorkflowPage.js.map +1 -0
- package/dist/admin/zones/OpportunityTasksPanel.d.ts +7 -0
- package/dist/admin/zones/OpportunityTasksPanel.d.ts.map +1 -0
- package/dist/admin/zones/OpportunityTasksPanel.js +9 -0
- package/dist/admin/zones/OpportunityTasksPanel.js.map +1 -0
- package/dist/admin/zones/OrderTasksPanel.d.ts +7 -0
- package/dist/admin/zones/OrderTasksPanel.d.ts.map +1 -0
- package/dist/admin/zones/OrderTasksPanel.js +9 -0
- package/dist/admin/zones/OrderTasksPanel.js.map +1 -0
- package/dist/admin/zones/QuoteRequestTasksPanel.d.ts +7 -0
- package/dist/admin/zones/QuoteRequestTasksPanel.d.ts.map +1 -0
- package/dist/admin/zones/QuoteRequestTasksPanel.js +9 -0
- package/dist/admin/zones/QuoteRequestTasksPanel.js.map +1 -0
- package/dist/admin/zones/TasksPanel.d.ts +22 -0
- package/dist/admin/zones/TasksPanel.d.ts.map +1 -0
- package/dist/admin/zones/TasksPanel.js +59 -0
- package/dist/admin/zones/TasksPanel.js.map +1 -0
- package/dist/backend/admin-search-provider.d.ts +38 -0
- package/dist/backend/admin-search-provider.d.ts.map +1 -0
- package/dist/backend/admin-search-provider.js +48 -0
- package/dist/backend/admin-search-provider.js.map +1 -0
- package/dist/backend/domain/board-card-fields.d.ts +35 -0
- package/dist/backend/domain/board-card-fields.d.ts.map +1 -0
- package/dist/backend/domain/board-card-fields.js +98 -0
- package/dist/backend/domain/board-card-fields.js.map +1 -0
- package/dist/backend/domain/due-moment.d.ts +28 -0
- package/dist/backend/domain/due-moment.d.ts.map +1 -0
- package/dist/backend/domain/due-moment.js +66 -0
- package/dist/backend/domain/due-moment.js.map +1 -0
- package/dist/backend/domain/hierarchy.d.ts +36 -0
- package/dist/backend/domain/hierarchy.d.ts.map +1 -0
- package/dist/backend/domain/hierarchy.js +13 -0
- package/dist/backend/domain/hierarchy.js.map +1 -0
- package/dist/backend/domain/list-cursor.d.ts +27 -0
- package/dist/backend/domain/list-cursor.d.ts.map +1 -0
- package/dist/backend/domain/list-cursor.js +75 -0
- package/dist/backend/domain/list-cursor.js.map +1 -0
- package/dist/backend/domain/task-status-graph.d.ts +73 -0
- package/dist/backend/domain/task-status-graph.d.ts.map +1 -0
- package/dist/backend/domain/task-status-graph.js +90 -0
- package/dist/backend/domain/task-status-graph.js.map +1 -0
- package/dist/backend/email-templates/digest-defaults.d.ts +30 -0
- package/dist/backend/email-templates/digest-defaults.d.ts.map +1 -0
- package/dist/backend/email-templates/digest-defaults.js +50 -0
- package/dist/backend/email-templates/digest-defaults.js.map +1 -0
- package/dist/backend/email-templates/reminder-defaults.d.ts +24 -0
- package/dist/backend/email-templates/reminder-defaults.d.ts.map +1 -0
- package/dist/backend/email-templates/reminder-defaults.js +46 -0
- package/dist/backend/email-templates/reminder-defaults.js.map +1 -0
- package/dist/backend/entities/task-assignee.entity.d.ts +15 -0
- package/dist/backend/entities/task-assignee.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-assignee.entity.js +47 -0
- package/dist/backend/entities/task-assignee.entity.js.map +1 -0
- package/dist/backend/entities/task-attachment.entity.d.ts +15 -0
- package/dist/backend/entities/task-attachment.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-attachment.entity.js +53 -0
- package/dist/backend/entities/task-attachment.entity.js.map +1 -0
- package/dist/backend/entities/task-comment.entity.d.ts +17 -0
- package/dist/backend/entities/task-comment.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-comment.entity.js +62 -0
- package/dist/backend/entities/task-comment.entity.js.map +1 -0
- package/dist/backend/entities/task-digest-subscription.entity.d.ts +15 -0
- package/dist/backend/entities/task-digest-subscription.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-digest-subscription.entity.js +46 -0
- package/dist/backend/entities/task-digest-subscription.entity.js.map +1 -0
- package/dist/backend/entities/task-list-saved-view.entity.d.ts +25 -0
- package/dist/backend/entities/task-list-saved-view.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-list-saved-view.entity.js +74 -0
- package/dist/backend/entities/task-list-saved-view.entity.js.map +1 -0
- package/dist/backend/entities/task-priority.entity.d.ts +17 -0
- package/dist/backend/entities/task-priority.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-priority.entity.js +66 -0
- package/dist/backend/entities/task-priority.entity.js.map +1 -0
- package/dist/backend/entities/task-record-link.entity.d.ts +17 -0
- package/dist/backend/entities/task-record-link.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-record-link.entity.js +58 -0
- package/dist/backend/entities/task-record-link.entity.js.map +1 -0
- package/dist/backend/entities/task-reference.entity.d.ts +21 -0
- package/dist/backend/entities/task-reference.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-reference.entity.js +60 -0
- package/dist/backend/entities/task-reference.entity.js.map +1 -0
- package/dist/backend/entities/task-relation.entity.d.ts +13 -0
- package/dist/backend/entities/task-relation.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-relation.entity.js +45 -0
- package/dist/backend/entities/task-relation.entity.js.map +1 -0
- package/dist/backend/entities/task-reminder-delivery.entity.d.ts +18 -0
- package/dist/backend/entities/task-reminder-delivery.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-reminder-delivery.entity.js +53 -0
- package/dist/backend/entities/task-reminder-delivery.entity.js.map +1 -0
- package/dist/backend/entities/task-reminder.entity.d.ts +21 -0
- package/dist/backend/entities/task-reminder.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-reminder.entity.js +70 -0
- package/dist/backend/entities/task-reminder.entity.js.map +1 -0
- package/dist/backend/entities/task-status-transition.entity.d.ts +14 -0
- package/dist/backend/entities/task-status-transition.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-status-transition.entity.js +48 -0
- package/dist/backend/entities/task-status-transition.entity.js.map +1 -0
- package/dist/backend/entities/task-status.entity.d.ts +29 -0
- package/dist/backend/entities/task-status.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-status.entity.js +85 -0
- package/dist/backend/entities/task-status.entity.js.map +1 -0
- package/dist/backend/entities/task-tag-assignment.entity.d.ts +10 -0
- package/dist/backend/entities/task-tag-assignment.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-tag-assignment.entity.js +35 -0
- package/dist/backend/entities/task-tag-assignment.entity.js.map +1 -0
- package/dist/backend/entities/task-tag.entity.d.ts +14 -0
- package/dist/backend/entities/task-tag.entity.d.ts.map +1 -0
- package/dist/backend/entities/task-tag.entity.js +50 -0
- package/dist/backend/entities/task-tag.entity.js.map +1 -0
- package/dist/backend/entities/task.entity.d.ts +66 -0
- package/dist/backend/entities/task.entity.d.ts.map +1 -0
- package/dist/backend/entities/task.entity.js +175 -0
- package/dist/backend/entities/task.entity.js.map +1 -0
- package/dist/backend/index.d.ts +40 -0
- package/dist/backend/index.d.ts.map +1 -0
- package/dist/backend/index.js +642 -0
- package/dist/backend/index.js.map +1 -0
- package/dist/backend/routes/routes.board.d.ts +21 -0
- package/dist/backend/routes/routes.board.d.ts.map +1 -0
- package/dist/backend/routes/routes.board.js +28 -0
- package/dist/backend/routes/routes.board.js.map +1 -0
- package/dist/backend/routes/routes.collaboration.d.ts +30 -0
- package/dist/backend/routes/routes.collaboration.d.ts.map +1 -0
- package/dist/backend/routes/routes.collaboration.js +124 -0
- package/dist/backend/routes/routes.collaboration.js.map +1 -0
- package/dist/backend/routes/routes.priorities.d.ts +15 -0
- package/dist/backend/routes/routes.priorities.d.ts.map +1 -0
- package/dist/backend/routes/routes.priorities.js +27 -0
- package/dist/backend/routes/routes.priorities.js.map +1 -0
- package/dist/backend/routes/routes.reminders.d.ts +23 -0
- package/dist/backend/routes/routes.reminders.d.ts.map +1 -0
- package/dist/backend/routes/routes.reminders.js +36 -0
- package/dist/backend/routes/routes.reminders.js.map +1 -0
- package/dist/backend/routes/routes.settings.d.ts +16 -0
- package/dist/backend/routes/routes.settings.d.ts.map +1 -0
- package/dist/backend/routes/routes.settings.js +19 -0
- package/dist/backend/routes/routes.settings.js.map +1 -0
- package/dist/backend/routes/routes.tags.d.ts +15 -0
- package/dist/backend/routes/routes.tags.d.ts.map +1 -0
- package/dist/backend/routes/routes.tags.js +27 -0
- package/dist/backend/routes/routes.tags.js.map +1 -0
- package/dist/backend/routes/routes.tasks.d.ts +42 -0
- package/dist/backend/routes/routes.tasks.d.ts.map +1 -0
- package/dist/backend/routes/routes.tasks.js +109 -0
- package/dist/backend/routes/routes.tasks.js.map +1 -0
- package/dist/backend/routes/routes.views.d.ts +17 -0
- package/dist/backend/routes/routes.views.d.ts.map +1 -0
- package/dist/backend/routes/routes.views.js +29 -0
- package/dist/backend/routes/routes.views.js.map +1 -0
- package/dist/backend/routes/routes.workflow.d.ts +19 -0
- package/dist/backend/routes/routes.workflow.d.ts.map +1 -0
- package/dist/backend/routes/routes.workflow.js +34 -0
- package/dist/backend/routes/routes.workflow.js.map +1 -0
- package/dist/backend/saved-view-actor.d.ts +16 -0
- package/dist/backend/saved-view-actor.d.ts.map +1 -0
- package/dist/backend/saved-view-actor.js +24 -0
- package/dist/backend/saved-view-actor.js.map +1 -0
- package/dist/backend/services/attachment-active-content.d.ts +22 -0
- package/dist/backend/services/attachment-active-content.d.ts.map +1 -0
- package/dist/backend/services/attachment-active-content.js +80 -0
- package/dist/backend/services/attachment-active-content.js.map +1 -0
- package/dist/backend/services/attachment-service.d.ts +71 -0
- package/dist/backend/services/attachment-service.d.ts.map +1 -0
- package/dist/backend/services/attachment-service.js +236 -0
- package/dist/backend/services/attachment-service.js.map +1 -0
- package/dist/backend/services/board-card-field-service.d.ts +36 -0
- package/dist/backend/services/board-card-field-service.d.ts.map +1 -0
- package/dist/backend/services/board-card-field-service.js +71 -0
- package/dist/backend/services/board-card-field-service.js.map +1 -0
- package/dist/backend/services/board-service.d.ts +38 -0
- package/dist/backend/services/board-service.d.ts.map +1 -0
- package/dist/backend/services/board-service.js +57 -0
- package/dist/backend/services/board-service.js.map +1 -0
- package/dist/backend/services/comment-service.d.ts +61 -0
- package/dist/backend/services/comment-service.d.ts.map +1 -0
- package/dist/backend/services/comment-service.js +219 -0
- package/dist/backend/services/comment-service.js.map +1 -0
- package/dist/backend/services/context-lookup.d.ts +19 -0
- package/dist/backend/services/context-lookup.d.ts.map +1 -0
- package/dist/backend/services/context-lookup.js +53 -0
- package/dist/backend/services/context-lookup.js.map +1 -0
- package/dist/backend/services/digest-service.d.ts +88 -0
- package/dist/backend/services/digest-service.d.ts.map +1 -0
- package/dist/backend/services/digest-service.js +212 -0
- package/dist/backend/services/digest-service.js.map +1 -0
- package/dist/backend/services/document-lookup-service.d.ts +40 -0
- package/dist/backend/services/document-lookup-service.d.ts.map +1 -0
- package/dist/backend/services/document-lookup-service.js +67 -0
- package/dist/backend/services/document-lookup-service.js.map +1 -0
- package/dist/backend/services/hierarchy-service.d.ts +66 -0
- package/dist/backend/services/hierarchy-service.d.ts.map +1 -0
- package/dist/backend/services/hierarchy-service.js +132 -0
- package/dist/backend/services/hierarchy-service.js.map +1 -0
- package/dist/backend/services/maintenance-service.d.ts +61 -0
- package/dist/backend/services/maintenance-service.d.ts.map +1 -0
- package/dist/backend/services/maintenance-service.js +119 -0
- package/dist/backend/services/maintenance-service.js.map +1 -0
- package/dist/backend/services/mention-service.d.ts +70 -0
- package/dist/backend/services/mention-service.d.ts.map +1 -0
- package/dist/backend/services/mention-service.js +113 -0
- package/dist/backend/services/mention-service.js.map +1 -0
- package/dist/backend/services/owner-read-permissions.d.ts +50 -0
- package/dist/backend/services/owner-read-permissions.d.ts.map +1 -0
- package/dist/backend/services/owner-read-permissions.js +58 -0
- package/dist/backend/services/owner-read-permissions.js.map +1 -0
- package/dist/backend/services/priority-service.d.ts +76 -0
- package/dist/backend/services/priority-service.d.ts.map +1 -0
- package/dist/backend/services/priority-service.js +188 -0
- package/dist/backend/services/priority-service.js.map +1 -0
- package/dist/backend/services/record-link-service.d.ts +73 -0
- package/dist/backend/services/record-link-service.d.ts.map +1 -0
- package/dist/backend/services/record-link-service.js +187 -0
- package/dist/backend/services/record-link-service.js.map +1 -0
- package/dist/backend/services/record-owners.d.ts +52 -0
- package/dist/backend/services/record-owners.d.ts.map +1 -0
- package/dist/backend/services/record-owners.js +54 -0
- package/dist/backend/services/record-owners.js.map +1 -0
- package/dist/backend/services/reference-service.d.ts +77 -0
- package/dist/backend/services/reference-service.d.ts.map +1 -0
- package/dist/backend/services/reference-service.js +184 -0
- package/dist/backend/services/reference-service.js.map +1 -0
- package/dist/backend/services/relation-service.d.ts +39 -0
- package/dist/backend/services/relation-service.d.ts.map +1 -0
- package/dist/backend/services/relation-service.js +77 -0
- package/dist/backend/services/relation-service.js.map +1 -0
- package/dist/backend/services/reminder-schedule.d.ts +28 -0
- package/dist/backend/services/reminder-schedule.d.ts.map +1 -0
- package/dist/backend/services/reminder-schedule.js +60 -0
- package/dist/backend/services/reminder-schedule.js.map +1 -0
- package/dist/backend/services/reminder-service.d.ts +93 -0
- package/dist/backend/services/reminder-service.d.ts.map +1 -0
- package/dist/backend/services/reminder-service.js +370 -0
- package/dist/backend/services/reminder-service.js.map +1 -0
- package/dist/backend/services/saved-view-service.d.ts +65 -0
- package/dist/backend/services/saved-view-service.d.ts.map +1 -0
- package/dist/backend/services/saved-view-service.js +209 -0
- package/dist/backend/services/saved-view-service.js.map +1 -0
- package/dist/backend/services/scheduled-work-probe.d.ts +34 -0
- package/dist/backend/services/scheduled-work-probe.d.ts.map +1 -0
- package/dist/backend/services/scheduled-work-probe.js +30 -0
- package/dist/backend/services/scheduled-work-probe.js.map +1 -0
- package/dist/backend/services/tag-service.d.ts +53 -0
- package/dist/backend/services/tag-service.d.ts.map +1 -0
- package/dist/backend/services/tag-service.js +165 -0
- package/dist/backend/services/tag-service.js.map +1 -0
- package/dist/backend/services/task-access.d.ts +95 -0
- package/dist/backend/services/task-access.d.ts.map +1 -0
- package/dist/backend/services/task-access.js +184 -0
- package/dist/backend/services/task-access.js.map +1 -0
- package/dist/backend/services/task-asset-references.d.ts +42 -0
- package/dist/backend/services/task-asset-references.d.ts.map +1 -0
- package/dist/backend/services/task-asset-references.js +52 -0
- package/dist/backend/services/task-asset-references.js.map +1 -0
- package/dist/backend/services/task-audit-references.d.ts +18 -0
- package/dist/backend/services/task-audit-references.d.ts.map +1 -0
- package/dist/backend/services/task-audit-references.js +26 -0
- package/dist/backend/services/task-audit-references.js.map +1 -0
- package/dist/backend/services/task-checks.d.ts +78 -0
- package/dist/backend/services/task-checks.d.ts.map +1 -0
- package/dist/backend/services/task-checks.js +148 -0
- package/dist/backend/services/task-checks.js.map +1 -0
- package/dist/backend/services/task-commands.d.ts +199 -0
- package/dist/backend/services/task-commands.d.ts.map +1 -0
- package/dist/backend/services/task-commands.js +483 -0
- package/dist/backend/services/task-commands.js.map +1 -0
- package/dist/backend/services/task-context-registry.d.ts +34 -0
- package/dist/backend/services/task-context-registry.d.ts.map +1 -0
- package/dist/backend/services/task-context-registry.js +49 -0
- package/dist/backend/services/task-context-registry.js.map +1 -0
- package/dist/backend/services/task-custom-fields.d.ts +21 -0
- package/dist/backend/services/task-custom-fields.d.ts.map +1 -0
- package/dist/backend/services/task-custom-fields.js +34 -0
- package/dist/backend/services/task-custom-fields.js.map +1 -0
- package/dist/backend/services/task-email.d.ts +116 -0
- package/dist/backend/services/task-email.d.ts.map +1 -0
- package/dist/backend/services/task-email.js +128 -0
- package/dist/backend/services/task-email.js.map +1 -0
- package/dist/backend/services/task-errors.d.ts +34 -0
- package/dist/backend/services/task-errors.d.ts.map +1 -0
- package/dist/backend/services/task-errors.js +56 -0
- package/dist/backend/services/task-errors.js.map +1 -0
- package/dist/backend/services/task-history-service.d.ts +34 -0
- package/dist/backend/services/task-history-service.d.ts.map +1 -0
- package/dist/backend/services/task-history-service.js +185 -0
- package/dist/backend/services/task-history-service.js.map +1 -0
- package/dist/backend/services/task-notifier.d.ts +85 -0
- package/dist/backend/services/task-notifier.d.ts.map +1 -0
- package/dist/backend/services/task-notifier.js +96 -0
- package/dist/backend/services/task-notifier.js.map +1 -0
- package/dist/backend/services/task-number.d.ts +17 -0
- package/dist/backend/services/task-number.d.ts.map +1 -0
- package/dist/backend/services/task-number.js +30 -0
- package/dist/backend/services/task-number.js.map +1 -0
- package/dist/backend/services/task-read-port.d.ts +25 -0
- package/dist/backend/services/task-read-port.d.ts.map +1 -0
- package/dist/backend/services/task-read-port.js +38 -0
- package/dist/backend/services/task-read-port.js.map +1 -0
- package/dist/backend/services/task-reassignment.d.ts +43 -0
- package/dist/backend/services/task-reassignment.d.ts.map +1 -0
- package/dist/backend/services/task-reassignment.js +41 -0
- package/dist/backend/services/task-reassignment.js.map +1 -0
- package/dist/backend/services/task-service.d.ts +219 -0
- package/dist/backend/services/task-service.d.ts.map +1 -0
- package/dist/backend/services/task-service.js +1112 -0
- package/dist/backend/services/task-service.js.map +1 -0
- package/dist/backend/services/task-settings-service.d.ts +23 -0
- package/dist/backend/services/task-settings-service.d.ts.map +1 -0
- package/dist/backend/services/task-settings-service.js +30 -0
- package/dist/backend/services/task-settings-service.js.map +1 -0
- package/dist/backend/services/task-transition-service.d.ts +56 -0
- package/dist/backend/services/task-transition-service.d.ts.map +1 -0
- package/dist/backend/services/task-transition-service.js +125 -0
- package/dist/backend/services/task-transition-service.js.map +1 -0
- package/dist/backend/services/task-visibility.d.ts +102 -0
- package/dist/backend/services/task-visibility.d.ts.map +1 -0
- package/dist/backend/services/task-visibility.js +106 -0
- package/dist/backend/services/task-visibility.js.map +1 -0
- package/dist/backend/services/task-workflow-read.d.ts +15 -0
- package/dist/backend/services/task-workflow-read.d.ts.map +1 -0
- package/dist/backend/services/task-workflow-read.js +53 -0
- package/dist/backend/services/task-workflow-read.js.map +1 -0
- package/dist/backend/services/task-write-port.d.ts +65 -0
- package/dist/backend/services/task-write-port.d.ts.map +1 -0
- package/dist/backend/services/task-write-port.js +115 -0
- package/dist/backend/services/task-write-port.js.map +1 -0
- package/dist/backend/services/time-zone-validator.d.ts +15 -0
- package/dist/backend/services/time-zone-validator.d.ts.map +1 -0
- package/dist/backend/services/time-zone-validator.js +28 -0
- package/dist/backend/services/time-zone-validator.js.map +1 -0
- package/dist/backend/services/workflow-config-service.d.ts +69 -0
- package/dist/backend/services/workflow-config-service.d.ts.map +1 -0
- package/dist/backend/services/workflow-config-service.js +262 -0
- package/dist/backend/services/workflow-config-service.js.map +1 -0
- package/dist/backend/workers/tasks-reminders-worker.d.ts +102 -0
- package/dist/backend/workers/tasks-reminders-worker.d.ts.map +1 -0
- package/dist/backend/workers/tasks-reminders-worker.js +134 -0
- package/dist/backend/workers/tasks-reminders-worker.js.map +1 -0
- package/dist/manifest.d.ts +168 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +374 -0
- package/dist/manifest.js.map +1 -0
- package/dist/migrations/20261026T133731_tasks_init.d.ts +23 -0
- package/dist/migrations/20261026T133731_tasks_init.d.ts.map +1 -0
- package/dist/migrations/20261026T133731_tasks_init.js +61 -0
- package/dist/migrations/20261026T133731_tasks_init.js.map +1 -0
- package/dist/migrations/20261028T140002_tasks_task_management.d.ts +34 -0
- package/dist/migrations/20261028T140002_tasks_task_management.d.ts.map +1 -0
- package/dist/migrations/20261028T140002_tasks_task_management.js +371 -0
- package/dist/migrations/20261028T140002_tasks_task_management.js.map +1 -0
- package/dist/migrations/index.d.ts +16 -0
- package/dist/migrations/index.d.ts.map +1 -0
- package/dist/migrations/index.js +16 -0
- package/dist/migrations/index.js.map +1 -0
- package/docs/tasks.md +597 -0
- package/i18n/en.json +567 -0
- package/i18n/pl.json +567 -0
- package/package.json +102 -3
- package/tailwind.css +14 -0
|
@@ -0,0 +1,1112 @@
|
|
|
1
|
+
import { ERROR_CODES, foldDiacritics, TASK_MINE_MAX, mentionedAdminUserIds, } from '@endora-commerce/contracts';
|
|
2
|
+
import { HttpError } from '@endora-commerce/platform/http';
|
|
3
|
+
import { cardFieldValues } from '../domain/board-card-fields.js';
|
|
4
|
+
import { dueOnFor, isOverdue } from '../domain/due-moment.js';
|
|
5
|
+
import { decodeListCursor, defaultDirection, encodeListCursor, keysetAfter, listOrdering, } from '../domain/list-cursor.js';
|
|
6
|
+
import { actingAdminUserId, isSomeoneElsesPrivate, isUuid, TASK_COLUMNS, } from './task-access.js';
|
|
7
|
+
import { assertAssigneesSeeContext, assertContextForCaller, assertMayBeAssigned, assertMayPutIn, assertMayTakeOut, } from './task-checks.js';
|
|
8
|
+
import { changeTaskAssigneesCommand, changeTaskCustomFieldsCommand, changeTaskPriorityCommand, changeTaskPrivacyCommand, changeTaskTagsCommand, createTaskCommand, deleteTaskCommand, publishTaskCommand, updateTaskCommand, } from './task-commands.js';
|
|
9
|
+
import { mergeTaskCustomFields } from './task-custom-fields.js';
|
|
10
|
+
import { mapDraftPrivateViolation, taskAlreadyPublished, taskContextInvalid, taskNotFound, taskPrivateAssignee, taskPrivateInContext, } from './task-errors.js';
|
|
11
|
+
import { tellAfterCommit } from './task-notifier.js';
|
|
12
|
+
import { taskVisibilitySql } from './task-visibility.js';
|
|
13
|
+
import { priorityRef, statusRef } from './task-workflow-read.js';
|
|
14
|
+
export { taskNotFound } from './task-errors.js';
|
|
15
|
+
export { actingAdminUserId } from './task-access.js';
|
|
16
|
+
/**
|
|
17
|
+
* Tasks — the HTTP side of `specs/165-task-management/contracts/admin-api.md`
|
|
18
|
+
* §1 (grown from 163's): the list on any sort with every filter, *My Tasks*,
|
|
19
|
+
* one Task, creating, editing, moving and deleting one, and the reads the read
|
|
20
|
+
* port and global search answer with.
|
|
21
|
+
*
|
|
22
|
+
* Every write is one or more Commands of `task-commands.ts` (Constitution
|
|
23
|
+
* XIII), every refusal checked before the first runs. A `PATCH` that changes
|
|
24
|
+
* several kinds of thing runs one Command per kind — fields, assignees — so
|
|
25
|
+
* each has the audit row and the event the contract names. A status move is
|
|
26
|
+
* its own route, checked against the configured workflow (research R-1).
|
|
27
|
+
*
|
|
28
|
+
* **Every read of the `tasks` table here composes the visibility pre-filter**
|
|
29
|
+
* (`TaskVisibility`: context, draft, private), and a Task read by id comes
|
|
30
|
+
* from `TaskAccess`. The child tables — assignees, tags, sub-tasks — are read
|
|
31
|
+
* only for ids those reads returned. `visibility-seam.test.ts` holds this.
|
|
32
|
+
*/
|
|
33
|
+
/** The most options the assignee picker offers for one search. */
|
|
34
|
+
export const ASSIGNEE_OPTIONS_LIMIT = 50;
|
|
35
|
+
const ADMIN_PERMISSION_WILDCARD = '*';
|
|
36
|
+
function holds(held, code) {
|
|
37
|
+
return held.includes(ADMIN_PERMISSION_WILDCARD) || held.includes(code);
|
|
38
|
+
}
|
|
39
|
+
/** The platform's own refusal of a write the caller's permissions do not cover (`requireAdmin`'s words). */
|
|
40
|
+
function forbidden(message = 'You do not have permission to perform this action.') {
|
|
41
|
+
return new HttpError(403, ERROR_CODES.FORBIDDEN, message);
|
|
42
|
+
}
|
|
43
|
+
/** A private Task is assigned to its Creator or to nobody (FR-038, R-3). */
|
|
44
|
+
function assertPrivateAssignees(assigneeIds, creatorId) {
|
|
45
|
+
if (assigneeIds.some((id) => id !== creatorId))
|
|
46
|
+
throw taskPrivateAssignee();
|
|
47
|
+
}
|
|
48
|
+
function personName(person) {
|
|
49
|
+
return `${person.firstName} ${person.lastName}`.trim() || person.email;
|
|
50
|
+
}
|
|
51
|
+
function isActive(admin) {
|
|
52
|
+
return admin.status === 'active' && admin.deletedAt === null;
|
|
53
|
+
}
|
|
54
|
+
function iso(value) {
|
|
55
|
+
return value === null ? null : new Date(value).toISOString();
|
|
56
|
+
}
|
|
57
|
+
function asDate(value) {
|
|
58
|
+
return value === null ? null : new Date(value);
|
|
59
|
+
}
|
|
60
|
+
/** A Postgres `uuid[]` literal of ids already checked to be uuids. */
|
|
61
|
+
function uuids(ids) {
|
|
62
|
+
return `{${ids.join(',')}}`;
|
|
63
|
+
}
|
|
64
|
+
/** A Postgres `text[]` literal of codes; each is quoted, so a comma or a quote in one stays inside it. */
|
|
65
|
+
function texts(values) {
|
|
66
|
+
return `{${values.map((value) => `"${value.replace(/["\\]/g, (m) => `\\${m}`)}"`).join(',')}}`;
|
|
67
|
+
}
|
|
68
|
+
function like(text) {
|
|
69
|
+
return `%${text.replace(/[\\%_]/g, (match) => `\\${match}`)}%`;
|
|
70
|
+
}
|
|
71
|
+
/** Whether `context` is the context `row` is already in. */
|
|
72
|
+
function sameContext(context, row) {
|
|
73
|
+
if (context === null)
|
|
74
|
+
return row.context_type === null;
|
|
75
|
+
return (context.contextType === row.context_type &&
|
|
76
|
+
context.contextId === row.context_id &&
|
|
77
|
+
(context.contextGroupId ?? null) === row.context_group_id);
|
|
78
|
+
}
|
|
79
|
+
/** A status is closed when the workflow puts it in category `done` or `cancelled`. */
|
|
80
|
+
const CLOSED_SQL = (alias) => `exists (select 1 from "task_statuses" cs where cs."code" = ${alias}."status" and cs."category" in ('done', 'cancelled'))`;
|
|
81
|
+
export class TaskService {
|
|
82
|
+
deps;
|
|
83
|
+
constructor(deps) {
|
|
84
|
+
this.deps = deps;
|
|
85
|
+
}
|
|
86
|
+
/** One Task the caller may see, or `null` — hidden and missing alike (`TaskAccess.findVisible`). */
|
|
87
|
+
async findVisibleRow(id) {
|
|
88
|
+
return this.deps.access.findVisible(id);
|
|
89
|
+
}
|
|
90
|
+
/** `GET /tasks/:id`. */
|
|
91
|
+
async get(id, language) {
|
|
92
|
+
return this.#detail(await this.deps.access.loadVisible(id), language);
|
|
93
|
+
}
|
|
94
|
+
/** The caller's visibility scope — computed once by a request that reads several times (the board). */
|
|
95
|
+
async visibilityScope() {
|
|
96
|
+
return this.deps.visibility.scope();
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* `GET /tasks` — a keyset page on any sort (research R-12), with every filter
|
|
100
|
+
* of `TaskListQuery`. Hidden Tasks are excluded by the visibility pre-filter,
|
|
101
|
+
* so a page and the next one are exact. Unknown codes and ids match nothing.
|
|
102
|
+
*
|
|
103
|
+
* The board asks it once per column (research R-11) with the `scope` it
|
|
104
|
+
* computed once, and with the card fields its cards carry.
|
|
105
|
+
*/
|
|
106
|
+
async list(query, language, options = {}) {
|
|
107
|
+
const scope = options.scope ?? (await this.deps.visibility.scope());
|
|
108
|
+
const filter = await this.#where(query, scope);
|
|
109
|
+
if (filter === null)
|
|
110
|
+
return { items: [], nextCursor: null };
|
|
111
|
+
const sort = query.sort ?? 'created';
|
|
112
|
+
const dir = query.dir ?? defaultDirection(sort);
|
|
113
|
+
const ordering = listOrdering(sort, dir, 't');
|
|
114
|
+
const where = [...filter.sql];
|
|
115
|
+
const params = [...filter.params];
|
|
116
|
+
const after = decodeListCursor(query.cursor, sort, dir);
|
|
117
|
+
if (after) {
|
|
118
|
+
const keyset = keysetAfter(sort, dir, 't', after);
|
|
119
|
+
where.push(keyset.sql);
|
|
120
|
+
params.push(...keyset.params);
|
|
121
|
+
}
|
|
122
|
+
const rows = (await this.deps.emFactory().execute(`select ${TASK_COLUMNS}, (${ordering.key})::text as "sort_key" from "tasks" t
|
|
123
|
+
${where.length > 0 ? `where ${where.join(' and ')}` : ''}
|
|
124
|
+
order by ${ordering.orderBy}
|
|
125
|
+
limit ?`, [...params, query.limit + 1]));
|
|
126
|
+
const hasMore = rows.length > query.limit;
|
|
127
|
+
const page = hasMore ? rows.slice(0, query.limit) : rows;
|
|
128
|
+
const last = page[page.length - 1];
|
|
129
|
+
return {
|
|
130
|
+
items: await this.#summaries(page, language, scope, options.cardFields),
|
|
131
|
+
nextCursor: hasMore && last ? encodeListCursor({ sort, dir, key: last.sort_key, id: last.id }) : null,
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* How many Tasks the caller may see in each status under `query`'s filters —
|
|
136
|
+
* the board's one grouped count (research R-11). The list's own conditions,
|
|
137
|
+
* so a column's count is the list's total for that status.
|
|
138
|
+
*/
|
|
139
|
+
async countByStatus(query, scope) {
|
|
140
|
+
const filter = await this.#where(query, scope);
|
|
141
|
+
if (filter === null)
|
|
142
|
+
return new Map();
|
|
143
|
+
const rows = (await this.deps.emFactory().execute(`select t."status", count(*)::int as "n" from "tasks" t
|
|
144
|
+
${filter.sql.length > 0 ? `where ${filter.sql.join(' and ')}` : ''}
|
|
145
|
+
group by t."status"`, filter.params));
|
|
146
|
+
return new Map(rows.map((row) => [row.status, Number(row.n)]));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The list's filters and the custom-field filter as one condition list over
|
|
150
|
+
* `tasks t`, the visibility pre-filter first; `null` when nothing can match.
|
|
151
|
+
* The custom-field condition is an id sub-select over `tasks`, intersected
|
|
152
|
+
* with the visible set: it narrows, never widens. A field the list does not
|
|
153
|
+
* offer throws, and the route answers 400 naming it (research R-8).
|
|
154
|
+
*/
|
|
155
|
+
async #where(query, scope) {
|
|
156
|
+
const filter = await this.#filters(query, scope);
|
|
157
|
+
if (filter === null)
|
|
158
|
+
return null;
|
|
159
|
+
if (query.customFieldFilters !== undefined && Object.keys(query.customFieldFilters).length > 0) {
|
|
160
|
+
const custom = await this.deps.customFieldListFilter.condition('task', query.customFieldFilters);
|
|
161
|
+
if (custom) {
|
|
162
|
+
filter.sql.push(`t."id" in (${custom.sql})`);
|
|
163
|
+
filter.params.push(...custom.params);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return filter;
|
|
167
|
+
}
|
|
168
|
+
/** `GET /tasks/custom-field-filters` — the `task` custom fields the list offers as filters. */
|
|
169
|
+
async customFieldFilterFields() {
|
|
170
|
+
return this.deps.customFieldListFilter.listFilterable('task');
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* The list's filters as SQL over `tasks t`, the visibility pre-filter first;
|
|
174
|
+
* `null` when nothing can match (`assignee=me` or `creator=me` with no
|
|
175
|
+
* administrator behind the request).
|
|
176
|
+
*/
|
|
177
|
+
async #filters(query, scope) {
|
|
178
|
+
const sql = [];
|
|
179
|
+
const params = [];
|
|
180
|
+
const add = (fragment) => {
|
|
181
|
+
if (typeof fragment === 'string')
|
|
182
|
+
sql.push(fragment);
|
|
183
|
+
else {
|
|
184
|
+
sql.push(fragment.sql);
|
|
185
|
+
params.push(...fragment.params);
|
|
186
|
+
}
|
|
187
|
+
};
|
|
188
|
+
const visible = taskVisibilitySql(scope, 't');
|
|
189
|
+
if (visible)
|
|
190
|
+
add(visible);
|
|
191
|
+
const me = actingAdminUserId();
|
|
192
|
+
if (query.status && query.status.length > 0)
|
|
193
|
+
add({ sql: `t."status" = any(?::text[])`, params: [texts(query.status)] });
|
|
194
|
+
if (query.statusCategory && query.statusCategory.length > 0) {
|
|
195
|
+
const categories = new Set(query.statusCategory);
|
|
196
|
+
const disjuncts = [];
|
|
197
|
+
// A code the workflow does not hold closes nothing: it counts as open (R-1).
|
|
198
|
+
if (categories.has('open'))
|
|
199
|
+
disjuncts.push(`not ${CLOSED_SQL('t')}`);
|
|
200
|
+
const closed = [...categories].filter((category) => category !== 'open');
|
|
201
|
+
if (closed.length > 0) {
|
|
202
|
+
disjuncts.push(`exists (select 1 from "task_statuses" fs where fs."code" = t."status" and fs."category" = any(?::text[]))`);
|
|
203
|
+
params.push(texts(closed));
|
|
204
|
+
}
|
|
205
|
+
sql.push(`(${disjuncts.join(' or ')})`);
|
|
206
|
+
}
|
|
207
|
+
if (query.assignee && query.assignee.length > 0) {
|
|
208
|
+
const disjuncts = [];
|
|
209
|
+
const ids = new Set();
|
|
210
|
+
for (const who of query.assignee) {
|
|
211
|
+
if (who === 'none')
|
|
212
|
+
disjuncts.push(`not exists (select 1 from "task_assignees" na where na."task_id" = t."id")`);
|
|
213
|
+
else if (who === 'me') {
|
|
214
|
+
if (me !== null)
|
|
215
|
+
ids.add(me);
|
|
216
|
+
}
|
|
217
|
+
else
|
|
218
|
+
ids.add(who);
|
|
219
|
+
}
|
|
220
|
+
if (ids.size > 0) {
|
|
221
|
+
disjuncts.push(`exists (select 1 from "task_assignees" ya where ya."task_id" = t."id" and ya."admin_user_id" = any(?::uuid[]))`);
|
|
222
|
+
params.push(uuids([...ids]));
|
|
223
|
+
}
|
|
224
|
+
if (disjuncts.length === 0)
|
|
225
|
+
return null;
|
|
226
|
+
sql.push(`(${disjuncts.join(' or ')})`);
|
|
227
|
+
}
|
|
228
|
+
if (query.creator) {
|
|
229
|
+
const creator = query.creator === 'me' ? me : query.creator;
|
|
230
|
+
if (creator === null)
|
|
231
|
+
return null;
|
|
232
|
+
add({ sql: `t."created_by_admin_user_id" = ?::uuid`, params: [creator] });
|
|
233
|
+
}
|
|
234
|
+
if (query.priority && query.priority.length > 0) {
|
|
235
|
+
const codes = query.priority.filter((code) => code !== 'none');
|
|
236
|
+
const disjuncts = [];
|
|
237
|
+
if (query.priority.includes('none'))
|
|
238
|
+
disjuncts.push(`t."priority_code" is null`);
|
|
239
|
+
if (codes.length > 0) {
|
|
240
|
+
disjuncts.push(`t."priority_code" = any(?::text[])`);
|
|
241
|
+
params.push(texts(codes));
|
|
242
|
+
}
|
|
243
|
+
sql.push(`(${disjuncts.join(' or ')})`);
|
|
244
|
+
}
|
|
245
|
+
for (const tagId of new Set(query.tagId ?? [])) {
|
|
246
|
+
add({
|
|
247
|
+
sql: `exists (select 1 from "task_tag_assignments" tg where tg."task_id" = t."id" and tg."tag_id" = ?::uuid)`,
|
|
248
|
+
params: [tagId],
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
if (query.dueFrom)
|
|
252
|
+
add({ sql: `t."due_on" >= ?::date`, params: [query.dueFrom] });
|
|
253
|
+
if (query.dueTo)
|
|
254
|
+
add({ sql: `t."due_on" <= ?::date`, params: [query.dueTo] });
|
|
255
|
+
if (query.overdue !== undefined) {
|
|
256
|
+
const overdue = await this.#overdueSql('t');
|
|
257
|
+
add(query.overdue ? overdue : { sql: `not ${overdue.sql}`, params: overdue.params });
|
|
258
|
+
}
|
|
259
|
+
if (query.linkedKind && query.linkedId) {
|
|
260
|
+
add({
|
|
261
|
+
sql: `exists (select 1 from "task_record_links" lk where lk."task_id" = t."id" and lk."record_kind" = ? and lk."record_id" = ?::uuid)`,
|
|
262
|
+
params: [query.linkedKind, query.linkedId],
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
if (query.contextType)
|
|
266
|
+
add({ sql: `t."context_type" = ?`, params: [query.contextType] });
|
|
267
|
+
if (query.contextId)
|
|
268
|
+
add({ sql: `t."context_id" = ?::uuid`, params: [query.contextId] });
|
|
269
|
+
if (query.parentId)
|
|
270
|
+
add({ sql: `t."parent_task_id" = ?::uuid`, params: [query.parentId] });
|
|
271
|
+
if (query.isSubtask !== undefined)
|
|
272
|
+
add(`t."parent_task_id" is ${query.isSubtask ? 'not ' : ''}null`);
|
|
273
|
+
if (query.hasSubtasks !== undefined) {
|
|
274
|
+
// A sub-task the reader may not see makes no parent of a Task for them.
|
|
275
|
+
const child = taskVisibilitySql(scope, 'c');
|
|
276
|
+
add({
|
|
277
|
+
sql: `${query.hasSubtasks ? '' : 'not '}exists (select 1 from "tasks" c where c."parent_task_id" = t."id"${child ? ` and ${child.sql}` : ''})`,
|
|
278
|
+
params: child?.params ?? [],
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
if (query.draft !== undefined) {
|
|
282
|
+
// `draft=true` is only ever the caller's own drafts (R-3).
|
|
283
|
+
if (query.draft) {
|
|
284
|
+
if (me === null)
|
|
285
|
+
return null;
|
|
286
|
+
add({ sql: `(t."is_draft" and t."created_by_admin_user_id" = ?::uuid)`, params: [me] });
|
|
287
|
+
}
|
|
288
|
+
else
|
|
289
|
+
add(`not t."is_draft"`);
|
|
290
|
+
}
|
|
291
|
+
if (query.private !== undefined)
|
|
292
|
+
add(`${query.private ? '' : 'not '}t."is_private"`);
|
|
293
|
+
if (query.q) {
|
|
294
|
+
const pattern = like(query.q);
|
|
295
|
+
add({ sql: `(t."title" ilike ? or t."number" ilike ?)`, params: [pattern, pattern] });
|
|
296
|
+
}
|
|
297
|
+
return { sql, params };
|
|
298
|
+
}
|
|
299
|
+
/** Open and past the due moment: at `due_at`, or once `due_on` is over in `tasks.time_zone`. */
|
|
300
|
+
async #overdueSql(alias) {
|
|
301
|
+
return {
|
|
302
|
+
sql: `(not ${CLOSED_SQL(alias)} and (case when ${alias}."due_at" is not null then ${alias}."due_at" < now()
|
|
303
|
+
else ${alias}."due_on" < (now() at time zone ?)::date end))`,
|
|
304
|
+
params: [await this.deps.timeZone()],
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* `GET /tasks/mine` — the caller's open, published Tasks by due date, undated
|
|
309
|
+
* last, then oldest first; narrowed by visibility like the list (FR-030), and
|
|
310
|
+
* by the list's filters (US3 scenario 6), `assignee=me`, `statusCategory=open`
|
|
311
|
+
* and no draft implied. A `sort` orders them as the list would.
|
|
312
|
+
*/
|
|
313
|
+
async mine(query, language) {
|
|
314
|
+
const me = actingAdminUserId();
|
|
315
|
+
if (me === null)
|
|
316
|
+
return [];
|
|
317
|
+
const scope = await this.deps.visibility.scope();
|
|
318
|
+
const filter = await this.#where({ ...query, assignee: ['me'], statusCategory: ['open'], draft: false }, scope);
|
|
319
|
+
if (filter === null)
|
|
320
|
+
return [];
|
|
321
|
+
const orderBy = query.sort
|
|
322
|
+
? listOrdering(query.sort, query.dir ?? defaultDirection(query.sort), 't').orderBy
|
|
323
|
+
: `t."due_on" asc nulls last, t."due_at" asc nulls last, t."created_at" asc, t."id" asc`;
|
|
324
|
+
const rows = (await this.deps.emFactory().execute(`select ${TASK_COLUMNS} from "tasks" t ${filter.sql.length > 0 ? `where ${filter.sql.join(' and ')}` : ''}
|
|
325
|
+
order by ${orderBy}
|
|
326
|
+
limit ${TASK_MINE_MAX}`, filter.params));
|
|
327
|
+
return this.#summaries(rows, language, scope);
|
|
328
|
+
}
|
|
329
|
+
/** The Tasks of `ids` the caller may see — the read port's `findByIds`, the audit trail's labels. */
|
|
330
|
+
async visibleRowsByIds(ids) {
|
|
331
|
+
return this.#visibleRowsByIds(ids, await this.deps.visibility.scope());
|
|
332
|
+
}
|
|
333
|
+
async #visibleRowsByIds(ids, scope) {
|
|
334
|
+
const candidates = [...new Set(ids.filter(isUuid))];
|
|
335
|
+
if (candidates.length === 0)
|
|
336
|
+
return [];
|
|
337
|
+
const where = [`t."id" = any(?::uuid[])`];
|
|
338
|
+
const params = [uuids(candidates)];
|
|
339
|
+
const visible = taskVisibilitySql(scope, 't');
|
|
340
|
+
if (visible) {
|
|
341
|
+
where.push(visible.sql);
|
|
342
|
+
params.push(...visible.params);
|
|
343
|
+
}
|
|
344
|
+
return (await this.deps.emFactory().execute(`select ${TASK_COLUMNS} from "tasks" t where ${where.join(' and ')}`, params));
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Tasks the caller may see whose number or title contains `q`, newest first,
|
|
348
|
+
* at most `limit` — `taskReadPort.search`, the `@@` document list's Tasks.
|
|
349
|
+
*/
|
|
350
|
+
async searchVisibleRows(q, limit) {
|
|
351
|
+
const where = [];
|
|
352
|
+
const params = [];
|
|
353
|
+
const visible = await this.deps.visibility.condition('t');
|
|
354
|
+
if (visible) {
|
|
355
|
+
where.push(visible.sql);
|
|
356
|
+
params.push(...visible.params);
|
|
357
|
+
}
|
|
358
|
+
const needle = (q ?? '').trim();
|
|
359
|
+
if (needle !== '') {
|
|
360
|
+
where.push(`(t."title" ilike ? or t."number" ilike ?)`);
|
|
361
|
+
params.push(like(needle), like(needle));
|
|
362
|
+
}
|
|
363
|
+
return (await this.deps.emFactory().execute(`select ${TASK_COLUMNS} from "tasks" t
|
|
364
|
+
${where.length > 0 ? `where ${where.join(' and ')}` : ''}
|
|
365
|
+
order by t."created_at" desc, t."id" desc
|
|
366
|
+
limit ?`, [...params, Math.max(0, Math.trunc(limit))]));
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Admin global search (`contracts/admin-surfaces.md` §6): the Tasks the
|
|
370
|
+
* caller may see whose number or title — whichever `fields` selects —
|
|
371
|
+
* contains the text, or whose id it is. The exact number ranks first, then a
|
|
372
|
+
* number it begins, then the newest; `limit + 1` rows are read to answer
|
|
373
|
+
* `hasMore`. The same visibility pre-filter as the list.
|
|
374
|
+
*/
|
|
375
|
+
async searchForAdmin(query) {
|
|
376
|
+
const fields = new Set(query.fields);
|
|
377
|
+
const pattern = `%${query.likeEscaped}%`;
|
|
378
|
+
const or = [];
|
|
379
|
+
const params = [];
|
|
380
|
+
if (fields.has('number')) {
|
|
381
|
+
or.push(`t."number" ilike ?`);
|
|
382
|
+
params.push(pattern);
|
|
383
|
+
}
|
|
384
|
+
if (fields.has('title')) {
|
|
385
|
+
or.push(`t."title" ilike ?`);
|
|
386
|
+
params.push(pattern);
|
|
387
|
+
}
|
|
388
|
+
if (query.isUuid && isUuid(query.text)) {
|
|
389
|
+
or.push(`t."id" = ?::uuid`);
|
|
390
|
+
params.push(query.text);
|
|
391
|
+
}
|
|
392
|
+
if (or.length === 0)
|
|
393
|
+
return { rows: [], hasMore: false };
|
|
394
|
+
const where = [`(${or.join(' or ')})`];
|
|
395
|
+
const visible = await this.deps.visibility.condition('t');
|
|
396
|
+
if (visible) {
|
|
397
|
+
where.push(visible.sql);
|
|
398
|
+
params.push(...visible.params);
|
|
399
|
+
}
|
|
400
|
+
const rank = fields.has('number')
|
|
401
|
+
? `case when lower(t."number") = lower(?) then 0 when t."number" ilike ? then 1 else 2 end, `
|
|
402
|
+
: '';
|
|
403
|
+
const rankParams = fields.has('number') ? [query.text, `${query.likeEscaped}%`] : [];
|
|
404
|
+
const rows = (await this.deps.emFactory().execute(`select ${TASK_COLUMNS} from "tasks" t
|
|
405
|
+
where ${where.join(' and ')}
|
|
406
|
+
order by ${rank}t."created_at" desc, t."id" desc
|
|
407
|
+
limit ?`, [...params, ...rankParams, query.limit + 1]));
|
|
408
|
+
const hasMore = rows.length > query.limit;
|
|
409
|
+
const page = hasMore ? rows.slice(0, query.limit) : rows;
|
|
410
|
+
return { rows: page.map((row) => ({ id: row.id, number: row.number, title: row.title, status: row.status })), hasMore };
|
|
411
|
+
}
|
|
412
|
+
/** A status's name in a language, for global search's hit — the workflow's own words. */
|
|
413
|
+
async statusLabel(code, language) {
|
|
414
|
+
return statusRef(await this.deps.workflow.graph(), code, language).name;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* `POST /tasks` — a Task of the caller's, in a context they may see or in
|
|
418
|
+
* none, in the initial status. Every field is checked before the Command
|
|
419
|
+
* runs: the assignees may read Tasks, the priority and the tags exist, the
|
|
420
|
+
* custom-field values fit their definitions.
|
|
421
|
+
*/
|
|
422
|
+
async create(body, language) {
|
|
423
|
+
const context = body.context ?? null;
|
|
424
|
+
const isDraft = body.draft ?? false;
|
|
425
|
+
const isPrivate = body.private ?? false;
|
|
426
|
+
// The schema refuses both together; this holds the rule wherever the body came from (FR-038).
|
|
427
|
+
if (isPrivate && context)
|
|
428
|
+
throw taskPrivateInContext();
|
|
429
|
+
if (context) {
|
|
430
|
+
await assertContextForCaller(this.deps.contexts, context);
|
|
431
|
+
await assertMayPutIn(this.deps.contexts, null, context);
|
|
432
|
+
}
|
|
433
|
+
const assigneeIds = [...new Set(body.assigneeIds ?? [])];
|
|
434
|
+
if (isPrivate)
|
|
435
|
+
assertPrivateAssignees(assigneeIds, actingAdminUserId());
|
|
436
|
+
await assertMayBeAssigned(this.deps.adminUsers, this.deps.permissions, assigneeIds);
|
|
437
|
+
await assertAssigneesSeeContext(this.deps.contexts, this.deps.adminUsers, context, assigneeIds);
|
|
438
|
+
const priorityCode = body.priorityCode ?? null;
|
|
439
|
+
await this.deps.priorities.assertKnown(priorityCode);
|
|
440
|
+
const tagIds = [...new Set(body.tagIds ?? [])];
|
|
441
|
+
await this.deps.tags.assertKnown(tagIds);
|
|
442
|
+
const customFieldValues = await mergeTaskCustomFields(this.deps.customFields, {}, body.customFieldValues ?? {});
|
|
443
|
+
const parentTaskId = body.parentTaskId ?? null;
|
|
444
|
+
if (parentTaskId !== null)
|
|
445
|
+
await this.deps.hierarchy.assertMayAdopt(parentTaskId);
|
|
446
|
+
const links = await this.deps.links.assertLinkable(body.links ?? []);
|
|
447
|
+
const due = await this.#due({ dueOn: null, dueAt: null }, body);
|
|
448
|
+
const description = body.description ?? '';
|
|
449
|
+
const graph = await this.deps.workflow.graph();
|
|
450
|
+
const id = await this.#run(createTaskCommand(context, {
|
|
451
|
+
title: body.title,
|
|
452
|
+
description,
|
|
453
|
+
assigneeIds,
|
|
454
|
+
dueOn: due.dueOn ?? null,
|
|
455
|
+
dueAt: due.dueAt ?? null,
|
|
456
|
+
startOn: body.startOn ?? null,
|
|
457
|
+
priorityCode,
|
|
458
|
+
tagIds,
|
|
459
|
+
customFieldValues,
|
|
460
|
+
parentTaskId,
|
|
461
|
+
links,
|
|
462
|
+
contextNote: null,
|
|
463
|
+
status: graph.initial().code,
|
|
464
|
+
draft: isDraft,
|
|
465
|
+
private: isPrivate,
|
|
466
|
+
}));
|
|
467
|
+
const row = await this.deps.access.rowAfterWrite(id);
|
|
468
|
+
const task = await this.#detail(row, language);
|
|
469
|
+
// A draft tells nobody: it is told about when it is published (FR-037).
|
|
470
|
+
if (!row.is_draft) {
|
|
471
|
+
await this.#tellAssignees(assigneeIds, row);
|
|
472
|
+
await this.deps.mentions.tell(row, mentionedAdminUserIds(description));
|
|
473
|
+
}
|
|
474
|
+
return task;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* `POST /tasks/:id/publish` — the Creator's draft becomes a normal Task, one
|
|
478
|
+
* way (FR-037, research R-3): `tasks.task.created.v1` is emitted now, and its
|
|
479
|
+
* assignees and the people its description mentions are told as for a new
|
|
480
|
+
* Task. Somebody else's draft does not exist for the caller (404, through
|
|
481
|
+
* `loadVisible`); a Task that is not a draft is 409 `TASK_ALREADY_PUBLISHED`.
|
|
482
|
+
*/
|
|
483
|
+
async publish(id, language) {
|
|
484
|
+
const row = await this.deps.access.loadVisible(id);
|
|
485
|
+
this.deps.access.assertMayChange(row);
|
|
486
|
+
if (!row.is_draft)
|
|
487
|
+
throw taskAlreadyPublished();
|
|
488
|
+
// Unreachable through visibility — a draft is its Creator's alone — and kept so.
|
|
489
|
+
if (row.created_by_admin_user_id !== actingAdminUserId())
|
|
490
|
+
throw taskNotFound();
|
|
491
|
+
const { assigneeIds } = await this.deps.commandBus.run(publishTaskCommand(row.id));
|
|
492
|
+
const written = await this.deps.access.rowAfterWrite(row.id);
|
|
493
|
+
const task = await this.#detail(written, language);
|
|
494
|
+
await this.#tellAssignees(assigneeIds, written);
|
|
495
|
+
await this.deps.mentions.tell(written, mentionedAdminUserIds(written.description));
|
|
496
|
+
return task;
|
|
497
|
+
}
|
|
498
|
+
/** One Command, a draft/private check the database refused answered as the service would (R-3). */
|
|
499
|
+
async #run(command) {
|
|
500
|
+
return this.deps.commandBus.run(command).catch(mapDraftPrivateViolation);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* `PATCH /tasks/:id` — one Command per kind of change, in this order, each
|
|
504
|
+
* only when it changes something: the parent, the fields, the priority, the
|
|
505
|
+
* tags, the custom fields, the assignees. A status is not changed here
|
|
506
|
+
* (`POST /tasks/:id/status`). The parent goes first: it is the one change
|
|
507
|
+
* refused inside its Command (a cycle or a depth, under the hierarchy lock),
|
|
508
|
+
* so a refusal leaves the rest of the request unwritten.
|
|
509
|
+
*/
|
|
510
|
+
async update(id, body, language) {
|
|
511
|
+
const row = await this.deps.access.loadVisible(id);
|
|
512
|
+
this.deps.access.assertMayChange(row);
|
|
513
|
+
if (body.context !== undefined && !sameContext(body.context, row)) {
|
|
514
|
+
await assertMayTakeOut(this.deps.contexts, { contextType: row.context_type, contextId: row.context_id }, body.context);
|
|
515
|
+
}
|
|
516
|
+
if (body.context) {
|
|
517
|
+
await assertContextForCaller(this.deps.contexts, body.context);
|
|
518
|
+
await assertMayPutIn(this.deps.contexts, { contextType: row.context_type, contextId: row.context_id }, body.context);
|
|
519
|
+
}
|
|
520
|
+
let assignees = null;
|
|
521
|
+
if (body.assigneeIds !== undefined)
|
|
522
|
+
assignees = { set: [...new Set(body.assigneeIds)] };
|
|
523
|
+
else if (body.addAssigneeIds !== undefined || body.removeAssigneeIds !== undefined) {
|
|
524
|
+
assignees = { add: body.addAssigneeIds ?? [], remove: body.removeAssigneeIds ?? [] };
|
|
525
|
+
}
|
|
526
|
+
if (assignees) {
|
|
527
|
+
await assertMayBeAssigned(this.deps.adminUsers, this.deps.permissions, 'set' in assignees ? assignees.set : assignees.add);
|
|
528
|
+
}
|
|
529
|
+
// Everybody assigned after this write may see the record it is in (#506):
|
|
530
|
+
// those named now, and — when the Task moves to another record — those it
|
|
531
|
+
// keeps. Within one record an assignee kept from before is not asked again.
|
|
532
|
+
const contextAfter = body.context !== undefined ? body.context : { contextType: row.context_type, contextId: row.context_id };
|
|
533
|
+
const movesRecord = body.context != null && (body.context.contextType !== row.context_type || body.context.contextId !== row.context_id);
|
|
534
|
+
if (contextAfter && (assignees || movesRecord)) {
|
|
535
|
+
const current = movesRecord ? ((await this.#assigneeIds([row.id])).get(row.id) ?? []) : [];
|
|
536
|
+
const asked = !assignees
|
|
537
|
+
? current
|
|
538
|
+
: 'set' in assignees
|
|
539
|
+
? assignees.set
|
|
540
|
+
: [...current.filter((who) => !assignees.remove.includes(who)), ...assignees.add];
|
|
541
|
+
await assertAssigneesSeeContext(this.deps.contexts, this.deps.adminUsers, contextAfter, asked);
|
|
542
|
+
}
|
|
543
|
+
// Private (FR-038): only its Creator says so, and a private Task is in no
|
|
544
|
+
// context and assigned to nobody but its Creator — as it will be after this write.
|
|
545
|
+
const privacyChange = body.private !== undefined && body.private !== row.is_private;
|
|
546
|
+
if (privacyChange && row.created_by_admin_user_id !== actingAdminUserId()) {
|
|
547
|
+
throw forbidden('Only the administrator who created this Task can change whether it is private.');
|
|
548
|
+
}
|
|
549
|
+
if (body.private ?? row.is_private) {
|
|
550
|
+
const contextAfter = body.context !== undefined ? body.context : row.context_type;
|
|
551
|
+
if (contextAfter)
|
|
552
|
+
throw taskPrivateInContext();
|
|
553
|
+
if (privacyChange || assignees) {
|
|
554
|
+
const current = (await this.#assigneeIds([row.id])).get(row.id) ?? [];
|
|
555
|
+
const after = !assignees
|
|
556
|
+
? current
|
|
557
|
+
: 'set' in assignees
|
|
558
|
+
? assignees.set
|
|
559
|
+
: [...current.filter((who) => !assignees.remove.includes(who)), ...assignees.add];
|
|
560
|
+
assertPrivateAssignees(after, row.created_by_admin_user_id);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
const priorityChange = body.priorityCode !== undefined && body.priorityCode !== row.priority_code;
|
|
564
|
+
if (priorityChange)
|
|
565
|
+
await this.deps.priorities.assertKnown(body.priorityCode ?? null);
|
|
566
|
+
if (body.tagIds !== undefined)
|
|
567
|
+
await this.deps.tags.assertKnown(body.tagIds);
|
|
568
|
+
const customFieldValues = body.customFieldValues !== undefined
|
|
569
|
+
? await mergeTaskCustomFields(this.deps.customFields, row.custom_field_values ?? {}, body.customFieldValues)
|
|
570
|
+
: null;
|
|
571
|
+
// Made public first, so a context given in the same write lands on a public Task.
|
|
572
|
+
if (privacyChange && body.private === false)
|
|
573
|
+
await this.#run(changeTaskPrivacyCommand(row.id, false));
|
|
574
|
+
if (body.parentTaskId !== undefined)
|
|
575
|
+
await this.deps.hierarchy.setParent(row, body.parentTaskId);
|
|
576
|
+
const fields = {};
|
|
577
|
+
if (body.title !== undefined && body.title !== row.title)
|
|
578
|
+
fields.title = body.title;
|
|
579
|
+
if (body.description !== undefined && body.description !== row.description)
|
|
580
|
+
fields.description = body.description;
|
|
581
|
+
const due = await this.#due({ dueOn: row.due_on, dueAt: asDate(row.due_at) }, body);
|
|
582
|
+
if (due.dueOn !== undefined && due.dueOn !== row.due_on)
|
|
583
|
+
fields.dueOn = due.dueOn;
|
|
584
|
+
if (due.dueAt !== undefined && iso(due.dueAt) !== iso(row.due_at))
|
|
585
|
+
fields.dueAt = due.dueAt;
|
|
586
|
+
if (body.startOn !== undefined && body.startOn !== row.start_on)
|
|
587
|
+
fields.startOn = body.startOn;
|
|
588
|
+
if (body.context !== undefined && !sameContext(body.context, row))
|
|
589
|
+
fields.context = body.context;
|
|
590
|
+
let mentioned = [];
|
|
591
|
+
if (Object.keys(fields).length > 0) {
|
|
592
|
+
const reminders = { timeZone: await this.deps.timeZone(), auditLog: this.deps.auditLog };
|
|
593
|
+
mentioned = (await this.#run(updateTaskCommand(row.id, fields, reminders))).mentioned;
|
|
594
|
+
}
|
|
595
|
+
if (priorityChange)
|
|
596
|
+
await this.deps.commandBus.run(changeTaskPriorityCommand(row.id, body.priorityCode ?? null));
|
|
597
|
+
if (body.tagIds !== undefined)
|
|
598
|
+
await this.deps.commandBus.run(changeTaskTagsCommand(row.id, body.tagIds));
|
|
599
|
+
if (customFieldValues)
|
|
600
|
+
await this.deps.commandBus.run(changeTaskCustomFieldsCommand(row.id, customFieldValues));
|
|
601
|
+
let added = [];
|
|
602
|
+
if (assignees) {
|
|
603
|
+
const changed = await this.deps.commandBus.run(changeTaskAssigneesCommand(row.id, assignees));
|
|
604
|
+
added = changed?.added ?? [];
|
|
605
|
+
}
|
|
606
|
+
// Made private last, once the context and the other assignees are gone.
|
|
607
|
+
if (privacyChange && body.private === true)
|
|
608
|
+
await this.#run(changeTaskPrivacyCommand(row.id, true));
|
|
609
|
+
const written = await this.deps.access.rowAfterWrite(row.id);
|
|
610
|
+
const task = await this.#detail(written, language);
|
|
611
|
+
// A draft tells nobody until it is published (FR-037).
|
|
612
|
+
if (!written.is_draft) {
|
|
613
|
+
await this.#tellAssignees(added, written);
|
|
614
|
+
await this.deps.mentions.tell(written, mentioned);
|
|
615
|
+
}
|
|
616
|
+
return task;
|
|
617
|
+
}
|
|
618
|
+
/**
|
|
619
|
+
* The due date and moment a write leaves (research R-17, FR-002): a moment
|
|
620
|
+
* sets the date to its day in `tasks.time_zone`; a date alone clears the
|
|
621
|
+
* moment; clearing the moment alone keeps the date. `undefined` for what the
|
|
622
|
+
* body does not change.
|
|
623
|
+
*/
|
|
624
|
+
async #due(current, body) {
|
|
625
|
+
if (body.dueAt !== undefined && body.dueAt !== null) {
|
|
626
|
+
const dueAt = new Date(body.dueAt);
|
|
627
|
+
return { dueAt, dueOn: dueOnFor(dueAt, await this.deps.timeZone()) };
|
|
628
|
+
}
|
|
629
|
+
if (body.dueAt === null)
|
|
630
|
+
return { dueAt: null, ...(body.dueOn !== undefined ? { dueOn: body.dueOn } : {}) };
|
|
631
|
+
if (body.dueOn !== undefined)
|
|
632
|
+
return { dueOn: body.dueOn, ...(current.dueAt !== null ? { dueAt: null } : {}) };
|
|
633
|
+
return {};
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* `POST /tasks/:id/status` — the move goes through {@link TaskTransitionService}
|
|
637
|
+
* (research R-1: 422 `TASK_STATUS_UNKNOWN`, 409 `TASK_TRANSITION_FORBIDDEN`
|
|
638
|
+
* naming the permitted next statuses, 409 `TASK_TRANSITION_CONFLICT`); the
|
|
639
|
+
* answer is the Task as it is now and how many of its visible sub-tasks are
|
|
640
|
+
* still open, for the screen's warning. A move to the status the Task is
|
|
641
|
+
* already in changes nothing.
|
|
642
|
+
*/
|
|
643
|
+
async changeStatus(id, body, language) {
|
|
644
|
+
const { taskId } = await this.deps.transitions.apply(id, body, language);
|
|
645
|
+
const task = await this.#detail(await this.deps.access.rowAfterWrite(taskId), language);
|
|
646
|
+
const subtasks = (await this.#subtaskCounts([taskId], await this.deps.visibility.scope())).get(taskId);
|
|
647
|
+
return { task, openSubtasks: subtasks ? subtasks.total - subtasks.closed : 0 };
|
|
648
|
+
}
|
|
649
|
+
/**
|
|
650
|
+
* `DELETE /tasks/:id` — by a holder of `tasks:write`, or of
|
|
651
|
+
* `tasks:see_private` when the Task is private (FR-041); anyone else is 403
|
|
652
|
+
* `FORBIDDEN`, as the route's gate would say. Its sub-tasks become top-level (FR-029), and the
|
|
653
|
+
* answer says how many of them the caller may see: a sub-task hidden from
|
|
654
|
+
* them is counted in no number of theirs (User Story 5 scenario 7).
|
|
655
|
+
*/
|
|
656
|
+
async delete(id) {
|
|
657
|
+
// `tasks:write`, or `tasks:see_private` on a private Task (FR-041, Q1 = B).
|
|
658
|
+
const me = actingAdminUserId();
|
|
659
|
+
const held = me === null ? [ADMIN_PERMISSION_WILDCARD] : await this.deps.permissions.listPermissions(me);
|
|
660
|
+
const mayWrite = holds(held, 'tasks:write');
|
|
661
|
+
if (!mayWrite && !holds(held, 'tasks:see_private'))
|
|
662
|
+
throw forbidden();
|
|
663
|
+
const row = await this.deps.access.loadVisible(id);
|
|
664
|
+
if (!mayWrite && !row.is_private)
|
|
665
|
+
throw forbidden();
|
|
666
|
+
await this.deps.access.assertMayDelete(row);
|
|
667
|
+
const { deleted, detachedIds } = await this.deps.commandBus.run(deleteTaskCommand(row.id, this.deps.auditLog));
|
|
668
|
+
if (!deleted)
|
|
669
|
+
throw taskNotFound();
|
|
670
|
+
return { subtasksDetached: (await this.deps.access.visibleIds(detachedIds)).size };
|
|
671
|
+
}
|
|
672
|
+
/** `GET /tasks/workflow` — the statuses with how many visible Tasks hold each, and the moves. */
|
|
673
|
+
async workflow() {
|
|
674
|
+
const graph = await this.deps.workflow.graph();
|
|
675
|
+
const where = [];
|
|
676
|
+
const params = [];
|
|
677
|
+
const visible = await this.deps.visibility.condition('t');
|
|
678
|
+
if (visible) {
|
|
679
|
+
where.push(visible.sql);
|
|
680
|
+
params.push(...visible.params);
|
|
681
|
+
}
|
|
682
|
+
const counts = (await this.deps.emFactory().execute(`select t."status", count(*)::int as "n" from "tasks" t ${where.length > 0 ? `where ${where.join(' and ')}` : ''}
|
|
683
|
+
group by t."status"`, params));
|
|
684
|
+
const inUse = new Map(counts.map((row) => [row.status, Number(row.n)]));
|
|
685
|
+
return {
|
|
686
|
+
statuses: graph.statuses.map((status) => ({
|
|
687
|
+
code: status.code,
|
|
688
|
+
name: status.name,
|
|
689
|
+
defaultName: status.defaultName,
|
|
690
|
+
category: status.category,
|
|
691
|
+
isInitial: status.isInitial,
|
|
692
|
+
weight: status.weight,
|
|
693
|
+
color: status.color,
|
|
694
|
+
inUseCount: inUse.get(status.code) ?? 0,
|
|
695
|
+
})),
|
|
696
|
+
transitions: graph.transitions.map((edge) => ({ from: edge.fromCode, to: edge.toCode })),
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
/**
|
|
700
|
+
* `GET /tasks/lookups/assignees` — active administrators who may be assigned,
|
|
701
|
+
* by name; for a private Task (`taskId`) its Creator alone (FR-038). A Task
|
|
702
|
+
* the caller may not see is 404.
|
|
703
|
+
*
|
|
704
|
+
* **Who may be assigned** is who the save accepts and who would see the
|
|
705
|
+
* Task: a holder of `tasks:read` (`assertMayBeAssigned` refuses anybody else
|
|
706
|
+
* with 422 — the walk found the list offering them, T095), and for an
|
|
707
|
+
* existing Task whoever passes the Task's audience as `mentionable` asks it —
|
|
708
|
+
* a Task in a record therefore offers only who may see the record
|
|
709
|
+
* (`canSeeAs`, #506). A draft is asked as if published: its assignees see it
|
|
710
|
+
* from then on. On the create form a `context` asks the same of the record
|
|
711
|
+
* the Task is about to be created in; the caller must see it themselves, or
|
|
712
|
+
* it is 422 `TASK_CONTEXT_INVALID` — the lookup answers nothing about a
|
|
713
|
+
* record they may not see. A `context` with a `taskId` replaces the Task's.
|
|
714
|
+
* Asked in name order, stopping at the limit, as `mentionable` does.
|
|
715
|
+
*/
|
|
716
|
+
async assignees(q, taskId, context) {
|
|
717
|
+
const needle = foldDiacritics(q ?? '').trim().toLowerCase();
|
|
718
|
+
const task = taskId !== undefined ? await this.deps.access.loadVisible(taskId) : null;
|
|
719
|
+
if (context)
|
|
720
|
+
await this.#assertSeesContext(context);
|
|
721
|
+
const only = task?.is_private ? task.created_by_admin_user_id : null;
|
|
722
|
+
const facts = {
|
|
723
|
+
// Read only for a draft or a private Task; a Task about to be created is neither here.
|
|
724
|
+
created_by_admin_user_id: task?.created_by_admin_user_id ?? actingAdminUserId() ?? '',
|
|
725
|
+
is_draft: false,
|
|
726
|
+
is_private: task?.is_private ?? false,
|
|
727
|
+
context_type: context?.contextType ?? task?.context_type ?? null,
|
|
728
|
+
context_id: context?.contextId ?? task?.context_id ?? null,
|
|
729
|
+
};
|
|
730
|
+
const candidates = (await this.deps.adminUsers.listAll({ activeOnly: true }))
|
|
731
|
+
.filter((admin) => isActive(admin) && (only === null || admin.id === only))
|
|
732
|
+
.map((admin) => ({ id: admin.id, name: personName(admin), email: admin.email }))
|
|
733
|
+
.filter((option) => needle === '' ||
|
|
734
|
+
[option.name, option.email].some((value) => foldDiacritics(value).toLowerCase().includes(needle)))
|
|
735
|
+
.sort((a, b) => a.name.localeCompare(b.name) || a.id.localeCompare(b.id));
|
|
736
|
+
const options = [];
|
|
737
|
+
for (const option of candidates) {
|
|
738
|
+
if (options.length >= ASSIGNEE_OPTIONS_LIMIT)
|
|
739
|
+
break;
|
|
740
|
+
if (await this.deps.audience(option.id, facts))
|
|
741
|
+
options.push(option);
|
|
742
|
+
}
|
|
743
|
+
return options;
|
|
744
|
+
}
|
|
745
|
+
/** The caller sees the record: its owner is present and lists it among theirs. */
|
|
746
|
+
async #assertSeesContext(context) {
|
|
747
|
+
const descriptor = this.deps.contexts.presentFor(context.contextType);
|
|
748
|
+
const visible = descriptor ? await descriptor.visibleContextIds([context.contextId]) : new Set();
|
|
749
|
+
if (!visible.has(context.contextId)) {
|
|
750
|
+
throw taskContextInvalid('The record does not exist or is not available to you.');
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
// --- Read port --------------------------------------------------------------
|
|
754
|
+
/**
|
|
755
|
+
* The Tasks of one context (or one group inside it), oldest first — what the
|
|
756
|
+
* read port answers. The context's own owner is asked once whether the
|
|
757
|
+
* caller may see it, and the draft/private rule applies; the system is not
|
|
758
|
+
* narrowed. `openOnly`: not closed and not a draft — the completion gate's
|
|
759
|
+
* question (R-1, R-3).
|
|
760
|
+
*/
|
|
761
|
+
async rowsInContext(q, options) {
|
|
762
|
+
const filter = await this.#inContext(q);
|
|
763
|
+
if (!filter)
|
|
764
|
+
return [];
|
|
765
|
+
return (await this.deps.emFactory().execute(`select ${TASK_COLUMNS} from "tasks" t where ${filter.sql}
|
|
766
|
+
${options.openOnly ? `and not ${CLOSED_SQL('t')} and not t."is_draft"` : ''}
|
|
767
|
+
order by t."created_at" asc, t."id" asc`, filter.params));
|
|
768
|
+
}
|
|
769
|
+
async countInContext(q) {
|
|
770
|
+
const filter = await this.#inContext(q);
|
|
771
|
+
if (!filter)
|
|
772
|
+
return 0;
|
|
773
|
+
const rows = (await this.deps.emFactory().execute(`select count(*)::int as "n" from "tasks" t where ${filter.sql}`, filter.params));
|
|
774
|
+
return Number(rows[0]?.n ?? 0);
|
|
775
|
+
}
|
|
776
|
+
/** The predicate selecting one context's Tasks the caller may see, or `null` when the context is hidden. */
|
|
777
|
+
async #inContext(q) {
|
|
778
|
+
if (!isUuid(q.contextId) || (q.contextGroupId !== undefined && !isUuid(q.contextGroupId)))
|
|
779
|
+
return null;
|
|
780
|
+
const visibleContext = await this.deps.visibility.canSeeContext({ contextType: q.contextType, contextId: q.contextId });
|
|
781
|
+
if (!visibleContext)
|
|
782
|
+
return null;
|
|
783
|
+
const sql = [`t."context_type" = ?`, `t."context_id" = ?`];
|
|
784
|
+
const params = [q.contextType, q.contextId];
|
|
785
|
+
if (q.contextGroupId !== undefined) {
|
|
786
|
+
sql.push(`t."context_group_id" = ?`);
|
|
787
|
+
params.push(q.contextGroupId);
|
|
788
|
+
}
|
|
789
|
+
const viewer = await this.deps.visibility.viewer();
|
|
790
|
+
if (viewer) {
|
|
791
|
+
// The context is visible; the draft/private conjunct still applies.
|
|
792
|
+
const scope = {
|
|
793
|
+
unrestricted: false,
|
|
794
|
+
contexts: [{ contextType: q.contextType, ids: [q.contextId] }],
|
|
795
|
+
viewer,
|
|
796
|
+
};
|
|
797
|
+
const visible = taskVisibilitySql(scope, 't');
|
|
798
|
+
sql.push(visible.sql);
|
|
799
|
+
params.push(...visible.params);
|
|
800
|
+
}
|
|
801
|
+
return { sql: sql.join(' and '), params };
|
|
802
|
+
}
|
|
803
|
+
/** Rows as they cross a module boundary — plain records, never the entity. */
|
|
804
|
+
async records(rows) {
|
|
805
|
+
if (rows.length === 0)
|
|
806
|
+
return [];
|
|
807
|
+
const [graph, assignees] = await Promise.all([this.deps.workflow.graph(), this.#assigneeIds(rows.map((r) => r.id))]);
|
|
808
|
+
return rows.map((row) => {
|
|
809
|
+
const def = graph.get(row.status);
|
|
810
|
+
const category = def?.category ?? 'open';
|
|
811
|
+
return {
|
|
812
|
+
id: row.id,
|
|
813
|
+
number: row.number,
|
|
814
|
+
title: row.title,
|
|
815
|
+
status: row.status,
|
|
816
|
+
statusCategory: category,
|
|
817
|
+
statusName: def?.name ?? {},
|
|
818
|
+
statusDefaultName: def?.defaultName || row.status,
|
|
819
|
+
statusColor: def?.color ?? '#94a3b8',
|
|
820
|
+
closed: category !== 'open',
|
|
821
|
+
dueOn: row.due_on,
|
|
822
|
+
dueAt: asDate(row.due_at),
|
|
823
|
+
assigneeIds: assignees.get(row.id) ?? [],
|
|
824
|
+
draft: row.is_draft,
|
|
825
|
+
private: row.is_private,
|
|
826
|
+
contextType: row.context_type,
|
|
827
|
+
contextId: row.context_id,
|
|
828
|
+
contextGroupId: row.context_group_id,
|
|
829
|
+
contextNote: row.context_note,
|
|
830
|
+
completedAt: asDate(row.completed_at),
|
|
831
|
+
createdAt: new Date(row.created_at),
|
|
832
|
+
updatedAt: new Date(row.updated_at),
|
|
833
|
+
};
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
// --- Assignment notifications (FR-032, research R-2) -------------------------
|
|
837
|
+
/**
|
|
838
|
+
* Each newly added assignee other than the caller is told once, after commit,
|
|
839
|
+
* and only when they may see the Task (`mention-service.ts`'s audience: they
|
|
840
|
+
* hold `tasks:read`, F-14, and the context's owner says they may see it). A
|
|
841
|
+
* bell is read outside any visibility, and a number must not reach someone
|
|
842
|
+
* the Task is hidden from. An owner that is not present vouches for nobody.
|
|
843
|
+
*/
|
|
844
|
+
async #tellAssignees(added, row) {
|
|
845
|
+
const me = actingAdminUserId();
|
|
846
|
+
for (const assignee of added) {
|
|
847
|
+
if (assignee === me)
|
|
848
|
+
continue;
|
|
849
|
+
await tellAfterCommit(row.id, async () => {
|
|
850
|
+
if (!(await this.deps.audience(assignee, row)))
|
|
851
|
+
return;
|
|
852
|
+
await this.deps.notifier.assigned({ targetAdminUserId: assignee, taskId: row.id, number: row.number });
|
|
853
|
+
});
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
// --- Shaping rows for the reader ---------------------------------------------
|
|
857
|
+
async #detail(row, language) {
|
|
858
|
+
const scope = await this.deps.visibility.scope();
|
|
859
|
+
const [[summary], subtaskRows, relatedRows, counts, creator, me] = await Promise.all([
|
|
860
|
+
this.#summaries([row], language, scope),
|
|
861
|
+
this.#visibleChildren(row.id, scope),
|
|
862
|
+
this.#visibleRelated(row.id, scope),
|
|
863
|
+
this.#collaborationCounts(row.id),
|
|
864
|
+
this.#people([row.created_by_admin_user_id]).then((people) => people.get(row.created_by_admin_user_id)),
|
|
865
|
+
Promise.resolve(actingAdminUserId()),
|
|
866
|
+
]);
|
|
867
|
+
const [references, customFieldValues, links, reminders] = await Promise.all([
|
|
868
|
+
this.deps.references.resolve(row.description),
|
|
869
|
+
this.deps.customFields.project('task', row.custom_field_values ?? {}),
|
|
870
|
+
this.deps.links.linksOf(row.id),
|
|
871
|
+
this.deps.reminders(row.id),
|
|
872
|
+
]);
|
|
873
|
+
const held = me === null ? [] : await this.deps.permissions.listPermissions(me);
|
|
874
|
+
const contextAvailable = summary.context?.available ?? false;
|
|
875
|
+
const canChangeTasks = await this.#mayChangeTasks(row, contextAvailable);
|
|
876
|
+
const mayWrite = holds(held, 'tasks:write');
|
|
877
|
+
return {
|
|
878
|
+
...summary,
|
|
879
|
+
description: row.description,
|
|
880
|
+
references,
|
|
881
|
+
context: summary.context && row.context_id
|
|
882
|
+
? { ...summary.context, id: row.context_id, groupId: row.context_group_id, canChangeTasks }
|
|
883
|
+
: null,
|
|
884
|
+
contextNote: await this.#note(row, language),
|
|
885
|
+
startOn: row.start_on,
|
|
886
|
+
customFieldValues,
|
|
887
|
+
links,
|
|
888
|
+
relatedTasks: await this.#summaries(relatedRows, language, scope),
|
|
889
|
+
subtaskItems: await this.#summaries(subtaskRows, language, scope),
|
|
890
|
+
attachmentsCount: counts.attachments,
|
|
891
|
+
commentsCount: counts.comments,
|
|
892
|
+
reminders,
|
|
893
|
+
createdBy: creator ? { id: creator.id, name: personName(creator) } : null,
|
|
894
|
+
publishedAt: iso(row.published_at),
|
|
895
|
+
completedAt: iso(row.completed_at),
|
|
896
|
+
permissions: {
|
|
897
|
+
canChange: mayWrite && !isSomeoneElsesPrivate(row),
|
|
898
|
+
canDelete: (mayWrite || (row.is_private && holds(held, 'tasks:see_private'))) &&
|
|
899
|
+
(row.context_type === null || canChangeTasks),
|
|
900
|
+
canPublish: row.is_draft && me !== null && row.created_by_admin_user_id === me,
|
|
901
|
+
},
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
/** The visible sub-tasks of one Task, oldest first. */
|
|
905
|
+
async #visibleChildren(parentId, scope) {
|
|
906
|
+
const where = [`t."parent_task_id" = ?::uuid`];
|
|
907
|
+
const params = [parentId];
|
|
908
|
+
const visible = taskVisibilitySql(scope, 't');
|
|
909
|
+
if (visible) {
|
|
910
|
+
where.push(visible.sql);
|
|
911
|
+
params.push(...visible.params);
|
|
912
|
+
}
|
|
913
|
+
return (await this.deps.emFactory().execute(`select ${TASK_COLUMNS} from "tasks" t where ${where.join(' and ')} order by t."created_at" asc, t."id" asc`, params));
|
|
914
|
+
}
|
|
915
|
+
/**
|
|
916
|
+
* The Tasks related to one Task that the reader may see, by number (FR-030):
|
|
917
|
+
* the pairs are read by the visible Task's id, and the other side through
|
|
918
|
+
* the visibility pre-filter.
|
|
919
|
+
*/
|
|
920
|
+
async #visibleRelated(taskId, scope) {
|
|
921
|
+
const pairs = (await this.deps.emFactory().execute(`select case when r."task_a_id" = ?::uuid then r."task_b_id" else r."task_a_id" end as "id"
|
|
922
|
+
from "task_relations" r where r."task_a_id" = ?::uuid or r."task_b_id" = ?::uuid`, [taskId, taskId, taskId]));
|
|
923
|
+
const rows = await this.#visibleRowsByIds(pairs.map((pair) => pair.id), scope);
|
|
924
|
+
return rows.sort((a, b) => a.number.localeCompare(b.number) || a.id.localeCompare(b.id));
|
|
925
|
+
}
|
|
926
|
+
/** How many attachments and live comments one visible Task has. */
|
|
927
|
+
async #collaborationCounts(taskId) {
|
|
928
|
+
const [row] = (await this.deps.emFactory().execute(`select (select count(*)::int from "task_attachments" a where a."task_id" = ?) as "attachments",
|
|
929
|
+
(select count(*)::int from "task_comments" c where c."task_id" = ? and c."deleted_at" is null) as "comments"`, [taskId, taskId]));
|
|
930
|
+
return { attachments: Number(row?.attachments ?? 0), comments: Number(row?.comments ?? 0) };
|
|
931
|
+
}
|
|
932
|
+
/**
|
|
933
|
+
* The context owner's `canChangeTasks` for the reader, so a screen does not
|
|
934
|
+
* offer a Delete or a move the server would refuse (163 T147). An
|
|
935
|
+
* unavailable context answers `false`.
|
|
936
|
+
*/
|
|
937
|
+
async #mayChangeTasks(row, available) {
|
|
938
|
+
if (!available || row.context_type === null || row.context_id === null)
|
|
939
|
+
return false;
|
|
940
|
+
const descriptor = this.deps.contexts.presentFor(row.context_type);
|
|
941
|
+
return descriptor ? descriptor.canChangeTasks(row.context_id) : false;
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
* The Task's note in the reader's language — worded by the context's owner
|
|
945
|
+
* when it says how (`renderNote`), otherwise as it was stored.
|
|
946
|
+
*/
|
|
947
|
+
async #note(row, language) {
|
|
948
|
+
if (row.context_note === null || !row.context_type)
|
|
949
|
+
return row.context_note;
|
|
950
|
+
const descriptor = this.deps.contexts.presentFor(row.context_type);
|
|
951
|
+
return descriptor?.renderNote ? descriptor.renderNote(row.context_note, language) : row.context_note;
|
|
952
|
+
}
|
|
953
|
+
async #summaries(rows, language, scope, cardFields) {
|
|
954
|
+
if (rows.length === 0)
|
|
955
|
+
return [];
|
|
956
|
+
const facts = await this.#facts(rows, scope);
|
|
957
|
+
const people = await this.#people([...new Set([...facts.assignees.values()].flat())]);
|
|
958
|
+
const descriptions = await this.#describe(rows);
|
|
959
|
+
let unavailable = null;
|
|
960
|
+
const contextOf = async (row) => {
|
|
961
|
+
if (!row.context_type || !row.context_id)
|
|
962
|
+
return null;
|
|
963
|
+
const description = descriptions.get(row.context_type)?.get(row.context_id);
|
|
964
|
+
if (description && description.label !== '') {
|
|
965
|
+
return {
|
|
966
|
+
type: row.context_type,
|
|
967
|
+
available: true,
|
|
968
|
+
label: description.label,
|
|
969
|
+
href: description.href || null,
|
|
970
|
+
groupLabel: (row.context_group_id && description.groups.get(row.context_group_id)) || null,
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
// Fail closed: the owner did not describe the record — gone since the
|
|
974
|
+
// visibility check, or its owner answered for fewer ids than asked.
|
|
975
|
+
unavailable ??= await this.deps.translate('context.unavailable', language);
|
|
976
|
+
return { type: row.context_type, available: false, label: unavailable, href: null, groupLabel: null };
|
|
977
|
+
};
|
|
978
|
+
const contexts = [];
|
|
979
|
+
for (const row of rows)
|
|
980
|
+
contexts.push(await contextOf(row));
|
|
981
|
+
const now = new Date();
|
|
982
|
+
const summaries = rows.map((row, index) => {
|
|
983
|
+
const status = statusRef(facts.graph, row.status, language);
|
|
984
|
+
const closed = status.category !== 'open';
|
|
985
|
+
const parent = row.parent_task_id ? facts.parents.get(row.parent_task_id) : undefined;
|
|
986
|
+
return {
|
|
987
|
+
id: row.id,
|
|
988
|
+
number: row.number,
|
|
989
|
+
title: row.title,
|
|
990
|
+
status,
|
|
991
|
+
closed,
|
|
992
|
+
assignees: (facts.assignees.get(row.id) ?? []).flatMap((id) => {
|
|
993
|
+
const person = people.get(id);
|
|
994
|
+
return person ? [{ id: person.id, name: personName(person), active: isActive(person) }] : [];
|
|
995
|
+
}),
|
|
996
|
+
dueOn: row.due_on,
|
|
997
|
+
dueAt: iso(row.due_at),
|
|
998
|
+
overdue: isOverdue({ closed, dueOn: row.due_on, dueAt: asDate(row.due_at) }, now, facts.timeZone),
|
|
999
|
+
priority: priorityRef(facts.priorities, row.priority_code, language),
|
|
1000
|
+
tags: facts.tags.get(row.id) ?? [],
|
|
1001
|
+
context: contexts[index] ?? null,
|
|
1002
|
+
parent: row.parent_task_id
|
|
1003
|
+
? { id: row.parent_task_id, number: parent?.number ?? null, available: parent !== undefined }
|
|
1004
|
+
: null,
|
|
1005
|
+
subtasks: facts.subtasks.get(row.id) ?? { closed: 0, total: 0 },
|
|
1006
|
+
draft: row.is_draft,
|
|
1007
|
+
private: row.is_private,
|
|
1008
|
+
createdAt: new Date(row.created_at).toISOString(),
|
|
1009
|
+
updatedAt: new Date(row.updated_at).toISOString(),
|
|
1010
|
+
};
|
|
1011
|
+
});
|
|
1012
|
+
if (!cardFields)
|
|
1013
|
+
return summaries;
|
|
1014
|
+
// The board's cards (FR-022): the chosen fields' values, off the summary
|
|
1015
|
+
// and the two columns it does not carry.
|
|
1016
|
+
return summaries.map((summary, index) => ({
|
|
1017
|
+
...summary,
|
|
1018
|
+
cardFields: cardFieldValues(cardFields, summary, {
|
|
1019
|
+
startOn: rows[index].start_on,
|
|
1020
|
+
customFieldValues: rows[index].custom_field_values,
|
|
1021
|
+
}),
|
|
1022
|
+
}));
|
|
1023
|
+
}
|
|
1024
|
+
/** Everything a page of rows needs beside itself, one query per kind, all keyed by the page's ids. */
|
|
1025
|
+
async #facts(rows, scope) {
|
|
1026
|
+
const ids = rows.map((row) => row.id);
|
|
1027
|
+
const parentIds = [...new Set(rows.map((row) => row.parent_task_id).filter((id) => id !== null))];
|
|
1028
|
+
const [graph, priorities, timeZone, assignees, tags, subtasks, parents] = await Promise.all([
|
|
1029
|
+
this.deps.workflow.graph(),
|
|
1030
|
+
this.deps.workflow.priorities(),
|
|
1031
|
+
this.deps.timeZone(),
|
|
1032
|
+
this.#assigneeIds(ids),
|
|
1033
|
+
this.#tags(ids),
|
|
1034
|
+
this.#subtaskCounts(ids, scope),
|
|
1035
|
+
this.#visibleRowsByIds(parentIds, scope),
|
|
1036
|
+
]);
|
|
1037
|
+
return { graph, priorities, timeZone, assignees, tags, subtasks, parents: new Map(parents.map((p) => [p.id, p])) };
|
|
1038
|
+
}
|
|
1039
|
+
/** The assignees of each Task, in the order they were given it. */
|
|
1040
|
+
async #assigneeIds(taskIds) {
|
|
1041
|
+
const out = new Map();
|
|
1042
|
+
if (taskIds.length === 0)
|
|
1043
|
+
return out;
|
|
1044
|
+
const rows = (await this.deps.emFactory().execute(`select a."task_id", a."admin_user_id" from "task_assignees" a where a."task_id" = any(?::uuid[])
|
|
1045
|
+
order by a."assigned_at" asc, a."admin_user_id" asc`, [uuids(taskIds)]));
|
|
1046
|
+
for (const row of rows)
|
|
1047
|
+
out.set(row.task_id, [...(out.get(row.task_id) ?? []), row.admin_user_id]);
|
|
1048
|
+
return out;
|
|
1049
|
+
}
|
|
1050
|
+
/** The tags of each Task, by name. */
|
|
1051
|
+
async #tags(taskIds) {
|
|
1052
|
+
const out = new Map();
|
|
1053
|
+
if (taskIds.length === 0)
|
|
1054
|
+
return out;
|
|
1055
|
+
const rows = (await this.deps.emFactory().execute(`select ta."task_id", g."id", g."name", g."color" from "task_tag_assignments" ta
|
|
1056
|
+
join "task_tags" g on g."id" = ta."tag_id"
|
|
1057
|
+
where ta."task_id" = any(?::uuid[])
|
|
1058
|
+
order by lower(g."name") asc, g."id" asc`, [uuids(taskIds)]));
|
|
1059
|
+
for (const row of rows) {
|
|
1060
|
+
out.set(row.task_id, [...(out.get(row.task_id) ?? []), { id: row.id, name: row.name, color: row.color }]);
|
|
1061
|
+
}
|
|
1062
|
+
return out;
|
|
1063
|
+
}
|
|
1064
|
+
/** Each Task's sub-tasks the reader may see, closed and in all (FR-028). */
|
|
1065
|
+
async #subtaskCounts(taskIds, scope) {
|
|
1066
|
+
const out = new Map();
|
|
1067
|
+
if (taskIds.length === 0)
|
|
1068
|
+
return out;
|
|
1069
|
+
const where = [`c."parent_task_id" = any(?::uuid[])`];
|
|
1070
|
+
const params = [uuids(taskIds)];
|
|
1071
|
+
const visible = taskVisibilitySql(scope, 'c');
|
|
1072
|
+
if (visible) {
|
|
1073
|
+
where.push(visible.sql);
|
|
1074
|
+
params.push(...visible.params);
|
|
1075
|
+
}
|
|
1076
|
+
const rows = (await this.deps.emFactory().execute(`select c."parent_task_id", count(*)::int as "total", count(*) filter (where ${CLOSED_SQL('c')})::int as "closed"
|
|
1077
|
+
from "tasks" c where ${where.join(' and ')} group by c."parent_task_id"`, params));
|
|
1078
|
+
for (const row of rows)
|
|
1079
|
+
out.set(row.parent_task_id, { closed: Number(row.closed), total: Number(row.total) });
|
|
1080
|
+
return out;
|
|
1081
|
+
}
|
|
1082
|
+
async #people(ids) {
|
|
1083
|
+
const unique = [...new Set(ids)];
|
|
1084
|
+
if (unique.length === 0)
|
|
1085
|
+
return new Map();
|
|
1086
|
+
const found = await this.deps.adminUsers.findByIds(unique);
|
|
1087
|
+
return new Map(found.map((admin) => [admin.id, admin]));
|
|
1088
|
+
}
|
|
1089
|
+
/**
|
|
1090
|
+
* What each context's owner says about the contexts of `rows`, asked once
|
|
1091
|
+
* per type, under the caller's context. Only a present owner is asked.
|
|
1092
|
+
*/
|
|
1093
|
+
async #describe(rows) {
|
|
1094
|
+
const byType = new Map();
|
|
1095
|
+
for (const row of rows) {
|
|
1096
|
+
if (!row.context_type || !row.context_id)
|
|
1097
|
+
continue;
|
|
1098
|
+
const ids = byType.get(row.context_type) ?? new Set();
|
|
1099
|
+
ids.add(row.context_id);
|
|
1100
|
+
byType.set(row.context_type, ids);
|
|
1101
|
+
}
|
|
1102
|
+
const out = new Map();
|
|
1103
|
+
for (const [contextType, ids] of byType) {
|
|
1104
|
+
const descriptor = this.deps.contexts.presentFor(contextType);
|
|
1105
|
+
if (!descriptor)
|
|
1106
|
+
continue;
|
|
1107
|
+
out.set(contextType, await descriptor.describe([...ids]));
|
|
1108
|
+
}
|
|
1109
|
+
return out;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
//# sourceMappingURL=task-service.js.map
|