Commit 67a95f4
feat: pin a default connection; fix Editor misdiagnosing malformed SQL as a permissions error (#107)
Two independent changes, one commit each.
---
## 1. `feat:` pin a connection as your per-user default
Requested feature. A pin toggle in **Manage Connections** and in the
sidebar connection switcher; a pinned connection is the one DeepSQL
opens on every load.
**The pin is per user, not a flag on the connection.** A connection can
be shared through `connection_access_grant`, so a column on
`database_connection` would let one person's choice decide what everyone
else opens on — and shared connections are `canManageConfig=false` for
their recipients, so exactly the people who most want a default could
not set one. New `connection_pin` table, one row per user, unique
constraint on `username`; pinning a second connection moves the row
rather than adding one.
**`PUT|DELETE /connections/{id}/pin` are gated on
`assertCanUseConnection`**, not `assertCanManageConnectionConfig` —
choosing where you land is a preference, not a change to the connection.
`GET /connections` carries `pinned` per caller, so no surface needs a
second request; `deleteConnection` clears every pin on the connection
alongside its grants.
**The pin has to beat an already-selected connection, not just an empty
one.** `useDashboardStore` persists `connectionId`, so after a reload
something is always selected and the existing auto-select never ran.
`useConnectionManager` now applies the pin once per page load, tracked
at module scope rather than in a ref — the hook is called from a dozen
sections, and a per-instance guard would let a later-mounted section
yank the user back to the pin after they deliberately switched.
Switching mid-session still sticks.
The sidebar toggle exists because Manage Connections needs
`MANAGE_CONNECTIONS` to open at all; without it a Developer or Data
Engineer, who typically holds exactly one granted connection, would have
no way to set a default.
### One thing reviewers should look at
`ConnectionScopedAuthorizationSafetyTest` now flags `GET /connections`,
because the handler resolves the caller's *pinned* connection id and the
scanner matches `(?i)connection_?id` anywhere in a handler body. That
endpoint takes **no arguments at all** — it returns whatever
`getConnectionsForUser(username, isAdmin)` gives. It is exempted in
`AUTHORIZED_ELSEWHERE`, and a new
`connectionListingTakesNoCallerSuppliedId` test re-derives the claim so
the exemption cannot rot into cover for a real gap. The scanner was not
weakened and no meaningless assert was added.
### Verified against a live backend
On a throwaway Postgres/backend stack, not inferred:
- `ddl-auto` creates `connection_pin` with its unique index on boot
- pinning a second connection flips the first to `false`
- unpinning a *non*-pinned connection leaves the real pin alone
- deleting a connection clears its pin row
- a DEVELOPER with **no grant** gets **403, not 500**
- a DEVELOPER holding only a grant (`canManageConfig: false`) pins
successfully, and their pin does **not** appear on the admin's list
---
## 2. `fix:` Editor reported malformed SQL as a permissions denial
Reported from the field. A user pasted a SELECT that still carried the
double quotes it had in source code (`"select h.id, ...`) and was told
**"Only admins can execute DDL or DML from the SQL Editor"** — which
reads as a permissions problem and sent people looking for a role fix.
The statement is neither DDL nor DML. With an unclosed `"` the whole
thing is one quoted identifier, so it is not valid SQL at all.
**Two keyword heuristics disagreed, and the disagreement was resolved as
"mutation":**
```
detectQueryType = SELECT isReadOnlyQuery = false parse = FAILED
```
`QueryNormalizer.detectQueryType` sanitizes a prefix away and answers
`SELECT`; the provider's `isReadOnlyQuery` strips only *comments*, still
sees the leading quote, and answers false. `mutating = !readOnly && type
!= UNKNOWN` then labelled a SELECT a mutation.
`classifyStatement` now records that the parser rejected the statement
and, when the detected verb is read-only and no hidden write was found,
returns `notParseable`; `enforce` throws `STATEMENT_NOT_PARSEABLE` ahead
of both the read-only and confirmation branches, with a message naming
the likely cause.
### This does not weaken the guard
**The statement is still blocked, admins included** — only the diagnosis
changed. An admin is deliberately *not* offered a confirmation prompt
for a statement nothing managed to classify, since confirming past the
guard is the one way this could become a bypass.
The reclassification is gated on `isReadOnlyVerb(queryType)` **and**
`hiddenWrite == null`. Both halves are tested:
- `anUnparseableWriteIsStillTreatedAsAMutation` — `DELETE FROM hotel
WHERE (((` still returns `EDITOR_MUTATION_FORBIDDEN`
- `aMalformedDataModifyingCteIsStillBlockedAsAWrite` — a broken `WITH x
AS (DELETE ...)` is still a blocked write, not a reported typo
The MCP guard already reported this case honestly ("Only read-only SQL
is allowed …") and was left alone.
---
## Testing
- `QueryExecutionPolicyServiceTest`: **49 pass** (43 before, 6 added),
including every pre-existing guard case — data-modifying CTEs, `SELECT
INTO`, `DROP` blocking, EXPLAIN-wrapped writes.
- **Full backend suite diffed against pristine HEAD**: 1531 vs 1512
tests, **failure sets byte-identical**. The 99 failures are pre-existing
environmental context-load failures (no DB/Redis in the test container),
unchanged by this branch.
- Commit 1 built and tested **in isolation** in a detached worktree, so
it is bisect-safe rather than only green as part of the combined tree.
- Frontend: `npm run build` clean; 0 lint errors in changed files.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>1 parent e358131 commit 67a95f4
22 files changed
Lines changed: 1088 additions & 39 deletions
File tree
- backend/src
- main
- java/com/dbaagent
- controller
- dto
- model
- repository
- service
- resources/db/migration
- test/java/com/dbaagent
- controller
- service
- src
- components
- layout
- hooks
- lib
- api
- hooks
- queries
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
499 | 499 | | |
500 | 500 | | |
501 | 501 | | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
502 | 547 | | |
503 | 548 | | |
504 | 549 | | |
| |||
680 | 725 | | |
681 | 726 | | |
682 | 727 | | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
683 | 747 | | |
684 | 748 | | |
685 | 749 | | |
| |||
Lines changed: 56 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| |||
429 | 431 | | |
430 | 432 | | |
431 | 433 | | |
| 434 | + | |
| 435 | + | |
432 | 436 | | |
433 | | - | |
| 437 | + | |
434 | 438 | | |
435 | 439 | | |
436 | 440 | | |
| |||
440 | 444 | | |
441 | 445 | | |
442 | 446 | | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
443 | 495 | | |
444 | 496 | | |
445 | 497 | | |
446 | 498 | | |
447 | 499 | | |
448 | 500 | | |
449 | 501 | | |
| 502 | + | |
450 | 503 | | |
451 | 504 | | |
452 | 505 | | |
| |||
781 | 834 | | |
782 | 835 | | |
783 | 836 | | |
784 | | - | |
| 837 | + | |
785 | 838 | | |
786 | 839 | | |
787 | 840 | | |
| |||
821 | 874 | | |
822 | 875 | | |
823 | 876 | | |
| 877 | + | |
824 | 878 | | |
825 | 879 | | |
826 | 880 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
34 | 43 | | |
Lines changed: 70 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
Lines changed: 27 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
Lines changed: 96 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
0 commit comments