Add annotations to APIRole and Role controllers #222

This commit is contained in:
Kendrick Chan 2019-06-08 14:52:01 +08:00
parent 4ccdb8c5aa
commit b6f7d70e13
2 changed files with 44 additions and 26 deletions

View file

@ -2,37 +2,37 @@
namespace App\Controller;
use App\Ramcar\BaseController;
use Catalyst\APIBundle\Entity\Role as APIRole;
use Catalyst\APIBundle\Access\Generator as APIACLGenerator;
use Doctrine\ORM\Query;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Doctrine\ORM\Query;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use App\Menu\Generator as MenuGenerator;
use Catalyst\MenuBundle\Annotation\Menu;
class APIRoleController extends BaseController
class APIRoleController extends Controller
{
protected $api_acl_gen;
public function __construct(MenuGenerator $menu_gen, APIACLGenerator $api_acl_gen)
public function __construct(APIACLGenerator $api_acl_gen)
{
$this->api_acl_gen = $api_acl_gen;
parent::__construct($menu_gen);
}
/**
* @Menu(selected="api_role_list")
*/
public function index()
{
$this->denyAccessUnlessGranted('apirole.list', null, 'No access.');
$params = $this->initParameters('api_role_list');
// response
return $this->render('api-role/list.html.twig', $params);
return $this->render('api-role/list.html.twig');
}
public function rows(Request $req)
@ -128,11 +128,14 @@ class APIRoleController extends BaseController
]);
}
/**
* @Menu(selected="api_role_list")
*/
public function addForm()
{
$this->denyAccessUnlessGranted('apirole.add', null, 'No access.');
$params = $this->initParameters('apirole_list');
$params = [];
$this->padAPIACLHierarchy($params);
$params['obj'] = new APIRole();
$params['mode'] = 'create';
@ -194,11 +197,14 @@ class APIRoleController extends BaseController
}
}
/**
* @Menu(selected="api_role_list")
*/
public function updateForm($id)
{
$this->denyAccessUnlessGranted('apirole.update', null, 'No access.');
$params = $this->initParameters('api_role_list');
$params = [];
$this->padAPIACLHierarchy($params);
$params['mode'] = 'update';
@ -291,11 +297,14 @@ class APIRoleController extends BaseController
}
}
/**
* @Menu(selected="api_role_list")
*/
public function destroy($id)
{
$this->denyAccessUnlessGranted('apirole.delete', null, 'No access.');
$params = $this->initParameters('apirole_list');
$params = [];
// get row data
$em = $this->getDoctrine()->getManager();

View file

@ -2,36 +2,36 @@
namespace App\Controller;
use App\Ramcar\BaseController;
use App\Entity\Role;
use Doctrine\ORM\Query;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Component\HttpFoundation\Request;
use Doctrine\ORM\Query;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
use App\Menu\Generator as MenuGenerator;
use Catalyst\AuthBundle\Service\ACLGenerator;
use Catalyst\MenuBundle\Annotation\Menu;
class RoleController extends BaseController
class RoleController extends Controller
{
protected $acl_gen;
public function __construct(MenuGenerator $menu_gen, ACLGenerator $acl_gen)
public function __construct(ACLGenerator $acl_gen)
{
$this->acl_gen = $acl_gen;
parent::__construct($menu_gen);
}
/**
* @Menu(selected="role_list")
*/
public function index()
{
$this->denyAccessUnlessGranted('role.list', null, 'No access.');
$params = $this->initParameters('role_list');
// response
return $this->render('role/list.html.twig', $params);
return $this->render('role/list.html.twig');
}
public function rows(Request $req)
@ -134,11 +134,14 @@ class RoleController extends BaseController
$params['acl_hierarchy'] = $acl_data['hierarchy'];
}
/**
* @Menu(selected="role_list")
*/
public function addForm()
{
$this->denyAccessUnlessGranted('role.add', null, 'No access.');
$params = $this->initParameters('role_list');
$params = [];
$this->padACLHierarchy($params);
$params['obj'] = new Role();
$params['mode'] = 'create';
@ -200,11 +203,14 @@ class RoleController extends BaseController
}
}
/**
* @Menu(selected="role_list")
*/
public function updateForm($id)
{
$this->denyAccessUnlessGranted('role.update', null, 'No access.');
$params = $this->initParameters('role_list');
$params = [];
$this->padACLHierarchy($params);
$params['mode'] = 'update';
@ -297,11 +303,14 @@ class RoleController extends BaseController
}
}
/**
* @Menu(selected="role_list")
*/
public function destroy($id)
{
$this->denyAccessUnlessGranted('role.delete', null, 'No access.');
$params = $this->initParameters('role_list');
$params = [];
// get row data
$em = $this->getDoctrine()->getManager();