Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions app/Models/GitHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Database\Factories\GitHookFactory;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Support\Facades\Log;

/**
* @property int $site_id
Expand Down Expand Up @@ -64,14 +65,16 @@ public function deployHook(): void
);
}

/**
* @throws FailedToDestroyGitHook
*/
public function destroyHook(): void
{
if ($this->hook_id) {
$this->sourceControl->provider()->destroyHook($this->site->repository, $this->hook_id);
try {
if ($this->hook_id) {
$this->sourceControl->provider()->destroyHook($this->site->repository, $this->hook_id);
}
} catch (FailedToDestroyGitHook $e) {
Log::warning('Failed to destroy git hook', ['error' => $e->getMessage()]);
} finally {
$this->delete();
}
$this->delete();
}
}
8 changes: 1 addition & 7 deletions app/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use App\Enums\RedirectStatus;
use App\Enums\SiteStatus;
use App\Enums\SslStatus;
use App\Exceptions\FailedToDestroyGitHook;
use App\Exceptions\SourceControlIsNotConnected;
use App\Exceptions\SSHError;
use App\Services\PHP\PHP;
Expand Down Expand Up @@ -112,11 +111,7 @@ public static function boot(): void
$site->ssls()->delete();
$site->deployments()->delete();
$site->deploymentScript()->delete();
try {
$site->gitHook?->destroyHook();
} catch (FailedToDestroyGitHook) {
$site->refresh()->gitHook?->delete();
}
$site->gitHook?->destroyHook();
});

static::created(function (Site $site): void {
Expand Down Expand Up @@ -386,7 +381,6 @@ public function enableAutoDeployment(): void

/**
* @throws SourceControlIsNotConnected
* @throws FailedToDestroyGitHook
*/
public function disableAutoDeployment(): void
{
Expand Down
2 changes: 1 addition & 1 deletion resources/js/pages/databases/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function Databases() {
</Button>
</a>
<SyncDatabases server={page.props.server} />
<CreateDatabase server={page.props.server.id} defaultCharset={defaultCharset} defaultCollation={defaultCollation}>
<CreateDatabase server={page.props.server.id} defaultCharset={defaultCharset} defaultCollation={defaultCollation}>
<Button>
<PlusIcon />
<span className="hidden lg:block">Create</span>
Expand Down
4 changes: 2 additions & 2 deletions resources/js/pages/sites/components/create-site.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@ export default function CreateSite({
<DialogTitle>Why Isolated Users?</DialogTitle>
<DialogDescription>
Isolated users are mandatory to ensure security for your sites. If a site has security vulnerabilities and gets
compromised, the attacker cannot take full control of the server because the site runs under its own isolated user
with limited permissions.
compromised, the attacker cannot take full control of the server because the site runs under its own isolated user with
limited permissions.
</DialogDescription>
</DialogHeader>
</DialogContent>
Expand Down
26 changes: 26 additions & 0 deletions tests/Feature/ApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,32 @@ public function test_disable_auto_deployment(): void
$this->assertFalse($this->site->isAutoDeployment());
}

public function test_disable_auto_deployment_even_if_hook_destroy_fails(): void
{
Http::fake([
'api.github.com/repos/organization/repository' => Http::response([
'id' => '123',
], 200),
'api.github.com/repos/organization/repository/hooks/*' => Http::response([], 404),
]);

$this->actingAs($this->user);

GitHook::factory()->create([
'site_id' => $this->site->id,
'source_control_id' => $this->site->source_control_id,
]);

$this->post(route('application.disable-auto-deployment', [
'server' => $this->server,
'site' => $this->site,
]))->assertSessionDoesntHaveErrors();

$this->site->refresh();

$this->assertFalse($this->site->isAutoDeployment());
}

public function test_update_env_file(): void
{
SSH::fake();
Expand Down