feat(alle opgaver): et endepunkt med alle åbne opgaver
GET /api/v1/all-tasks: hver åben opgave på øverste niveau i hvert aktivt projekt, man kan se. Arkiverede projekter er udeladt, underopgaver vises som deres forælders tal. Højst 2000, og svaret siger det, når der var flere. Og en kalendertest, der var blevet rød på main: dens begivenhed lå fast på 20. august, og vinduet holder 90 dage tilbage. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
f578dee45f
commit
6dba7ab60a
@@ -141,16 +141,25 @@ func TestAuthorizeWithoutAClientSaysSo(t *testing.T) {
|
||||
// The whole path, minus the consent screen: sync fetches the list, refreshes the
|
||||
// events of what was chosen, and the grid endpoint answers with them.
|
||||
func TestSyncFetchesTheChosenCalendarsAndTheGridReadsThem(t *testing.T) {
|
||||
// A week from today, not a fixed date: verdande only keeps a window around now,
|
||||
// and a fixture pinned to August aged out of it in November and turned this
|
||||
// test red with "events = 0" — which reads like the sync broke.
|
||||
day := time.Now().AddDate(0, 0, 7)
|
||||
on := day.Format("2006-01-02")
|
||||
next := day.AddDate(0, 0, 1).Format("2006-01-02")
|
||||
grid := "/api/v1/calendar/events?from=" + day.AddDate(0, 0, -10).Format("2006-01-02") +
|
||||
"&to=" + day.AddDate(0, 0, 10).Format("2006-01-02")
|
||||
|
||||
g := newFakeCalendarGoogle(t)
|
||||
g.events["fam"] = []map[string]any{
|
||||
{"id": "e1", "summary": "Bestyrelsesmøde", "htmlLink": "https://calendar.google.com/e1",
|
||||
"start": map[string]string{"dateTime": "2026-08-20T14:00:00+02:00"},
|
||||
"end": map[string]string{"dateTime": "2026-08-20T15:30:00+02:00"}},
|
||||
"start": map[string]string{"dateTime": on + "T14:00:00+01:00"},
|
||||
"end": map[string]string{"dateTime": on + "T15:30:00+01:00"}},
|
||||
}
|
||||
g.events["[email protected]"] = []map[string]any{
|
||||
{"id": "e2", "summary": "Skal ikke med",
|
||||
"start": map[string]string{"date": "2026-08-21"},
|
||||
"end": map[string]string{"date": "2026-08-22"}},
|
||||
"start": map[string]string{"date": next},
|
||||
"end": map[string]string{"date": day.AddDate(0, 0, 2).Format("2006-01-02")}},
|
||||
}
|
||||
ts, user := connectedCalendar(t, g, nil)
|
||||
|
||||
@@ -209,8 +218,7 @@ func TestSyncFetchesTheChosenCalendarsAndTheGridReadsThem(t *testing.T) {
|
||||
t.Fatalf("events = %v, want 1 — only the chosen calendar", body["events"])
|
||||
}
|
||||
|
||||
resp, body = ts.do(t, "GET",
|
||||
"/api/v1/calendar/events?from=2026-08-01&to=2026-08-31", nil)
|
||||
resp, body = ts.do(t, "GET", grid, nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("events: status %d, body %v", resp.StatusCode, body)
|
||||
}
|
||||
@@ -219,7 +227,7 @@ func TestSyncFetchesTheChosenCalendarsAndTheGridReadsThem(t *testing.T) {
|
||||
t.Fatalf("got %d events, want 1: %v", len(events), body["events"])
|
||||
}
|
||||
event := events[0].(map[string]any)
|
||||
if event["summary"] != "Bestyrelsesmøde" || event["start_day"] != "2026-08-20" {
|
||||
if event["summary"] != "Bestyrelsesmøde" || event["start_day"] != on {
|
||||
t.Errorf("the event came back as %v", event)
|
||||
}
|
||||
// The calendar's colour rides along, or the chip has to ask for it per row.
|
||||
@@ -235,7 +243,7 @@ func TestSyncFetchesTheChosenCalendarsAndTheGridReadsThem(t *testing.T) {
|
||||
// And it is one person's calendar. Somebody else on the same instance sees
|
||||
// nothing of it.
|
||||
other := ts.newUser(t, "[email protected]", "Andreas")
|
||||
_, body = other.do(t, "GET", "/api/v1/calendar/events?from=2026-08-01&to=2026-08-31", nil)
|
||||
_, body = other.do(t, "GET", grid, nil)
|
||||
if events, _ := body["events"].([]any); len(events) != 0 {
|
||||
t.Errorf("somebody else's calendar was visible: %v", body["events"])
|
||||
}
|
||||
|
||||
@@ -64,6 +64,7 @@ func TestNotesEditionServesOnlyItsOwnRoutes(t *testing.T) {
|
||||
"DELETE /caldav/{userID}/{projectID}/{taskFile}",
|
||||
"GET /.well-known/caldav",
|
||||
"GET /api/v1/ai/plan",
|
||||
"GET /api/v1/all-tasks",
|
||||
"GET /api/v1/delegated",
|
||||
"GET /api/v1/export/projects.zip",
|
||||
"GET /api/v1/export/projects/{projectID}.csv",
|
||||
|
||||
@@ -645,6 +645,7 @@ func New(cfg *config.Config, db *store.DB, log *slog.Logger, web fs.FS) *Server
|
||||
})
|
||||
r.Get("/upcoming", s.handleUpcoming)
|
||||
r.Get("/delegated", s.handleDelegated)
|
||||
r.Get("/all-tasks", s.handleAllTasks)
|
||||
}
|
||||
r.Get("/people", s.handlePeople)
|
||||
r.Get("/search", s.handleSearch)
|
||||
|
||||
@@ -184,6 +184,46 @@ func (s *Server) handleDelegated(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, map[string]any{"people": out})
|
||||
}
|
||||
|
||||
// allTasksCap is how many rows "Alle opgaver" will send. Far above what one
|
||||
// person has open; it exists so an account with tens of thousands of imported
|
||||
// tasks gets a slow page rather than an unbounded response. When it is reached the
|
||||
// response says so, because a list that quietly stops is a list that lies about
|
||||
// what is left.
|
||||
const allTasksCap = 2000
|
||||
|
||||
// handleAllTasks is "Alle opgaver": every open task in every active project the
|
||||
// caller can see, top level only — a sub-task is shown as its parent's count, the
|
||||
// way a project shows it, rather than as a second loose row.
|
||||
//
|
||||
// Flat, not grouped. The grouping is by project group and project, and the client
|
||||
// already holds both lists with their names, colours and order; a server-side
|
||||
// grouping would be a second copy of the sidebar's order to keep in step with the
|
||||
// first.
|
||||
func (s *Server) handleAllTasks(w http.ResponseWriter, r *http.Request) {
|
||||
user := userFrom(r.Context())
|
||||
|
||||
tasks, err := s.db.ListTasks(r.Context(), user.ID, store.TaskFilter{
|
||||
TopLevelOnly: true,
|
||||
ActiveProjectsOnly: true,
|
||||
// One past the cap, so "exactly the cap" and "more than the cap" can be told
|
||||
// apart.
|
||||
Limit: allTasksCap + 1,
|
||||
})
|
||||
if err != nil {
|
||||
s.internal(w, r, "all tasks", err)
|
||||
return
|
||||
}
|
||||
|
||||
truncated := len(tasks) > allTasksCap
|
||||
if truncated {
|
||||
tasks = tasks[:allTasksCap]
|
||||
}
|
||||
writeJSON(w, http.StatusOK, map[string]any{
|
||||
"tasks": toTaskList(tasks),
|
||||
"truncated": truncated,
|
||||
})
|
||||
}
|
||||
|
||||
// sortByName orders the groups the way a list of people reads. Insertion sort:
|
||||
// this is a handful of entries, and it keeps the package free of a dependency on
|
||||
// sort just for this.
|
||||
|
||||
@@ -200,3 +200,70 @@ func TestPeopleIsWhoYouShareWorkWith(t *testing.T) {
|
||||
t.Errorf("a stranger is listed: %v", seen)
|
||||
}
|
||||
}
|
||||
|
||||
// "Alle opgaver" is every open task the caller can act on, and the test names
|
||||
// each thing that must stay out — because a list of everything passes any check
|
||||
// that only asks whether the right task is in it.
|
||||
func TestAllTasksIsEveryOpenTopLevelTaskInActiveProjects(t *testing.T) {
|
||||
ts := newTestServer(t)
|
||||
ts.bootstrap(t)
|
||||
|
||||
_, a := ts.do(t, "POST", "/api/v1/projects", map[string]any{"name": "Have"})
|
||||
_, b := ts.do(t, "POST", "/api/v1/projects", map[string]any{"name": "Hus"})
|
||||
_, gone := ts.do(t, "POST", "/api/v1/projects", map[string]any{"name": "Gammelt"})
|
||||
|
||||
_, parent := ts.do(t, "POST", "/api/v1/tasks", map[string]any{
|
||||
"content": "slå græs", "project_id": a["id"],
|
||||
})
|
||||
ts.do(t, "POST", "/api/v1/tasks", map[string]any{
|
||||
"content": "find benzin", "project_id": a["id"], "parent_id": parent["id"],
|
||||
})
|
||||
ts.do(t, "POST", "/api/v1/tasks", map[string]any{
|
||||
"content": "mal døren", "project_id": b["id"],
|
||||
})
|
||||
_, done := ts.do(t, "POST", "/api/v1/tasks", map[string]any{
|
||||
"content": "skift pære", "project_id": b["id"],
|
||||
})
|
||||
ts.do(t, "POST", "/api/v1/tasks/"+done["id"].(string)+"/complete", nil)
|
||||
ts.do(t, "POST", "/api/v1/tasks", map[string]any{
|
||||
"content": "glemt opgave", "project_id": gone["id"],
|
||||
})
|
||||
if resp, body := ts.do(t, "PATCH", "/api/v1/projects/"+gone["id"].(string),
|
||||
map[string]any{"archived": true}); resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("archive: %d %v", resp.StatusCode, body)
|
||||
}
|
||||
|
||||
// Somebody else's task, in a project the caller is not in.
|
||||
other := ts.newUser(t, "[email protected]", "Tredje")
|
||||
_, theirs := other.do(t, "POST", "/api/v1/projects", map[string]any{"name": "Deres"})
|
||||
other.do(t, "POST", "/api/v1/tasks", map[string]any{
|
||||
"content": "deres opgave", "project_id": theirs["id"],
|
||||
})
|
||||
|
||||
resp, body := ts.do(t, "GET", "/api/v1/all-tasks", nil)
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("all-tasks: %d %v", resp.StatusCode, body)
|
||||
}
|
||||
if body["truncated"] != false {
|
||||
t.Errorf("truncated = %v on five tasks", body["truncated"])
|
||||
}
|
||||
|
||||
got := map[string]bool{}
|
||||
for _, raw := range body["tasks"].([]any) {
|
||||
got[raw.(map[string]any)["content"].(string)] = true
|
||||
}
|
||||
want := map[string]bool{"slå græs": true, "mal døren": true}
|
||||
for c := range want {
|
||||
if !got[c] {
|
||||
t.Errorf("missing %q: %v", c, got)
|
||||
}
|
||||
}
|
||||
for _, c := range []string{"find benzin", "skift pære", "glemt opgave", "deres opgave"} {
|
||||
if got[c] {
|
||||
t.Errorf("%q should not be in Alle opgaver: %v", c, got)
|
||||
}
|
||||
}
|
||||
if len(got) != len(want) {
|
||||
t.Errorf("got %d tasks, want %d: %v", len(got), len(want), got)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,7 +69,12 @@ type TaskFilter struct {
|
||||
// TopLevelOnly excludes sub-tasks, which a project view wants because it
|
||||
// renders them nested under their parents rather than as separate rows.
|
||||
TopLevelOnly bool
|
||||
AssigneeID string
|
||||
// ActiveProjectsOnly leaves out tasks in archived projects. An archived
|
||||
// project is one somebody put away; its open tasks are not work that is
|
||||
// waiting, and a view of "everything I have to do" that fills up with them is
|
||||
// a view that has to be read past.
|
||||
ActiveProjectsOnly bool
|
||||
AssigneeID string
|
||||
// DelegatedBy is the other side of AssigneeID: assigned, but not to this
|
||||
// person. A second field rather than a magic value in AssigneeID, because the
|
||||
// two are different questions — "what is on my plate" and "what have I handed
|
||||
@@ -140,6 +145,9 @@ func (db *DB) ListTasks(ctx context.Context, userID string, f TaskFilter) ([]Tas
|
||||
if f.TopLevelOnly {
|
||||
where = append(where, `t.parent_id IS NULL`)
|
||||
}
|
||||
if f.ActiveProjectsOnly {
|
||||
where = append(where, `p.archived = 0`)
|
||||
}
|
||||
if f.AssigneeID != "" {
|
||||
where = append(where, `t.assignee_id = ?`)
|
||||
args = append(args, f.AssigneeID)
|
||||
|
||||
Reference in New Issue
Block a user