Merge branch 'next' into feat/disable-default-redirect

This commit is contained in:
Kael
2024-11-01 16:52:09 +11:00
committed by GitHub
128 changed files with 553 additions and 842 deletions

View File

@@ -2,7 +2,6 @@
namespace App\Livewire;
use App\Enums\ProcessStatus;
use App\Models\User;
use Livewire\Component;
use Spatie\Activitylog\Models\Activity;

View File

@@ -34,7 +34,7 @@ class Discord extends Component
{
try {
$this->submit();
} catch (\Throwable $e) {
} catch (\Throwable) {
$this->team->discord_enabled = false;
$this->validate();
}

View File

@@ -41,7 +41,7 @@ class Telegram extends Component
{
try {
$this->submit();
} catch (\Throwable $e) {
} catch (\Throwable) {
$this->team->telegram_enabled = false;
$this->validate();
}

View File

@@ -64,7 +64,7 @@ class Show extends Component
{
$this->dispatch('deploymentFinished');
$this->application_deployment_queue->refresh();
if (data_get($this->application_deployment_queue, 'status') == 'finished' || data_get($this->application_deployment_queue, 'status') == 'failed') {
if (data_get($this->application_deployment_queue, 'status') === 'finished' || data_get($this->application_deployment_queue, 'status') === 'failed') {
$this->isKeepAliveOn = false;
}
}

View File

@@ -36,7 +36,7 @@ class Form extends Component
$url = Url::fromString($firstFqdn);
$host = $url->getHost();
$this->preview_url_template = str($this->application->preview_url_template)->replace('{{domain}}', $host);
} catch (\Exception $e) {
} catch (\Exception) {
$this->dispatch('error', 'Invalid FQDN.');
}
}

View File

@@ -5,6 +5,7 @@ namespace App\Livewire\Project\Application;
use App\Actions\Docker\GetContainersStatus;
use App\Models\Application;
use App\Models\ApplicationPreview;
use Carbon\Carbon;
use Illuminate\Process\InvokedProcess;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Process;
@@ -239,7 +240,7 @@ class Previews extends Component
$processes[$containerName] = $this->stopContainer($containerName, $timeout);
}
$startTime = time();
$startTime = Carbon::now()->getTimestamp();
while (count($processes) > 0) {
$finishedProcesses = array_filter($processes, function ($process) {
return ! $process->running();
@@ -249,7 +250,7 @@ class Previews extends Component
$this->removeContainer($containerName, $server);
}
if (time() - $startTime >= $timeout) {
if (Carbon::now()->getTimestamp() - $startTime >= $timeout) {
$this->forceStopRemainingContainers(array_keys($processes), $server);
break;
}

View File

@@ -121,7 +121,7 @@ class BackupEdit extends Component
{
try {
$this->custom_validate();
if ($this->backup->databases_to_backup == '' || $this->backup->databases_to_backup === null) {
if ($this->backup->databases_to_backup === '' || $this->backup->databases_to_backup === null) {
$this->backup->databases_to_backup = null;
}
$this->backup->save();

View File

@@ -119,9 +119,8 @@ class BackupExecutions extends Component
if (! $server) {
return 'UTC';
}
$serverTimezone = $server->settings->server_timezone;
return $serverTimezone;
return $server->settings->server_timezone;
}
public function formatDateInServerTimezone($date)
@@ -130,7 +129,7 @@ class BackupExecutions extends Component
$dateObj = new \DateTime($date);
try {
$dateObj->setTimezone(new \DateTimeZone($serverTimezone));
} catch (\Exception $e) {
} catch (\Exception) {
$dateObj->setTimezone(new \DateTimeZone('UTC'));
}

View File

@@ -77,10 +77,10 @@ class Import extends Component
}
if (
$this->resource->getMorphClass() == \App\Models\StandaloneRedis::class ||
$this->resource->getMorphClass() == \App\Models\StandaloneKeydb::class ||
$this->resource->getMorphClass() == \App\Models\StandaloneDragonfly::class ||
$this->resource->getMorphClass() == \App\Models\StandaloneClickhouse::class
$this->resource->getMorphClass() === \App\Models\StandaloneRedis::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneKeydb::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneDragonfly::class ||
$this->resource->getMorphClass() === \App\Models\StandaloneClickhouse::class
) {
$this->unsupported = true;
}
@@ -88,8 +88,7 @@ class Import extends Component
public function runImport()
{
if ($this->filename == '') {
if ($this->filename === '') {
$this->dispatch('error', 'Please select a file to import.');
return;

View File

@@ -51,7 +51,6 @@ class General extends Component
$this->db_url = $this->database->internal_db_url;
$this->db_url_public = $this->database->external_db_url;
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()

View File

@@ -57,7 +57,6 @@ class General extends Component
$this->db_url = $this->database->internal_db_url;
$this->db_url_public = $this->database->external_db_url;
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()

View File

@@ -55,7 +55,6 @@ class General extends Component
$this->db_url = $this->database->internal_db_url;
$this->db_url_public = $this->database->external_db_url;
$this->server = data_get($this->database, 'destination.server');
}
public function instantSaveAdvanced()

View File

@@ -198,7 +198,7 @@ class GithubPrivateRepositoryDeployKey extends Component
$this->git_host = $this->repository_url_parsed->getHost();
$this->git_repository = $this->repository_url_parsed->getSegment(1).'/'.$this->repository_url_parsed->getSegment(2);
if ($this->git_host == 'github.com') {
if ($this->git_host === 'github.com') {
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
return;

View File

@@ -99,7 +99,6 @@ class PublicGitRepository extends Component
$this->base_directory = '/'.$this->base_directory;
}
}
}
public function updatedDockerComposeLocation()
@@ -174,7 +173,7 @@ class PublicGitRepository extends Component
return;
}
if (! $this->branchFound && $this->git_branch == 'main') {
if (! $this->branchFound && $this->git_branch === 'main') {
try {
$this->git_branch = 'master';
$this->getBranch();
@@ -197,7 +196,7 @@ class PublicGitRepository extends Component
} else {
$this->git_branch = 'main';
}
if ($this->git_host == 'github.com') {
if ($this->git_host === 'github.com') {
$this->git_source = GithubApp::where('name', 'Public GitHub')->first();
return;

View File

@@ -100,7 +100,6 @@ class Create extends Component
'is_preview' => false,
]);
}
});
}
$service->parse(isNew: true);

View File

@@ -95,7 +95,7 @@ class Database extends Component
$this->database->save();
updateCompose($this->database);
$this->dispatch('success', 'Database saved.');
} catch (\Throwable $e) {
} catch (\Throwable) {
} finally {
$this->dispatch('generateDockerCompose');
}

View File

@@ -48,7 +48,6 @@ class Index extends Component
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function generateDockerCompose()

View File

@@ -76,7 +76,7 @@ class Navbar extends Component
} else {
$this->isDeploymentProgress = false;
}
} catch (\Throwable $e) {
} catch (\Throwable) {
$this->isDeploymentProgress = false;
}
}

View File

@@ -62,32 +62,21 @@ class Danger extends Component
return;
}
switch ($this->resource->type()) {
case 'application':
$this->resourceName = $this->resource->name ?? 'Application';
break;
case 'standalone-postgresql':
case 'standalone-redis':
case 'standalone-mongodb':
case 'standalone-mysql':
case 'standalone-mariadb':
case 'standalone-keydb':
case 'standalone-dragonfly':
case 'standalone-clickhouse':
$this->resourceName = $this->resource->name ?? 'Database';
break;
case 'service':
$this->resourceName = $this->resource->name ?? 'Service';
break;
case 'service-application':
$this->resourceName = $this->resource->name ?? 'Service Application';
break;
case 'service-database':
$this->resourceName = $this->resource->name ?? 'Service Database';
break;
default:
$this->resourceName = 'Unknown Resource';
}
$this->resourceName = match ($this->resource->type()) {
'application' => $this->resource->name ?? 'Application',
'standalone-postgresql',
'standalone-redis',
'standalone-mongodb',
'standalone-mysql',
'standalone-mariadb',
'standalone-keydb',
'standalone-dragonfly',
'standalone-clickhouse' => $this->resource->name ?? 'Database',
'service' => $this->resource->name ?? 'Service',
'service-application' => $this->resource->name ?? 'Service Application',
'service-database' => $this->resource->name ?? 'Service Database',
default => 'Unknown Resource',
};
}
public function delete($password)

View File

@@ -132,7 +132,6 @@ class ExecuteContainerCommand extends Component
}
});
}
}
if ($this->containers->count() > 0) {
$this->container = $this->containers->first();
@@ -155,7 +154,6 @@ class ExecuteContainerCommand extends Component
data_get($this->server, 'name'),
data_get($this->server, 'uuid')
);
} catch (\Throwable $e) {
return handleError($e, $this);
}
@@ -185,7 +183,6 @@ class ExecuteContainerCommand extends Component
data_get($container, 'container.Names'),
data_get($container, 'server.uuid')
);
} catch (\Throwable $e) {
return handleError($e, $this);
}

View File

@@ -109,9 +109,7 @@ class Logs extends Component
$this->containers = $this->containers->filter(function ($container) {
return str_contains($container, $this->query['pull_request_id']);
});
}
} catch (\Exception $e) {
return handleError($e, $this);
}

View File

@@ -147,7 +147,6 @@ class ResourceOperations extends Component
return redirect()->to($route);
}
}
public function moveTo($environment_id)

View File

@@ -55,8 +55,8 @@ class Add extends Component
return;
}
if (empty($this->container) || $this->container == 'null') {
if ($this->type == 'service') {
if (empty($this->container) || $this->container === 'null') {
if ($this->type === 'service') {
$this->container = $this->subServiceName;
}
}

View File

@@ -21,10 +21,10 @@ class All extends Component
public function mount()
{
$this->parameters = get_route_parameters();
if ($this->resource->type() == 'service') {
if ($this->resource->type() === 'service') {
$this->containerNames = $this->resource->applications()->pluck('name');
$this->containerNames = $this->containerNames->merge($this->resource->databases()->pluck('name'));
} elseif ($this->resource->type() == 'application') {
} elseif ($this->resource->type() === 'application') {
if ($this->resource->build_pack === 'dockercompose') {
$parsed = $this->resource->parse();
$containers = collect(data_get($parsed, 'services'))->keys();

View File

@@ -54,9 +54,8 @@ class Executions extends Component
if (! $server) {
return 'UTC';
}
$serverTimezone = $server->settings->server_timezone;
return $serverTimezone;
return $server->settings->server_timezone;
}
public function formatDateInServerTimezone($date)
@@ -65,7 +64,7 @@ class Executions extends Component
$dateObj = new \DateTime($date);
try {
$dateObj->setTimezone(new \DateTimeZone($serverTimezone));
} catch (\Exception $e) {
} catch (\Exception) {
$dateObj->setTimezone(new \DateTimeZone('UTC'));
}

View File

@@ -77,7 +77,7 @@ class Show extends Component
try {
$this->task->delete();
if ($this->type == 'application') {
if ($this->type === 'application') {
return redirect()->route('project.application.configuration', $this->parameters, $this->scheduledTaskName);
} else {
return redirect()->route('project.service.configuration', $this->parameters, $this->scheduledTaskName);

View File

@@ -100,7 +100,6 @@ class Add extends Component
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function submitFileStorageDirectory()
@@ -127,7 +126,6 @@ class Add extends Component
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function submitPersistentVolume()
@@ -144,7 +142,6 @@ class Add extends Component
'mount_path' => $this->mount_path,
'host_path' => $this->host_path,
]);
} catch (\Throwable $e) {
return handleError($e, $this);
}

View File

@@ -26,7 +26,6 @@ class Terminal extends Component
#[On('send-terminal-command')]
public function sendTerminalCommand($isContainer, $identifier, $serverUuid)
{
$server = Server::ownedByCurrentTeam()->whereUuid($serverUuid)->firstOrFail();
if ($isContainer) {

View File

@@ -37,7 +37,6 @@ class UploadConfig extends Component
return;
}
}
public function render()

View File

@@ -28,7 +28,7 @@ class Show extends Component
{
try {
$this->private_key = PrivateKey::ownedByCurrentTeam(['name', 'description', 'private_key', 'is_git_related'])->whereUuid(request()->private_key_uuid)->firstOrFail();
} catch (\Throwable $e) {
} catch (\Throwable) {
abort(404);
}
}

View File

@@ -43,7 +43,7 @@ class Advanced extends Component
$this->server = Server::ownedByCurrentTeam()->whereUuid($server_uuid)->firstOrFail();
$this->parameters = get_route_parameters();
$this->syncData();
} catch (\Throwable $e) {
} catch (\Throwable) {
return redirect()->route('server.show');
}
}

View File

@@ -49,7 +49,6 @@ class Charts extends Component
$this->dispatch("refreshChartData-{$this->chartId}-memory", [
'seriesData' => $memoryMetrics,
]);
} catch (\Throwable $e) {
return handleError($e, $this);
}

View File

@@ -86,7 +86,6 @@ class Form extends Component
$this->server = $server;
$this->timezones = collect(timezone_identifiers_list())->sort()->values()->toArray();
$this->wildcard_domain = $this->server->settings->wildcard_domain;
}
public function checkSyncStatus()
@@ -169,7 +168,6 @@ class Form extends Component
public function instantSave()
{
try {
$this->validate();
refresh_server_connection($this->server->privateKey);
$this->validateServer(false);

View File

@@ -51,7 +51,6 @@ class LogDrains extends Component
public function syncData(bool $toModel = false)
{
if ($toModel) {
$this->validate();
$this->server->settings->is_logdrain_newrelic_enabled = $this->isLogDrainNewRelicEnabled;
@@ -78,7 +77,6 @@ class LogDrains extends Component
$this->logDrainCustomConfig = $this->server->settings->logdrain_custom_config;
$this->logDrainCustomConfigParser = $this->server->settings->logdrain_custom_config_parser;
}
}
public function instantSave()

View File

@@ -113,7 +113,6 @@ class Proxy extends Component
} else {
$this->dispatch('traefikDashboardAvailable', false);
}
} catch (\Throwable $e) {
return handleError($e, $this);
}

View File

@@ -6,6 +6,7 @@ use App\Actions\Proxy\CheckProxy;
use App\Actions\Proxy\StartProxy;
use App\Events\ProxyStatusChanged;
use App\Models\Server;
use Carbon\Carbon;
use Illuminate\Process\InvokedProcess;
use Illuminate\Support\Facades\Process;
use Livewire\Component;
@@ -102,9 +103,9 @@ class Deploy extends Component
$process = $this->stopContainer($containerName, $timeout);
$startTime = time();
$startTime = Carbon::now()->getTimestamp();
while ($process->running()) {
if (time() - $startTime >= $timeout) {
if (Carbon::now()->getTimestamp() - $startTime >= $timeout) {
$this->forceStopContainer($containerName);
break;
}

View File

@@ -47,7 +47,6 @@ class SettingsEmail extends Component
} else {
return redirect()->route('dashboard');
}
}
public function submitFromFields()

View File

@@ -4,7 +4,6 @@ namespace App\Livewire\Source\Github;
use App\Jobs\GithubAppPermissionJob;
use App\Models\GithubApp;
use Illuminate\Support\Facades\Http;
use Livewire\Component;
class Change extends Component
@@ -141,7 +140,6 @@ class Change extends Component
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function submit()

View File

@@ -8,49 +8,16 @@ use Stripe\Stripe;
class PricingPlans extends Component
{
public bool $isTrial = false;
public function mount()
{
$this->isTrial = ! data_get(currentTeam(), 'subscription.stripe_trial_already_ended');
if (config('constants.limits.trial_period') == 0) {
$this->isTrial = false;
}
}
public function subscribeStripe($type)
{
$team = currentTeam();
Stripe::setApiKey(config('subscription.stripe_api_key'));
switch ($type) {
case 'basic-monthly':
$priceId = config('subscription.stripe_price_id_basic_monthly');
break;
case 'basic-yearly':
$priceId = config('subscription.stripe_price_id_basic_yearly');
break;
case 'pro-monthly':
$priceId = config('subscription.stripe_price_id_pro_monthly');
break;
case 'pro-yearly':
$priceId = config('subscription.stripe_price_id_pro_yearly');
break;
case 'ultimate-monthly':
$priceId = config('subscription.stripe_price_id_ultimate_monthly');
break;
case 'ultimate-yearly':
$priceId = config('subscription.stripe_price_id_ultimate_yearly');
break;
case 'dynamic-monthly':
$priceId = config('subscription.stripe_price_id_dynamic_monthly');
break;
case 'dynamic-yearly':
$priceId = config('subscription.stripe_price_id_dynamic_yearly');
break;
default:
$priceId = config('subscription.stripe_price_id_basic_monthly');
break;
}
$priceId = match ($type) {
'dynamic-monthly' => config('subscription.stripe_price_id_dynamic_monthly'),
'dynamic-yearly' => config('subscription.stripe_price_id_dynamic_yearly'),
default => config('subscription.stripe_price_id_dynamic_monthly'),
};
if (! $priceId) {
$this->dispatch('error', 'Price ID not found! Please contact the administrator.');
@@ -62,7 +29,11 @@ class PricingPlans extends Component
'client_reference_id' => auth()->user()->id.':'.currentTeam()->id,
'line_items' => [[
'price' => $priceId,
'quantity' => 1,
'adjustable_quantity' => [
'enabled' => true,
'minimum' => 2,
],
'quantity' => 2,
]],
'tax_id_collection' => [
'enabled' => true,
@@ -70,39 +41,18 @@ class PricingPlans extends Component
'automatic_tax' => [
'enabled' => true,
],
'subscription_data' => [
'metadata' => [
'user_id' => auth()->user()->id,
'team_id' => currentTeam()->id,
],
],
'payment_method_collection' => 'if_required',
'mode' => 'subscription',
'success_url' => route('dashboard', ['success' => true]),
'cancel_url' => route('subscription.index', ['cancelled' => true]),
];
if (str($type)->contains('ultimate')) {
$payload['line_items'][0]['adjustable_quantity'] = [
'enabled' => true,
'minimum' => 10,
];
$payload['line_items'][0]['quantity'] = 10;
}
if (str($type)->contains('dynamic')) {
$payload['line_items'][0]['adjustable_quantity'] = [
'enabled' => true,
'minimum' => 2,
];
$payload['line_items'][0]['quantity'] = 2;
}
if (! data_get($team, 'subscription.stripe_trial_already_ended')) {
if (config('constants.limits.trial_period') > 0) {
$payload['subscription_data'] = [
'trial_period_days' => config('constants.limits.trial_period'),
'trial_settings' => [
'end_behavior' => [
'missing_payment_method' => 'cancel',
],
],
];
}
$payload['payment_method_collection'] = 'if_required';
}
$customer = currentTeam()->subscription?->stripe_customer_id ?? null;
if ($customer) {
$payload['customer'] = $customer;

View File

@@ -47,7 +47,7 @@ class Index extends Component
public function tagUpdated()
{
if ($this->tag == '') {
if ($this->tag === '') {
return;
}
$sanitizedTag = htmlspecialchars($this->tag, ENT_QUOTES, 'UTF-8');

View File

@@ -18,7 +18,7 @@ class Invitations extends Component
$initiation_found->delete();
$this->refreshInvitations();
$this->dispatch('success', 'Invitation revoked.');
} catch (\Exception $e) {
} catch (\Exception) {
return $this->dispatch('error', 'Invitation not found.');
}
}

View File

@@ -23,11 +23,9 @@ class Upgrade extends Component
try {
$this->latestVersion = get_latest_version_of_coolify();
$this->isUpgradeAvailable = data_get(InstanceSettings::get(), 'new_version_available', false);
} catch (\Throwable $e) {
return handleError($e, $this);
}
}
public function upgrade()

View File

@@ -15,7 +15,6 @@ class VerifyEmail extends Component
$this->rateLimit(1, 300);
auth()->user()->sendVerificationEmail();
$this->dispatch('success', 'Email verification link sent!');
} catch (\Exception $e) {
return handleError($e, $this);
}