mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Support purging account data
This commit is contained in:
parent
55fc704596
commit
b9328ff2b9
@ -1307,6 +1307,16 @@ class AccountController extends BaseController
|
||||
return RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function purgeData()
|
||||
{
|
||||
$this->dispatch(new \App\Jobs\PurgeAccountData());
|
||||
|
||||
return redirect('/settings/account_management')->withMessage(trans('texts.purge_successful'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
|
@ -257,6 +257,7 @@ Route::group([
|
||||
|
||||
Route::post('settings/change_plan', 'AccountController@changePlan');
|
||||
Route::post('settings/cancel_account', 'AccountController@cancelAccount');
|
||||
Route::post('settings/purge_data', 'AccountController@purgeData');
|
||||
Route::post('settings/company_details', 'AccountController@updateDetails');
|
||||
Route::post('settings/{section?}', 'AccountController@doSection');
|
||||
|
||||
|
61
app/Jobs/PurgeAccountData.php
Normal file
61
app/Jobs/PurgeAccountData.php
Normal file
@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Jobs\Job;
|
||||
use App\Models\Document;
|
||||
use Auth;
|
||||
use DB;
|
||||
use Exception;
|
||||
|
||||
class PurgeAccountData extends Job
|
||||
{
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$user = Auth::user();
|
||||
$account = $user->account;
|
||||
|
||||
if (! $user->is_admin) {
|
||||
throw new Exception(trans('texts.forbidden'));
|
||||
}
|
||||
|
||||
// delete the documents from cloud storage
|
||||
Document::scope()->each(function ($item, $key) {
|
||||
$item->delete();
|
||||
});
|
||||
|
||||
$tables = [
|
||||
'activities',
|
||||
'invitations',
|
||||
'account_gateway_tokens',
|
||||
'payment_methods',
|
||||
'credits',
|
||||
'expense_categories',
|
||||
'expenses',
|
||||
'invoice_items',
|
||||
'payments',
|
||||
'invoices',
|
||||
'tasks',
|
||||
'projects',
|
||||
'products',
|
||||
'vendor_contacts',
|
||||
'vendors',
|
||||
'contacts',
|
||||
'clients',
|
||||
];
|
||||
|
||||
foreach ($tables as $table) {
|
||||
DB::table($table)->where('account_id', '=', $user->account_id)->delete();
|
||||
}
|
||||
|
||||
$account->invoice_number_counter = 1;
|
||||
$account->quote_number_counter = 1;
|
||||
$account->client_number_counter = 1;
|
||||
$account->save();
|
||||
}
|
||||
}
|
@ -369,7 +369,7 @@ $LANG = array(
|
||||
'confirm_email_quote' => 'Are you sure you want to email this quote?',
|
||||
'confirm_recurring_email_invoice' => 'Are you sure you want this invoice emailed?',
|
||||
'cancel_account' => 'Delete Account',
|
||||
'cancel_account_message' => 'Warning: This will permanently erase all of your data, there is no undo.',
|
||||
'cancel_account_message' => 'Warning: This will permanently delete your account, there is no undo.',
|
||||
'go_back' => 'Go Back',
|
||||
'data_visualizations' => 'Data Visualizations',
|
||||
'sample_data' => 'Sample data shown',
|
||||
@ -2449,6 +2449,13 @@ $LANG = array(
|
||||
'create_credit_note' => 'Create Credit Note',
|
||||
'menu' => 'Menu',
|
||||
'error_incorrect_gateway_ids' => 'Error: The gateways table has incorrect ids.',
|
||||
'purge_data' => 'Purge Data',
|
||||
'delete_data' => 'Delete Data',
|
||||
'purge_data_help' => 'Permanently delete all data in the account, keeping the account and settings.',
|
||||
'cancel_account_help' => 'Permanently delete the account along with all data and setting.',
|
||||
'purge_successful' => 'Successfully purged account data',
|
||||
'forbidden' => 'Forbidden',
|
||||
'purge_data_message' => 'Warning: This will permanently erase your data, there is no undo.',
|
||||
|
||||
);
|
||||
|
||||
|
@ -221,16 +221,55 @@
|
||||
|
||||
{!! Former::close() !!}
|
||||
|
||||
{!! Former::open('settings/cancel_account')->addClass('cancel-account') !!}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h3 class="panel-title">{!! trans('texts.cancel_account') !!}</h3>
|
||||
<h3 class="panel-title">{!! trans('texts.delete_data') !!}</h3>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
{!! Former::actions( Button::danger(trans('texts.cancel_account'))->large()->withAttributes(['onclick' => 'showConfirm()'])->appendIcon(Icon::create('trash'))) !!}
|
||||
{!! Former::open('settings/purge_data')->addClass('purge-data') !!}
|
||||
{!! Former::actions(
|
||||
Button::danger(trans('texts.purge_data'))
|
||||
->withAttributes(['onclick' => 'showPurgeConfirm()'])
|
||||
->appendIcon(Icon::create('trash'))
|
||||
->large()
|
||||
) !!}
|
||||
<div class="form-group">
|
||||
<div class="col-lg-8 col-sm-8 col-lg-offset-4 col-sm-offset-4">
|
||||
<span class="help-block">{{ trans('texts.purge_data_help')}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<br/>
|
||||
<div class="modal fade" id="confirmPurgeModal" tabindex="-1" role="dialog" aria-labelledby="confirmPurgeModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" style="min-width:150px">
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="confirmPurgeModalLabel">{!! trans('texts.purge_data') !!}</h4>
|
||||
</div>
|
||||
<div class="container" style="width: 100%; padding-bottom: 0px !important">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p><b>{{ trans('texts.purge_data_message') }}</b></p>
|
||||
<br/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal-footer" style="margin-top: 2px">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.go_back') }}</button>
|
||||
<button type="button" class="btn btn-danger" onclick="confirmPurge()">{{ trans('texts.purge_data') }}</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{!! Former::close() !!}
|
||||
|
||||
{!! Former::open('settings/cancel_account')->addClass('cancel-account') !!}
|
||||
{!! Former::actions( Button::danger(trans('texts.cancel_account'))->large()->withAttributes(['onclick' => 'showCancelConfirm()'])->appendIcon(Icon::create('trash'))) !!}
|
||||
<div class="form-group">
|
||||
<div class="col-lg-8 col-sm-8 col-lg-offset-4 col-sm-offset-4">
|
||||
<span class="help-block">{{ trans('texts.cancel_account_help')}}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="modal fade" id="confirmCancelModal" tabindex="-1" role="dialog" aria-labelledby="confirmCancelModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog" style="min-width:150px">
|
||||
<div class="modal-content">
|
||||
@ -238,22 +277,30 @@
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h4 class="modal-title" id="confirmCancelModalLabel">{!! trans('texts.cancel_account') !!}</h4>
|
||||
</div>
|
||||
|
||||
<div style="background-color: #fff; padding-left: 16px; padding-right: 16px">
|
||||
<p>{{ trans('texts.cancel_account_message') }}</p>
|
||||
<p>{!! Former::textarea('reason')->placeholder(trans('texts.reason_for_canceling'))->raw() !!}</p>
|
||||
<div class="container" style="width: 100%; padding-bottom: 0px !important">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-body">
|
||||
<p><b>{{ trans('texts.cancel_account_message') }}</b></p><br/>
|
||||
<p>{!! Former::textarea('reason')
|
||||
->placeholder(trans('texts.reason_for_canceling'))
|
||||
->raw()
|
||||
->rows(4) !!}</p>
|
||||
<br/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer" style="margin-top: 2px">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal">{{ trans('texts.go_back') }}</button>
|
||||
<button type="button" class="btn btn-danger" onclick="confirmCancel()">{{ trans('texts.cancel_account') }}</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{!! Former::close() !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -271,14 +318,22 @@
|
||||
$('form.change-plan').submit();
|
||||
}
|
||||
|
||||
function showConfirm() {
|
||||
function showCancelConfirm() {
|
||||
$('#confirmCancelModal').modal('show');
|
||||
}
|
||||
|
||||
function showPurgeConfirm() {
|
||||
$('#confirmPurgeModal').modal('show');
|
||||
}
|
||||
|
||||
function confirmCancel() {
|
||||
$('form.cancel-account').submit();
|
||||
}
|
||||
|
||||
function confirmPurge() {
|
||||
$('form.purge-data').submit();
|
||||
}
|
||||
|
||||
function onPlanChange() {
|
||||
if ($('#plan').val() == '{{ PLAN_ENTERPRISE }}') {
|
||||
$('#numUsersDiv').show();
|
||||
|
Loading…
x
Reference in New Issue
Block a user