From cb5afe3343124f31d52224bc2a46064192f052a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Jaussoin?= Date: Tue, 24 Jun 2025 13:04:59 +0000 Subject: [PATCH] Fix FLEXIAPI-337 Generate the provisioning URLs based on the user space --- CHANGELOG.md | 2 ++ flexiapi/app/Account.php | 28 +++++++++++++++++++ .../Accounts/ClearAccountsTombstones.php | 4 +-- .../Commands/Accounts/ClearApiKeys.php | 2 +- .../Commands/Accounts/ClearUnconfirmed.php | 4 +-- .../Commands/Accounts/CreateAdminAccount.php | 2 +- .../Commands/Accounts/CreateAdminTest.php | 2 +- .../Console/Commands/Accounts/SetAdmin.php | 6 ++-- .../Console/Commands/Spaces/CreateUpdate.php | 15 +++++++--- .../Spaces/ImportConfigurationFromDotEnv.php | 3 +- flexiapi/app/Helpers/Utils.php | 6 ++++ flexiapi/app/Space.php | 2 +- flexiapi/lang/fr.json | 1 + .../views/admin/account/index.blade.php | 2 +- .../views/admin/account/show.blade.php | 8 ++++-- .../views/mails/parts/provisioning.blade.php | 4 +-- 16 files changed, 69 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6d54ac8..4ed66a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -52,6 +52,8 @@ v2.0 - Fix FLEXIAPI-324 Add an app setup wizard page - Fix FLEXIAPI-335 Safari rendering issues with font icons - Fix FLEXIAPI-336 Fix broken ph icons +- Fix FLEXIAPI-333 Remove HTML buttons because they cannot be rendered in "old" Outlook versions +- Fix FLEXIAPI-337 Generate the provisioning URLs based on the user space v1.6 ---- diff --git a/flexiapi/app/Account.php b/flexiapi/app/Account.php index 80e3d8b..3a60ee5 100644 --- a/flexiapi/app/Account.php +++ b/flexiapi/app/Account.php @@ -354,6 +354,34 @@ class Account extends Authenticatable return Space::where('domain', $this->domain)->where('super', true)->exists() && $this->admin; } + /** + * Provisioning + */ + + public function getProvisioningUrlAttribute(): string + { + return replaceHost( + route('provisioning.provision', $this->getProvisioningTokenAttribute()), + $this->space->host + ); + } + + public function getProvisioningQrcodeUrlAttribute(): string + { + return replaceHost( + route('provisioning.qrcode', $this->getProvisioningTokenAttribute()), + $this->space->host + ); + } + + public function getProvisioningWizardUrlAttribute(): string + { + return replaceHost( + route('provisioning.wizard', $this->getProvisioningTokenAttribute()), + $this->space->host + ); + } + /** * Utils */ diff --git a/flexiapi/app/Console/Commands/Accounts/ClearAccountsTombstones.php b/flexiapi/app/Console/Commands/Accounts/ClearAccountsTombstones.php index 9deac53..4493e08 100644 --- a/flexiapi/app/Console/Commands/Accounts/ClearAccountsTombstones.php +++ b/flexiapi/app/Console/Commands/Accounts/ClearAccountsTombstones.php @@ -46,10 +46,10 @@ class ClearAccountsTombstones extends Command $this->info($tombstones->count() . ' tombstones deleted'); $tombstones->delete(); - return 0; + return Command::SUCCESS; } $this->info($tombstones->count() . ' tombstones to delete'); - return 0; + return Command::SUCCESS; } } diff --git a/flexiapi/app/Console/Commands/Accounts/ClearApiKeys.php b/flexiapi/app/Console/Commands/Accounts/ClearApiKeys.php index 716a96b..a1d7c30 100644 --- a/flexiapi/app/Console/Commands/Accounts/ClearApiKeys.php +++ b/flexiapi/app/Console/Commands/Accounts/ClearApiKeys.php @@ -36,7 +36,7 @@ class ClearApiKeys extends Command if ($minutes == 0) { $this->info('Expiration time is set to 0, nothing to clear'); - return 0; + return Command::SUCCESS; } $this->info('Deleting user API Keys unused after ' . $minutes . ' minutes'); diff --git a/flexiapi/app/Console/Commands/Accounts/ClearUnconfirmed.php b/flexiapi/app/Console/Commands/Accounts/ClearUnconfirmed.php index a362934..50d333e 100644 --- a/flexiapi/app/Console/Commands/Accounts/ClearUnconfirmed.php +++ b/flexiapi/app/Console/Commands/Accounts/ClearUnconfirmed.php @@ -53,10 +53,10 @@ class ClearUnconfirmed extends Command $accounts->delete(); $this->info($count . ' accounts deleted'); - return 0; + return Command::SUCCESS; } $this->info($count . ' accounts to delete'); - return 0; + return Command::SUCCESS; } } diff --git a/flexiapi/app/Console/Commands/Accounts/CreateAdminAccount.php b/flexiapi/app/Console/Commands/Accounts/CreateAdminAccount.php index 7f18f58..1005853 100644 --- a/flexiapi/app/Console/Commands/Accounts/CreateAdminAccount.php +++ b/flexiapi/app/Console/Commands/Accounts/CreateAdminAccount.php @@ -94,6 +94,6 @@ class CreateAdminAccount extends Command $this->info('Admin test account created: "' . $username . '@' . $domain . '" | Password: "' . $password . '" | API Key: "' . $account->apiKey->key . '" (valid on ' . ($account->apiKey->ip ?? 'any') . ' ip)'); - return 0; + return Command::SUCCESS; } } diff --git a/flexiapi/app/Console/Commands/Accounts/CreateAdminTest.php b/flexiapi/app/Console/Commands/Accounts/CreateAdminTest.php index 27ea5af..9e1c674 100644 --- a/flexiapi/app/Console/Commands/Accounts/CreateAdminTest.php +++ b/flexiapi/app/Console/Commands/Accounts/CreateAdminTest.php @@ -68,6 +68,6 @@ class CreateAdminTest extends Command $this->info('API Key updated to: ' . $secret); - return 0; + return Command::SUCCESS; } } diff --git a/flexiapi/app/Console/Commands/Accounts/SetAdmin.php b/flexiapi/app/Console/Commands/Accounts/SetAdmin.php index cb6671d..157cf46 100644 --- a/flexiapi/app/Console/Commands/Accounts/SetAdmin.php +++ b/flexiapi/app/Console/Commands/Accounts/SetAdmin.php @@ -39,12 +39,12 @@ class SetAdmin extends Command if (!$account) { $this->error('Account not found, please use an existing account id'); - return 1; + return Command::FAILURE; } if ($account->admin) { $this->error('The account is already having the admin role'); - return 1; + return Command::FAILURE; } $account->admin = true; @@ -52,6 +52,6 @@ class SetAdmin extends Command $this->info('Account '.$account->identifier.' is now admin'); - return 0; + return Command::SUCCESS; } } diff --git a/flexiapi/app/Console/Commands/Spaces/CreateUpdate.php b/flexiapi/app/Console/Commands/Spaces/CreateUpdate.php index a897704..90a2d05 100644 --- a/flexiapi/app/Console/Commands/Spaces/CreateUpdate.php +++ b/flexiapi/app/Console/Commands/Spaces/CreateUpdate.php @@ -44,14 +44,21 @@ class CreateUpdate extends Command $space->domain = $this->argument('sip_domain'); $space->name = $this->argument('name'); + if ($hostSpace = Space::where('host', $this->argument('host'))->first()) { + if (!$space->exists && $hostSpace->domain != $space->domain) { + $this->error('A Space with this host and a different sip_domain already exists in the database'); + return Command::FAILURE; + } + } + $space->exists - ? $this->info('The domain already exists, updating it') - : $this->info('A new domain will be created'); + ? $this->info('The space already exists, updating it') + : $this->info('A new Space will be created'); $space->super = (bool)$this->option('super'); $space->super - ? $this->info('Set as a super domain') - : $this->info('Set as a normal domain'); + ? $this->info('Set as a super Space') + : $this->info('Set as a normal Space'); $space->save(); diff --git a/flexiapi/app/Console/Commands/Spaces/ImportConfigurationFromDotEnv.php b/flexiapi/app/Console/Commands/Spaces/ImportConfigurationFromDotEnv.php index 17d0206..6c35f9f 100644 --- a/flexiapi/app/Console/Commands/Spaces/ImportConfigurationFromDotEnv.php +++ b/flexiapi/app/Console/Commands/Spaces/ImportConfigurationFromDotEnv.php @@ -16,8 +16,7 @@ class ImportConfigurationFromDotEnv extends Command if (!$space) { $this->error('The space cannot be found'); - - return 0; + return Command::SUCCESS; } $this->info('The following configuration will be imported in the space ' . $space->domain); diff --git a/flexiapi/app/Helpers/Utils.php b/flexiapi/app/Helpers/Utils.php index a4c9303..f133e57 100644 --- a/flexiapi/app/Helpers/Utils.php +++ b/flexiapi/app/Helpers/Utils.php @@ -155,6 +155,12 @@ function isRegularExpression(string $string): bool return $isRegularExpression; } +function replaceHost(string $url, string $host): string +{ + $components = parse_url($url); + return str_replace($components['host'], $host, $url); +} + function resolveDomain(Request $request): string { return $request->has('domain') diff --git a/flexiapi/app/Space.php b/flexiapi/app/Space.php index 69ef1c9..03c1976 100644 --- a/flexiapi/app/Space.php +++ b/flexiapi/app/Space.php @@ -94,7 +94,7 @@ class Space extends Model return (int)($this->accounts()->count() / $this->max_accounts * 100); } - return 0; + return Command::SUCCESS; } public function isFull(): bool diff --git a/flexiapi/lang/fr.json b/flexiapi/lang/fr.json index 03c9399..e052649 100644 --- a/flexiapi/lang/fr.json +++ b/flexiapi/lang/fr.json @@ -145,6 +145,7 @@ "Provisioning of your device": "Déploiement sur votre appareil", "Provisioning tokens": "Jetons de déploiement", "Provisioning": "Déploiement", + "Provisioning wizard URL": "URL de l'assistant de déploiement", "Public registration": "Inscription publiques", "QR Code scanning": "Scan de QR Code", "Realm": "Royaume", diff --git a/flexiapi/resources/views/admin/account/index.blade.php b/flexiapi/resources/views/admin/account/index.blade.php index 82d9d5c..9351d4e 100644 --- a/flexiapi/resources/views/admin/account/index.blade.php +++ b/flexiapi/resources/views/admin/account/index.blade.php @@ -4,7 +4,7 @@

{{ __('Users') }}

@if ($space) -

{{ $accounts->count()}} / @if ($space->max_accounts > 0){{ $space->max_accounts }} @else

+

{{ $accounts->count()}} / @if ($space->max_accounts > 0){{ $space->max_accounts }} @else @endif

@endif diff --git a/flexiapi/resources/views/admin/account/show.blade.php b/flexiapi/resources/views/admin/account/show.blade.php index 00a697b..85999e1 100644 --- a/flexiapi/resources/views/admin/account/show.blade.php +++ b/flexiapi/resources/views/admin/account/show.blade.php @@ -111,16 +111,20 @@ @if ($account->provisioning_token)
- +
+ value="{{ $account->provisioning_url }}"> {{ __('The link can only be visited once') }}
+

+ + {{ __('Provisioning wizard URL') }} +

@else {{ __('Create') }} @endif diff --git a/flexiapi/resources/views/mails/parts/provisioning.blade.php b/flexiapi/resources/views/mails/parts/provisioning.blade.php index de4104d..42ef9da 100644 --- a/flexiapi/resources/views/mails/parts/provisioning.blade.php +++ b/flexiapi/resources/views/mails/parts/provisioning.blade.php @@ -1,7 +1,7 @@ To connect your account to the application, click on the following link: -[{{__('Login to my account')}}]({{ route('provisioning.wizard', ['provisioning_token' => $account->provisioning_token]) }}) +[{{__('Login to my account')}}]({{ $account->provisioning_wizard_url }}) You can also configure your device by scanning the QR code with the mobile app, or by pasting the link below into the desktop application. -![QRCode]({{ route('provisioning.qrcode', ['provisioning_token' => $account->provisioning_token]) }}) +![QRCode]({{ $account->provisioning_qrcode_url }})