-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(permissions): remove Casbin and refactor permission logic (#399
) * refactor(permissions): remove Casbin and refactor permission logic - Remove Casbin dependency and related code - Refactor permission logic to use database-based approach - Update menu and role models to use new permission system - Modify permission controller and middleware to reflect changes - Update tests to cover new permission functionality * refactor(user-seeder): remove unused import - Remove unused import of Casbin\Enforcer from user_seeder_20240926.php * refactor(casbin): remove casbin factory and update role status - Remove Casbin\Enforcer and Mine\Casbin\Factory from dependencies.php- Comment out 'adapter' setting in permission.php - Update RoleSchema to use status value instead of status object- Improve type safety in RoleService by ignoring phpstan check * refactor(config): update dependencies and permission configurations - Update UploadInterface class reference in dependencies.php - Comment out adapter setting in permission.php
- Loading branch information
Showing
39 changed files
with
393 additions
and
491 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* This file is part of MineAdmin. | ||
* | ||
* @link https://www.mineadmin.com | ||
* @document https://doc.mineadmin.com | ||
* @contact [email protected] | ||
* @license https://github.com/mineadmin/MineAdmin/blob/master/LICENSE | ||
*/ | ||
|
||
namespace App\Command; | ||
|
||
use App\Model\Permission\Menu; | ||
use App\Model\Permission\Role; | ||
use App\Model\Permission\User; | ||
use Hyperf\Command\Annotation\AsCommand; | ||
use Hyperf\Command\Concerns\InteractsWithIO; | ||
use Hyperf\DbConnection\Db; | ||
|
||
class UpdateCommand | ||
{ | ||
use InteractsWithIO; | ||
|
||
#[AsCommand( | ||
signature: 'mine:update-20241031' | ||
)] | ||
public function handle() | ||
{ | ||
$this->output->title('Update 2024_10_31_193302_create_user_belongs_role'); | ||
Db::table(\Hyperf\Config\config('permission.database.table'))->insert([ | ||
'v0' => 'admin', | ||
'v1' => 'superAdmin', | ||
'ptype' => 'g', | ||
]); | ||
$result = Db::table(\Hyperf\Config\config('permission.database.table'))->select([ | ||
'v1', 'v0', 'ptype', | ||
])->get(); | ||
$result->map(static function (\stdClass $item) { | ||
if ($item->ptype === 'g') { | ||
$username = $item->v0; | ||
$roleCode = $item->v1; | ||
$userId = User::where('username', $username)->value('id'); | ||
$roleId = Role::where('code', $roleCode)->value('id'); | ||
$userId && $roleId && Db::table('user_belongs_role')->insert([ | ||
'user_id' => $userId, | ||
'role_id' => $roleId, | ||
'created_at' => date('Y-m-d H:i:s'), | ||
'updated_at' => date('Y-m-d H:i:s'), | ||
]); | ||
} elseif ($item->ptype === 'p') { | ||
$menuId = Menu::where('name', $item->v1)->value('id'); | ||
$roleId = Role::where('code', $item->v0)->value('id'); | ||
$menuId && $roleId && Db::table('user_belongs_role')->insert([ | ||
'menu_id' => $menuId, | ||
'role_id' => $roleId, | ||
'created_at' => date('Y-m-d H:i:s'), | ||
'updated_at' => date('Y-m-d H:i:s'), | ||
]); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.