Conversation
All fields can now be supplied via options (--name, --code, --admin-username, --admin-name, --admin-email, --admin2-username, --admin2-name, --admin2-email). When all required options are present the command skips the summary table and confirmation prompt, making it suitable for scripted / CI use (e.g. docker compose e2e setup). Interactive behaviour is unchanged when options are omitted.
When --admin-password is provided, both admin users are created with a bcrypt hash of that password and pw_changed=1, allowing immediate login without the email-based initial-password setup flow. Useful for scripted/CI environments (e.g. e2e test docker compose) where a known, stable password is required from the start.
…nteractive) When all required options are provided and a tenant with the requested --code already exists, exit 0 instead of failing. This allows `docker compose up` to be re-run against a persistent volume (e.g. when the backend-setup container restarts) without error.
## Context <!-- ie. explanations, background, documentation --> I found it hard to explain my thoughts about refactor. Do you think this approach is more readable? There's less if/else branches. **Didn't test this yet locally, DO NOT MERGE** ## Checklist - [ ] Tested manually <!-- you can strikethrough this option in case you haven't tested manually --> - [ ] GitHub issue linked <!-- Use the "Development" field of the Issue, or add a link if it's outside this Repo --> - [ ] Changelist updated - [ ] Backward and forward compatible with [aula-frontend/releases](https://github.com/aula-app/aula-frontend/releases) <!-- If not, please describe in detail and include other PR links --> - [ ] Doesn't need update in the database <!-- If it does, please describe how to deploy it without downtime --> - [ ] Must be deployed ASAP (HOTFIX) - [ ] Needs update of [docs.aula.de](https://docs.aula.de/) ([repo](https://github.com/leonard-haas/docs_aula)) <!-- If it does, please ping Leonard OR include link to the change in the docs repo -->
- Unify variable naming to admin1/admin2 throughout (origin/main convention) - Replace inline DB operations with CreateTenantUseCase delegation - Add adminPassword parameter to CreateTenantUseCase for --admin-password support - Use tenantsService->generateUniqueInstanceCode() instead of private method - Extract createTenant() private method to deduplicate interactive/non-interactive paths - Auto-generate instance code when --code not supplied in non-interactive mode
d9a23c3 to
1473214
Compare
| if (Tenant::firstWhere('instance_code', $instanceCode) !== null) { | ||
| $this->info("Tenant with code '{$instanceCode}' already exists, skipping."); | ||
|
|
||
| return self::SUCCESS; |
There was a problem hiding this comment.
issue(nitpick): we behave differently in case of non-interactive and interactive mode
should we be solving the problem of duplicate codes in this Command? so far we behaved: "if tenant exists, creation of tenant with the same code is a failure"..
problem: if we let it pass, then what if two separate invocations of this Command supply different values of other parameters? we'd have a false success..
is it easy to let the calling code (docker compose) deal with randomizing the instance code (or rather providing the empty database for testing)? what do you think?
There was a problem hiding this comment.
I think the interactive mode is different from the CLI because in the interactive mode the user can't provide the instance code. For me it could me possible to change the CLI behaviour that if the user doesn't provide a instance code we generate on automatically as in the interactive model and we continue not creating anything in case the provided code already exist and we report that to the user.
There was a problem hiding this comment.
in CLI, we already do:
- if instance code is provided:
1.a. if (already exists) log info and return success
1.b. if doesn't exist, then create a new one - if instance code isn't provided: we generate unique one
so i don't see what are you suggesting to change?
- Accept optional adminPassword parameter in execute() - Skip reset-password URL generation when password is pre-set - Skip au_change_password record when password is pre-set - Set password hash and pw_changed=1 when adminPassword is provided
…nantUseCase Tests cover: - Non-interactive creation with all options - adminPassword passed through to use case - Auto-generated instance code when --code omitted - Idempotency skip when tenant code already exists - Validation failures: duplicate name, same admin usernames, invalid code format - SINGLE accepted as valid instance code CreateTenantUseCase changes: - Accept adminPassword parameter - Skip reset-password URLs when password is pre-set - Skip au_change_password record when password is pre-set
Context
Fix #433
Checklist