修改权限

This commit is contained in:
wuyanwen 2020-01-17 15:17:51 +08:00
parent fb482ded01
commit 691518c8c8
4 changed files with 47 additions and 53 deletions

View File

@ -24,6 +24,10 @@ class PermissionsMiddleware
*/
public function handle(Request $request, \Closure $next)
{
if ($request->isGet() && config('catch.is_allow_get')) {
return $next($request);
}
$rule = $request->rule()->getName();
if (!$rule) {

View File

@ -21,6 +21,7 @@ class Job extends CatchController
* @time 2020年01月09日
* @param CatchRequest $request
* @return \think\response\Json
* @throws \think\db\exception\DbException
*/
public function index(): \think\response\Json
{

View File

@ -7,7 +7,8 @@ use catcher\base\CatchController;
use catcher\CatchResponse;
use catcher\exceptions\FailedException;
use catcher\Tree;
use catchAdmin\permissions\model\Permissions as Permissions;
use catchAdmin\permissions\model\Permissions;
use think\response\Json;
class Permission extends CatchController
{
@ -22,55 +23,54 @@ class Permission extends CatchController
*
* @time 2019年12月11日
* @param Request $request
* @return \think\response\Json
* @return Json
*/
public function index()
public function index(): Json
{
return CatchResponse::success(Tree::done($this->permissions->getList()));
}
/**
*
* @time 2019年12月11日
* @throws \Exception
* @return string
*/
public function create()
{}
/**
*
* @time 2019年12月11日
* @param Request $request
* @return \think\response\Json
*/
public function save(Request $request)
/**
*
* @time 2019年12月11日
* @param Request $request
* @return Json
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\db\exception\DataNotFoundException
*/
public function save(Request $request): Json
{
$params = $request->param();
// 如果是子分类 自动写入父类模块
$parentId = $params['parent_id'] ?? 0;
if ($parentId) {
$parent = $this->permissions->findBy($parentId);
$params['module'] = $parent['module'];
}
return CatchResponse::success($this->permissions->storeBy($request->param()));
}
public function read()
{}
/**
*
* @time 2019年12月11日
* @param $id
* @throws \Exception
* @return string
*/
public function edit($id)
{}
/**
*
* @time 2019年12月11日
* @param $id
* @param Request $request
* @return \think\response\Json
* @return Json
*/
public function update($id, Request $request)
public function update($id, Request $request): Json
{
$permission = $this->permissions->findBy($id);
// 如果是父分类需要更新所有子分类的模块
if (!$permission->parent_id) {
$this->permissions->updateBy($permission->parent_id, [
'module' => $permission->module,
], 'parent_id');
}
return CatchResponse::success($this->permissions->updateBy($id, $request->param()));
}
@ -82,9 +82,9 @@ class Permission extends CatchController
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @return \think\response\Json
* @return Json
*/
public function delete($id)
public function delete($id): Json
{
if ($this->permissions->where('parent_id', $id)->find()) {
throw new FailedException('存在子菜单,无法删除');

View File

@ -1,6 +1,7 @@
<?php
namespace catchAdmin\permissions\controller;
use catchAdmin\permissions\model\Permissions;
use catcher\base\CatchRequest as Request;
use catcher\base\CatchController;
use catcher\CatchResponse;
@ -66,16 +67,6 @@ class Role extends CatchController
return CatchResponse::success($role);
}
/**
*
* @time 2019年12月11日
* @param $id
* @throws \Exception
* @return string
*/
public function edit($id)
{}
/**
*
* @time 2019年12月11日
@ -84,7 +75,7 @@ class Role extends CatchController
* @return Json
* @throws \think\db\exception\DbException
*/
public function update($id, Request $request)
public function update($id, Request $request): Json
{
$this->role->updateBy($id, $request->param());
@ -112,7 +103,7 @@ class Role extends CatchController
* @throws \think\db\exception\ModelNotFoundException
* @return Json
*/
public function delete($id)
public function delete($id): Json
{
if ($this->role->where('parent_id', $id)->find()) {
throw new FailedException('存在子角色,无法删除');
@ -139,7 +130,7 @@ class Role extends CatchController
*/
public function getPermissions(Request $request, \catchAdmin\permissions\model\Permissions $permission): Json
{
$parentRoleHasPermissionIds = null;
$parentRoleHasPermissionIds = [];
if ($request->param('parent_id')) {
$permissions = $this->role->findBy($request->param('parent_id'))->getPermissions();
foreach ($permissions as $_permission) {
@ -147,9 +138,7 @@ class Role extends CatchController
}
}
$permissions = Tree::done($permission->getList([
'permission_ids' => $parentRoleHasPermissionIds
]));
$permissions = Tree::done(Permissions::whereIn('id', $parentRoleHasPermissionIds)->select()->toArray());
$permissionIds = [];
if ($request->param('role_id')) {