First setup: module registry, switchable modules, permissions
This commit is contained in:
commit
936c794597
52 files changed
+1304
No files matched your search
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules;
|
||||
|
||||
use IriksIT\Manager\Contracts\Module;
|
||||
|
||||
/**
|
||||
* Convention over configuration: a module `Foo` lives in src/Modules/Foo, with
|
||||
* routes.php and a migrations/ folder next to its class when it needs them.
|
||||
*/
|
||||
abstract class BaseModule implements Module
|
||||
{
|
||||
public function enabledByDefault(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function requires(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function navigation(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function routes(): ?string
|
||||
{
|
||||
return $this->path('routes.php');
|
||||
}
|
||||
|
||||
public function migrations(): ?string
|
||||
{
|
||||
return $this->path('migrations');
|
||||
}
|
||||
|
||||
private function path(string $name): ?string
|
||||
{
|
||||
$path = dirname((new \ReflectionClass($this))->getFileName()).'/'.$name;
|
||||
|
||||
return file_exists($path) ? $path : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Media;
|
||||
|
||||
use IriksIT\Manager\Models\Media;
|
||||
|
||||
class MediaController
|
||||
{
|
||||
/** First opzet: lists the records as JSON. The screens come with the frontend. */
|
||||
public function index()
|
||||
{
|
||||
return response()->json(Media::query()->latest()->paginate(25));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Media;
|
||||
|
||||
use IriksIT\Manager\Modules\BaseModule;
|
||||
|
||||
class MediaModule extends BaseModule
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'media';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Media';
|
||||
}
|
||||
|
||||
public function enabledByDefault(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
return [
|
||||
'media.view' => 'See the media library',
|
||||
'media.upload' => 'Upload files',
|
||||
'media.edit' => 'Change name and description of a file',
|
||||
'media.delete' => 'Delete files',
|
||||
];
|
||||
}
|
||||
|
||||
public function navigation(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Media', 'route' => 'manager.media.index', 'permission' => 'media.view'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create(config('manager.table_prefix').'media', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('disk');
|
||||
$table->string('path');
|
||||
$table->string('filename');
|
||||
$table->string('mime_type');
|
||||
$table->unsignedBigInteger('size');
|
||||
$table->unsignedInteger('width')->nullable();
|
||||
$table->unsignedInteger('height')->nullable();
|
||||
$table->string('title')->nullable();
|
||||
$table->text('description')->nullable();
|
||||
$table->unsignedBigInteger('uploaded_by')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists(config('manager.table_prefix').'media');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use IriksIT\Manager\Modules\Media\MediaController;
|
||||
|
||||
Route::get('/media', [MediaController::class, 'index'])->name('media.index')->middleware('can:media.view');
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Pages;
|
||||
|
||||
use IriksIT\Manager\Models\Page;
|
||||
|
||||
class PagesController
|
||||
{
|
||||
/** First opzet: lists the records as JSON. The screens come with the frontend. */
|
||||
public function index()
|
||||
{
|
||||
return response()->json(Page::query()->latest()->paginate(25));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Pages;
|
||||
|
||||
use IriksIT\Manager\Modules\BaseModule;
|
||||
|
||||
class PagesModule extends BaseModule
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'pages';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Pages';
|
||||
}
|
||||
|
||||
public function enabledByDefault(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
return [
|
||||
'pages.edit' => 'Change the texts of the pages',
|
||||
];
|
||||
}
|
||||
|
||||
public function navigation(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Pages', 'route' => 'manager.pages.index', 'permission' => 'pages.edit'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create(config('manager.table_prefix').'pages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('slug')->unique();
|
||||
$table->string('title');
|
||||
$table->longText('body')->nullable();
|
||||
$table->boolean('is_published')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists(config('manager.table_prefix').'pages');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use IriksIT\Manager\Modules\Pages\PagesController;
|
||||
|
||||
Route::get('/pages', [PagesController::class, 'index'])->name('pages.index')->middleware('can:pages.edit');
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Posts;
|
||||
|
||||
use IriksIT\Manager\Models\Post;
|
||||
|
||||
class PostsController
|
||||
{
|
||||
/** First opzet: lists the records as JSON. The screens come with the frontend. */
|
||||
public function index()
|
||||
{
|
||||
return response()->json(Post::query()->latest()->paginate(25));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Posts;
|
||||
|
||||
use IriksIT\Manager\Modules\BaseModule;
|
||||
|
||||
class PostsModule extends BaseModule
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'posts';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Posts';
|
||||
}
|
||||
|
||||
public function enabledByDefault(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
return [
|
||||
'posts.view' => 'See the posts, drafts included',
|
||||
'posts.write' => 'Write and change posts',
|
||||
'posts.publish' => 'Publish and unpublish posts',
|
||||
'posts.delete' => 'Delete posts',
|
||||
];
|
||||
}
|
||||
|
||||
public function navigation(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Posts', 'route' => 'manager.posts.index', 'permission' => 'posts.view'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create(config('manager.table_prefix').'posts', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('slug')->unique();
|
||||
$table->string('title');
|
||||
$table->text('excerpt')->nullable();
|
||||
$table->longText('body')->nullable();
|
||||
$table->timestamp('published_at')->nullable()->index();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists(config('manager.table_prefix').'posts');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use IriksIT\Manager\Modules\Posts\PostsController;
|
||||
|
||||
Route::get('/posts', [PostsController::class, 'index'])->name('posts.index')->middleware('can:posts.view');
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Reviews;
|
||||
|
||||
use IriksIT\Manager\Models\Review;
|
||||
|
||||
class ReviewsController
|
||||
{
|
||||
/** First opzet: lists the records as JSON. The screens come with the frontend. */
|
||||
public function index()
|
||||
{
|
||||
return response()->json(Review::query()->latest()->paginate(25));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Reviews;
|
||||
|
||||
use IriksIT\Manager\Modules\BaseModule;
|
||||
|
||||
class ReviewsModule extends BaseModule
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'reviews';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Reviews';
|
||||
}
|
||||
|
||||
public function enabledByDefault(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
return [
|
||||
'reviews.manage' => 'Manage the reviews',
|
||||
];
|
||||
}
|
||||
|
||||
public function navigation(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Reviews', 'route' => 'manager.reviews.index', 'permission' => 'reviews.manage'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create(config('manager.table_prefix').'reviews', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('author');
|
||||
$table->string('place')->nullable();
|
||||
$table->unsignedTinyInteger('rating')->nullable();
|
||||
$table->text('body');
|
||||
$table->boolean('is_visible')->default(true);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists(config('manager.table_prefix').'reviews');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use IriksIT\Manager\Modules\Reviews\ReviewsController;
|
||||
|
||||
Route::get('/reviews', [ReviewsController::class, 'index'])->name('reviews.index')->middleware('can:reviews.manage');
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Users;
|
||||
|
||||
class UsersController
|
||||
{
|
||||
/** First opzet: lists the accounts as JSON. The screens come with the frontend. */
|
||||
public function index()
|
||||
{
|
||||
$user = config('manager.user_model');
|
||||
|
||||
return response()->json($user::query()->with('managerGroups')->latest()->paginate(25));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace IriksIT\Manager\Modules\Users;
|
||||
|
||||
use IriksIT\Manager\Modules\BaseModule;
|
||||
|
||||
class UsersModule extends BaseModule
|
||||
{
|
||||
public function key(): string
|
||||
{
|
||||
return 'users';
|
||||
}
|
||||
|
||||
public function label(): string
|
||||
{
|
||||
return 'Users';
|
||||
}
|
||||
|
||||
public function enabledByDefault(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function permissions(): array
|
||||
{
|
||||
return [
|
||||
'users.manage' => 'Create, change and delete accounts, and put them in groups',
|
||||
];
|
||||
}
|
||||
|
||||
public function navigation(): array
|
||||
{
|
||||
return [
|
||||
['label' => 'Users', 'route' => 'manager.users.index', 'permission' => 'users.manage'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
$prefix = config('manager.table_prefix');
|
||||
|
||||
Schema::create($prefix.'groups', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->json('permissions')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Schema::create($prefix.'group_user', function (Blueprint $table) use ($prefix) {
|
||||
$table->foreignId('group_id')->constrained($prefix.'groups')->cascadeOnDelete();
|
||||
$table->unsignedBigInteger('user_id')->index();
|
||||
$table->primary(['group_id', 'user_id']);
|
||||
});
|
||||
|
||||
Schema::table('users', function (Blueprint $table) {
|
||||
$table->boolean('manager_super_admin')->default(false);
|
||||
});
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
$prefix = config('manager.table_prefix');
|
||||
|
||||
Schema::table('users', fn (Blueprint $table) => $table->dropColumn('manager_super_admin'));
|
||||
Schema::dropIfExists($prefix.'group_user');
|
||||
Schema::dropIfExists($prefix.'groups');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use IriksIT\Manager\Modules\Users\UsersController;
|
||||
|
||||
Route::get('/users', [UsersController::class, 'index'])->name('users.index')->middleware('can:users.manage');
|
||||
Reference in new issue
Block a user