Fix error message when the user tries to update an API Role that has already been assigned to a user. #194
This commit is contained in:
parent
e22c62ebab
commit
3c9802bbd2
2 changed files with 15 additions and 2 deletions
|
|
@ -11,6 +11,7 @@ use Doctrine\ORM\Query;
|
|||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Validator\Validator\ValidatorInterface;
|
||||
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
|
||||
|
||||
use App\Menu\Generator as MenuGenerator;
|
||||
use App\Access\Generator as ACLGenerator;
|
||||
|
|
@ -272,7 +273,19 @@ class APIRoleController extends BaseController
|
|||
], 422);
|
||||
} else {
|
||||
// validated! save the entity
|
||||
$em->flush();
|
||||
// catch the exception in case user updated the id
|
||||
try
|
||||
{
|
||||
$em->flush();
|
||||
}
|
||||
catch(ForeignKeyConstraintViolationException $e)
|
||||
{
|
||||
$error_array['id'] = 'Role has already been assigned to user/s and id cannot be updated';
|
||||
return $this->json([
|
||||
'success' => false,
|
||||
'errors' => $error_array
|
||||
], 403);
|
||||
}
|
||||
|
||||
// return successful response
|
||||
return $this->json([
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@
|
|||
}
|
||||
});
|
||||
}).fail(function(response) {
|
||||
if (response.status == 422) {
|
||||
if (response.status == 422 || response.status == 403) {
|
||||
var errors = response.responseJSON.errors;
|
||||
var firstfield = false;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue