fix: treat recovered instances with users as initialized - #5216
Open
BetterAndBetterII wants to merge 1 commit into
Open
fix: treat recovered instances with users as initialized#5216BetterAndBetterII wants to merge 1 commit into
BetterAndBetterII wants to merge 1 commit into
Conversation
isAdminPresent only checked member.role=owner, so a partial DB restore that kept user/org rows but lost the owner membership sent / to Setup. Fall back to organization.owner and any existing user. Self-hosted first-admin signup uses the same check; the post-create hook still keys off owner membership so a real first install creates the org. Fixes Dokploy#5192
Comment on lines
+50
to
+58
| const org = await db.query.organization.findFirst({ | ||
| with: { | ||
| owner: true, | ||
| }, | ||
| }); | ||
|
|
||
| if (org?.owner) { | ||
| return true; | ||
| } |
Contributor
There was a problem hiding this comment.
Redundant organization owner query
The organization-owner lookup cannot affect the result because every loaded owner is also an existing user covered by the subsequent user lookup. Removing this query avoids unnecessary database work and simplifies the fallback logic.
Suggested change
| const org = await db.query.organization.findFirst({ | |
| with: { | |
| owner: true, | |
| }, | |
| }); | |
| if (org?.owner) { | |
| return true; | |
| } |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
After a partial DB restore, user / organization rows can survive while the member.role = owner row is gone. isAdminPresent() only checked owner membership, so / treated the instance as a fresh install and redirected to Setup.
Changes
Test plan
Fixes #5192
Greptile Summary
This PR broadens initialized-instance detection so partially restored installations with surviving users cannot re-enter first-admin setup.
Confidence Score: 4/5
The PR appears safe to merge; the only identified issue is a non-blocking redundant database query in initialization detection.
The changed checks prevent recovered instances from reopening first-admin registration as intended, while the organization-owner lookup adds avoidable work because the following user lookup already covers every successful owner relation.
Files Needing Attention: packages/server/src/services/admin.ts
Reviews (1): Last reviewed commit: "fix: treat recovered instances with user..." | Re-trigger Greptile