Skip to content
Open
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
8 changes: 8 additions & 0 deletions app/Enums/PluginActivityType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ enum PluginActivityType: string
case Approved = 'approved';
case Rejected = 'rejected';
case DescriptionUpdated = 'description_updated';
case Withdrawn = 'withdrawn';
case ReturnedToDraft = 'returned_to_draft';

public function label(): string
{
Expand All @@ -18,6 +20,8 @@ public function label(): string
self::Approved => 'Approved',
self::Rejected => 'Rejected',
self::DescriptionUpdated => 'Description Updated',
self::Withdrawn => 'Withdrawn',
self::ReturnedToDraft => 'Returned to Draft',
};
}

Expand All @@ -29,6 +33,8 @@ public function color(): string
self::Approved => 'success',
self::Rejected => 'danger',
self::DescriptionUpdated => 'gray',
self::Withdrawn => 'warning',
self::ReturnedToDraft => 'warning',
};
}

Expand All @@ -40,6 +46,8 @@ public function icon(): string
self::Approved => 'heroicon-o-check-circle',
self::Rejected => 'heroicon-o-x-circle',
self::DescriptionUpdated => 'heroicon-o-pencil-square',
self::Withdrawn => 'heroicon-o-arrow-uturn-left',
self::ReturnedToDraft => 'heroicon-o-arrow-uturn-left',
};
}
}
3 changes: 3 additions & 0 deletions app/Enums/PluginStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

enum PluginStatus: string
{
case Draft = 'draft';
case Pending = 'pending';
case Approved = 'approved';
case Rejected = 'rejected';

public function label(): string
{
return match ($this) {
self::Draft => 'Draft',
self::Pending => 'Pending Review',
self::Approved => 'Approved',
self::Rejected => 'Rejected',
Expand All @@ -20,6 +22,7 @@ public function label(): string
public function color(): string
{
return match ($this) {
self::Draft => 'zinc',
self::Pending => 'yellow',
self::Approved => 'green',
self::Rejected => 'red',
Expand Down
1 change: 1 addition & 0 deletions app/Filament/Resources/PluginResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('status')
->badge()
->color(fn (PluginStatus $state): string => match ($state) {
PluginStatus::Draft => 'gray',
PluginStatus::Pending => 'warning',
PluginStatus::Approved => 'success',
PluginStatus::Rejected => 'danger',
Expand Down
8 changes: 8 additions & 0 deletions app/Filament/Resources/PluginResource/Pages/ListPlugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

namespace App\Filament\Resources\PluginResource\Pages;

use App\Enums\PluginStatus;
use App\Filament\Resources\PluginResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use Illuminate\Database\Eloquent\Builder;

class ListPlugins extends ListRecords
{
Expand All @@ -16,4 +18,10 @@ protected function getHeaderActions(): array
Actions\CreateAction::make(),
];
}

protected function getTableQuery(): ?Builder
{
return parent::getTableQuery()
->where('status', '!=', PluginStatus::Draft);
}
}
1 change: 1 addition & 0 deletions app/Http/Controllers/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,7 @@ public function status(Request $request, string $sessionId): JsonResponse
'id' => $license->id,
'plugin_id' => $license->plugin->id,
'plugin_name' => $license->plugin->name,
'plugin_display_name' => $license->plugin->display_name,
'plugin_slug' => $license->plugin->slug,
]),
'products' => $productLicenses->map(fn ($license) => [
Expand Down
11 changes: 7 additions & 4 deletions app/Http/Controllers/PluginDirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public function index(): View

$featuredPlugins = Plugin::query()
->approved()
->where('is_active', true)
->featured()
->latest()
->take(16)
Expand All @@ -24,6 +25,7 @@ public function index(): View

$latestPlugins = Plugin::query()
->approved()
->where('is_active', true)
->where('featured', false)
->latest()
->take(16)
Expand Down Expand Up @@ -52,11 +54,12 @@ public function show(string $vendor, string $package): View
$user = Auth::user();

$isAdmin = $user?->isAdmin() ?? false;
$isOwner = $user && $plugin->user_id === $user->id;

abort_unless($plugin->isApproved() || $isAdmin, 404);
abort_unless(($plugin->isApproved() && $plugin->is_active) || $isAdmin || $isOwner, 404);

// For paid plugins, check if user has an accessible price (admins bypass)
if (! $isAdmin && $plugin->isPaid() && ! $plugin->hasAccessiblePriceFor($user)) {
// For paid plugins, check if user has an accessible price (admins and owners bypass)
if (! $isAdmin && ! $isOwner && $plugin->isPaid() && ! $plugin->hasAccessiblePriceFor($user)) {
abort(404);
}

Expand All @@ -74,7 +77,7 @@ public function show(string $vendor, string $package): View
'bestPrice' => $bestPrice,
'regularPrice' => $regularPrice,
'hasDiscount' => $bestPrice && $regularPrice && $bestPrice->id !== $regularPrice->id,
'isAdminPreview' => ! $plugin->isApproved(),
'isAdminPreview' => (! $plugin->isApproved() || ! $plugin->is_active) && ($isAdmin || $isOwner),
]);
}

Expand Down
56 changes: 6 additions & 50 deletions app/Livewire/Customer/Plugins/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

use App\Enums\PluginStatus;
use App\Features\AllowPaidPlugins;
use App\Jobs\ReviewPluginRepository;
use App\Models\Plugin;
use App\Notifications\PluginSubmitted;
use App\Services\GitHubUserService;
use App\Services\PluginSyncService;
use Illuminate\Support\Facades\Cache;
Expand All @@ -17,7 +15,7 @@
use Livewire\Component;

#[Layout('components.layouts.dashboard')]
#[Title('Submit Your Plugin')]
#[Title('Create Your Plugin')]
class Create extends Component
{
public string $pluginType = 'free';
Expand All @@ -26,10 +24,6 @@ class Create extends Component

public string $repository = '';

public string $notes = '';

public string $supportChannel = '';

/** @var array<int, array{id: int, full_name: string, name: string, owner: string, private: bool}> */
public array $repositories = [];

Expand Down Expand Up @@ -113,12 +107,12 @@ public function loadRepositories(): void
$this->loadingRepos = false;
}

public function submitPlugin(PluginSyncService $syncService): void
public function createPlugin(PluginSyncService $syncService): void
{
$user = auth()->user();

if (! $user->github_id) {
$this->addError('repository', 'You must connect your GitHub account to submit a plugin.');
$this->addError('repository', 'You must connect your GitHub account to create a plugin.');

return;
}
Expand All @@ -132,26 +126,14 @@ public function submitPlugin(PluginSyncService $syncService): void
function ($attribute, $value, $fail): void {
$url = 'https://github.com/'.trim($value, '/');
if (Plugin::where('repository_url', $url)->exists()) {
$fail('This repository has already been submitted.');
$fail('A plugin for this repository already exists.');
}
},
],
'pluginType' => ['required', 'string', 'in:free,paid'],
'notes' => ['nullable', 'string', 'max:5000'],
'supportChannel' => [
'required',
'string',
'max:255',
function (string $attribute, mixed $value, \Closure $fail) {
if (! filter_var($value, FILTER_VALIDATE_EMAIL) && ! filter_var($value, FILTER_VALIDATE_URL)) {
$fail('The support channel must be a valid email address or URL.');
}
},
],
], [
'repository.required' => 'Please select a repository for your plugin.',
'repository.regex' => 'Please enter a valid repository in the format vendor/repo-name.',
'supportChannel.required' => 'Please provide a support channel (email or URL) for your plugin.',
]);

if ($this->pluginType === 'paid' && ! Feature::active(AllowPaidPlugins::class)) {
Expand Down Expand Up @@ -195,31 +177,12 @@ function (string $attribute, mixed $value, \Closure $fail) {
$plugin = $user->plugins()->create([
'repository_url' => $repositoryUrl,
'type' => $this->pluginType,
'status' => PluginStatus::Pending,
'status' => PluginStatus::Draft,
'developer_account_id' => $developerAccountId,
'notes' => $this->notes ?: null,
'support_channel' => $this->supportChannel ?: null,
]);

$webhookSecret = $plugin->generateWebhookSecret();

$webhookInstalled = false;
if ($user->hasGitHubToken()) {
$webhookResult = $githubService->createWebhook(
$owner,
$repo,
$plugin->getWebhookUrl(),
$webhookSecret
);
$webhookInstalled = $webhookResult['success'];
}

$plugin->update(['webhook_installed' => $webhookInstalled]);

$syncService->sync($plugin);

(new ReviewPluginRepository($plugin))->handle();

if (! $plugin->name) {
$plugin->delete();

Expand All @@ -228,21 +191,14 @@ function (string $attribute, mixed $value, \Closure $fail) {
return;
}

$user->notify(new PluginSubmitted($plugin));

$successMessage = 'Your plugin has been submitted for review!';
if (! $webhookInstalled) {
$successMessage .= ' Please set up the webhook manually to enable automatic syncing.';
}

[$vendor, $package] = explode('/', $plugin->name);

$this->redirect(
route('customer.plugins.show', ['vendor' => $vendor, 'package' => $package]),
navigate: true
);

session()->flash('success', $successMessage);
session()->flash('success', 'Your plugin has been created as a draft. You can edit it and submit for review when ready.');
}

public function render()
Expand Down
3 changes: 2 additions & 1 deletion app/Livewire/Customer/Plugins/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class Index extends Component
{
#[Url]
public string $status = 'pending';
public string $status = 'draft';

#[Computed]
public function plugins(): Collection
Expand All @@ -37,6 +37,7 @@ public function pluginCounts(): array
->toArray();

return [
PluginStatus::Draft->value => $counts[PluginStatus::Draft->value] ?? 0,
PluginStatus::Approved->value => $counts[PluginStatus::Approved->value] ?? 0,
PluginStatus::Pending->value => $counts[PluginStatus::Pending->value] ?? 0,
PluginStatus::Rejected->value => $counts[PluginStatus::Rejected->value] ?? 0,
Expand Down
Loading
Loading