3 files changed
+1
-47
No files matched your search
@@ -34,11 +34,6 @@ administrator. That account can sign in at `/manager/sign-in`, create
|
|||||||
businesses, edit their primary domains, and share the one-time owner setup
|
businesses, edit their primary domains, and share the one-time owner setup
|
||||||
link generated during provisioning.
|
link generated during provisioning.
|
||||||
|
|
||||||
For an existing installation created before this platform/tenant split, the
|
|
||||||
recorded `initialAdminUserId` account is allowed to sign in once and is
|
|
||||||
promoted to the platform administrator. No other business owner can use that
|
|
||||||
upgrade path.
|
|
||||||
|
|
||||||
Business provisioning creates the tenant domain, settings, booking rules,
|
Business provisioning creates the tenant domain, settings, booking rules,
|
||||||
opening hours, system roles, owner staff profile, and seven-day owner
|
opening hours, system roles, owner staff profile, and seven-day owner
|
||||||
invitation in one transaction. The owner chooses a password through that
|
invitation in one transaction. The owner chooses a password through that
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Enums\InstallationStatus;
|
use App\Enums\InstallationStatus;
|
||||||
use App\Models\ApplicationInstallation;
|
use App\Models\ApplicationInstallation;
|
||||||
use App\Models\User;
|
|
||||||
use Illuminate\Http\RedirectResponse;
|
use Illuminate\Http\RedirectResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@@ -32,34 +31,12 @@ class PlatformAuthController extends Controller
|
|||||||
'password' => ['required', 'string'],
|
'password' => ['required', 'string'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
if (! Auth::attempt($credentials, $request->boolean('remember'))) {
|
if (! Auth::attempt($credentials, $request->boolean('remember')) || ! $request->user()?->isSuperAdmin) {
|
||||||
Auth::logout();
|
Auth::logout();
|
||||||
|
|
||||||
return back()->withErrors(['email' => 'Those platform administrator details do not match our records.'])->onlyInput('email');
|
return back()->withErrors(['email' => 'Those platform administrator details do not match our records.'])->onlyInput('email');
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $request->user();
|
|
||||||
if (! $user?->isSuperAdmin) {
|
|
||||||
$installation = ApplicationInstallation::query()
|
|
||||||
->where('status', InstallationStatus::Installed)
|
|
||||||
->first();
|
|
||||||
|
|
||||||
$canUpgradeLegacyAdmin = ! User::query()->where('isSuperAdmin', true)->exists()
|
|
||||||
&& $installation?->initialAdminUserId === $user?->id;
|
|
||||||
|
|
||||||
if (! $canUpgradeLegacyAdmin) {
|
|
||||||
Auth::logout();
|
|
||||||
|
|
||||||
return back()->withErrors(['email' => 'Those platform administrator details do not match our records.'])->onlyInput('email');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Existing installations created before platform administration
|
|
||||||
// was separated may have only an initial business owner. Promote
|
|
||||||
// that exact recorded account once so the migration is usable.
|
|
||||||
$user->forceFill(['isSuperAdmin' => true])->save();
|
|
||||||
Auth::setUser($user->fresh());
|
|
||||||
}
|
|
||||||
|
|
||||||
$request->session()->regenerate();
|
$request->session()->regenerate();
|
||||||
|
|
||||||
return redirect()->intended(route('manager.dashboard'));
|
return redirect()->intended(route('manager.dashboard'));
|
||||||
|
|||||||
@@ -49,22 +49,4 @@ class InstallationTest extends TestCase
|
|||||||
|
|
||||||
$this->assertDatabaseMissing('User', ['email' => 'another@example.test']);
|
$this->assertDatabaseMissing('User', ['email' => 'another@example.test']);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_an_existing_installation_can_upgrade_its_recorded_initial_admin_once(): void
|
|
||||||
{
|
|
||||||
$legacyOwner = User::factory()->create(['isSuperAdmin' => false, 'passwordHash' => password_hash('password123', PASSWORD_BCRYPT)]);
|
|
||||||
ApplicationInstallation::create([
|
|
||||||
'id' => 'singleton',
|
|
||||||
'status' => 'INSTALLED',
|
|
||||||
'installedAt' => now(),
|
|
||||||
'initialAdminUserId' => $legacyOwner->id,
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->post('/manager/sign-in', [
|
|
||||||
'email' => $legacyOwner->email,
|
|
||||||
'password' => 'password123',
|
|
||||||
])->assertRedirect(route('manager.dashboard'));
|
|
||||||
|
|
||||||
$this->assertDatabaseHas('User', ['id' => $legacyOwner->id, 'isSuperAdmin' => 1]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user