New feature: option to delete all meta data from your account.

This commit is contained in:
James Cole 2019-09-27 21:35:21 +02:00
parent 7337d73c1d
commit 8a0abc23c3
No known key found for this signature in database
GPG Key ID: C16961E655E74B5E
14 changed files with 218 additions and 5 deletions

View File

@ -0,0 +1,89 @@
<?php
/**
* DataController.php
* Copyright (c) 2019 thegrumpydictator@gmail.com
*
* This file is part of Firefly III.
*
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Http\Controllers\Profile;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetLimitRepositoryInterface;
use FireflyIII\Repositories\Budget\BudgetRepositoryInterface;
use FireflyIII\Repositories\Category\CategoryRepositoryInterface;
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
use Illuminate\Http\RedirectResponse;
/**
* Class DataController
*/
class DataController extends Controller
{
/**
*
*/
public function deleteBudgets(): RedirectResponse
{
/** @var AvailableBudgetRepositoryInterface $abRepository */
$abRepository = app(AvailableBudgetRepositoryInterface::class);
$abRepository->destroyAll();
/** @var BudgetLimitRepositoryInterface $blRepository */
$blRepository = app(BudgetLimitRepositoryInterface::class);
$blRepository->destroyAll();
/** @var BudgetRepositoryInterface $budgetRepository */
$budgetRepository = app(BudgetRepositoryInterface::class);
$budgetRepository->destroyAll();
session()->flash('success', trans('firefly.deleted_all_budgets'));
return redirect(route('profile.index'));
}
/**
*
*/
public function deleteCategories(): RedirectResponse
{
/** @var CategoryRepositoryInterface $categoryRepos */
$categoryRepos = app(CategoryRepositoryInterface::class);
$categoryRepos->destroyAll();
session()->flash('success', trans('firefly.deleted_all_categories'));
return redirect(route('profile.index'));
}
/**
*
*/
public function deleteTags(): RedirectResponse
{
/** @var TagRepositoryInterface $tagRepository */
$tagRepository = app(TagRepositoryInterface::class);
$tagRepository->destroyAll();
session()->flash('success', trans('firefly.deleted_all_tags'));
return redirect(route('profile.index'));
}
}

View File

@ -282,4 +282,12 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
return $availableBudget;
}
/**
* Delete all available budgets.
*/
public function destroyAll(): void
{
$this->user->availableBudgets()->delete();
}
}

View File

@ -34,6 +34,12 @@ use Illuminate\Support\Collection;
*/
interface AvailableBudgetRepositoryInterface
{
/**
* Delete all available budgets.
*/
public function destroyAll(): void;
/**
* @param AvailableBudget $availableBudget
*/

View File

@ -447,4 +447,16 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
return $limit;
}
/**
* Destroy all budget limits.
*/
public function destroyAll(): void
{
$budgets = $this->user->budgets()->get();
/** @var Budget $budget */
foreach ($budgets as $budget) {
$budget->budgetlimits()->delete();
}
}
}

View File

@ -35,6 +35,12 @@ use Illuminate\Support\Collection;
*/
interface BudgetLimitRepositoryInterface
{
/**
* Destroy all budget limits.
*/
public function destroyAll(): void;
/**
* Tells you which amount has been budgeted (for the given budgets)
* in the selected query. Returns a positive amount as a string.

View File

@ -23,9 +23,11 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon;
use DB;
use Exception;
use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleTrigger;
use FireflyIII\Services\Internal\Destroy\BudgetDestroyService;
@ -341,4 +343,20 @@ class BudgetRepository implements BudgetRepositoryInterface
Log::debug(sprintf('Updated trigger %d: %s', $trigger->id, $trigger->trigger_value));
}
}
/**
* Destroy all budgets.
*/
public function destroyAll(): void
{
$budgets = $this->getBudgets();
/** @var Budget $budget */
foreach ($budgets as $budget) {
DB::table('budget_transaction')->where('budget_id', $budget->id)->delete();
DB::table('budget_transaction_journal')->where('budget_id', $budget->id)->delete();
RecurrenceTransactionMeta::where('name', 'budget_id')->where('value', $budget->id)->delete();
RuleAction::where('action_type', 'set_budget')->where('action_value', $budget->id)->delete();
$budget->delete();
}
}
}

View File

@ -32,6 +32,12 @@ use Illuminate\Support\Collection;
*/
interface BudgetRepositoryInterface
{
/**
* Destroy all budgets.
*/
public function destroyAll(): void;
/**
* @return bool
*/

View File

@ -23,8 +23,11 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Category;
use Carbon\Carbon;
use DB;
use FireflyIII\Factory\CategoryFactory;
use FireflyIII\Models\Category;
use FireflyIII\Models\RecurrenceTransactionMeta;
use FireflyIII\Models\RuleAction;
use FireflyIII\Services\Internal\Destroy\CategoryDestroyService;
use FireflyIII\Services\Internal\Update\CategoryUpdateService;
use FireflyIII\User;
@ -347,4 +350,19 @@ class CategoryRepository implements CategoryRepositoryInterface
return null;
}
/**
* Delete all categories.
*/
public function destroyAll(): void
{
$categories = $this->getCategories();
/** @var Category $category */
foreach ($categories as $category) {
DB::table('category_transaction')->where('category_id', $category->id)->delete();
DB::table('category_transaction_journal')->where('category_id', $category->id)->delete();
RecurrenceTransactionMeta::where('name', 'category_id')->where('value', $category->id)->delete();
RuleAction::where('action_type', 'set_category')->where('action_value', $category->name)->delete();
$category->delete();
}
}
}

View File

@ -32,6 +32,10 @@ use Illuminate\Support\Collection;
*/
interface CategoryRepositoryInterface
{
/**
* Delete all categories.
*/
public function destroyAll(): void;
/**
* @param Category $category

View File

@ -486,4 +486,17 @@ class TagRepository implements TagRepositoryInterface
return $tagQuery->get(['tags.id', 'tags.tag','tags.created_at', DB::raw('SUM(transactions.amount) as amount_sum')]);
}
/**
* Destroy all tags.
*/
public function destroyAll(): void
{
$tags = $this->get();
/** @var Tag $tag */
foreach ($tags as $tag) {
DB::table('tag_transaction_journal')->where('tag_id', $tag->id)->delete();
$tag->delete();
}
}
}

View File

@ -32,6 +32,11 @@ use Illuminate\Support\Collection;
*/
interface TagRepositoryInterface
{
/**
* Destroy all tags.
*/
public function destroyAll(): void;
/**
* @return int
*/

View File

@ -539,6 +539,13 @@ return [
'optional_field_meta_data' => 'Optional meta data',
// profile:
'permanent_delete_stuff' => 'Be careful with these buttons. Deleting stuff is permanent.',
'delete_all_budgets' => 'Delete ALL your budgets',
'delete_all_categories' => 'Delete ALL your categories',
'delete_all_tags' => 'Delete ALL your tags',
'deleted_all_budgets' => 'All budgets have been deleted',
'deleted_all_categories' => 'All categories have been deleted',
'deleted_all_tags' => 'All tags have been deleted',
'change_your_password' => 'Change your password',
'delete_account' => 'Delete account',
'current_password' => 'Current password',

View File

@ -17,11 +17,26 @@
{{ trans('firefly.user_id_is',{user: userId})|raw }}
</p>
{% if not SANDSTORM %}
<ul>
<li><a href="{{ route('profile.change-email') }}">{{ 'change_your_email'|_ }}</a></li>
<li><a href="{{ route('profile.change-password') }}">{{ 'change_your_password'|_ }}</a></li>
<li><a class="text-danger" href="{{ route('profile.delete-account') }}">{{ 'delete_account'|_ }}</a></li>
</ul>
<div class="row">
<div class="col-lg-6">
<ul>
<li><a href="{{ route('profile.change-email') }}">{{ 'change_your_email'|_ }}</a></li>
<li><a href="{{ route('profile.change-password') }}">{{ 'change_your_password'|_ }}</a></li>
<li><a class="text-danger" href="{{ route('profile.delete-account') }}">{{ 'delete_account'|_ }}</a></li>
</ul>
</div>
<div class="col-lg-6">
<p>
{{ 'permanent_delete_stuff'|_ }}
</p>
<ul>
<li><a onclick="return confirm('{{ trans('firefly.are_you_sure')|escape('js') }}');" class="text-danger" href="{{ route('profile.delete-budgets') }}">{{ 'delete_all_budgets'|_ }}</a></li>
<li><a onclick="return confirm('{{ trans('firefly.are_you_sure')|escape('js') }}');" class="text-danger" href="{{ route('profile.delete-categories') }}">{{ 'delete_all_categories'|_ }}</a></li>
<li><a onclick="return confirm('{{ trans('firefly.are_you_sure')|escape('js') }}');" class="text-danger" href="{{ route('profile.delete-tags') }}">{{ 'delete_all_tags'|_ }}</a></li>
</ul>
</div>
</div>
{% endif %}
</div>
</div>

View File

@ -655,6 +655,12 @@ Route::group(
Route::get('/delete-code', ['uses' => 'ProfileController@deleteCode', 'as' => 'delete-code']);
Route::get('2fa/new-codes', ['uses' => 'ProfileController@newBackupCodes', 'as' => 'new-backup-codes']);
// routes to delete stuff.
Route::get('delete-budgets', ['uses' => 'Profile\DataController@deleteBudgets', 'as' => 'delete-budgets']);
Route::get('delete-categories', ['uses' => 'Profile\DataController@deleteCategories', 'as' => 'delete-categories']);
Route::get('delete-tags', ['uses' => 'Profile\DataController@deleteTags', 'as' => 'delete-tags']);
}
);