Files
kandev/apps/web/lib/state/default-state.ts
T
João Salavisa 5693c10d8c feat(jira): poll JQL queries to auto-create tasks (issue watchers) (#746)
* feat(jira): poll JQL queries to auto-create tasks (issue watchers)

* fix(jira): address review feedback on issue watcher

- Poller: gate per-watch by `LastPolledAt` + `PollIntervalSeconds` so the
  user-configured cadence actually applies (was silently ignored, every
  watch polled every 5 min). Tick interval reduced to 60s to match the
  smallest valid per-watch interval.
- Service: validate `pollIntervalSeconds` against the documented 60-3600s
  bounds on create/update so the UI's range check is enforced server-side.
- Service: stamp `last_polled_at` via a fresh `context.Background()` with a
  short write deadline; the poller's ctx may be cancelled at shutdown,
  which would otherwise drop the timestamp on the floor.
- Service/store: replace per-ticket `HasIssueWatchTask` round-trips with a
  single `ListSeenIssueKeys` set lookup (up to 50× fewer DB queries per
  tick on broad JQL queries).
- Hook: reset cached watch list on workspace switch — the store's `loaded`
  flag is global, so without this the table renders the previous
  workspace's watchers stale.
- Section component: pull the CRUD callbacks from a single
  `useJiraIssueWatches` call and pass them down, instead of invoking the
  hook twice on the same workspace.
- Dialog: add the three placeholders (`{{issue.type}}`, `{{issue.reporter}}`,
  `{{issue.project}}`) supported by the backend interpolator but missing
  from the help text.

* fix(jira): repair workspace-switch refetch + drop double trigger toast

The previous a9bd9fa attempt at the workspace-switch reset was incomplete:
`setJiraIssueWatches([])` flips `loaded=true`, so the fetch effect's
`if (!workspaceId || loaded || loading) return` guard still short-circuited
and the new workspace's data was never fetched. Switching workspaces left
the table empty with no recovery path.

- Add a dedicated `resetJiraIssueWatches` action that zeroes both `items`
  and `loaded`, and use it from the hook's workspace-change effect.
- Drop the inline "Checking JIRA…" toast in the watcher table — the
  parent's `wrappedTrigger` already fires a result toast on completion,
  so the click was double-toasting.

* fix(jira): reject empty workflowId/workflowStepId on issue-watch PATCH

`applyIssueWatchPatch` writes the field whenever the patch pointer is
non-nil, but Go's JSON decoder returns a non-nil pointer to "" for an
explicit `{"workflowId": ""}` body. The post-patch JQL check guarded
against the same hole for `jql`; this extends it to the workflow
fields. Without it, a stripped row would silently drop every event the
orchestrator tries to handle (the watcher looks active but produces no
tasks).

* fix(jira): require workspace ownership on issue-watch mutate/trigger

The PATCH/DELETE/trigger handlers looked up watches by the path :id with
no workspace check, while the list/create handlers correctly required
workspace_id. A user authenticated to workspace A who learned a watch
UUID from workspace B could mutate it, delete it, or trigger it
(running JQL with workspace B's stored credentials and creating tasks
there). Closes the IDOR by:

- backend: PATCH/DELETE/trigger now require ?workspace_id=... and 404
  on mismatch (404 not 403, so probing can't enumerate IDs across
  workspaces).
- frontend: api client + hook thread workspaceId through all mutation
  calls.
- store: drop the no-longer-used HasIssueWatchTask method (replaced by
  ListSeenIssueKeys after the N+1 fix); test now asserts via the
  bulk-fetched set.

---------

Co-authored-by: Kandev Agent <agent@kandev.dev>
2026-05-01 11:01:02 +01:00

168 lines
9.2 KiB
TypeScript

import {
defaultKanbanState,
defaultWorkspaceState,
defaultSettingsState,
defaultSessionState,
defaultSessionRuntimeState,
defaultUIState,
defaultGitHubState,
defaultJiraState,
} from "./slices";
export const defaultState = {
kanban: defaultKanbanState.kanban,
kanbanMulti: defaultKanbanState.kanbanMulti,
workflows: defaultKanbanState.workflows,
tasks: defaultKanbanState.tasks,
workspaces: defaultWorkspaceState.workspaces,
repositories: defaultWorkspaceState.repositories,
repositoryBranches: defaultWorkspaceState.repositoryBranches,
repositoryScripts: defaultWorkspaceState.repositoryScripts,
executors: defaultSettingsState.executors,
settingsAgents: defaultSettingsState.settingsAgents,
agentDiscovery: defaultSettingsState.agentDiscovery,
availableAgents: defaultSettingsState.availableAgents,
agentProfiles: defaultSettingsState.agentProfiles,
editors: defaultSettingsState.editors,
prompts: defaultSettingsState.prompts,
secrets: defaultSettingsState.secrets,
notificationProviders: defaultSettingsState.notificationProviders,
settingsData: defaultSettingsState.settingsData,
userSettings: defaultSettingsState.userSettings,
messages: defaultSessionState.messages,
turns: defaultSessionState.turns,
taskSessions: defaultSessionState.taskSessions,
taskSessionsByTask: defaultSessionState.taskSessionsByTask,
sessionAgentctl: defaultSessionState.sessionAgentctl,
worktrees: defaultSessionState.worktrees,
sessionWorktreesBySessionId: defaultSessionState.sessionWorktreesBySessionId,
pendingModel: defaultSessionState.pendingModel,
activeModel: defaultSessionState.activeModel,
taskPlans: defaultSessionState.taskPlans,
queue: defaultSessionState.queue,
terminal: defaultSessionRuntimeState.terminal,
shell: defaultSessionRuntimeState.shell,
processes: defaultSessionRuntimeState.processes,
gitStatus: defaultSessionRuntimeState.gitStatus,
environmentIdBySessionId: defaultSessionRuntimeState.environmentIdBySessionId,
sessionCommits: defaultSessionRuntimeState.sessionCommits,
contextWindow: defaultSessionRuntimeState.contextWindow,
agents: defaultSessionRuntimeState.agents,
availableCommands: defaultSessionRuntimeState.availableCommands,
sessionMode: defaultSessionRuntimeState.sessionMode,
userShells: defaultSessionRuntimeState.userShells,
prepareProgress: defaultSessionRuntimeState.prepareProgress,
sessionTodos: defaultSessionRuntimeState.sessionTodos,
agentCapabilities: defaultSessionRuntimeState.agentCapabilities,
sessionModels: defaultSessionRuntimeState.sessionModels,
promptUsage: defaultSessionRuntimeState.promptUsage,
sessionPollMode: defaultSessionRuntimeState.sessionPollMode,
githubStatus: defaultGitHubState.githubStatus,
taskPRs: defaultGitHubState.taskPRs,
prWatches: defaultGitHubState.prWatches,
reviewWatches: defaultGitHubState.reviewWatches,
issueWatches: defaultGitHubState.issueWatches,
actionPresets: defaultGitHubState.actionPresets,
jiraIssueWatches: defaultJiraState.jiraIssueWatches,
previewPanel: defaultUIState.previewPanel,
rightPanel: defaultUIState.rightPanel,
diffs: defaultUIState.diffs,
connection: defaultUIState.connection,
mobileKanban: defaultUIState.mobileKanban,
mobileSession: defaultUIState.mobileSession,
chatInput: defaultUIState.chatInput,
documentPanel: defaultUIState.documentPanel,
systemHealth: defaultUIState.systemHealth,
quickChat: defaultUIState.quickChat,
sessionFailureNotification: defaultUIState.sessionFailureNotification,
bottomTerminal: defaultUIState.bottomTerminal,
sidebarViews: defaultUIState.sidebarViews,
collapsedSubtaskParents: defaultUIState.collapsedSubtaskParents,
};
export type DefaultState = typeof defaultState;
export function mergeInitialState(initialState?: Partial<DefaultState>): DefaultState {
if (!initialState) return defaultState;
return {
...defaultState,
...initialState,
// Ensure nested objects are properly merged
kanban: { ...defaultState.kanban, ...initialState.kanban },
kanbanMulti: { ...defaultState.kanbanMulti, ...initialState.kanbanMulti },
workflows: { ...defaultState.workflows, ...initialState.workflows },
tasks: { ...defaultState.tasks, ...initialState.tasks },
workspaces: { ...defaultState.workspaces, ...initialState.workspaces },
repositories: { ...defaultState.repositories, ...initialState.repositories },
repositoryBranches: { ...defaultState.repositoryBranches, ...initialState.repositoryBranches },
repositoryScripts: { ...defaultState.repositoryScripts, ...initialState.repositoryScripts },
executors: { ...defaultState.executors, ...initialState.executors },
settingsAgents: { ...defaultState.settingsAgents, ...initialState.settingsAgents },
agentDiscovery: { ...defaultState.agentDiscovery, ...initialState.agentDiscovery },
availableAgents: { ...defaultState.availableAgents, ...initialState.availableAgents },
agentProfiles: { ...defaultState.agentProfiles, ...initialState.agentProfiles },
editors: { ...defaultState.editors, ...initialState.editors },
prompts: { ...defaultState.prompts, ...initialState.prompts },
secrets: { ...defaultState.secrets, ...initialState.secrets },
notificationProviders: {
...defaultState.notificationProviders,
...initialState.notificationProviders,
},
settingsData: { ...defaultState.settingsData, ...initialState.settingsData },
userSettings: { ...defaultState.userSettings, ...initialState.userSettings },
messages: { ...defaultState.messages, ...initialState.messages },
turns: { ...defaultState.turns, ...initialState.turns },
taskSessions: { ...defaultState.taskSessions, ...initialState.taskSessions },
taskSessionsByTask: { ...defaultState.taskSessionsByTask, ...initialState.taskSessionsByTask },
sessionAgentctl: { ...defaultState.sessionAgentctl, ...initialState.sessionAgentctl },
worktrees: { ...defaultState.worktrees, ...initialState.worktrees },
sessionWorktreesBySessionId: {
...defaultState.sessionWorktreesBySessionId,
...initialState.sessionWorktreesBySessionId,
},
pendingModel: { ...defaultState.pendingModel, ...initialState.pendingModel },
activeModel: { ...defaultState.activeModel, ...initialState.activeModel },
taskPlans: { ...defaultState.taskPlans, ...initialState.taskPlans },
queue: { ...defaultState.queue, ...initialState.queue },
terminal: { ...defaultState.terminal, ...initialState.terminal },
shell: { ...defaultState.shell, ...initialState.shell },
processes: { ...defaultState.processes, ...initialState.processes },
gitStatus: { ...defaultState.gitStatus, ...initialState.gitStatus },
sessionCommits: { ...defaultState.sessionCommits, ...initialState.sessionCommits },
contextWindow: { ...defaultState.contextWindow, ...initialState.contextWindow },
agents: { ...defaultState.agents, ...initialState.agents },
sessionMode: { ...defaultState.sessionMode, ...initialState.sessionMode },
userShells: { ...defaultState.userShells, ...initialState.userShells },
prepareProgress: { ...defaultState.prepareProgress, ...initialState.prepareProgress },
sessionTodos: { ...defaultState.sessionTodos, ...initialState.sessionTodos },
agentCapabilities: { ...defaultState.agentCapabilities, ...initialState.agentCapabilities },
sessionModels: { ...defaultState.sessionModels, ...initialState.sessionModels },
promptUsage: { ...defaultState.promptUsage, ...initialState.promptUsage },
sessionPollMode: { ...defaultState.sessionPollMode, ...initialState.sessionPollMode },
githubStatus: { ...defaultState.githubStatus, ...initialState.githubStatus },
taskPRs: { ...defaultState.taskPRs, ...initialState.taskPRs },
prWatches: { ...defaultState.prWatches, ...initialState.prWatches },
reviewWatches: { ...defaultState.reviewWatches, ...initialState.reviewWatches },
issueWatches: { ...defaultState.issueWatches, ...initialState.issueWatches },
actionPresets: { ...defaultState.actionPresets, ...initialState.actionPresets },
jiraIssueWatches: { ...defaultState.jiraIssueWatches, ...initialState.jiraIssueWatches },
previewPanel: { ...defaultState.previewPanel, ...initialState.previewPanel },
rightPanel: { ...defaultState.rightPanel, ...initialState.rightPanel },
diffs: { ...defaultState.diffs, ...initialState.diffs },
connection: { ...defaultState.connection, ...initialState.connection },
mobileKanban: { ...defaultState.mobileKanban, ...initialState.mobileKanban },
mobileSession: { ...defaultState.mobileSession, ...initialState.mobileSession },
chatInput: { ...defaultState.chatInput, ...initialState.chatInput },
documentPanel: { ...defaultState.documentPanel, ...initialState.documentPanel },
systemHealth: { ...defaultState.systemHealth, ...initialState.systemHealth },
quickChat: { ...defaultState.quickChat, ...initialState.quickChat },
sessionFailureNotification:
initialState.sessionFailureNotification ?? defaultState.sessionFailureNotification,
bottomTerminal: { ...defaultState.bottomTerminal, ...initialState.bottomTerminal },
sidebarViews: { ...defaultState.sidebarViews, ...initialState.sidebarViews },
collapsedSubtaskParents:
initialState.collapsedSubtaskParents ?? defaultState.collapsedSubtaskParents,
};
}