Skip to content

Commit 2b1134a

Browse files
committed
fix:修改
1 parent 6f12fa3 commit 2b1134a

File tree

5 files changed

+78
-4
lines changed

5 files changed

+78
-4
lines changed

config/routing/admin/admin.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ admin_manage_edit_password:
1818
path: /edit-password
1919
controller: App\Controller\Admin\AuthController:editPassword
2020

21+
# 清除缓存
22+
admin_manage_clearCache:
23+
path: /clearCache
24+
controller: App\Controller\Admin\AdminController:clearCache
25+
2126
# 管理端-统计台
2227
admin_manage_statistical_station:
2328
prefix: /statistical-station

src/Business/AdminBusiness/AdminAuth.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010

1111
namespace App\Business\AdminBusiness;
1212

13+
use App\Business\AuthBusiness\CurAuthSubject;
1314
use App\Business\AuthBusiness\SubjectAuthInterface;
1415
use App\Business\AuthBusiness\UserAuthBusiness;
16+
use App\Business\PlatformBusiness\PlatformClass;
17+
use App\Business\RBACBusiness\RBACBusiness;
1518
use App\Entity\Admin;
1619
use App\Entity\UserAuth;
1720
use App\Repository\AdminRepository;
@@ -182,7 +185,27 @@ public function delete(Admin $admin)
182185
*/
183186
public function inletSet(UserAuth $userAuth)
184187
{
188+
$rbac = new RBACBusiness($this->container, PlatformClass::getPlatform());
189+
$user = $this->adminRepository->find($userAuth->getSubjectId());
190+
$rbac->setIsSuper($user->getIsSuper());
191+
192+
if(!$rbac->can('statistical_station', 'and', $userAuth)) {
193+
if($rbac->can('classify', 'and', $userAuth)){
194+
$curAuthSuccessGoUrl = $this->generateUrl('admin_manage_sort_index');
195+
}elseif ($rbac->can('user', 'and', $userAuth)){
196+
$curAuthSuccessGoUrl = $this->generateUrl('admin_users_index');
197+
}elseif ($rbac->can('blog_manage', 'and', $userAuth)){
198+
$curAuthSuccessGoUrl = $this->generateUrl('admin_blog_manage_article_index');
199+
}elseif ($rbac->can('system-setting', 'and', $userAuth)){
200+
$curAuthSuccessGoUrl = $this->generateUrl('admin_manage_admin_role_index');
201+
}
202+
}else{
203+
$curAuthSuccessGoUrl = $this->generateUrl('admin_manage_statistical_station_index');
204+
}
185205

206+
if(!empty($curAuthSuccessGoUrl)){
207+
CurAuthSubject::setCurAuthSuccessGoUrl($curAuthSuccessGoUrl);
208+
}
186209
}
187210

188211
}

src/Business/ArticleBusiness/ArticleBusiness.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ public function validator($class): bool
7373
*
7474
* @param Article $article
7575
* @param null $labels
76-
* @param null $sort
76+
* @param false $is_built
7777
* @return bool
7878
* @throws \Doctrine\DBAL\ConnectionException
7979
*/
80-
public function create(Article $article, $labels = null, $sort = null)
80+
public function create(Article $article, $labels = null, $is_built = false)
8181
{
8282
if(!$this->validator($article)){
8383
return false;
@@ -113,6 +113,11 @@ public function create(Article $article, $labels = null, $sort = null)
113113
}
114114
}
115115

116+
if($is_built){
117+
$user = $this->getDoctrine()->getRepository('App:Admin')->findAssoc(['name' => '超级管理员']);
118+
$article->setUserAuth($user->getUserAuth());
119+
}
120+
116121
$this->em->flush();
117122

118123
$this->conn->commit();

src/Controller/Admin/AdminController.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use App\Business\AuthBusiness\CurAuthSubject;
1414
use App\Business\AuthBusiness\UserAuthBusiness;
1515
use App\Business\PlatformBusiness\PlatformClass;
16+
use App\Business\RBACBusiness\PermissionBusiness;
17+
use App\Business\RBACBusiness\RBACBusiness;
1618
use App\Entity\UserAuth;
1719
use App\Repository\AdminRepository;
1820
use PHPZlc\Admin\Strategy\AdminStrategy;
@@ -21,6 +23,7 @@
2123
use PHPZlc\PHPZlc\Bundle\Controller\SystemBaseController;
2224
use PHPZlc\PHPZlc\Doctrine\ORM\Rule\Rule;
2325
use PHPZlc\PHPZlc\Responses\Responses;
26+
use Symfony\Component\HttpFoundation\JsonResponse;
2427
use Symfony\Component\HttpFoundation\RedirectResponse;
2528
use Symfony\Component\HttpFoundation\Response;
2629

@@ -54,11 +57,17 @@ class AdminController extends SystemBaseController
5457
*/
5558
protected $page_tag;
5659

60+
/**
61+
* @var RBACBusiness
62+
*/
63+
protected $rbac;
64+
5765
public function inlet($returnType = SystemBaseController::RETURN_HIDE_RESOURCE, $isLogin = true)
5866
{
5967
PlatformClass::setPlatform($this->getParameter('platform_admin'));
6068

6169
$this->adminRepository = $this->getDoctrine()->getRepository('App:Admin');
70+
$this->rbac = new RBACBusiness($this->container, PlatformClass::getPlatform());
6271

6372
//菜单
6473
$menus = [
@@ -89,6 +98,7 @@ public function inlet($returnType = SystemBaseController::RETURN_HIDE_RESOURCE,
8998
->setSettingPwdUrl($this->generateUrl('admin_manage_edit_password'))
9099
->setMenuModel(AdminStrategy::menu_model_simple)
91100
->setPageTag($this->page_tag)
101+
->setClearCacheApiUrl($this->generateUrl('admin_manage_clearCache'))
92102
->setLogo($this->adminStrategy->getBaseUrl() . '/asset/logo.png')
93103
->setMenus($menus);
94104

@@ -115,11 +125,19 @@ public function inlet($returnType = SystemBaseController::RETURN_HIDE_RESOURCE,
115125
$this->adminStrategy->setAdminName(CurAuthSubject::getCurUser()->getAccount());
116126
$this->adminStrategy->setAdminRoleName(CurAuthSubject::getCurUser()->getName());
117127

128+
$this->rbac->setIsSuper(CurAuthSubject::getCurUser()->getIsSuper());
118129

119130
//对路由进行权限校验
120-
131+
if(!$this->rbac->canRoute($this->get('request_stack')->getCurrentRequest()->get('_route'))){
132+
if(self::getReturnType() == SystemBaseController::RETURN_HIDE_RESOURCE){
133+
return Responses::error('权限不足');
134+
}else{
135+
return $this->render('@PHPZlcAdmin/page/no_permission.html.twig');
136+
}
137+
}
121138

122139
//对菜单进行权限筛选
140+
$this->adminStrategy->setMenus($this->rbac->menusFilter($this->adminStrategy->getMenus()));
123141
}
124142

125143
return true;
@@ -145,6 +163,29 @@ public function index()
145163
return $this->render('admin/auth/login.html.twig');
146164
}
147165

166+
/**
167+
* 清除缓存
168+
*
169+
* @return bool|JsonResponse|RedirectResponse|Response
170+
*/
171+
public function clearCache()
172+
{
173+
$r = $this->inlet();
174+
if($r !== true){
175+
return $r;
176+
}
177+
178+
(new PermissionBusiness($this->container))->builtUpdatePermission();
179+
180+
$this->get('session')->remove(($this->rbac->getCacheSessionName()));
181+
182+
if(Errors::isExistError()){
183+
return Responses::error(Errors::getError());
184+
}
185+
186+
return Responses::success('缓存清除成功');
187+
}
188+
148189
/**
149190
* 时间段筛选
150191
*

src/DataFixtures/BlogFixtures.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,6 @@ public function load(ObjectManager $manager)
5858

5959
$labels[] = $label->getId();
6060

61-
(new ArticleBusiness($this->container))->create($article, $labels);
61+
(new ArticleBusiness($this->container))->create($article, $labels, true );
6262
}
6363
}

0 commit comments

Comments
 (0)