mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
Refactoring user permissions
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use Nexus\Plugin\BasePlugin;
|
||||
|
||||
class Plugin extends Command
|
||||
{
|
||||
@@ -30,11 +31,18 @@ class Plugin extends Command
|
||||
$plugin = new \Nexus\Plugin\Plugin();
|
||||
$action = $this->argument('action');
|
||||
$name = $this->argument('name');
|
||||
/** @var BasePlugin $mainClass */
|
||||
$mainClass = $plugin->getMainClass($name);
|
||||
if (!$mainClass) {
|
||||
$this->error("Can not find plugin: $name");
|
||||
return 1;
|
||||
}
|
||||
try {
|
||||
$mainClass->checkMainApplicationVersion();
|
||||
} catch (\Exception $exception) {
|
||||
$this->error($exception->getMessage());
|
||||
return 1;
|
||||
}
|
||||
if ($action == 'install') {
|
||||
call_user_func([$mainClass, 'install']);
|
||||
} elseif ($action == 'uninstall') {
|
||||
|
||||
@@ -86,9 +86,9 @@ class Test extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$user = User::query()->find(10003);
|
||||
$permissions = $user->rolePermissions;
|
||||
dd($permissions);
|
||||
$role = Role::query()->first();
|
||||
$r = $role->permissions()->createMany([['permission' => 'sss']]);
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,9 +11,9 @@ class Setting extends NexusModel
|
||||
|
||||
public $timestamps = true;
|
||||
|
||||
public static array $permissionDegeneration = [
|
||||
'torrent-approval' => 'torrentmanage',
|
||||
];
|
||||
const PERMISSION_NO_CLASS = 100;
|
||||
|
||||
public static array $permissionMustHaveClass = ['defaultclass', 'staffmem'];
|
||||
|
||||
/**
|
||||
* get setting autoload = yes with cache
|
||||
|
||||
+5
-5
@@ -17,8 +17,8 @@ use Laravel\Sanctum\HasApiTokens;
|
||||
use Nexus\Database\NexusDB;
|
||||
use Filament\Models\Contracts\FilamentUser;
|
||||
use Filament\Models\Contracts\HasName;
|
||||
use NexusPlugin\Permission\Models\Permission;
|
||||
use NexusPlugin\Permission\Models\Role;
|
||||
use NexusPlugin\Permission\Models\UserPermission;
|
||||
|
||||
class User extends Authenticatable implements FilamentUser, HasName
|
||||
{
|
||||
@@ -239,15 +239,15 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
|
||||
public static function getClassName($class, $compact = false, $b_colored = false, $I18N = false)
|
||||
{
|
||||
$class_name = self::$classes[$class]['text'];
|
||||
$class_name = self::$classes[$class]['text'] ?? '';
|
||||
if ($class >= self::CLASS_VIP && $I18N) {
|
||||
$class_name = nexus_trans("user.class_names.$class");
|
||||
}
|
||||
$class_name_color = self::$classes[$class]['text'];
|
||||
$class_name_color = self::$classes[$class]['text'] ?? '';
|
||||
if ($compact) {
|
||||
$class_name = str_replace(" ", "",$class_name);
|
||||
}
|
||||
if ($b_colored) {
|
||||
if ($class_name && $b_colored) {
|
||||
return "<b class='" . str_replace(" ", "",$class_name_color) . "_Name'>" . $class_name . "</b>";
|
||||
}
|
||||
return $class_name;
|
||||
@@ -476,7 +476,7 @@ class User extends Authenticatable implements FilamentUser, HasName
|
||||
|
||||
public function directPermissions()
|
||||
{
|
||||
return $this->belongsToMany(Permission::class, 'user_permissions', 'uid', 'permission_id')->withTimestamps();
|
||||
return $this->hasMany(UserPermission::class, 'uid');
|
||||
}
|
||||
|
||||
public function getAvatarAttribute($value)
|
||||
|
||||
@@ -40,7 +40,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
'User',
|
||||
'Torrent',
|
||||
'Other',
|
||||
'Permission',
|
||||
'System',
|
||||
]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user