Merge branch 'master' of github.com:w00d5t0ck/kekrozsak
Conflicts: src/KekRozsak/AdminBundle/Controller/DefaultController.php
This commit is contained in:
commit
a9f3811299
@ -6,19 +6,27 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
|||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
|
||||||
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
|
||||||
|
use JMS\DiExtraBundle\Annotation as DI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/admin")
|
* @Route("/admin")
|
||||||
*/
|
*/
|
||||||
class DefaultController extends Controller
|
class DefaultController extends Controller
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* @var Symfony\Component\Security\Core\SecurityContext $securityContext
|
||||||
|
*
|
||||||
|
* @DI\Inject("security.context")
|
||||||
|
*/
|
||||||
|
private $securityContext;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/regisztraltak.html", name="KekRozsakAdminBundle_manage_regs")
|
* @Route("/regisztraltak.html", name="KekRozsakAdminBundle_manage_regs")
|
||||||
* @Template()
|
* @Template()
|
||||||
*/
|
*/
|
||||||
public function manageRegsAction()
|
public function manageRegsAction()
|
||||||
{
|
{
|
||||||
if (!$this->get('security.context')->isGranted('ROLE_ADMIN')) {
|
if (!$this->$securityContext->isGranted('ROLE_ADMIN')) {
|
||||||
throw new AccessDeniedException('Ehhez a művelethez nincs jogosultságod.');
|
throw new AccessDeniedException('Ehhez a művelethez nincs jogosultságod.');
|
||||||
}
|
}
|
||||||
$users = $this->getDoctrine()->getEntityManager()->createQuery('SELECT u FROM KekRozsakSecurityBundle:User u WHERE u.acceptedBy IS NULL')->getResult();
|
$users = $this->getDoctrine()->getEntityManager()->createQuery('SELECT u FROM KekRozsakSecurityBundle:User u WHERE u.acceptedBy IS NULL')->getResult();
|
||||||
@ -27,7 +35,7 @@ class DefaultController extends Controller
|
|||||||
if ($request->getMethod() == 'POST') {
|
if ($request->getMethod() == 'POST') {
|
||||||
if (is_numeric($userid = $request->get('userid'))) {
|
if (is_numeric($userid = $request->get('userid'))) {
|
||||||
if (($user = $this->getDoctrine()->getRepository('KekRozsakSecurityBundle:User')->findOneById($userid)) != null) {
|
if (($user = $this->getDoctrine()->getRepository('KekRozsakSecurityBundle:User')->findOneById($userid)) != null) {
|
||||||
$activeUser = $this->get('security.context')->getToken()->getUser();
|
$activeUser = $this->$securityContext->getToken()->getUser();
|
||||||
$user->setAcceptedBy($activeUser);
|
$user->setAcceptedBy($activeUser);
|
||||||
$em = $this->getDoctrine()->getEntityManager();
|
$em = $this->getDoctrine()->getEntityManager();
|
||||||
$em->persist($user);
|
$em->persist($user);
|
||||||
@ -49,17 +57,26 @@ class DefaultController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function groupJoinRequestsAction()
|
public function groupJoinRequestsAction()
|
||||||
{
|
{
|
||||||
$user = $this->get('security.context')->getToken()->getUser();
|
$user = $this->securityContext->getToken()->getUser();
|
||||||
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
|
||||||
$myGroups = $groupRepo->findByLeader($user);
|
|
||||||
|
|
||||||
$request = $this->getRequest();
|
$request = $this->getRequest();
|
||||||
|
|
||||||
|
$groupRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:Group');
|
||||||
|
if ($this->securityContext->isGranted('ROLE_ADMIN') === false) {
|
||||||
|
$myGroups = $groupRepo->findByLeader($user);
|
||||||
|
} else {
|
||||||
|
$myGroups = $groupRepo->findAll();
|
||||||
|
}
|
||||||
|
|
||||||
if ($request->getMethod() == 'POST') {
|
if ($request->getMethod() == 'POST') {
|
||||||
if ($request->request->has('group') && $request->request->has('user')) {
|
if ($request->request->has('group') && $request->request->has('user')) {
|
||||||
$userRepo = $this->getDoctrine()->getRepository('KekRozsakSecurityBundle:User');
|
$userRepo = $this->getDoctrine()->getRepository('KekRozsakSecurityBundle:User');
|
||||||
$aUser = $userRepo->findOneById($request->request->get('user'));
|
$aUser = $userRepo->findOneById($request->request->get('user'));
|
||||||
$aGroup = $groupRepo->findOneById($request->request->get('group'));
|
$aGroup = $groupRepo->findOneById($request->request->get('group'));
|
||||||
if ($aUser && $aGroup) {
|
if ($aUser && $aGroup) {
|
||||||
|
if (
|
||||||
|
($aGroup->getLeader() == $user)
|
||||||
|
|| $this->securityContext->isGranted('ROLE_ADMIN')
|
||||||
|
) {
|
||||||
$membershipRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:UserGroupMembership');
|
$membershipRepo = $this->getDoctrine()->getRepository('KekRozsakFrontBundle:UserGroupMembership');
|
||||||
$membershipObject = $membershipRepo->findOneBy(array('user' => $aUser, 'group' => $aGroup));
|
$membershipObject = $membershipRepo->findOneBy(array('user' => $aUser, 'group' => $aGroup));
|
||||||
if ($membershipObject) {
|
if ($membershipObject) {
|
||||||
@ -72,6 +89,9 @@ class DefaultController extends Controller
|
|||||||
|
|
||||||
return $this->redirect($this->generateUrl('KekRozsakAdminBundle_groupJoinRequests'));
|
return $this->redirect($this->generateUrl('KekRozsakAdminBundle_groupJoinRequests'));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
throw new AccessDeniedException('Csak a csoport vezetője hagyhatja jóvá a jelentkezéseket!');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user