lasthourcloud/app/Http/Livewire/Source/Github/Change.php

68 lines
2.0 KiB
PHP
Raw Normal View History

2023-05-08 11:36:49 +00:00
<?php
namespace App\Http\Livewire\Source\Github;
use App\Models\GithubApp;
use App\Models\InstanceSettings;
use Livewire\Component;
class Change extends Component
{
public string $host;
public $parameters;
public GithubApp $github_app;
public bool $is_system_wide;
protected $rules = [
'github_app.name' => 'required|string',
'github_app.organization' => 'nullable|string',
'github_app.api_url' => 'required|string',
'github_app.html_url' => 'required|string',
'github_app.custom_user' => 'required|string',
'github_app.custom_port' => 'required|int',
'github_app.app_id' => 'required|int',
'github_app.installation_id' => 'required|int',
'github_app.client_id' => 'required|string',
'github_app.client_secret' => 'required|string',
'github_app.webhook_secret' => 'required|string',
'github_app.is_system_wide' => 'required|bool',
];
public function submit()
{
try {
$this->validate();
$this->github_app->save();
} catch (\Exception $e) {
2023-05-09 09:33:50 +00:00
return generalErrorHandler($e, $this);
2023-05-08 11:36:49 +00:00
}
}
public function instantSave()
{
try {
$this->github_app->is_system_wide = $this->is_system_wide;
$this->github_app->save();
2023-05-09 07:54:43 +00:00
$this->emit('saved', 'GitHub settings updated!');
2023-05-08 11:36:49 +00:00
} catch (\Exception $e) {
2023-05-09 09:33:50 +00:00
return generalErrorHandler($e, $this);
2023-05-08 11:36:49 +00:00
}
}
public function mount()
{
2023-05-16 15:09:50 +00:00
$settings = InstanceSettings::get();
2023-05-08 12:31:18 +00:00
if ($settings->fqdn) {
$this->host = $settings->fqdn;
}
2023-05-08 11:36:49 +00:00
$this->parameters = getParameters();
$this->is_system_wide = $this->github_app->is_system_wide;
}
2023-05-09 08:01:57 +00:00
public function delete()
2023-05-08 11:36:49 +00:00
{
2023-05-09 08:01:57 +00:00
try {
$this->github_app->delete();
redirect()->route('dashboard');
} catch (\Exception $e) {
2023-05-09 09:33:50 +00:00
return generalErrorHandler($e, $this);
2023-05-08 11:36:49 +00:00
}
}
}