Browse Source

Use isGranted shortcut

Jordi Boggiano 9 years ago
parent
commit
34d8b42e42

+ 3 - 3
src/Packagist/WebBundle/Controller/PackageController.php

@@ -30,7 +30,7 @@ class PackageController extends Controller
      */
     public function editAction(Request $req, Package $package)
     {
-        if (!$package->getMaintainers()->contains($this->getUser()) && !$this->get('security.authorization_checker')->isGranted('ROLE_EDIT_PACKAGES')) {
+        if (!$package->getMaintainers()->contains($this->getUser()) && !$this->isGranted('ROLE_EDIT_PACKAGES')) {
             throw new AccessDeniedException;
         }
 
@@ -72,7 +72,7 @@ class PackageController extends Controller
      */
     public function abandonAction(Request $request, Package $package)
     {
-        if (!$package->getMaintainers()->contains($this->getUser()) && !$this->get('security.authorization_checker')->isGranted('ROLE_EDIT_PACKAGES')) {
+        if (!$package->getMaintainers()->contains($this->getUser()) && !$this->isGranted('ROLE_EDIT_PACKAGES')) {
             throw new AccessDeniedException;
         }
 
@@ -106,7 +106,7 @@ class PackageController extends Controller
      */
     public function unabandonAction(Package $package)
     {
-        if (!$package->getMaintainers()->contains($this->getUser()) && !$this->get('security.authorization_checker')->isGranted('ROLE_EDIT_PACKAGES')) {
+        if (!$package->getMaintainers()->contains($this->getUser()) && !$this->isGranted('ROLE_EDIT_PACKAGES')) {
             throw new AccessDeniedException;
         }
 

+ 6 - 6
src/Packagist/WebBundle/Controller/WebController.php

@@ -701,7 +701,7 @@ class WebController extends Controller
             $data['deleteForm'] = $deleteForm->createView();
         }
         if ($this->getUser() && (
-            $this->get('security.authorization_checker')->isGranted('ROLE_DELETE_PACKAGES')
+            $this->isGranted('ROLE_DELETE_PACKAGES')
             || $package->getMaintainers()->contains($this->getUser())
         )) {
             $data['deleteVersionCsrfToken'] = $this->get('security.csrf.token_manager')->getToken('delete_version');
@@ -805,7 +805,7 @@ class WebController extends Controller
         $version = $repo->getFullVersion($versionId);
         $package = $version->getPackage();
 
-        if (!$package->getMaintainers()->contains($this->getUser()) && !$this->get('security.authorization_checker')->isGranted('ROLE_DELETE_PACKAGES')) {
+        if (!$package->getMaintainers()->contains($this->getUser()) && !$this->isGranted('ROLE_DELETE_PACKAGES')) {
             throw new AccessDeniedException;
         }
 
@@ -859,7 +859,7 @@ class WebController extends Controller
             return new Response(json_encode(array('status' => 'error', 'message' => 'Invalid credentials',)), 403);
         }
 
-        if ($package->getMaintainers()->contains($user) || $this->get('security.authorization_checker')->isGranted('ROLE_UPDATE_PACKAGES')) {
+        if ($package->getMaintainers()->contains($user) || $this->isGranted('ROLE_UPDATE_PACKAGES')) {
             $req->getSession()->save();
 
             if (null !== $autoUpdated) {
@@ -1171,7 +1171,7 @@ class WebController extends Controller
             return;
         }
 
-        if ($this->get('security.authorization_checker')->isGranted('ROLE_EDIT_PACKAGES') || $package->getMaintainers()->contains($user)) {
+        if ($this->isGranted('ROLE_EDIT_PACKAGES') || $package->getMaintainers()->contains($user)) {
             $maintainerRequest = new MaintainerRequest;
             return $this->createForm(new AddMaintainerRequestType, $maintainerRequest);
         }
@@ -1183,7 +1183,7 @@ class WebController extends Controller
             return;
         }
 
-        if ($this->get('security.authorization_checker')->isGranted('ROLE_EDIT_PACKAGES') || $package->getMaintainers()->contains($user)) {
+        if ($this->isGranted('ROLE_EDIT_PACKAGES') || $package->getMaintainers()->contains($user)) {
             $maintainerRequest = new MaintainerRequest;
             return $this->createForm(new RemoveMaintainerRequestType(), $maintainerRequest, array('package'=>$package, 'excludeUser'=>$user));
         }
@@ -1196,7 +1196,7 @@ class WebController extends Controller
         }
 
         // super admins bypass additional checks
-        if (!$this->get('security.authorization_checker')->isGranted('ROLE_DELETE_PACKAGES')) {
+        if (!$this->isGranted('ROLE_DELETE_PACKAGES')) {
             // non maintainers can not delete
             if (!$package->getMaintainers()->contains($user)) {
                 return;