Skip to content

Commit

Permalink
inspector delete application (#4521)
Browse files Browse the repository at this point in the history
  • Loading branch information
aynsix authored Jun 11, 2024
1 parent 99de0c0 commit cf42672
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 1 deletion.
16 changes: 16 additions & 0 deletions lib/Alchemy/Phrasea/Controller/Admin/RootController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository;
use Alchemy\Phrasea\Exception\SessionNotFound;
use Alchemy\Phrasea\Model\Entities\ApiApplication;
use Alchemy\Phrasea\Model\Manipulator\ApiApplicationManipulator;
use Alchemy\Phrasea\Model\Manipulator\ApiOauthTokenManipulator;
use Alchemy\Phrasea\Model\Repositories\ApiAccountRepository;
use Alchemy\Phrasea\Model\Repositories\ApiOauthTokenRepository;
Expand Down Expand Up @@ -507,6 +508,13 @@ public function renewAccessToken(Request $request, ApiApplication $application)
return $this->app->json(['success' => true]);
}

public function deleteApplication(Request $request, ApiApplication $application)
{
$this->getApiApplicationManipulator()->delete($application);

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

/**
* @return ApiOauthTokenRepository
*/
Expand Down Expand Up @@ -582,4 +590,12 @@ private function getSectionParameters($section)
'off_databoxes' => $off_databoxes,
];
}

/**
* @return ApiApplicationManipulator
*/
private function getApiApplicationManipulator()
{
return $this->app['manipulator.api-application'];
}
}
5 changes: 5 additions & 0 deletions lib/Alchemy/Phrasea/ControllerProvider/Admin/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ public function connect(Application $app)
->assert('application', '\d+')
->bind('admin_inspector_application_token');

$controllers->post('/inspector/application/{application}/delete/', 'controller.admin.root:deleteApplication')
->before($app['middleware.api-application.converter'])
->assert('application', '\d+')
->bind('admin_inspector_application_delete');

return $controllers;
}
}
33 changes: 32 additions & 1 deletion templates/web/admin/inspector/record-index.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<th>{{ 'admin::inspector: api creation date' | trans }}</th>
<th>{{ 'admin::inspector: api modification date' | trans }}</th>
<th></th>
<th></th>
</thead>
<tbody>
{% for apiApplication in apiApplications %}
Expand Down Expand Up @@ -133,6 +134,9 @@
<button class="generate_token btn btn-warning btn-small" data-app-id="{{ apiApplication.getId() }}" href="{{ path('admin_inspector_application_token', { 'application' : apiApplication.getId(), 'user_id' : apiApplication.getCreator().getId() }) }}">{{ 'generate token' }}</button>
{% endif %}
</td>
<td>
<button class="delete_application btn btn-danger btn-small" data-app-id="{{ apiApplication.getId() }}" href="{{ path('admin_inspector_application_delete', { 'application' : apiApplication.getId() }) }}">{{ 'delete' }}</button>
</td>
</tr>
{% endfor %}
</tbody>
Expand Down Expand Up @@ -237,7 +241,7 @@
$('button.generate_token').bind('click', function (e) {
e.preventDefault();
var $this = $(this);
if (confirm('Your are about to generate token for application with ID: ' + $this.data('app-id'))) {
if (confirm('You are about to generate token for application with ID: ' + $this.data('app-id'))) {
$.ajax({
type: 'POST',
url: $this.attr('href'),
Expand All @@ -251,5 +255,32 @@
return false;
}
});
$('button.delete_application').bind('click', function (e) {
e.preventDefault();
var $this = $(this);
if (confirm('You are about to delete application with ID: ' + $this.data('app-id'))) {
$.ajax({
type: 'POST',
url: $this.attr('href'),
dataType: 'json',
success: function (data) {
if (data.success) {
$('#tree li.selected a').trigger('click');
setTimeout(function(){
$('li a[href="#api-info"]').trigger('click');
}
, 500
);
}
}
});
return false;
} else {
return false;
}
});
});
</script>

0 comments on commit cf42672

Please sign in to comment.