inspector delete application (#4521)

This commit is contained in:
Aina Sitraka
2024-06-11 11:51:51 +03:00
committed by GitHub
parent 99de0c0b37
commit cf4267214b
3 changed files with 53 additions and 1 deletions

View File

@@ -17,6 +17,7 @@ use Alchemy\Phrasea\Core\Event\Record\Structure\StatusBitUpdatedEvent;
use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository; use Alchemy\Phrasea\Databox\Subdef\MediaSubdefRepository;
use Alchemy\Phrasea\Exception\SessionNotFound; use Alchemy\Phrasea\Exception\SessionNotFound;
use Alchemy\Phrasea\Model\Entities\ApiApplication; use Alchemy\Phrasea\Model\Entities\ApiApplication;
use Alchemy\Phrasea\Model\Manipulator\ApiApplicationManipulator;
use Alchemy\Phrasea\Model\Manipulator\ApiOauthTokenManipulator; use Alchemy\Phrasea\Model\Manipulator\ApiOauthTokenManipulator;
use Alchemy\Phrasea\Model\Repositories\ApiAccountRepository; use Alchemy\Phrasea\Model\Repositories\ApiAccountRepository;
use Alchemy\Phrasea\Model\Repositories\ApiOauthTokenRepository; use Alchemy\Phrasea\Model\Repositories\ApiOauthTokenRepository;
@@ -507,6 +508,13 @@ class RootController extends Controller
return $this->app->json(['success' => true]); 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 * @return ApiOauthTokenRepository
*/ */
@@ -582,4 +590,12 @@ class RootController extends Controller
'off_databoxes' => $off_databoxes, 'off_databoxes' => $off_databoxes,
]; ];
} }
/**
* @return ApiApplicationManipulator
*/
private function getApiApplicationManipulator()
{
return $this->app['manipulator.api-application'];
}
} }

View File

@@ -94,6 +94,11 @@ class Root implements ControllerProviderInterface, ServiceProviderInterface
->assert('application', '\d+') ->assert('application', '\d+')
->bind('admin_inspector_application_token'); ->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; return $controllers;
} }
} }

View File

@@ -82,6 +82,7 @@
<th>{{ 'admin::inspector: api creation date' | trans }}</th> <th>{{ 'admin::inspector: api creation date' | trans }}</th>
<th>{{ 'admin::inspector: api modification date' | trans }}</th> <th>{{ 'admin::inspector: api modification date' | trans }}</th>
<th></th> <th></th>
<th></th>
</thead> </thead>
<tbody> <tbody>
{% for apiApplication in apiApplications %} {% for apiApplication in apiApplications %}
@@ -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> <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 %} {% endif %}
</td> </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> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>
@@ -237,7 +241,7 @@
$('button.generate_token').bind('click', function (e) { $('button.generate_token').bind('click', function (e) {
e.preventDefault(); e.preventDefault();
var $this = $(this); 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({ $.ajax({
type: 'POST', type: 'POST',
url: $this.attr('href'), url: $this.attr('href'),
@@ -251,5 +255,32 @@
return false; 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> </script>