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,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