hide inactive delete user button #78 (#79)

This commit is contained in:
Kevin Papst
2018-01-10 23:14:58 +01:00
committed by GitHub
parent 36e72552d8
commit 2644818547
9 changed files with 33 additions and 164 deletions

View File

@@ -116,20 +116,6 @@ class ProfileController extends AbstractController
return $this->getProfileView($profile, null, null, $rolesForm, 'roles');
}
/**
* FIXME implement profile deletion
*
* @Route("/{username}/delete", name="user_profile_delete")
* @Method({"GET", "POST"})
* @Security("is_granted('delete', profile)")
*/
public function deleteAction(User $profile, Request $request)
{
$deleteForm = $this->createDeleteForm($profile);
throw new \Exception('Delete not implemented yet');
}
/**
* @param User $user
* @param Form|null $editForm
@@ -225,17 +211,4 @@ class ProfileController extends AbstractController
]
);
}
/**
* @param User $user
* @return \Symfony\Component\Form\FormInterface
*/
private function createDeleteForm(User $user)
{
return $this->createFormBuilder()
->setAction($this->generateUrl('user_profile_delete', ['username' => $user->getUsername()]))
->setMethod('DELETE')
->getForm()
;
}
}

View File

@@ -70,11 +70,10 @@ class UserVoter extends AbstractVoter
case self::EDIT:
case self::PASSWORD:
return $this->canEdit($subject, $user, $token);
case self::VIEW_ALL:
case self::CREATE:
// create actually passes in the current user as $subject, not the new one
case self::DELETE:
// if we allow to delete user for ADMIN: make sure the user to be deleted is not in a higher level
return $this->canDelete($subject, $user, $token);
case self::VIEW_ALL:
case self::CREATE: // create actually passes in the current user as $subject, not the new one
case self::ROLES:
return $this->canAdminUsers($token);
}
@@ -110,6 +109,16 @@ class UserVoter extends AbstractVoter
return $profile->getId() == $user->getId();
}
/**
* @param User $profile
* @param User $user
* @return bool
*/
protected function canDelete(User $profile, User $user, TokenInterface $token)
{
return false;
}
/**
* @param TokenInterface $token
* @return bool

View File

@@ -21,7 +21,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use TimesheetBundle\Entity\Customer;
use TimesheetBundle\Entity\Project;
use TimesheetBundle\Form\ActivityDeleteForm;
use TimesheetBundle\Form\ActivityEditForm;
use TimesheetBundle\Form\Toolbar\ActivityToolbarForm;
use TimesheetBundle\Repository\Query\ActivityQuery;
@@ -141,10 +140,10 @@ class ActivityController extends AbstractController
{
$stats = $this->getRepository()->getActivityStatistics($activity);
$deleteForm = $this->createForm(ActivityDeleteForm::class, $activity, [
'action' => $this->generateUrl('admin_activity_delete', ['id' => $activity->getId()]),
'method' => 'POST'
]);
$deleteForm = $this->createFormBuilder()
->setAction($this->generateUrl('admin_activity_delete', ['id' => $activity->getId()]))
->setMethod('POST')
->getForm();
$deleteForm->handleRequest($request);

View File

@@ -19,7 +19,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use TimesheetBundle\Form\CustomerDeleteForm;
use TimesheetBundle\Form\CustomerEditForm;
use TimesheetBundle\Form\Toolbar\CustomerToolbarForm;
use TimesheetBundle\Repository\Query\CustomerQuery;
@@ -145,10 +144,10 @@ class CustomerController extends AbstractController
{
$stats = $this->getRepository()->getCustomerStatistics($customer);
$deleteForm = $this->createForm(CustomerDeleteForm::class, $customer, [
'action' => $this->generateUrl('admin_customer_delete', ['id' => $customer->getId()]),
'method' => 'POST'
]);
$deleteForm = $this->createFormBuilder()
->setAction($this->generateUrl('admin_customer_delete', ['id' => $customer->getId()]))
->setMethod('POST')
->getForm();
$deleteForm->handleRequest($request);

View File

@@ -20,7 +20,6 @@ use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
use TimesheetBundle\Form\ProjectDeleteForm;
use TimesheetBundle\Form\ProjectEditForm;
use TimesheetBundle\Form\Toolbar\ProjectToolbarForm;
use TimesheetBundle\Repository\Query\ProjectQuery;
@@ -129,10 +128,10 @@ class ProjectController extends AbstractController
{
$stats = $this->getRepository()->getProjectStatistics($project);
$deleteForm = $this->createForm(ProjectDeleteForm::class, $project, [
'action' => $this->generateUrl('admin_project_delete', ['id' => $project->getId()]),
'method' => 'POST'
]);
$deleteForm = $this->createFormBuilder()
->setAction($this->generateUrl('admin_project_delete', ['id' => $project->getId()]))
->setMethod('POST')
->getForm();
$deleteForm->handleRequest($request);

View File

@@ -1,38 +0,0 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TimesheetBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TimesheetBundle\Entity\Activity;
/**
* The form used to delete Activities.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ActivityDeleteForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Activity::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_activity_delete',
]);
}
}

View File

@@ -1,38 +0,0 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TimesheetBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TimesheetBundle\Entity\Customer;
/**
* The form used to delete Customers.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class CustomerDeleteForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Customer::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_customer_delete',
]);
}
}

View File

@@ -1,38 +0,0 @@
<?php
/*
* This file is part of the Kimai package.
*
* (c) Kevin Papst <kevin@kevinpapst.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace TimesheetBundle\Form;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use TimesheetBundle\Entity\Project;
/**
* The form used to delete Projects.
*
* @author Kevin Papst <kevin@kevinpapst.de>
*/
class ProjectDeleteForm extends AbstractType
{
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'data_class' => Project::class,
'csrf_protection' => true,
'csrf_field_name' => '_token',
'csrf_token_id' => 'admin_project_delete',
]);
}
}