wip: boarding
This commit is contained in:
147
app/Http/Livewire/Boarding.php
Normal file
147
app/Http/Livewire/Boarding.php
Normal file
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use App\Models\PrivateKey;
|
||||
use App\Models\Project;
|
||||
use App\Models\Server;
|
||||
use Livewire\Component;
|
||||
|
||||
class Boarding extends Component
|
||||
{
|
||||
|
||||
public string $currentState = 'create-private-key';
|
||||
// public ?string $serverType = null;
|
||||
|
||||
public ?string $privateKeyType = null;
|
||||
public ?string $privateKey = null;
|
||||
public ?string $privateKeyName = null;
|
||||
public ?string $privateKeyDescription = null;
|
||||
public ?PrivateKey $createdPrivateKey = null;
|
||||
|
||||
public ?string $remoteServerName = null;
|
||||
public ?string $remoteServerDescription = null;
|
||||
public ?string $remoteServerHost = null;
|
||||
public ?int $remoteServerPort = 22;
|
||||
public ?string $remoteServerUser = 'root';
|
||||
public ?Server $createdServer = null;
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->privateKeyName = generate_random_name();
|
||||
$this->remoteServerName = generate_random_name();
|
||||
if (is_dev()) {
|
||||
$this->privateKey = '-----BEGIN OPENSSH PRIVATE KEY-----
|
||||
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
|
||||
QyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevAAAAJi/QySHv0Mk
|
||||
hwAAAAtzc2gtZWQyNTUxOQAAACBbhpqHhqv6aI67Mj9abM3DVbmcfYhZAhC7ca4d9UCevA
|
||||
AAAECBQw4jg1WRT2IGHMncCiZhURCts2s24HoDS0thHnnRKVuGmoeGq/pojrsyP1pszcNV
|
||||
uZx9iFkCELtxrh31QJ68AAAAEXNhaWxANzZmZjY2ZDJlMmRkAQIDBA==
|
||||
-----END OPENSSH PRIVATE KEY-----';
|
||||
$this->privateKeyDescription = 'Created by Coolify';
|
||||
$this->remoteServerDescription = 'Created by Coolify';
|
||||
$this->remoteServerHost = 'coolify-testing-host';
|
||||
}
|
||||
}
|
||||
public function restartBoarding()
|
||||
{
|
||||
if ($this->createdServer) {
|
||||
$this->createdServer->delete();
|
||||
}
|
||||
if ($this->createdPrivateKey) {
|
||||
$this->createdPrivateKey->delete();
|
||||
}
|
||||
return redirect()->route('boarding');
|
||||
}
|
||||
public function skipBoarding()
|
||||
{
|
||||
currentTeam()->update([
|
||||
'show_boarding' => false
|
||||
]);
|
||||
refreshSession();
|
||||
return redirect()->route('dashboard');
|
||||
}
|
||||
public function setServer(string $type)
|
||||
{
|
||||
if ($type === 'localhost') {
|
||||
$this->currentState = 'create-project';
|
||||
} elseif ($type === 'remote') {
|
||||
$this->currentState = 'private-key';
|
||||
}
|
||||
}
|
||||
public function setPrivateKey(string $type)
|
||||
{
|
||||
$this->privateKeyType = $type;
|
||||
$this->currentState = 'create-private-key';
|
||||
}
|
||||
public function savePrivateKey()
|
||||
{
|
||||
$this->validate([
|
||||
'privateKeyName' => 'required',
|
||||
'privateKey' => 'required',
|
||||
]);
|
||||
$this->currentState = 'create-server';
|
||||
}
|
||||
public function saveServer()
|
||||
{
|
||||
$this->validate([
|
||||
'remoteServerName' => 'required',
|
||||
'remoteServerHost' => 'required',
|
||||
'remoteServerPort' => 'required',
|
||||
'remoteServerUser' => 'required',
|
||||
]);
|
||||
if ($this->privateKeyType === 'create') {
|
||||
$this->createNewPrivateKey();
|
||||
}
|
||||
$this->privateKey = formatPrivateKey($this->privateKey);
|
||||
$this->createdPrivateKey = PrivateKey::create([
|
||||
'name' => $this->privateKeyName,
|
||||
'description' => $this->privateKeyDescription,
|
||||
'private_key' => $this->privateKey,
|
||||
'team_id' => currentTeam()->id
|
||||
]);
|
||||
$this->createdServer = Server::create([
|
||||
'name' => $this->remoteServerName,
|
||||
'ip' => $this->remoteServerHost,
|
||||
'port' => $this->remoteServerPort,
|
||||
'user' => $this->remoteServerUser,
|
||||
'description' => $this->remoteServerDescription,
|
||||
'private_key_id' => $this->createdPrivateKey->id,
|
||||
'team_id' => currentTeam()->id
|
||||
]);
|
||||
try {
|
||||
['uptime' => $uptime, 'dockerVersion' => $dockerVersion] = validateServer($this->createdServer);
|
||||
if (!$uptime) {
|
||||
$this->createdServer->delete();
|
||||
$this->createdPrivateKey->delete();
|
||||
throw new \Exception('Server is not reachable.');
|
||||
} else {
|
||||
$this->createdServer->settings->update([
|
||||
'is_reachable' => true,
|
||||
]);
|
||||
$this->emit('success', 'Server is reachable.');
|
||||
}
|
||||
if ($dockerVersion) {
|
||||
$this->emit('error', 'Docker is not installed on the server.');
|
||||
$this->currentState = 'install-docker';
|
||||
return;
|
||||
}
|
||||
ray($uptime, $dockerVersion);
|
||||
} catch (\Exception $e) {
|
||||
return general_error_handler(customErrorMessage: "Server is not reachable. Reason: {$e->getMessage()}", that: $this);
|
||||
}
|
||||
}
|
||||
private function createNewPrivateKey()
|
||||
{
|
||||
$this->privateKeyName = generate_random_name();
|
||||
$this->privateKeyDescription = 'Created by Coolify';
|
||||
$this->privateKey = generateSSHKey();
|
||||
}
|
||||
public function createNewProject()
|
||||
{
|
||||
Project::create([
|
||||
'name' => generate_random_name(),
|
||||
'team_id' => currentTeam()->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ class StandaloneDocker extends Component
|
||||
'name' => $this->name,
|
||||
'network' => $this->network,
|
||||
'server_id' => $this->server_id,
|
||||
'team_id' => auth()->user()->currentTeam()->id
|
||||
'team_id' => currentTeam()->id
|
||||
]);
|
||||
}
|
||||
$this->createNetworkAndAttachToProxy();
|
||||
|
||||
@@ -41,10 +41,9 @@ class DiscordSettings extends Component
|
||||
|
||||
public function saveModel()
|
||||
{
|
||||
ray($this->model);
|
||||
$this->model->save();
|
||||
if (is_a($this->model, Team::class)) {
|
||||
session(['currentTeam' => $this->model]);
|
||||
refreshSession();
|
||||
}
|
||||
$this->emit('success', 'Settings saved.');
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ class EmailSettings extends Component
|
||||
{
|
||||
$settings = InstanceSettings::get();
|
||||
if ($settings->smtp_enabled) {
|
||||
$team = auth()->user()->currentTeam();
|
||||
$team = currentTeam();
|
||||
$team->update([
|
||||
'smtp_enabled' => $settings->smtp_enabled,
|
||||
'smtp_from_address' => $settings->smtp_from_address,
|
||||
@@ -74,7 +74,7 @@ class EmailSettings extends Component
|
||||
]);
|
||||
$this->decrypt();
|
||||
if (is_a($team, Team::class)) {
|
||||
session(['currentTeam' => $team]);
|
||||
refreshSession();
|
||||
}
|
||||
$this->model = $team;
|
||||
$this->emit('success', 'Settings saved.');
|
||||
@@ -119,7 +119,7 @@ class EmailSettings extends Component
|
||||
$this->model->save();
|
||||
$this->decrypt();
|
||||
if (is_a($this->model, Team::class)) {
|
||||
session(['currentTeam' => $this->model]);
|
||||
refreshSession();
|
||||
}
|
||||
$this->emit('success', 'Settings saved.');
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class Change extends Component
|
||||
try {
|
||||
if ($this->private_key->isEmpty()) {
|
||||
$this->private_key->delete();
|
||||
auth()->user()->currentTeam()->privateKeys = PrivateKey::where('team_id', auth()->user()->currentTeam()->id)->get();
|
||||
currentTeam()->privateKeys = PrivateKey::where('team_id', currentTeam()->id)->get();
|
||||
return redirect()->route('private-key.all');
|
||||
}
|
||||
$this->emit('error', 'This private key is in use and cannot be deleted. Please delete all servers, applications, and GitHub/GitLab apps that use this private key before deleting it.');
|
||||
@@ -38,10 +38,7 @@ class Change extends Component
|
||||
public function changePrivateKey()
|
||||
{
|
||||
try {
|
||||
$this->private_key->private_key = trim($this->private_key->private_key);
|
||||
if (!str_ends_with($this->private_key->private_key, "\n")) {
|
||||
$this->private_key->private_key .= "\n";
|
||||
}
|
||||
$this->private_key->private_key = formatPrivateKey($this->private_key->private_key);
|
||||
$this->private_key->save();
|
||||
refresh_server_connection($this->private_key);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -32,7 +32,7 @@ class Create extends Component
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'private_key' => $this->value,
|
||||
'team_id' => auth()->user()->currentTeam()->id
|
||||
'team_id' => currentTeam()->id
|
||||
]);
|
||||
if ($this->from === 'server') {
|
||||
return redirect()->route('server.create');
|
||||
|
||||
@@ -25,7 +25,7 @@ class AddEmpty extends Component
|
||||
$project = Project::create([
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'team_id' => currentTeam()->id,
|
||||
]);
|
||||
return redirect()->route('project.show', $project->uuid);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -29,7 +29,7 @@ class Source extends Component
|
||||
|
||||
private function get_private_keys()
|
||||
{
|
||||
$this->private_keys = PrivateKey::whereTeamId(auth()->user()->currentTeam()->id)->get()->reject(function ($key) {
|
||||
$this->private_keys = PrivateKey::whereTeamId(currentTeam()->id)->get()->reject(function ($key) {
|
||||
return $key->id == $this->application->private_key_id;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class CreateScheduledBackup extends Component
|
||||
's3_storage_id' => $this->s3_storage_id,
|
||||
'database_id' => $this->database->id,
|
||||
'database_type' => $this->database->getMorphClass(),
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'team_id' => currentTeam()->id,
|
||||
]);
|
||||
$this->emit('refreshScheduledBackups');
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -11,7 +11,7 @@ class EmptyProject extends Component
|
||||
{
|
||||
$project = Project::create([
|
||||
'name' => generate_random_name(),
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'team_id' => currentTeam()->id,
|
||||
]);
|
||||
return redirect()->route('project.show', ['project_uuid' => $project->uuid, 'environment_name' => 'production']);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ class GithubPrivateRepositoryDeployKey extends Component
|
||||
}
|
||||
$this->parameters = get_route_parameters();
|
||||
$this->query = request()->query();
|
||||
$this->private_keys = PrivateKey::where('team_id', auth()->user()->currentTeam()->id)->where('id', '!=', 0)->get();
|
||||
$this->private_keys = PrivateKey::where('team_id', currentTeam()->id)->where('id', '!=', 0)->get();
|
||||
}
|
||||
|
||||
public function instantSave()
|
||||
|
||||
@@ -42,7 +42,7 @@ class Form extends Component
|
||||
|
||||
public function installDocker()
|
||||
{
|
||||
$activity = resolve(InstallDocker::class)($this->server, auth()->user()->currentTeam());
|
||||
$activity = resolve(InstallDocker::class)($this->server, currentTeam());
|
||||
$this->emit('newMonitorActivity', $activity->id);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class ByIp extends Component
|
||||
'ip' => $this->ip,
|
||||
'user' => $this->user,
|
||||
'port' => $this->port,
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'team_id' => currentTeam()->id,
|
||||
'private_key_id' => $this->private_key_id,
|
||||
]);
|
||||
$server->settings->is_part_of_swarm = $this->is_part_of_swarm;
|
||||
|
||||
@@ -65,7 +65,7 @@ class Backup extends Component
|
||||
'frequency' => '0 0 * * *',
|
||||
'database_id' => $this->database->id,
|
||||
'database_type' => 'App\Models\StandalonePostgresql',
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'team_id' => currentTeam()->id,
|
||||
]);
|
||||
$this->database->refresh();
|
||||
$this->backup->refresh();
|
||||
|
||||
@@ -40,7 +40,7 @@ class Create extends Component
|
||||
'custom_user' => $this->custom_user,
|
||||
'custom_port' => $this->custom_port,
|
||||
'is_system_wide' => $this->is_system_wide,
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'team_id' => currentTeam()->id,
|
||||
]);
|
||||
redirect()->route('source.github.show', ['github_app_uuid' => $github_app->uuid]);
|
||||
} catch (\Exception $e) {
|
||||
|
||||
@@ -10,7 +10,7 @@ class Actions extends Component
|
||||
public function cancel()
|
||||
{
|
||||
try {
|
||||
$subscription_id = auth()->user()->currentTeam()->subscription->lemon_subscription_id;
|
||||
$subscription_id = currentTeam()->subscription->lemon_subscription_id;
|
||||
if (!$subscription_id) {
|
||||
throw new \Exception('No subscription found');
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class Actions extends Component
|
||||
public function resume()
|
||||
{
|
||||
try {
|
||||
$subscription_id = auth()->user()->currentTeam()->subscription->lemon_subscription_id;
|
||||
$subscription_id = currentTeam()->subscription->lemon_subscription_id;
|
||||
if (!$subscription_id) {
|
||||
throw new \Exception('No subscription found');
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ class Create extends Component
|
||||
'personal_team' => false,
|
||||
]);
|
||||
auth()->user()->teams()->attach($team, ['role' => 'admin']);
|
||||
session(['currentTeam' => $team]);
|
||||
refreshSession();
|
||||
return redirect()->route('team.show');
|
||||
} catch (\Throwable $th) {
|
||||
return general_error_handler($th, $this);
|
||||
|
||||
@@ -9,7 +9,7 @@ class Delete extends Component
|
||||
{
|
||||
public function delete()
|
||||
{
|
||||
$currentTeam = auth()->user()->currentTeam();
|
||||
$currentTeam = currentTeam();
|
||||
$currentTeam->delete();
|
||||
|
||||
$team = auth()->user()->teams()->first();
|
||||
@@ -24,7 +24,7 @@ class Delete extends Component
|
||||
}
|
||||
});
|
||||
|
||||
session(['currentTeam' => $team]);
|
||||
refreshSession();
|
||||
return redirect()->route('team.show');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ class Form extends Component
|
||||
|
||||
public function mount()
|
||||
{
|
||||
$this->team = auth()->user()->currentTeam();
|
||||
$this->team = currentTeam();
|
||||
}
|
||||
|
||||
public function submit()
|
||||
@@ -27,7 +27,7 @@ class Form extends Component
|
||||
$this->validate();
|
||||
try {
|
||||
$this->team->save();
|
||||
session(['currentTeam' => $this->team]);
|
||||
refreshSession();
|
||||
$this->emit('reloadWindow');
|
||||
} catch (\Throwable $th) {
|
||||
return general_error_handler($th, $this);
|
||||
|
||||
@@ -18,6 +18,6 @@ class Invitations extends Component
|
||||
|
||||
public function refreshInvitations()
|
||||
{
|
||||
$this->invitations = TeamInvitation::whereTeamId(auth()->user()->currentTeam()->id)->get();
|
||||
$this->invitations = TeamInvitation::whereTeamId(currentTeam()->id)->get();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,9 +35,9 @@ class InviteLink extends Component
|
||||
return general_error_handler(that: $this, customErrorMessage: "$this->email must be registered first (or activate transactional emails to invite via email).");
|
||||
}
|
||||
|
||||
$member_emails = auth()->user()->currentTeam()->members()->get()->pluck('email');
|
||||
$member_emails = currentTeam()->members()->get()->pluck('email');
|
||||
if ($member_emails->contains($this->email)) {
|
||||
return general_error_handler(that: $this, customErrorMessage: "$this->email is already a member of " . auth()->user()->currentTeam()->name . ".");
|
||||
return general_error_handler(that: $this, customErrorMessage: "$this->email is already a member of " . currentTeam()->name . ".");
|
||||
}
|
||||
|
||||
$invitation = TeamInvitation::whereEmail($this->email);
|
||||
@@ -53,7 +53,7 @@ class InviteLink extends Component
|
||||
}
|
||||
|
||||
TeamInvitation::firstOrCreate([
|
||||
'team_id' => auth()->user()->currentTeam()->id,
|
||||
'team_id' => currentTeam()->id,
|
||||
'uuid' => $uuid,
|
||||
'email' => $this->email,
|
||||
'role' => $this->role,
|
||||
|
||||
@@ -11,19 +11,19 @@ class Member extends Component
|
||||
|
||||
public function makeAdmin()
|
||||
{
|
||||
$this->member->teams()->updateExistingPivot(auth()->user()->currentTeam()->id, ['role' => 'admin']);
|
||||
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => 'admin']);
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
|
||||
public function makeReadonly()
|
||||
{
|
||||
$this->member->teams()->updateExistingPivot(auth()->user()->currentTeam()->id, ['role' => 'member']);
|
||||
$this->member->teams()->updateExistingPivot(currentTeam()->id, ['role' => 'member']);
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->member->teams()->detach(auth()->user()->currentTeam());
|
||||
$this->member->teams()->detach(currentTeam());
|
||||
$this->emit('reloadWindow');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ class Create extends Component
|
||||
} else {
|
||||
$this->storage->endpoint = $this->endpoint;
|
||||
}
|
||||
$this->storage->team_id = auth()->user()->currentTeam()->id;
|
||||
$this->storage->team_id = currentTeam()->id;
|
||||
$this->storage->testConnection();
|
||||
$this->emit('success', 'Connection is working. Tested with "ListObjectsV2" action.');
|
||||
$this->storage->save();
|
||||
|
||||
Reference in New Issue
Block a user