Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHRAS-4018 admin- inspector delete application #4521

Merged
merged 2 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading