GetRootFolderContents auto-personal-tenant never persisted (no-tracking user mutation) #44
Labels
No labels
epic
phase-0
phase-1
phase-2
phase-3
phase-4
phase-5
phase-6
phase-7
phase-8
phase-9
priority/P0
priority/P1
priority/P2
type/backend
type/client
type/docs
type/ops
type/security
type/spike
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
primatekuntech/failsulit#44
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Found by the #27 coverage-gap tests (GetRootFolderContentsTests.TenantLessUser_AutoCreatesPersonalTenantAndRoot, red on current code).
GetRootFolderContents.Handle(Folders) mutatesaccessor.User.TenantIdfor tenant-less users and callsSaveChangesAsync— butaccessor.Usercomes fromSsdidAuthMiddleware, which loads usersAsNoTracking(). The mutation happens on a detached instance: the new personal Tenant + UserTenant rows persist, butusers.tenant_idstays NULL.Effect: every call to
GET /api/folders/root/contentsby a tenant-less user (e.g. a fresh SuperAdmin) mints ANOTHER personal tenant, and the user never gains a persisted tenant — duplicate-tenant drift.Fix: resolve a tracked user inside the handler (
db.Users.FirstAsync(u => u.Id == accessor.UserId)) instead of mutating the detachedaccessor.User; add a regression assertion on persisted TenantId.