diff --git a/src/LocalizationsServiceProvider.php b/src/LocalizationsServiceProvider.php index 2fc0b90..c66c23f 100644 --- a/src/LocalizationsServiceProvider.php +++ b/src/LocalizationsServiceProvider.php @@ -4,9 +4,7 @@ use AdminKit\Localizations\Commands\InstallCommand; use AdminKit\Localizations\Providers\RouteServiceProvider; -use AdminKit\Localizations\UI\API\Repositories\CachedLocalizationRepository; -use AdminKit\Localizations\UI\API\Repositories\LocalizationRepository; -use AdminKit\Localizations\UI\API\Repositories\LocalizationRepositoryInterface; +use Illuminate\Support\Facades\Gate; use Spatie\LaravelPackageTools\Package; use Spatie\LaravelPackageTools\PackageServiceProvider; @@ -39,11 +37,9 @@ public function bootingPackage() { $this->publishFiles(); - $repository = match ((bool) config('admin-kit.cache.enabled')) { - true => CachedLocalizationRepository::class, - false => LocalizationRepository::class, - }; - $this->app->bind(LocalizationRepositoryInterface::class, $repository); + $this->bindingPolicies(); + + $this->bindingRepositories(); } protected function registerConfigs(): self @@ -63,4 +59,19 @@ protected function publishFiles(): self return $this; } + + protected function bindingPolicies(): void + { + Gate::policy(\AdminKit\Localizations\Models\Localization::class, \AdminKit\Localizations\Policies\LocalizationPolicy::class); + } + + protected function bindingRepositories(): void + { + $repository = \AdminKit\Localizations\UI\API\Repositories\LocalizationRepository::class; + if (config('admin-kit.cache.enabled')) { + $repository = \AdminKit\Localizations\UI\API\Repositories\CachedLocalizationRepository::class; + } + + $this->app->bind(\AdminKit\Localizations\UI\API\Repositories\LocalizationRepositoryInterface::class, $repository); + } } diff --git a/src/Models/Localization.php b/src/Models/Localization.php index a334c01..670e056 100644 --- a/src/Models/Localization.php +++ b/src/Models/Localization.php @@ -42,6 +42,6 @@ protected static function boot() protected static function newFactory(): LocalizationFactory { - return new LocalizationFactory(); + return new LocalizationFactory; } } diff --git a/src/Policies/LocalizationPolicy.php b/src/Policies/LocalizationPolicy.php new file mode 100644 index 0000000..fb5c0ad --- /dev/null +++ b/src/Policies/LocalizationPolicy.php @@ -0,0 +1,108 @@ +can('view_any_localization'); + } + + /** + * Determine whether the adminKitUser can view the model. + */ + public function view(AdminKitUser $adminKitUser, Localization $localization): bool + { + return $adminKitUser->can('view_localization'); + } + + /** + * Determine whether the adminKitUser can create models. + */ + public function create(AdminKitUser $adminKitUser): bool + { + return $adminKitUser->can('create_localization'); + } + + /** + * Determine whether the adminKitUser can update the model. + */ + public function update(AdminKitUser $adminKitUser, Localization $localization): bool + { + return $adminKitUser->can('update_localization'); + } + + /** + * Determine whether the adminKitUser can delete the model. + */ + public function delete(AdminKitUser $adminKitUser, Localization $localization): bool + { + return $adminKitUser->can('delete_localization'); + } + + /** + * Determine whether the adminKitUser can bulk delete. + */ + public function deleteAny(AdminKitUser $adminKitUser): bool + { + return $adminKitUser->can('delete_any_localization'); + } + + /** + * Determine whether the adminKitUser can permanently delete. + */ + public function forceDelete(AdminKitUser $adminKitUser, Localization $localization): bool + { + return $adminKitUser->can('force_delete_localization'); + } + + /** + * Determine whether the adminKitUser can permanently bulk delete. + */ + public function forceDeleteAny(AdminKitUser $adminKitUser): bool + { + return $adminKitUser->can('force_delete_any_localization'); + } + + /** + * Determine whether the adminKitUser can restore. + */ + public function restore(AdminKitUser $adminKitUser, Localization $localization): bool + { + return $adminKitUser->can('restore_localization'); + } + + /** + * Determine whether the adminKitUser can bulk restore. + */ + public function restoreAny(AdminKitUser $adminKitUser): bool + { + return $adminKitUser->can('restore_any_localization'); + } + + /** + * Determine whether the adminKitUser can replicate. + */ + public function replicate(AdminKitUser $adminKitUser, Localization $localization): bool + { + return $adminKitUser->can('replicate_localization'); + } + + /** + * Determine whether the adminKitUser can reorder. + */ + public function reorder(AdminKitUser $adminKitUser): bool + { + return $adminKitUser->can('reorder_localization'); + } +} diff --git a/src/UI/Filament/Filters/NotTranslatedFilter.php b/src/UI/Filament/Filters/NotTranslatedFilter.php index a1ead3c..91f9c72 100644 --- a/src/UI/Filament/Filters/NotTranslatedFilter.php +++ b/src/UI/Filament/Filters/NotTranslatedFilter.php @@ -3,7 +3,6 @@ namespace AdminKit\Localizations\UI\Filament\Filters; use AdminKit\Core\DTO\LocaleData; -use AdminKit\Core\Facades\AdminKit; use Filament\Forms\Components\Select; use Filament\Tables\Filters\Filter; use Illuminate\Database\Eloquent\Builder;