mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-15 05:00:49 +08:00
cresate role basic tables
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Models\ExamUser;
|
||||
use App\Models\HitAndRun;
|
||||
use App\Models\Medal;
|
||||
use App\Models\Peer;
|
||||
use App\Models\Role;
|
||||
use App\Models\SearchBox;
|
||||
use App\Models\Snatch;
|
||||
use App\Models\Tag;
|
||||
@@ -86,8 +87,7 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$r = date('P');
|
||||
dd($r);
|
||||
Role::initClassRoles();
|
||||
}
|
||||
|
||||
|
||||
|
||||
68
app/Filament/Resources/Permission/PermissionResource.php
Normal file
68
app/Filament/Resources/Permission/PermissionResource.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Permission;
|
||||
|
||||
use App\Filament\Resources\Permission\PermissionResource\Pages;
|
||||
use App\Filament\Resources\Permission\PermissionResource\RelationManagers;
|
||||
use App\Models\Permission;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class PermissionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Permission::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-lock-open';
|
||||
|
||||
protected static ?string $navigationGroup = 'Permission';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.permissions');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
//
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
Tables\Actions\DeleteAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ManagePermissions::route('/'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Permission\PermissionResource\Pages;
|
||||
|
||||
use App\Filament\Resources\Permission\PermissionResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ManageRecords;
|
||||
|
||||
class ManagePermissions extends ManageRecords
|
||||
{
|
||||
protected static string $resource = PermissionResource::class;
|
||||
|
||||
protected ?string $maxContentWidth = 'full';
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
79
app/Filament/Resources/Permission/RoleResource.php
Normal file
79
app/Filament/Resources/Permission/RoleResource.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Permission;
|
||||
|
||||
use App\Filament\Resources\Permission\RoleResource\Pages;
|
||||
use App\Filament\Resources\Permission\RoleResource\RelationManagers;
|
||||
use App\Models\Role;
|
||||
use Filament\Forms;
|
||||
use Filament\Resources\Form;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Resources\Table;
|
||||
use Filament\Tables;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\SoftDeletingScope;
|
||||
|
||||
class RoleResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Role::class;
|
||||
|
||||
protected static ?string $navigationIcon = 'heroicon-o-user-group';
|
||||
|
||||
protected static ?string $navigationGroup = 'Permission';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static function getNavigationLabel(): string
|
||||
{
|
||||
return __('admin.sidebar.roles');
|
||||
}
|
||||
|
||||
public static function getBreadcrumb(): string
|
||||
{
|
||||
return self::getNavigationLabel();
|
||||
}
|
||||
|
||||
public static function form(Form $form): Form
|
||||
{
|
||||
return $form
|
||||
->schema([
|
||||
//
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->columns([
|
||||
Tables\Columns\TextColumn::make('id'),
|
||||
Tables\Columns\TextColumn::make('name')->label(__('label.name')),
|
||||
Tables\Columns\TextColumn::make('classText')->label(__('label.role.class')),
|
||||
Tables\Columns\TextColumn::make('updated_at')->label(__('label.updated_at')),
|
||||
])
|
||||
->filters([
|
||||
//
|
||||
])
|
||||
->actions([
|
||||
Tables\Actions\EditAction::make(),
|
||||
])
|
||||
->bulkActions([
|
||||
Tables\Actions\DeleteBulkAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => Pages\ListRoles::route('/'),
|
||||
'create' => Pages\CreateRole::route('/create'),
|
||||
'edit' => Pages\EditRole::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Permission\RoleResource\Pages;
|
||||
|
||||
use App\Filament\Resources\Permission\RoleResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateRole extends CreateRecord
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Permission\RoleResource\Pages;
|
||||
|
||||
use App\Filament\Resources\Permission\RoleResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditRole extends EditRecord
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Permission\RoleResource\Pages;
|
||||
|
||||
use App\Filament\PageList;
|
||||
use App\Filament\Resources\Permission\RoleResource;
|
||||
use Filament\Pages\Actions;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListRoles extends PageList
|
||||
{
|
||||
protected static string $resource = RoleResource::class;
|
||||
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
Actions\CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
11
app/Models/Permission.php
Normal file
11
app/Models/Permission.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Permission extends NexusModel
|
||||
{
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = ['name', ];
|
||||
|
||||
}
|
||||
37
app/Models/Role.php
Normal file
37
app/Models/Role.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class Role extends NexusModel
|
||||
{
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = ['name', 'class'];
|
||||
|
||||
public function permissions(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Permission::class, 'role_id');
|
||||
}
|
||||
|
||||
public function getClassTextAttribute()
|
||||
{
|
||||
if ($this->class < 0) {
|
||||
return '';
|
||||
}
|
||||
return User::getClassText($this->class);
|
||||
}
|
||||
|
||||
public static function initClassRoles()
|
||||
{
|
||||
foreach (User::$classes as $class => $info) {
|
||||
$attributes = [
|
||||
'class' => $class
|
||||
];
|
||||
$values = [
|
||||
'name' => $info['text'],
|
||||
];
|
||||
Role::query()->firstOrCreate($attributes, $values);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
11
app/Models/RolePermission.php
Normal file
11
app/Models/RolePermission.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class RolePermission extends NexusModel
|
||||
{
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = ['role_id', 'permission_id'];
|
||||
|
||||
}
|
||||
@@ -93,11 +93,20 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
|
||||
public function getClassTextAttribute(): string
|
||||
{
|
||||
if (!isset(self::$classes[$this->class]['text'])) {
|
||||
return self::getClassText($this->class);
|
||||
}
|
||||
|
||||
public static function getClassText($class)
|
||||
{
|
||||
if (!isset(self::$classes[$class])) {
|
||||
return '';
|
||||
}
|
||||
$classText = self::$classes[$this->class]['text'];
|
||||
$alias = Setting::get("account.{$this->class}_alias");
|
||||
if ($class >= self::CLASS_VIP) {
|
||||
$classText = nexus_trans('user.class_names.' . $class);
|
||||
} else {
|
||||
$classText = self::$classes[$class]['text'];
|
||||
}
|
||||
$alias = Setting::get("account.{$class}_alias");
|
||||
if (!empty($alias)) {
|
||||
$classText .= "({$alias})";
|
||||
}
|
||||
@@ -449,6 +458,16 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
return $this->hasMany(UsernameChangeLog::class, 'uid');
|
||||
}
|
||||
|
||||
public function roles()
|
||||
{
|
||||
return $this->belongsToMany(Role::class, 'user_roles', 'uid', 'role_id')->withTimestamps();
|
||||
}
|
||||
|
||||
public function permissions()
|
||||
{
|
||||
return $this->belongsToMany(Permission::class, 'user_permissions', 'uid', 'permission_id')->withTimestamps();
|
||||
}
|
||||
|
||||
public function getAvatarAttribute($value)
|
||||
{
|
||||
if ($value) {
|
||||
|
||||
11
app/Models/UserPermission.php
Normal file
11
app/Models/UserPermission.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UserPermission extends NexusModel
|
||||
{
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = ['uid', 'permission_id'];
|
||||
|
||||
}
|
||||
11
app/Models/UserRole.php
Normal file
11
app/Models/UserRole.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
class UserRole extends NexusModel
|
||||
{
|
||||
public $timestamps = true;
|
||||
|
||||
protected $fillable = ['uid', 'role_id'];
|
||||
|
||||
}
|
||||
@@ -40,6 +40,7 @@ class AppServiceProvider extends ServiceProvider
|
||||
'User',
|
||||
'Torrent',
|
||||
'Other',
|
||||
'Permission',
|
||||
'System',
|
||||
]);
|
||||
});
|
||||
|
||||
33
database/migrations/2022_08_17_052202_create_roles_table.php
Normal file
33
database/migrations/2022_08_17_052202_create_roles_table.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->integer('class')->default(-1);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('roles');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('permissions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('permissions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('role_permissions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('role_id');
|
||||
$table->integer('permission_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('role_permissions');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_roles', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('uid');
|
||||
$table->integer('role_id');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('user_roles');
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('user_permissions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->integer('uid');
|
||||
$table->integer('permission_id');
|
||||
$table->text('payload');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('user_permissions');
|
||||
}
|
||||
};
|
||||
@@ -15,8 +15,6 @@ return [
|
||||
'claims' => '用户认领',
|
||||
'torrent_list' => '种子',
|
||||
'torrent_state' => '全站优惠',
|
||||
'roles_list' => '角色',
|
||||
'ability_list' => '权限',
|
||||
'seed_box_records' => 'SeedBox',
|
||||
'upload_speed' => '上行带宽',
|
||||
'download_speed' => '下行带宽',
|
||||
@@ -24,6 +22,8 @@ return [
|
||||
'menu' => '自定义菜单',
|
||||
'username_change_log' => '改名记录',
|
||||
'torrent_deny_reason' => '拒绝原因',
|
||||
'roles' => '角色',
|
||||
'permissions' => '权限',
|
||||
],
|
||||
'resources' => [
|
||||
'agent_allow' => [
|
||||
|
||||
Reference in New Issue
Block a user