-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathEditPlugin.php
More file actions
258 lines (229 loc) · 12.6 KB
/
EditPlugin.php
File metadata and controls
258 lines (229 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php
namespace App\Filament\Resources\PluginResource\Pages;
use App\Enums\PluginTier;
use App\Enums\PluginType;
use App\Filament\Resources\PluginResource;
use App\Jobs\ReviewPluginRepository;
use App\Jobs\SyncPlugin;
use App\Jobs\SyncPluginReleases;
use App\Models\PluginLicense;
use App\Models\User;
use App\Notifications\PluginGranted;
use Filament\Actions;
use Filament\Forms;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Illuminate\Support\HtmlString;
class EditPlugin extends EditRecord
{
protected static string $resource = PluginResource::class;
protected function getHeaderActions(): array
{
return [
Actions\ActionGroup::make([
Actions\Action::make('approve')
->icon('heroicon-o-check')
->color('success')
->visible(fn () => $this->record->isPending())
->action(fn () => $this->record->approve(auth()->id()))
->requiresConfirmation()
->modalHeading('Approve Plugin')
->modalDescription(fn () => "Are you sure you want to approve '{$this->record->name}'?"),
Actions\Action::make('reject')
->icon('heroicon-o-x-mark')
->color('danger')
->visible(fn () => $this->record->isPending() || $this->record->isApproved())
->form([
Forms\Components\Textarea::make('rejection_reason')
->label('Reason for Rejection')
->required()
->rows(3)
->placeholder('Please explain why this plugin is being rejected...'),
])
->action(fn (array $data) => $this->record->reject($data['rejection_reason'], auth()->id()))
->modalHeading('Reject Plugin')
->modalDescription(fn () => "Are you sure you want to reject '{$this->record->name}'?"),
Actions\Action::make('convertToPaid')
->label('Convert to Paid')
->icon('heroicon-o-currency-dollar')
->color('success')
->visible(fn () => $this->record->isFree())
->form([
Forms\Components\Select::make('tier')
->label('Pricing Tier')
->options(PluginTier::class)
->required()
->helperText('This sets the pricing for the plugin.'),
])
->action(function (array $data): void {
$this->record->update([
'type' => PluginType::Paid,
'tier' => $data['tier'],
]);
SyncPluginReleases::dispatch($this->record);
Notification::make()
->title("Converted '{$this->record->name}' to paid")
->body('Plugin type updated, prices synced, and Satis ingestion queued.')
->success()
->send();
})
->modalHeading('Convert Plugin to Paid')
->modalDescription(fn () => "This will convert '{$this->record->name}' from free to paid, set up pricing, and trigger a Satis build so it's available via Composer.")
->modalSubmitActionLabel('Convert & Ingest'),
Actions\Action::make('syncToSatis')
->label(fn () => $this->record->isSatisSynced() ? 'Re-sync to Satis' : 'Sync to Satis')
->icon('heroicon-o-arrow-path')
->color('warning')
->visible(fn () => $this->record->isPaid())
->requiresConfirmation()
->modalHeading(fn () => $this->record->isSatisSynced() ? 'Re-sync to Satis' : 'Sync to Satis')
->modalDescription(fn () => $this->record->isSatisSynced()
? "Last synced: {$this->record->satis_synced_at->diffForHumans()}. This will trigger a new Satis build for '{$this->record->name}'."
: "This will trigger a Satis build for '{$this->record->name}' so it's available via Composer.")
->action(function (): void {
SyncPluginReleases::dispatch($this->record);
Notification::make()
->title('Satis sync queued')
->body("A Satis build has been queued for '{$this->record->name}'.")
->success()
->send();
}),
Actions\Action::make('grantToUser')
->label('Grant to User')
->icon('heroicon-o-gift')
->color('success')
->form([
Forms\Components\Select::make('user_id')
->label('User')
->searchable()
->getSearchResultsUsing(function (string $search): array {
return User::query()
->where('name', 'like', "%{$search}%")
->orWhere('email', 'like', "%{$search}%")
->limit(50)
->get()
->mapWithKeys(fn (User $user) => [$user->id => "{$user->name} ({$user->email})"])
->toArray();
})
->required(),
])
->action(function (array $data): void {
$user = User::findOrFail($data['user_id']);
$existingLicense = $user->pluginLicenses()
->where('plugin_id', $this->record->id)
->exists();
if ($existingLicense) {
Notification::make()
->title('User already has a license for this plugin')
->warning()
->send();
return;
}
PluginLicense::create([
'user_id' => $user->id,
'plugin_id' => $this->record->id,
'price_paid' => 0,
'currency' => 'USD',
'is_grandfathered' => true,
'purchased_at' => now(),
]);
$user->getPluginLicenseKey();
$user->notify(new PluginGranted($this->record));
Notification::make()
->title("Granted '{$this->record->name}' license to {$user->name}")
->success()
->send();
})
->modalHeading('Grant Plugin to User')
->modalDescription(fn () => "Grant '{$this->record->name}' to a user for free.")
->modalSubmitActionLabel('Grant'),
Actions\Action::make('viewListing')
->label('View Listing Page')
->icon('heroicon-o-eye')
->color('gray')
->url(fn () => route('plugins.show', $this->record->routeParams()))
->openUrlInNewTab()
->visible(fn () => $this->record->isApproved() || $this->record->isPending()),
Actions\Action::make('viewPackagist')
->label('View on Packagist')
->icon('heroicon-o-arrow-top-right-on-square')
->color('gray')
->url(fn () => $this->record->getPackagistUrl())
->openUrlInNewTab()
->visible(fn () => $this->record->isFree()),
Actions\Action::make('runReviewChecks')
->label('Run Review Checks')
->icon('heroicon-o-clipboard-document-check')
->color('primary')
->visible(fn () => $this->record->repository_url !== null)
->requiresConfirmation()
->modalHeading('Run Review Checks')
->modalDescription(fn () => "This will fetch the repository tree, README, and composer.json for '{$this->record->name}' and run automated checks.")
->action(function (): void {
$checks = (new ReviewPluginRepository($this->record))->handle();
if (empty($checks)) {
Notification::make()
->title('Review checks failed')
->body('Could not fetch repository data. Check the repository URL.')
->danger()
->send();
return;
}
$lines = collect([
['iOS support', $checks['supports_ios']],
['Android support', $checks['supports_android']],
['JS support', $checks['supports_js']],
['Support email', $checks['has_support_email'] ? $checks['support_email'] : false],
['Requires nativephp/mobile', $checks['requires_mobile_sdk'] ? $checks['mobile_sdk_constraint'] : false],
['iOS min_version', $checks['has_ios_min_version'] ? $checks['ios_min_version'] : false],
['Android min_version', $checks['has_android_min_version'] ? $checks['android_min_version'] : false],
])->map(function (array $item): string {
[$label, $value] = $item;
if ($value === true) {
return "✅ {$label}";
}
if ($value === false) {
return "❌ {$label}";
}
return "✅ {$label}: {$value}";
})->implode('<br>');
$passed = collect($checks)->only([
'supports_ios', 'supports_android', 'supports_js',
'has_support_email', 'requires_mobile_sdk',
'has_ios_min_version', 'has_android_min_version',
])->filter()->count();
Notification::make()
->title("Review checks complete ({$passed}/7 passed)")
->body(new HtmlString($lines))
->duration(15000)
->color($passed === 7 ? 'success' : 'warning')
->send();
}),
Actions\Action::make('resync')
->label('Re-sync from GitHub')
->icon('heroicon-o-arrow-path')
->color('primary')
->visible(fn () => $this->record->repository_url !== null)
->requiresConfirmation()
->modalHeading('Re-sync Plugin')
->modalDescription(fn () => "This will re-fetch the README, composer.json, nativephp.json, license, and latest version from GitHub for '{$this->record->name}'.")
->action(function (): void {
SyncPlugin::dispatch($this->record);
Notification::make()
->title('Sync queued')
->body("A background sync has been queued for '{$this->record->name}'. Refresh the page in a moment to see updates.")
->success()
->send();
}),
Actions\Action::make('viewGithub')
->label('View on GitHub')
->icon('heroicon-o-arrow-top-right-on-square')
->color('gray')
->visible(fn () => $this->record->repository_url !== null)
->url(fn () => $this->record->getGithubUrl())
->openUrlInNewTab(),
])
->icon('heroicon-m-ellipsis-vertical'),
];
}
}