-
Notifications
You must be signed in to change notification settings - Fork 0
Create admin user on startup #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
66f6771
3c49e62
dd7a749
b030ebe
28353a7
f1114f6
d06116f
3ae101f
c860440
4f2c820
edae105
8bc9942
2d969b0
d0e5d0d
fe829bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| echo "Starting API ..." | ||
| exec node api/dist/server | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| echo "Starting CLI ..." | ||
| exec node cli/dist/server | ||
ralf-berger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| MONGO_HOST="${MONGO_HOST:-localhost}" | ||
| MONGO_PORT="${MONGO_PORT:-27017}" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| echo "Executing database migrations ..." | ||
| node cli/dist/server migrateMongo --up |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| echo "Setting up seed data ..." | ||
| node cli/dist/server createSiteAdmin "${LL_ADMIN_EMAIL:?}" "${LL_ADMIN_ORG:?}" "${LL_ADMIN_PASSWORD:?}" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainVerify idempotency/upsert semantics of createSiteAdmin The PR objective requires creating or upserting an admin on startup. Please confirm the CLI operation is idempotent (no duplicate users, safe on re-runs). Run this script to locate the implementation and check for upsert/exists handling: 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "Searching for CLI command createSiteAdmin definition and usage..."
rg -n -C3 -S '\bcreateSiteAdmin\b'
echo
echo "Scanning for idempotent patterns near user creation (upsert/exists/unique)..."
rg -n -C3 -iP 'upsert|onConflict|unique|ensureIndex|already exists|duplicate key|findOne|findUnique|findFirst'
echo
echo "If Prisma is used, look for upsert calls:"
rg -n -C3 -iP '\bupsert\s*\('
echo
echo "If Mongoose is used, check for findOneAndUpdate with upsert: true:"
rg -n -C3 -iP 'findOneAndUpdate\s*\(.*upsert\s*:\s*true'Length of output: 133165 🏁 Script executed: #!/bin/bash
# Display the key parts of createSiteAdmin implementation to verify idempotency
sed -n '1,200p' cli/src/commands/createSiteAdmin.jsLength of output: 3909 Fix idempotency in createSiteAdmin The current implementation of
Please update
- const foundOrg = _.find(user.organisations, org => org.toString() === organisation.name);
+ const foundOrg = _.find(
+ user.organisations,
+ orgId => orgId.toString() === organisation._id.toString()
+ );
- async function ensureSiteAdmin(user, password, forceUpdatePassword) {
- if (forceUpdatePassword) user.password = password;
- if (!_.includes(user.scopes, scopes.SITE_ADMIN)) {
- user.scopes.push(scopes.SITE_ADMIN);
- return await user.save();
- }
- return user;
- }
+ async function ensureSiteAdmin(user, password, forceUpdatePassword) {
+ let modified = false;
+ if (forceUpdatePassword) {
+ user.password = password;
+ modified = true;
+ }
+ if (!_.includes(user.scopes, scopes.SITE_ADMIN)) {
+ user.scopes.push(scopes.SITE_ADMIN);
+ modified = true;
+ }
+ if (modified) {
+ await user.save();
+ }
+ return user;
+ }With these changes, rerunning
🤖 Prompt for AI Agents
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| echo "Starting UI ..." | ||
| exec node ui/dist/server | ||
ralf-berger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| #!/usr/bin/env sh | ||
| set -eu | ||
|
|
||
| echo "Starting worker ..." | ||
| exec node worker/dist/server | ||
ralf-berger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Uh oh!
There was an error while loading. Please reload this page.