diff --git a/app/Api/V2/Controllers/Autocomplete/AccountController.php b/app/Api/V2/Controllers/Autocomplete/AccountController.php index 42b267c4a7..cfab89a40b 100644 --- a/app/Api/V2/Controllers/Autocomplete/AccountController.php +++ b/app/Api/V2/Controllers/Autocomplete/AccountController.php @@ -79,7 +79,7 @@ class AccountController extends Controller */ public function accounts(AutocompleteRequest $request): JsonResponse { - die('uses old administration ID check, needs to be updated. 1'); + throw new FireflyException('uses old administration ID check, needs to be updated. 1'); $data = $request->getData(); $types = $data['types']; $query = $data['query']; diff --git a/app/Api/V2/Controllers/Chart/AccountController.php b/app/Api/V2/Controllers/Chart/AccountController.php index 2d7a298c67..371c9705e0 100644 --- a/app/Api/V2/Controllers/Chart/AccountController.php +++ b/app/Api/V2/Controllers/Chart/AccountController.php @@ -55,7 +55,7 @@ class AccountController extends Controller $this->middleware( function ($request, $next) { $this->repository = app(AccountRepositoryInterface::class); - die('uses old administration ID check, needs to be updated.2'); + throw new FireflyException('uses old administration ID check, needs to be updated.2'); $this->repository->setAdministrationId(auth()->user()->user_group_id); return $next($request); } diff --git a/app/Api/V2/Controllers/Chart/BudgetController.php b/app/Api/V2/Controllers/Chart/BudgetController.php index e5e468f3f4..1cdb5266fa 100644 --- a/app/Api/V2/Controllers/Chart/BudgetController.php +++ b/app/Api/V2/Controllers/Chart/BudgetController.php @@ -78,7 +78,7 @@ class BudgetController extends Controller */ public function dashboard(DateRequest $request): JsonResponse { - die('uses old administration ID check, needs to be updated.3'); + throw new FireflyException('uses old administration ID check, needs to be updated.3'); // get user. /** @var User $user */ $user = auth()->user(); diff --git a/app/Api/V2/Controllers/Chart/CategoryController.php b/app/Api/V2/Controllers/Chart/CategoryController.php index 8b82845247..393af631c2 100644 --- a/app/Api/V2/Controllers/Chart/CategoryController.php +++ b/app/Api/V2/Controllers/Chart/CategoryController.php @@ -53,7 +53,7 @@ class CategoryController extends Controller parent::__construct(); $this->middleware( function ($request, $next) { - die('uses old administration ID check, needs to be updated.4'); + throw new FireflyException('uses old administration ID check, needs to be updated.4'); $this->accountRepos = app(AccountRepositoryInterface::class); $this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->accountRepos->setAdministrationId(auth()->user()->user_group_id); diff --git a/app/Api/V2/Controllers/Model/Bill/ShowController.php b/app/Api/V2/Controllers/Model/Bill/ShowController.php index f06c47a524..a31cde11a7 100644 --- a/app/Api/V2/Controllers/Model/Bill/ShowController.php +++ b/app/Api/V2/Controllers/Model/Bill/ShowController.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V2\Controllers\Model\Bill; use FireflyIII\Api\V2\Controllers\Controller; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Bill; use FireflyIII\Repositories\UserGroups\Bill\BillRepositoryInterface; use FireflyIII\Transformers\V2\AccountTransformer; @@ -46,7 +47,7 @@ class ShowController extends Controller parent::__construct(); $this->middleware( function ($request, $next) { - die('uses old administration ID check, needs to be updated.5'); + throw new FireflyException('uses old administration ID check, needs to be updated.5'); $this->repository = app(BillRepositoryInterface::class); $this->repository->setAdministrationId(auth()->user()->user_group_id); return $next($request); diff --git a/app/Api/V2/Controllers/Model/Bill/SumController.php b/app/Api/V2/Controllers/Model/Bill/SumController.php index 402d768eb6..41d0e49316 100644 --- a/app/Api/V2/Controllers/Model/Bill/SumController.php +++ b/app/Api/V2/Controllers/Model/Bill/SumController.php @@ -26,6 +26,7 @@ namespace FireflyIII\Api\V2\Controllers\Model\Bill; use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Request\Generic\DateRequest; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\UserGroups\Bill\BillRepositoryInterface; use Illuminate\Http\JsonResponse; @@ -63,7 +64,7 @@ class SumController extends Controller */ public function paid(DateRequest $request): JsonResponse { - die('uses old administration ID check, needs to be updated.6'); + throw new FireflyException('uses old administration ID check, needs to be updated.6'); $this->repository->setAdministrationId(auth()->user()->user_group_id); $result = $this->repository->sumPaidInRange($this->parameters->get('start'), $this->parameters->get('end')); @@ -83,7 +84,7 @@ class SumController extends Controller */ public function unpaid(DateRequest $request): JsonResponse { - die('uses old administration ID check, needs to be updated.7'); + throw new FireflyException('uses old administration ID check, needs to be updated.7'); $this->repository->setAdministrationId(auth()->user()->user_group_id); $result = $this->repository->sumUnpaidInRange($this->parameters->get('start'), $this->parameters->get('end')); diff --git a/app/Api/V2/Controllers/Model/Budget/ShowController.php b/app/Api/V2/Controllers/Model/Budget/ShowController.php index 74f34709b6..a451b07662 100644 --- a/app/Api/V2/Controllers/Model/Budget/ShowController.php +++ b/app/Api/V2/Controllers/Model/Budget/ShowController.php @@ -27,6 +27,7 @@ namespace FireflyIII\Api\V2\Controllers\Model\Budget; use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Request\Generic\DateRequest; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Models\Budget; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use Illuminate\Http\JsonResponse; @@ -60,7 +61,7 @@ class ShowController extends Controller */ public function budgeted(DateRequest $request, Budget $budget): JsonResponse { - die('deprecated use of thing.'); + throw new FireflyException('deprecated use of thing.'); $data = $request->getAll(); $result = $this->repository->budgetedInPeriodForBudget($budget, $data['start'], $data['end']); $converted = $this->cerSum(array_values($result)); @@ -75,7 +76,7 @@ class ShowController extends Controller */ public function spent(DateRequest $request, Budget $budget): JsonResponse { - die('deprecated use of thing.'); + throw new FireflyException('deprecated use of thing.'); $data = $request->getAll(); $result = $this->repository->spentInPeriodForBudget($budget, $data['start'], $data['end']); $converted = $this->cerSum(array_values($result)); diff --git a/app/Api/V2/Controllers/Model/Budget/SumController.php b/app/Api/V2/Controllers/Model/Budget/SumController.php index 0f27fed42b..e9e178dd7c 100644 --- a/app/Api/V2/Controllers/Model/Budget/SumController.php +++ b/app/Api/V2/Controllers/Model/Budget/SumController.php @@ -26,6 +26,7 @@ namespace FireflyIII\Api\V2\Controllers\Model\Budget; use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Request\Generic\DateRequest; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\Budget\BudgetRepositoryInterface; use Illuminate\Http\JsonResponse; @@ -61,7 +62,7 @@ class SumController extends Controller */ public function budgeted(DateRequest $request): JsonResponse { - die('deprecated use of thing.'); + throw new FireflyException('deprecated use of thing.'); $data = $request->getAll(); $result = $this->repository->budgetedInPeriod($data['start'], $data['end']); $converted = $this->cerSum(array_values($result)); @@ -79,7 +80,7 @@ class SumController extends Controller */ public function spent(DateRequest $request): JsonResponse { - die('deprecated use of thing.'); + throw new FireflyException('deprecated use of thing.'); $data = $request->getAll(); $result = $this->repository->spentInPeriod($data['start'], $data['end']); $converted = $this->cerSum(array_values($result)); diff --git a/app/Api/V2/Controllers/Model/PiggyBank/ShowController.php b/app/Api/V2/Controllers/Model/PiggyBank/ShowController.php index aa32aeaa90..7159c1385e 100644 --- a/app/Api/V2/Controllers/Model/PiggyBank/ShowController.php +++ b/app/Api/V2/Controllers/Model/PiggyBank/ShowController.php @@ -26,6 +26,7 @@ declare(strict_types=1); namespace FireflyIII\Api\V2\Controllers\Model\PiggyBank; use FireflyIII\Api\V2\Controllers\Controller; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\UserGroups\PiggyBank\PiggyBankRepositoryInterface; use FireflyIII\Transformers\V2\PiggyBankTransformer; use Illuminate\Http\JsonResponse; @@ -44,7 +45,7 @@ class ShowController extends Controller parent::__construct(); $this->middleware( function ($request, $next) { - die('uses old administration ID check, needs to be updated.8'); + throw new FireflyException('uses old administration ID check, needs to be updated.8'); $this->repository = app(PiggyBankRepositoryInterface::class); $this->repository->setAdministrationId(auth()->user()->user_group_id); return $next($request); diff --git a/app/Api/V2/Controllers/Summary/BasicController.php b/app/Api/V2/Controllers/Summary/BasicController.php index 35c92a743f..aff2859dbf 100644 --- a/app/Api/V2/Controllers/Summary/BasicController.php +++ b/app/Api/V2/Controllers/Summary/BasicController.php @@ -77,7 +77,7 @@ class BasicController extends Controller $this->currencyRepos = app(CurrencyRepositoryInterface::class); $this->opsRepository = app(OperationsRepositoryInterface::class); - die('uses old administration ID check, needs to be updated.9'); + throw new FireflyException('uses old administration ID check, needs to be updated.9'); $this->abRepository->setAdministrationId($user->user_group_id); $this->accountRepository->setAdministrationId($user->user_group_id); diff --git a/app/Api/V2/Controllers/Summary/NetWorthController.php b/app/Api/V2/Controllers/Summary/NetWorthController.php index 25c1889aa2..7700a135d7 100644 --- a/app/Api/V2/Controllers/Summary/NetWorthController.php +++ b/app/Api/V2/Controllers/Summary/NetWorthController.php @@ -26,6 +26,7 @@ namespace FireflyIII\Api\V2\Controllers\Summary; use FireflyIII\Api\V2\Controllers\Controller; use FireflyIII\Api\V2\Request\Generic\SingleDateRequest; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Report\NetWorthInterface; use Illuminate\Http\JsonResponse; @@ -62,7 +63,7 @@ class NetWorthController extends Controller */ public function get(SingleDateRequest $request): JsonResponse { - die('deprecated use of thing.'); + throw new FireflyException('deprecated use of thing.'); $date = $request->getDate(); $result = $this->netWorth->sumNetWorthByCurrency($date); $converted = $this->cerSum($result); diff --git a/app/Helpers/Report/NetWorth.php b/app/Helpers/Report/NetWorth.php index d7401b48d3..bebbf46c07 100644 --- a/app/Helpers/Report/NetWorth.php +++ b/app/Helpers/Report/NetWorth.php @@ -245,7 +245,7 @@ class NetWorth implements NetWorthInterface { $this->userGroup = $userGroup; $this->adminAccountRepository = app(AdminAccountRepositoryInterface::class); - die('uses old administration ID check, needs to be updated.A'); + throw new FireflyException('uses old administration ID check, needs to be updated.A'); $this->adminAccountRepository->setAdministrationId($userGroup->id); } diff --git a/app/Models/RuleGroup.php b/app/Models/RuleGroup.php index 8d7b42ff04..ae8863fdd3 100644 --- a/app/Models/RuleGroup.php +++ b/app/Models/RuleGroup.php @@ -90,7 +90,7 @@ class RuleGroup extends Model ]; /** @var array Fields that can be filled */ - protected $fillable = ['user_id', 'stop_processing', 'order', 'title', 'description', 'active']; + protected $fillable = ['user_id', 'user_group_id', 'stop_processing', 'order', 'title', 'description', 'active']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). diff --git a/app/Models/TransactionGroup.php b/app/Models/TransactionGroup.php index eb0008f3c3..06a58e9257 100644 --- a/app/Models/TransactionGroup.php +++ b/app/Models/TransactionGroup.php @@ -84,7 +84,7 @@ class TransactionGroup extends Model ]; /** @var array Fields that can be filled */ - protected $fillable = ['user_id', 'title']; + protected $fillable = ['user_id', 'user_group_id', 'title']; /** * Route binder. Converts the key in the URL to the specified object (or throw 404). @@ -116,6 +116,14 @@ class TransactionGroup extends Model throw new NotFoundHttpException(); } + /** + * @return BelongsTo + */ + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + /** * @return HasMany */ @@ -124,14 +132,6 @@ class TransactionGroup extends Model return $this->hasMany(TransactionJournal::class); } - /** - * @return BelongsTo - */ - public function user(): BelongsTo - { - return $this->belongsTo(User::class); - } - /** * @return BelongsTo */ diff --git a/app/Providers/BudgetServiceProvider.php b/app/Providers/BudgetServiceProvider.php index 7babaddc10..41542ee7f2 100644 --- a/app/Providers/BudgetServiceProvider.php +++ b/app/Providers/BudgetServiceProvider.php @@ -23,6 +23,7 @@ declare(strict_types=1); namespace FireflyIII\Providers; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\Budget\AvailableBudgetRepository; use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface; use FireflyIII\Repositories\UserGroups\Budget\AvailableBudgetRepository as AdminAbRepository; @@ -78,7 +79,7 @@ class BudgetServiceProvider extends ServiceProvider $repository = app(AdminBudgetRepository::class); if ($app->auth->check()) { // @phpstan-ignore-line $repository->setUser(auth()->user()); - die('uses old administration ID check, needs to be updated.C'); + throw new FireflyException('uses old administration ID check, needs to be updated.C'); $repository->setAdministrationId(auth()->user()->user_group_id); } @@ -108,7 +109,7 @@ class BudgetServiceProvider extends ServiceProvider $repository = app(AdminAbRepository::class); if ($app->auth->check()) { // @phpstan-ignore-line $repository->setUser(auth()->user()); - die('uses old administration ID check, needs to be updated.D'); + throw new FireflyException('uses old administration ID check, needs to be updated.D'); $repository->setAdministrationId(auth()->user()->user_group_id); } @@ -164,7 +165,7 @@ class BudgetServiceProvider extends ServiceProvider $repository = app(AdminOperationsRepository::class); if ($app->auth->check()) { // @phpstan-ignore-line $repository->setUser(auth()->user()); - die('uses old administration ID check, needs to be updated.E'); + throw new FireflyException('uses old administration ID check, needs to be updated.E'); $repository->setAdministrationId(auth()->user()->user_group_id); } diff --git a/app/Repositories/RuleGroup/RuleGroupRepository.php b/app/Repositories/RuleGroup/RuleGroupRepository.php index b60e0035cc..d26fe17600 100644 --- a/app/Repositories/RuleGroup/RuleGroupRepository.php +++ b/app/Repositories/RuleGroup/RuleGroupRepository.php @@ -462,11 +462,12 @@ class RuleGroupRepository implements RuleGroupRepositoryInterface { $newRuleGroup = new RuleGroup( [ - 'user_id' => $this->user->id, - 'title' => $data['title'], - 'description' => $data['description'], - 'order' => 31337, - 'active' => array_key_exists('active', $data) ? $data['active'] : true, + 'user_id' => $this->user->id, + 'user_group_id' => $this->user->user_group_id, + 'title' => $data['title'], + 'description' => $data['description'], + 'order' => 31337, + 'active' => array_key_exists('active', $data) ? $data['active'] : true, ] ); $newRuleGroup->save(); diff --git a/app/Repositories/UserGroups/Budget/OperationsRepository.php b/app/Repositories/UserGroups/Budget/OperationsRepository.php index 90423858a1..e6ceba589a 100644 --- a/app/Repositories/UserGroups/Budget/OperationsRepository.php +++ b/app/Repositories/UserGroups/Budget/OperationsRepository.php @@ -132,7 +132,7 @@ class OperationsRepository implements OperationsRepositoryInterface { /** @var BudgetRepositoryInterface $repos */ $repos = app(BudgetRepositoryInterface::class); - die('uses old administration ID check, needs to be updated.F'); + throw new FireflyException('uses old administration ID check, needs to be updated.F'); $repos->setAdministrationId($this->getAdministrationId()); return $repos->getActiveBudgets(); diff --git a/app/Rules/BelongsUserGroup.php b/app/Rules/BelongsUserGroup.php index 7fc37fa978..54cc6a57e2 100644 --- a/app/Rules/BelongsUserGroup.php +++ b/app/Rules/BelongsUserGroup.php @@ -62,11 +62,11 @@ class BelongsUserGroup implements ValidationRule { $attribute = $this->parseAttribute($attribute); if (!auth()->check()) { - $fail('validation.belongs_user')->translate(); + $fail('validation.belongs_user_or_user_group')->translate(); return; } $attribute = (string)$attribute; - Log::debug(sprintf('Going to validate %s', $attribute)); + Log::debug(sprintf('Group: Going to validate "%s"', $attribute)); $result = match ($attribute) { 'piggy_bank_id' => $this->validatePiggyBankId((int)$value), @@ -252,7 +252,7 @@ class BelongsUserGroup implements ValidationRule private function validateAccountId(int $value): bool { if (0 === $value) { - // its ok to submit 0. other checks will fail. + // it's ok to submit 0. other checks will fail. return true; } $count = Account::where('id', '=', $value)->where('user_group_id', '=', $this->userGroup->id)->count(); diff --git a/app/Support/Http/Api/ConvertsExchangeRates.php b/app/Support/Http/Api/ConvertsExchangeRates.php index e4bcef608b..b8372bc44a 100644 --- a/app/Support/Http/Api/ConvertsExchangeRates.php +++ b/app/Support/Http/Api/ConvertsExchangeRates.php @@ -115,7 +115,7 @@ trait ConvertsExchangeRates */ public function cerSum(array $entries): array { - die('do not use me, needs refactor'); + throw new FireflyException('do not use me, needs refactor'); if (null === $this->enabled) { $this->getPreference(); } diff --git a/app/Support/Request/ConvertsDataTypes.php b/app/Support/Request/ConvertsDataTypes.php index a08a223d2f..bc88bebc63 100644 --- a/app/Support/Request/ConvertsDataTypes.php +++ b/app/Support/Request/ConvertsDataTypes.php @@ -26,6 +26,7 @@ namespace FireflyIII\Support\Request; use Carbon\Carbon; use Carbon\Exceptions\InvalidDateException; use Carbon\Exceptions\InvalidFormatException; +use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Log; @@ -171,7 +172,7 @@ trait ConvertsDataTypes // set administration ID // group ID $administrationId = auth()->user()->getAdministrationId(); - die('uses old administration ID check, needs to be updated.G'); + throw new FireflyException('uses old administration ID check, needs to be updated.G'); $repository->setAdministrationId($administrationId); $set = $this->get('accounts'); diff --git a/app/Validation/Administration/ValidatesAdministrationAccess.php b/app/Validation/Administration/ValidatesAdministrationAccess.php index 7108bee116..61a13ccf64 100644 --- a/app/Validation/Administration/ValidatesAdministrationAccess.php +++ b/app/Validation/Administration/ValidatesAdministrationAccess.php @@ -48,7 +48,7 @@ trait ValidatesAdministrationAccess */ protected function validateAdministration(Validator $validator, array $allowedRoles): void { - die('deprecated method, must be done through user.'); + throw new FireflyException('deprecated method, must be done through user.'); Log::debug('Now in validateAdministration()'); if (!auth()->check()) { Log::error('User is not authenticated.'); diff --git a/resources/lang/en_US/validation.php b/resources/lang/en_US/validation.php index 595547aaf2..c9e990f2ab 100644 --- a/resources/lang/en_US/validation.php +++ b/resources/lang/en_US/validation.php @@ -49,8 +49,8 @@ return [ 'transaction_types_equal' => 'All splits must be of the same type.', 'invalid_transaction_type' => 'Invalid transaction type.', 'invalid_selection' => 'Your selection is invalid.', - 'belongs_user' => 'This value is invalid for this field.', - 'belongs_user_or_user_group' => 'This value is invalid for this field.', + 'belongs_user' => 'This value is linked to an object that does not belong to you.', + 'belongs_user_or_user_group' => 'This value is linked to an object that does not belong to your current financial administration.', 'at_least_one_transaction' => 'Need at least one transaction.', 'recurring_transaction_id' => 'Need at least one transaction.', 'need_id_to_match' => 'You need to submit this entry with an ID for the API to be able to match it.',