mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-14 00:33:44 -04:00
- Require write access on the target environment to clone or move a resource - Check read access on shared variables before a reference is added or resolved - Limit team credentials, git sources, and imports of other backups to team-wide writers - Require the delete level for backup, volume, storage, and task deletes - Require create access for previews, new projects, and git sources - Use the token team for the access scope, and check team-wide access on Livewire updates - Require instance admin to toggle the API and MCP server - Hide server pickers and broadcast details from members without access
106 lines
3.6 KiB
PHP
106 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Source\Github;
|
|
|
|
use App\Models\GithubApp;
|
|
use App\Rules\SafeExternalUrl;
|
|
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
|
use Illuminate\Validation\ValidationException;
|
|
use Livewire\Component;
|
|
|
|
class Create extends Component
|
|
{
|
|
use AuthorizesRequests;
|
|
|
|
public string $name;
|
|
|
|
public ?string $organization = null;
|
|
|
|
public string $api_url = 'https://api.github.com';
|
|
|
|
public string $html_url = 'https://github.com';
|
|
|
|
public string $custom_user = 'git';
|
|
|
|
public int $custom_port = 22;
|
|
|
|
public bool $is_system_wide = false;
|
|
|
|
public bool $use_for_pull_request_previews = true;
|
|
|
|
public bool $use_for_github_runners = false;
|
|
|
|
private bool $shouldDeriveApiUrlAfterHtmlUrlUpdate = false;
|
|
|
|
public function mount()
|
|
{
|
|
$this->name = substr(generate_random_name(), 0, 30);
|
|
}
|
|
|
|
public function updatingHtmlUrl(): void
|
|
{
|
|
$this->shouldDeriveApiUrlAfterHtmlUrlUpdate = blank($this->api_url)
|
|
|| $this->api_url === githubApiUrlFromHtmlUrl($this->html_url);
|
|
}
|
|
|
|
public function updatedHtmlUrl(): void
|
|
{
|
|
if ($this->shouldDeriveApiUrlAfterHtmlUrlUpdate) {
|
|
$this->api_url = githubApiUrlFromHtmlUrl($this->html_url);
|
|
}
|
|
}
|
|
|
|
public function createGitHubApp()
|
|
{
|
|
try {
|
|
$this->authorize('create', GithubApp::class);
|
|
|
|
$this->organization = normalizeGithubOrganization($this->organization);
|
|
$this->api_url = filled($this->api_url)
|
|
? $this->api_url
|
|
: githubApiUrlFromHtmlUrl($this->html_url);
|
|
|
|
$this->validate([
|
|
'name' => 'required|string',
|
|
'organization' => [$this->use_for_github_runners ? 'required' : 'nullable', 'string', 'regex:/\A[^\s\/?#]+\z/'],
|
|
'api_url' => ['required', 'string', 'url', SafeExternalUrl::forGitSource()],
|
|
'html_url' => ['required', 'string', 'url', SafeExternalUrl::forGitSource()],
|
|
'custom_user' => 'required|string',
|
|
'custom_port' => 'required|int',
|
|
'is_system_wide' => 'required|bool',
|
|
'use_for_pull_request_previews' => 'required|bool',
|
|
'use_for_github_runners' => 'required|bool',
|
|
], [
|
|
'organization.required' => 'GitHub Actions runners are registered at organization level. Enter the organization.',
|
|
]);
|
|
$payload = [
|
|
'name' => $this->name,
|
|
'organization' => $this->organization,
|
|
'api_url' => $this->api_url,
|
|
'html_url' => $this->html_url,
|
|
'custom_user' => $this->custom_user,
|
|
'custom_port' => $this->custom_port,
|
|
'is_system_wide' => $this->is_system_wide,
|
|
'team_id' => currentTeam()->id,
|
|
];
|
|
if ($this->is_system_wide) {
|
|
$this->authorize('makeSystemWide', GithubApp::class);
|
|
}
|
|
$github_app = GithubApp::create($payload);
|
|
if (session('from')) {
|
|
session(['from' => session('from') + ['source_id' => $github_app->id]]);
|
|
}
|
|
|
|
return redirectRoute($this, 'source.github.show', [
|
|
'github_app_uuid' => $github_app->uuid,
|
|
'previews' => (int) $this->use_for_pull_request_previews,
|
|
'runners' => (int) $this->use_for_github_runners,
|
|
]);
|
|
} catch (ValidationException $e) {
|
|
throw $e;
|
|
} catch (\Throwable $e) {
|
|
return handleError($e, $this);
|
|
}
|
|
}
|
|
}
|