Skip to content

Commit

Permalink
delete user request
Browse files Browse the repository at this point in the history
  • Loading branch information
aynsix committed May 13, 2024
1 parent 6831681 commit 4544185
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/Alchemy/Phrasea/Controller/Admin/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,30 @@ public function displayRegistrationsAction()
]);
}

public function deleteUserRegistrationAction(Request $request)
{
/** @var EntityManager $manager */
$manager = $this->app['orm.em'];
/** @var RegistrationRepository $registrationRepository */
$registrationRepository = $this->app['repo.registrations'];

/** @var UserRepository $userRepository */
$userRepository = $this->app['repo.users'];
$registrations = $registrationRepository->findBy(['user' => $userRepository->find($request->request->get('userId'))]);

if (empty($registrations)) {
return $this->app->json(['success' => false, 'message' => 'registration not found']);
}

foreach ($registrations as $registration) {
$manager->remove($registration);
}

$manager->flush();

return $this->app->json(['success' => true]);
}

public function displayAuthFailureAction(Request $request)
{
return $this->render('admin/auth-failure.html.twig', [
Expand Down
2 changes: 2 additions & 0 deletions lib/Alchemy/Phrasea/ControllerProvider/Admin/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function connect(Application $app)
->bind('users_display_registrations');
$controllers->post('/registrations/', 'controller.admin.users:submitRegistrationAction')
->bind('users_submit_registrations');
$controllers->post('/registrations/delete/', 'controller.admin.users:deleteUserRegistrationAction')
->bind('delete_user_registrations');
$controllers->get('/import/file/', 'controller.admin.users:displayImportFileAction')
->bind('users_display_import_file');
$controllers->post('/import/file/', 'controller.admin.users:submitImportFileAction')
Expand Down
28 changes: 28 additions & 0 deletions templates/web/admin/user/registrations.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,31 @@
$form.submit();
});
$("#registrations").on('click', '.cancel-user-request', function() {
if(confirm('Do you want to delete this user request ?')) {
$.ajax({
type: "POST",
url: "/admin/users/registrations/delete/",
data: {
userId : $(this).attr('data-user-id'),
},
success: function (data) {
if (data.success == true) {
$.ajax({
type: "GET",
url: "/admin/users/registrations/",
success: function (data) {
}
});
}
}
});
} else {
return false;
}
});
});
</script>

Expand Down Expand Up @@ -263,6 +288,9 @@
{% endfor %}
</select>
</td>
<td>
<button data-user-id="{{ user.getId() }}" class="btn btn-danger cancel-user-request">{{ 'admin:: cancel user request' }}</button>
</td>
</tr>
</table>
</div>
Expand Down

0 comments on commit 4544185

Please sign in to comment.