Skip to content

Commit d4f4632

Browse files
authored
Merge pull request coollabsio#2812 from coollabsio/next
v4.0.0-beta.311
2 parents 4e6ea4f + 666aa04 commit d4f4632

File tree

32 files changed

+161
-147
lines changed

32 files changed

+161
-147
lines changed

app/Events/ServiceStatusChanged.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __construct($userId = null)
2727

2828
public function broadcastOn(): ?array
2929
{
30-
if ($this->userId) {
30+
if (! is_null($this->userId)) {
3131
return [
3232
new PrivateChannel("user.{$this->userId}"),
3333
];

app/Exceptions/Handler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function register(): void
6565
if ($e instanceof RuntimeException) {
6666
return;
6767
}
68-
$this->settings = InstanceSettings::get();
68+
$this->settings = view()->shared('instanceSettings');
6969
if ($this->settings->do_not_track) {
7070
return;
7171
}

app/Http/Controllers/Api/OtherController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Http\Controllers\Api;
44

55
use App\Http\Controllers\Controller;
6-
use App\Models\InstanceSettings;
76
use Illuminate\Http\Request;
87
use Illuminate\Support\Facades\Http;
98
use OpenApi\Attributes as OA;
@@ -85,7 +84,7 @@ public function enable_api(Request $request)
8584
if ($teamId !== '0') {
8685
return response()->json(['message' => 'You are not allowed to enable the API.'], 403);
8786
}
88-
$settings = InstanceSettings::get();
87+
$settings = view()->shared('instanceSettings');
8988
$settings->update(['is_api_enabled' => true]);
9089

9190
return response()->json(['message' => 'API enabled.'], 200);
@@ -136,7 +135,7 @@ public function disable_api(Request $request)
136135
if ($teamId !== '0') {
137136
return response()->json(['message' => 'You are not allowed to disable the API.'], 403);
138137
}
139-
$settings = InstanceSettings::get();
138+
$settings = view()->shared('instanceSettings');
140139
$settings->update(['is_api_enabled' => false]);
141140

142141
return response()->json(['message' => 'API disabled.'], 200);

app/Http/Controllers/Api/ServersController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use App\Http\Controllers\Controller;
66
use App\Models\Application;
7-
use App\Models\InstanceSettings;
87
use App\Models\Project;
98
use App\Models\Server as ModelsServer;
109
use Illuminate\Http\Request;
@@ -301,7 +300,7 @@ public function domains_by_server(Request $request)
301300
$projects = Project::where('team_id', $teamId)->get();
302301
$domains = collect();
303302
$applications = $projects->pluck('applications')->flatten();
304-
$settings = InstanceSettings::get();
303+
$settings = view()->shared('instanceSettings');
305304
if ($applications->count() > 0) {
306305
foreach ($applications as $application) {
307306
$ip = $application->destination->server->ip;

app/Http/Middleware/ApiAllowed.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Http\Middleware;
44

5-
use App\Models\InstanceSettings;
65
use Closure;
76
use Illuminate\Http\Request;
87
use Symfony\Component\HttpFoundation\Response;
@@ -15,7 +14,7 @@ public function handle(Request $request, Closure $next): Response
1514
if (isCloud()) {
1615
return $next($request);
1716
}
18-
$settings = InstanceSettings::get();
17+
$settings = view()->shared('instanceSettings');
1918
if ($settings->is_api_enabled === false) {
2019
return response()->json(['success' => true, 'message' => 'API is disabled.'], 403);
2120
}

app/Jobs/PullCoolifyImageJob.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Jobs;
44

5-
use App\Models\InstanceSettings;
65
use App\Models\Server;
76
use Illuminate\Bus\Queueable;
87
use Illuminate\Contracts\Queue\ShouldBeEncrypted;
@@ -36,7 +35,7 @@ public function handle(): void
3635
$latest_version = get_latest_version_of_coolify();
3736
instant_remote_process(["docker pull -q ghcr.io/coollabsio/coolify:{$latest_version}"], $server, false);
3837

39-
$settings = InstanceSettings::get();
38+
$settings = view()->shared('instanceSettings');
4039
$current_version = config('version');
4140
if (! $settings->is_auto_update_enabled) {
4241
return;

app/Livewire/Help.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Livewire;
44

5-
use App\Models\InstanceSettings;
65
use DanHarrin\LivewireRateLimiting\WithRateLimiting;
76
use Illuminate\Notifications\Messages\MailMessage;
87
use Illuminate\Support\Facades\Http;
@@ -48,7 +47,7 @@ public function submit()
4847
]
4948
);
5049
$mail->subject("[HELP]: {$this->subject}");
51-
$settings = InstanceSettings::get();
50+
$settings = view()->shared('instanceSettings');
5251
$type = set_transanctional_email_settings($settings);
5352
if (! $type) {
5453
$url = 'https://app.coolify.io/api/feedback';

app/Livewire/Notifications/Email.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace App\Livewire\Notifications;
44

5-
use App\Models\InstanceSettings;
65
use App\Models\Team;
76
use App\Notifications\Test;
87
use Livewire\Component;
@@ -173,7 +172,7 @@ public function submitResend()
173172

174173
public function copyFromInstanceSettings()
175174
{
176-
$settings = InstanceSettings::get();
175+
$settings = view()->shared('instanceSettings');
177176
if ($settings->smtp_enabled) {
178177
$team = currentTeam();
179178
$team->update([

app/Livewire/Project/Shared/Tags.php

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,100 @@
33
namespace App\Livewire\Project\Shared;
44

55
use App\Models\Tag;
6+
use Livewire\Attributes\Validate;
67
use Livewire\Component;
78

9+
// Refactored ✅
810
class Tags extends Component
911
{
1012
public $resource = null;
1113

12-
public ?string $new_tag = null;
14+
#[Validate('required|string|min:2')]
15+
public string $newTags;
1316

1417
public $tags = [];
1518

16-
protected $listeners = [
17-
'refresh' => '$refresh',
18-
];
19-
20-
protected $rules = [
21-
'resource.tags.*.name' => 'required|string|min:2',
22-
'new_tag' => 'required|string|min:2',
23-
];
24-
25-
protected $validationAttributes = [
26-
'new_tag' => 'tag',
27-
];
19+
public $filteredTags = [];
2820

2921
public function mount()
22+
{
23+
$this->loadTags();
24+
}
25+
26+
public function loadTags()
3027
{
3128
$this->tags = Tag::ownedByCurrentTeam()->get();
29+
$this->filteredTags = $this->tags->filter(function ($tag) {
30+
return ! $this->resource->tags->contains($tag);
31+
});
3232
}
3333

34-
public function addTag(string $id, string $name)
34+
public function submit()
3535
{
3636
try {
37-
if ($this->resource->tags()->where('id', $id)->exists()) {
38-
$this->dispatch('error', 'Duplicate tags.', "Tag <span class='dark:text-warning'>$name</span> already added.");
37+
$this->validate();
38+
$tags = str($this->newTags)->trim()->explode(' ');
39+
foreach ($tags as $tag) {
40+
if (strlen($tag) < 2) {
41+
$this->dispatch('error', 'Invalid tag.', "Tag <span class='dark:text-warning'>$tag</span> is invalid. Min length is 2.");
3942

40-
return;
43+
continue;
44+
}
45+
if ($this->resource->tags()->where('name', $tag)->exists()) {
46+
$this->dispatch('error', 'Duplicate tags.', "Tag <span class='dark:text-warning'>$tag</span> already added.");
47+
48+
continue;
49+
}
50+
$found = Tag::ownedByCurrentTeam()->where(['name' => $tag])->exists();
51+
if (! $found) {
52+
$found = Tag::create([
53+
'name' => $tag,
54+
'team_id' => currentTeam()->id,
55+
]);
56+
}
57+
$this->resource->tags()->attach($found->id);
4158
}
42-
$this->resource->tags()->syncWithoutDetaching($id);
4359
$this->refresh();
4460
} catch (\Exception $e) {
4561
return handleError($e, $this);
4662
}
4763
}
4864

49-
public function deleteTag(string $id)
65+
public function addTag(string $id, string $name)
5066
{
5167
try {
52-
$this->resource->tags()->detach($id);
68+
if ($this->resource->tags()->where('id', $id)->exists()) {
69+
$this->dispatch('error', 'Duplicate tags.', "Tag <span class='dark:text-warning'>$name</span> already added.");
5370

54-
$found_more_tags = Tag::where(['id' => $id, 'team_id' => currentTeam()->id])->first();
55-
if ($found_more_tags->applications()->count() == 0 && $found_more_tags->services()->count() == 0) {
56-
$found_more_tags->delete();
71+
return;
5772
}
73+
$this->resource->tags()->attach($id);
5874
$this->refresh();
75+
$this->dispatch('success', 'Tag added.');
5976
} catch (\Exception $e) {
6077
return handleError($e, $this);
6178
}
6279
}
6380

64-
public function refresh()
65-
{
66-
$this->resource->load(['tags']);
67-
$this->tags = Tag::ownedByCurrentTeam()->get();
68-
$this->new_tag = null;
69-
}
70-
71-
public function submit()
81+
public function deleteTag(string $id)
7282
{
7383
try {
74-
$this->validate([
75-
'new_tag' => 'required|string|min:2',
76-
]);
77-
$tags = str($this->new_tag)->trim()->explode(' ');
78-
foreach ($tags as $tag) {
79-
if ($this->resource->tags()->where('name', $tag)->exists()) {
80-
$this->dispatch('error', 'Duplicate tags.', "Tag <span class='dark:text-warning'>$tag</span> already added.");
81-
82-
continue;
83-
}
84-
$found = Tag::where(['name' => $tag, 'team_id' => currentTeam()->id])->first();
85-
if (! $found) {
86-
$found = Tag::create([
87-
'name' => $tag,
88-
'team_id' => currentTeam()->id,
89-
]);
90-
}
91-
$this->resource->tags()->syncWithoutDetaching($found->id);
84+
$this->resource->tags()->detach($id);
85+
$found_more_tags = Tag::ownedByCurrentTeam()->find($id);
86+
if ($found_more_tags && $found_more_tags->applications()->count() == 0 && $found_more_tags->services()->count() == 0) {
87+
$found_more_tags->delete();
9288
}
9389
$this->refresh();
90+
$this->dispatch('success', 'Tag deleted.');
9491
} catch (\Exception $e) {
9592
return handleError($e, $this);
9693
}
9794
}
9895

99-
public function render()
96+
public function refresh()
10097
{
101-
return view('livewire.project.shared.tags');
98+
$this->resource->refresh(); // Remove this when legacy_model_binding is false
99+
$this->loadTags();
100+
$this->reset('newTags');
102101
}
103102
}

app/Livewire/Project/Shared/Webhooks.php

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,61 @@
44

55
use Livewire\Component;
66

7+
// Refactored ✅
78
class Webhooks extends Component
89
{
910
public $resource;
1011

11-
public ?string $deploywebhook = null;
12+
public ?string $deploywebhook;
1213

13-
public ?string $githubManualWebhook = null;
14+
public ?string $githubManualWebhook;
1415

15-
public ?string $gitlabManualWebhook = null;
16+
public ?string $gitlabManualWebhook;
1617

17-
public ?string $bitbucketManualWebhook = null;
18+
public ?string $bitbucketManualWebhook;
1819

19-
public ?string $giteaManualWebhook = null;
20+
public ?string $giteaManualWebhook;
2021

21-
protected $rules = [
22-
'resource.manual_webhook_secret_github' => 'nullable|string',
23-
'resource.manual_webhook_secret_gitlab' => 'nullable|string',
24-
'resource.manual_webhook_secret_bitbucket' => 'nullable|string',
25-
'resource.manual_webhook_secret_gitea' => 'nullable|string',
26-
];
22+
public ?string $githubManualWebhookSecret = null;
2723

28-
public function saveSecret()
29-
{
30-
try {
31-
$this->validate();
32-
$this->resource->save();
33-
$this->dispatch('success', 'Secret Saved.');
34-
} catch (\Exception $e) {
35-
return handleError($e, $this);
36-
}
37-
}
24+
public ?string $gitlabManualWebhookSecret = null;
25+
26+
public ?string $bitbucketManualWebhookSecret = null;
27+
28+
public ?string $giteaManualWebhookSecret = null;
3829

3930
public function mount()
4031
{
32+
// ray()->clearAll();
33+
// ray()->showQueries();
4134
$this->deploywebhook = generateDeployWebhook($this->resource);
35+
36+
$this->githubManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_github');
4237
$this->githubManualWebhook = generateGitManualWebhook($this->resource, 'github');
38+
39+
$this->gitlabManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitlab');
4340
$this->gitlabManualWebhook = generateGitManualWebhook($this->resource, 'gitlab');
41+
42+
$this->bitbucketManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_bitbucket');
4443
$this->bitbucketManualWebhook = generateGitManualWebhook($this->resource, 'bitbucket');
44+
45+
$this->giteaManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitea');
4546
$this->giteaManualWebhook = generateGitManualWebhook($this->resource, 'gitea');
4647
}
4748

48-
public function render()
49+
public function submit()
4950
{
50-
return view('livewire.project.shared.webhooks');
51+
try {
52+
$this->authorize('update', $this->resource);
53+
$this->resource->update([
54+
'manual_webhook_secret_github' => $this->githubManualWebhookSecret,
55+
'manual_webhook_secret_gitlab' => $this->gitlabManualWebhookSecret,
56+
'manual_webhook_secret_bitbucket' => $this->bitbucketManualWebhookSecret,
57+
'manual_webhook_secret_gitea' => $this->giteaManualWebhookSecret,
58+
]);
59+
$this->dispatch('success', 'Secret Saved.');
60+
} catch (\Exception $e) {
61+
return handleError($e, $this);
62+
}
5163
}
5264
}

0 commit comments

Comments
 (0)