feat: expand companion platform, device controls, and memoir workflows
ci / verify (push) Canceled after 0s
ci / verify (push) Canceled after 0s
Add customer and operator login, BLE provisioning, device fleet controls, call memory, memoir generation, and refreshed family and maintenance portals. Include API contracts, migrations, firmware sources, tests, assets, and deployment documentation.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package webevents
|
||||
|
||||
import (
|
||||
"context"
|
||||
"data-terminal-cloud/internal/identity"
|
||||
"time"
|
||||
)
|
||||
|
||||
// History only returns retained metadata from households the caller still belongs to.
|
||||
func (s *Service) History(ctx context.Context, principal identity.Principal, since time.Time, limit int) ([]Event, error) {
|
||||
if limit < 1 || limit > 200 {
|
||||
limit = 200
|
||||
}
|
||||
rows, err := s.pool.Query(ctx, `SELECT we.id,we.event_type,h.public_id::text,we.resource_type,we.resource_public_id::text,COALESCE(sp.public_id::text,''),we.status,we.occurred_at
|
||||
FROM web_event we JOIN household h ON h.id=we.household_id AND h.tenant_id=we.tenant_id AND h.status='active'
|
||||
LEFT JOIN subject_profile sp ON sp.id=we.subject_id AND sp.tenant_id=we.tenant_id
|
||||
WHERE we.occurred_at >= $3 AND we.expires_at>now() AND EXISTS (
|
||||
SELECT 1 FROM household_member hm JOIN user_account ua ON ua.id=hm.user_id AND ua.tenant_id=hm.tenant_id AND ua.status='active'
|
||||
JOIN tenant t ON t.id=ua.tenant_id AND t.status='active'
|
||||
WHERE hm.tenant_id=we.tenant_id AND hm.household_id=we.household_id AND hm.status='active' AND ua.oidc_issuer=$1 AND ua.oidc_subject=$2)
|
||||
ORDER BY we.id DESC LIMIT $4`, principal.Issuer, principal.Subject, since, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
items := make([]Event, 0)
|
||||
for rows.Next() {
|
||||
var item Event
|
||||
if err := rows.Scan(&item.ID, &item.Type, &item.HouseholdID, &item.ResourceType, &item.ResourceID, &item.SubjectID, &item.Status, &item.OccurredAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
items = append(items, item)
|
||||
}
|
||||
return items, rows.Err()
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package webevents
|
||||
|
||||
import (
|
||||
"context"
|
||||
"data-terminal-cloud/internal/identity"
|
||||
"github.com/google/uuid"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestHistorySurvivesRefreshAndEnforcesHouseholdBoundary(t *testing.T) {
|
||||
url := os.Getenv("TEST_DATABASE_URL")
|
||||
if url == "" {
|
||||
t.Skip("TEST_DATABASE_URL is not set")
|
||||
}
|
||||
ctx := context.Background()
|
||||
pool, err := pgxpool.New(ctx, url)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer pool.Close()
|
||||
owner := identity.Principal{Issuer: "http://localhost:58180/realms/voice-local", Subject: "00000000-0000-0000-0000-000000000101"}
|
||||
outsider := identity.Principal{Issuer: owner.Issuer, Subject: "00000000-0000-0000-0000-000000000103"}
|
||||
ids := []string{uuid.NewString(), uuid.NewString(), uuid.NewString()}
|
||||
defer pool.Exec(ctx, `DELETE FROM web_event WHERE resource_public_id=ANY($1::uuid[])`, ids)
|
||||
for index, id := range ids {
|
||||
age := time.Duration(index+1) * time.Hour
|
||||
expiry := time.Now().Add(24 * time.Hour)
|
||||
if index == 2 {
|
||||
expiry = time.Now().Add(-time.Hour)
|
||||
}
|
||||
_, err = pool.Exec(ctx, `INSERT INTO web_event(tenant_id,household_id,event_type,resource_type,resource_public_id,status,occurred_at,expires_at) VALUES('10000000-0000-0000-0000-000000000001','10000000-0000-0000-0000-000000000201','conversation.completed','conversation',$1::uuid,'COMPLETED',$2,$3)`, id, time.Now().Add(-age), expiry)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
service := NewService(pool)
|
||||
for attempt := 0; attempt < 2; attempt++ {
|
||||
items, err := service.History(ctx, owner, time.Now().Add(-7*24*time.Hour), 200)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
found := map[string]bool{}
|
||||
for _, item := range items {
|
||||
found[item.ResourceID] = true
|
||||
}
|
||||
if !found[ids[0]] || !found[ids[1]] || found[ids[2]] {
|
||||
t.Fatal("missing retained history or returned expired metadata")
|
||||
}
|
||||
}
|
||||
items, err := service.History(ctx, outsider, time.Now().Add(-7*24*time.Hour), 200)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, item := range items {
|
||||
for _, id := range ids {
|
||||
if item.ResourceID == id {
|
||||
t.Fatal("history exposed another household")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,10 @@ func TestServiceCursorIsolationCleanupAndPresenceExpiry(t *testing.T) {
|
||||
service := NewService(pool)
|
||||
owner := identity.Principal{Issuer: "http://localhost:58180/realms/voice-local", Subject: "00000000-0000-0000-0000-000000000101"}
|
||||
outsider := identity.Principal{Issuer: owner.Issuer, Subject: "00000000-0000-0000-0000-000000000103"}
|
||||
outsideBaseline, err := service.StartingCursor(ctx, outsider)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
resourceIDs := []string{uuid.NewString(), uuid.NewString(), uuid.NewString()}
|
||||
testStarted := time.Now().UTC().Add(-time.Second)
|
||||
defer func() {
|
||||
@@ -51,7 +55,7 @@ func TestServiceCursorIsolationCleanupAndPresenceExpiry(t *testing.T) {
|
||||
t.Fatalf("owner starting cursor=%d want=%d err=%v", cursor, ids[1], err)
|
||||
}
|
||||
outsideCursor, err := service.StartingCursor(ctx, outsider)
|
||||
if err != nil || outsideCursor != 0 {
|
||||
if err != nil || outsideCursor != outsideBaseline {
|
||||
t.Fatalf("outsider starting cursor=%d err=%v", outsideCursor, err)
|
||||
}
|
||||
if err := service.ValidateCursor(ctx, owner, 0); err != nil {
|
||||
@@ -83,7 +87,7 @@ func TestServiceCursorIsolationCleanupAndPresenceExpiry(t *testing.T) {
|
||||
if found != 2 {
|
||||
t.Fatalf("active synthetic events found=%d", found)
|
||||
}
|
||||
outsideItems, err := service.ListAfter(ctx, outsider, 0, 100)
|
||||
outsideItems, err := service.ListAfter(ctx, outsider, outsideBaseline, 100)
|
||||
if err != nil || len(outsideItems) != 0 {
|
||||
t.Fatalf("outsider events=%+v err=%v", outsideItems, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user