mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
New feature: option to delete all meta data from your account.
This commit is contained in:
parent
7337d73c1d
commit
8a0abc23c3
89
app/Http/Controllers/Profile/DataController.php
Normal file
89
app/Http/Controllers/Profile/DataController.php
Normal 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'));
|
||||
}
|
||||
}
|
@ -282,4 +282,12 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
||||
return $availableBudget;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all available budgets.
|
||||
*/
|
||||
public function destroyAll(): void
|
||||
{
|
||||
$this->user->availableBudgets()->delete();
|
||||
}
|
||||
}
|
@ -34,6 +34,12 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface AvailableBudgetRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* Delete all available budgets.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param AvailableBudget $availableBudget
|
||||
*/
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
@ -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.
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,12 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface BudgetRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Destroy all budgets.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,10 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Delete all categories.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,6 +32,11 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface TagRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* Destroy all tags.
|
||||
*/
|
||||
public function destroyAll(): void;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
|
@ -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',
|
||||
|
@ -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>
|
||||
|
@ -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']);
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user