mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Clean up some code.
This commit is contained in:
parent
b930ad4da7
commit
7d8d773f8f
@ -28,7 +28,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
/**
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Api\V1\Controllers\Controller;
|
||||
use FireflyIII\Api\V1\Requests\Insight\GenericRequest;
|
||||
use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Tag\TagRepositoryInterface;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
|
@ -32,7 +32,6 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\Bill\BillRepositoryInterface;
|
||||
use FireflyIII\Repositories\Budget\AvailableBudgetRepositoryInterface;
|
||||
|
@ -57,6 +57,7 @@ class UpdateRequest extends FormRequest
|
||||
// ignore notes, not submitted.
|
||||
unset($fields['notes']);
|
||||
}
|
||||
|
||||
return $this->getAllData($fields);
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,6 @@ namespace FireflyIII\Api\V1\Requests\Models\PiggyBank;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Rules\IsValidPositiveAmount;
|
||||
use FireflyIII\Rules\IsValidZeroOrMoreAmount;
|
||||
use FireflyIII\Support\Request\ChecksLogin;
|
||||
use FireflyIII\Support\Request\ConvertsDataTypes;
|
||||
@ -121,7 +120,7 @@ class StoreRequest extends FormRequest
|
||||
}
|
||||
}
|
||||
}
|
||||
if(bccomp($targetAmount, $currentAmount) === -1 && bccomp($targetAmount, '0') === 1) {
|
||||
if (-1 === bccomp($targetAmount, $currentAmount) && 1 === bccomp($targetAmount, '0')) {
|
||||
$validator->errors()->add('target_amount', trans('validation.current_amount_too_much'));
|
||||
}
|
||||
}
|
||||
@ -146,6 +145,7 @@ class StoreRequest extends FormRequest
|
||||
'current_amount' => $this->clearString((string) ($entry['current_amount'] ?? '0')),
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@ -163,6 +163,7 @@ class StoreRequest extends FormRequest
|
||||
return $currency;
|
||||
}
|
||||
}
|
||||
|
||||
throw new FireflyException('Unexpected empty currency.');
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,6 @@ use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Support\Chart\ChartData;
|
||||
use FireflyIII\Support\Http\Api\AccountBalanceGrouped;
|
||||
|
@ -31,7 +31,6 @@ use FireflyIII\Enums\TransactionTypeEnum;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\UserGroups\Currency\CurrencyRepositoryInterface;
|
||||
use FireflyIII\Support\Http\Api\CleansChartData;
|
||||
|
@ -33,7 +33,6 @@ use FireflyIII\Helpers\Collector\GroupCollectorInterface;
|
||||
use FireflyIII\Helpers\Report\NetWorthInterface;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\AccountType;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Repositories\UserGroups\Account\AccountRepositoryInterface;
|
||||
use FireflyIII\Repositories\UserGroups\Bill\BillRepositoryInterface;
|
||||
|
@ -1,4 +1,6 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/*
|
||||
* UpgradeMultiPiggyBanks.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -43,8 +45,6 @@ class UpgradeMultiPiggyBanks extends Command
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
@ -61,9 +61,6 @@ class UpgradeMultiPiggyBanks extends Command
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
private function isExecuted(): bool
|
||||
{
|
||||
$configVar = app('fireflyconfig')->get(self::CONFIG_NAME, false);
|
||||
@ -74,10 +71,6 @@ class UpgradeMultiPiggyBanks extends Command
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private function markAsExecuted(): void
|
||||
{
|
||||
app('fireflyconfig')->set(self::CONFIG_NAME, true);
|
||||
@ -89,6 +82,7 @@ class UpgradeMultiPiggyBanks extends Command
|
||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||
$set = PiggyBank::whereNotNull('account_id')->get();
|
||||
Log::debug(sprintf('Will update %d piggy banks(s).', $set->count()));
|
||||
|
||||
/** @var PiggyBank $piggyBank */
|
||||
foreach ($set as $piggyBank) {
|
||||
$this->upgradePiggyBank($piggyBank);
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* UnknownUserAttemptedLogin.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -24,7 +25,6 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Events\Security;
|
||||
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UnknownUserAttemptedLogin
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* TestEmailChannel.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
|
@ -43,7 +43,8 @@ use Illuminate\Support\Facades\Notification;
|
||||
*/
|
||||
class AdminEventHandler
|
||||
{
|
||||
public function sendLoginAttemptNotification(UnknownUserAttemptedLogin $event): void {
|
||||
public function sendLoginAttemptNotification(UnknownUserAttemptedLogin $event): void
|
||||
{
|
||||
try {
|
||||
$owner = new OwnerNotifiable();
|
||||
Notification::send($owner, new UnknownUserLoginAttempt($event->address));
|
||||
@ -64,13 +65,13 @@ class AdminEventHandler
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function sendInvitationNotification(InvitationCreated $event): void
|
||||
{
|
||||
$sendMail = app('fireflyconfig')->get('notification_invite_created', true)->data;
|
||||
if (false === $sendMail) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$owner = new OwnerNotifiable();
|
||||
Notification::send($owner, new UserInvitation($owner, $event->invitee));
|
||||
@ -131,18 +132,27 @@ class AdminEventHandler
|
||||
switch ($event->channel) {
|
||||
case 'email':
|
||||
$class = TestNotificationEmail::class;
|
||||
|
||||
break;
|
||||
|
||||
case 'slack':
|
||||
$class = TestNotificationSlack::class;
|
||||
|
||||
break;
|
||||
|
||||
case 'ntfy':
|
||||
$class = TestNotificationNtfy::class;
|
||||
|
||||
break;
|
||||
|
||||
case 'pushover':
|
||||
$class = TestNotificationPushover::class;
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
app('log')->error(sprintf('Unknown channel "%s" in sendTestNotification method.', $event->channel));
|
||||
|
||||
return;
|
||||
}
|
||||
Log::debug(sprintf('Will send %s as a notification.', $class));
|
||||
|
@ -223,6 +223,7 @@ class UserEventHandler
|
||||
$sendMail = (bool) app('fireflyconfig')->get('notification_admin_new_reg', true)->data;
|
||||
if ($sendMail) {
|
||||
$owner = $event->owner;
|
||||
|
||||
try {
|
||||
Notification::send($owner, new AdminRegistrationNotification($event->owner, $event->user));
|
||||
} catch (\Exception $e) { // @phpstan-ignore-line
|
||||
|
@ -23,15 +23,9 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Http\Controllers\Admin;
|
||||
|
||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Http\Middleware\IsDemoUser;
|
||||
use FireflyIII\Support\Notifications\UrlValidator;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Contracts\View\Factory;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Redirector;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\View\View;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* NotificationController.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -68,13 +69,26 @@ class NotificationController extends Controller
|
||||
$forcedAvailability['ntfy'] = '' !== $ntfyTopic;
|
||||
$forcedAvailability['pushover'] = '' !== $pushoverAppToken && '' !== $pushoverUserToken;
|
||||
|
||||
return view('admin.notifications.index',
|
||||
return view(
|
||||
'admin.notifications.index',
|
||||
compact(
|
||||
'title', 'subTitle', 'forcedAvailability', 'mainTitleIcon', 'subTitleIcon', 'channels',
|
||||
'slackUrl', 'notifications',
|
||||
'pushoverAppToken', 'pushoverUserToken',
|
||||
'ntfyServer', 'ntfyTopic', 'ntfyAuth', 'ntfyUser', 'ntfyPass'
|
||||
));
|
||||
'title',
|
||||
'subTitle',
|
||||
'forcedAvailability',
|
||||
'mainTitleIcon',
|
||||
'subTitleIcon',
|
||||
'channels',
|
||||
'slackUrl',
|
||||
'notifications',
|
||||
'pushoverAppToken',
|
||||
'pushoverUserToken',
|
||||
'ntfyServer',
|
||||
'ntfyTopic',
|
||||
'ntfyAuth',
|
||||
'ntfyUser',
|
||||
'ntfyPass'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function postIndex(NotificationRequest $request): RedirectResponse
|
||||
@ -112,7 +126,9 @@ class NotificationController extends Controller
|
||||
switch ($channel) {
|
||||
default:
|
||||
session()->flash('error', (string) trans('firefly.notification_test_failed', ['channel' => $channel]));
|
||||
|
||||
break;
|
||||
|
||||
case 'email':
|
||||
case 'slack':
|
||||
case 'pushover':
|
||||
|
@ -28,7 +28,6 @@ use FireflyIII\Events\ActuallyLoggedIn;
|
||||
use FireflyIII\Events\Security\UnknownUserAttemptedLogin;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Http\Controllers\Controller;
|
||||
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
|
||||
use FireflyIII\Providers\RouteServiceProvider;
|
||||
use FireflyIII\Repositories\User\UserRepositoryInterface;
|
||||
use Illuminate\Contracts\Foundation\Application;
|
||||
|
@ -107,6 +107,7 @@ class BudgetLimitController extends Controller
|
||||
public function show(BudgetLimit $budgetLimit)
|
||||
{
|
||||
$notes = $this->blRepository->getNoteText($budgetLimit);
|
||||
|
||||
return view('budgets.budget-limits.show', compact('budgetLimit', 'notes'));
|
||||
}
|
||||
|
||||
@ -116,6 +117,7 @@ class BudgetLimitController extends Controller
|
||||
public function edit(BudgetLimit $budgetLimit)
|
||||
{
|
||||
$notes = $this->blRepository->getNoteText($budgetLimit);
|
||||
|
||||
return view('budgets.budget-limits.edit', compact('budgetLimit', 'notes'));
|
||||
}
|
||||
|
||||
@ -278,6 +280,7 @@ class BudgetLimitController extends Controller
|
||||
if ('true' === $request->get('redirect')) {
|
||||
return redirect(route('budgets.index'));
|
||||
}
|
||||
|
||||
return response()->json($array);
|
||||
}
|
||||
}
|
||||
|
@ -43,7 +43,6 @@ use Illuminate\Support\Facades\Log;
|
||||
*/
|
||||
class HomeController extends Controller
|
||||
{
|
||||
|
||||
/**
|
||||
* HomeController constructor.
|
||||
*/
|
||||
|
@ -165,6 +165,7 @@ class IndexController extends Controller
|
||||
$transformer = app(PiggyBankTransformer::class);
|
||||
$transformer->setParameters(new ParameterBag());
|
||||
$piggyBanks = [];
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($collection as $piggy) {
|
||||
$array = $transformer->transform($piggy);
|
||||
@ -179,6 +180,7 @@ class IndexController extends Controller
|
||||
// sum the total amount for the index.
|
||||
$piggyBanks[$groupOrder]['piggy_banks'][] = $array;
|
||||
}
|
||||
|
||||
return $piggyBanks;
|
||||
}
|
||||
|
||||
@ -196,9 +198,11 @@ class IndexController extends Controller
|
||||
$accountTransformer->setParameters($parameters);
|
||||
|
||||
$return = [];
|
||||
|
||||
/** @var PiggyBank $piggy */
|
||||
foreach ($collection as $piggy) {
|
||||
$accounts = $piggy->accounts;
|
||||
|
||||
/** @var Account $account */
|
||||
foreach ($accounts as $account) {
|
||||
$array = $accountTransformer->transform($account);
|
||||
@ -222,12 +226,13 @@ class IndexController extends Controller
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
private function mergeAccountsAndPiggies(array $piggyBanks, array $accounts): array
|
||||
{
|
||||
/** @var array $piggyBank */
|
||||
// @var array $piggyBank
|
||||
foreach ($piggyBanks as $group) {
|
||||
foreach ($group['piggy_banks'] as $piggyBank) {
|
||||
// loop all accounts in this piggy bank subtract the current amount from "left to save" in the $accounts array.
|
||||
@ -243,6 +248,7 @@ class IndexController extends Controller
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $accounts;
|
||||
}
|
||||
}
|
||||
|
@ -117,9 +117,10 @@ class PreferencesController extends Controller
|
||||
$ntfyAuth = app('preferences')->get('ntfy_auth', false)->data;
|
||||
$ntfyUser = app('preferences')->getEncrypted('ntfy_user', '')->data;
|
||||
$ntfyPass = app('preferences')->getEncrypted('ntfy_pass', '')->data;
|
||||
$channels = config('notifications.channels');
|
||||
$forcedAvailability = [];
|
||||
|
||||
|
||||
// notification preferences (single value for each):
|
||||
// notification preferences
|
||||
$notifications = [];
|
||||
foreach (config('notifications.notifications.user') as $key => $info) {
|
||||
if ($info['enabled']) {
|
||||
@ -130,6 +131,12 @@ class PreferencesController extends Controller
|
||||
];
|
||||
}
|
||||
}
|
||||
// loop all channels to see if they are available.
|
||||
foreach ($channels as $channel => $info) {
|
||||
$forcedAvailability[$channel] = true;
|
||||
}
|
||||
$forcedAvailability['ntfy'] = '' !== $ntfyTopic;
|
||||
$forcedAvailability['pushover'] = '' !== $pushoverAppToken && '' !== $pushoverUserToken;
|
||||
|
||||
ksort($languages);
|
||||
|
||||
@ -161,9 +168,32 @@ class PreferencesController extends Controller
|
||||
$ntfyPass = '';
|
||||
}
|
||||
|
||||
return view('preferences.index', compact('language', 'pushoverAppToken', 'pushoverUserToken',
|
||||
'ntfyServer', 'ntfyTopic', 'ntfyAuth', 'ntfyUser', 'ntfyPass',
|
||||
'groupedAccounts', 'isDocker', 'frontpageAccounts', 'languages', 'darkMode', 'availableDarkModes', 'notifications', 'slackUrl', 'locales', 'locale', 'tjOptionalFields', 'viewRange', 'customFiscalYear', 'listPageSize', 'fiscalYearStart'));
|
||||
return view('preferences.index', compact(
|
||||
'language',
|
||||
'pushoverAppToken',
|
||||
'pushoverUserToken',
|
||||
'ntfyServer',
|
||||
'ntfyTopic',
|
||||
'ntfyAuth',
|
||||
'ntfyUser',
|
||||
'forcedAvailability',
|
||||
'ntfyPass',
|
||||
'groupedAccounts',
|
||||
'isDocker',
|
||||
'frontpageAccounts',
|
||||
'languages',
|
||||
'darkMode',
|
||||
'availableDarkModes',
|
||||
'notifications',
|
||||
'slackUrl',
|
||||
'locales',
|
||||
'locale',
|
||||
'tjOptionalFields',
|
||||
'viewRange',
|
||||
'customFiscalYear',
|
||||
'listPageSize',
|
||||
'fiscalYearStart'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -189,7 +219,8 @@ class PreferencesController extends Controller
|
||||
|
||||
// extract notifications:
|
||||
$all = $request->all();
|
||||
die('fix the reference to the available notifications.');
|
||||
|
||||
exit('fix the reference to the available notifications.');
|
||||
foreach (config('firefly.available_notifications') as $option) {
|
||||
$key = sprintf('notification_%s', $option);
|
||||
if (array_key_exists($key, $all)) {
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* NotificationRequest.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -53,6 +54,7 @@ class NotificationRequest extends FormRequest
|
||||
$return['ntfy_auth'] = $this->convertBoolean($this->get('ntfy_auth'));
|
||||
$return['ntfy_user'] = $this->convertString('ntfy_user');
|
||||
$return['ntfy_pass'] = $this->convertString('ntfy_pass');
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
@ -70,7 +72,7 @@ class NotificationRequest extends FormRequest
|
||||
foreach (config('notifications.notifications.owner') as $key => $info) {
|
||||
$rules[sprintf('notification_%s', $key)] = 'in:0,1';
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class PiggyBankStoreRequest extends FormRequest
|
||||
$accounts = [];
|
||||
}
|
||||
foreach ($accounts as $item) {
|
||||
$data['accounts'][] = ['account_id' => (int) ($item)];
|
||||
$data['accounts'][] = ['account_id' => (int) $item];
|
||||
}
|
||||
|
||||
return $data;
|
||||
@ -127,6 +127,7 @@ class PiggyBankStoreRequest extends FormRequest
|
||||
if (null === $currency) {
|
||||
return app('amount')->getDefaultCurrency();
|
||||
}
|
||||
|
||||
return $currency;
|
||||
}
|
||||
}
|
||||
|
@ -69,7 +69,8 @@ class PiggyBank extends Model
|
||||
$piggyBank = self::where('piggy_banks.id', $piggyBankId)
|
||||
->leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||
->where('accounts.user_id', auth()->user()->id)->first(['piggy_banks.*']);
|
||||
->where('accounts.user_id', auth()->user()->id)->first(['piggy_banks.*'])
|
||||
;
|
||||
if (null !== $piggyBank) {
|
||||
return $piggyBank;
|
||||
}
|
||||
|
@ -38,7 +38,6 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* UnknownUserLoginAttempt.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -64,15 +65,14 @@ class UnknownUserLoginAttempt extends Notification
|
||||
/**
|
||||
* Get the mail representation of the notification.
|
||||
*
|
||||
* @return MailMessage
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function toMail(OwnerNotifiable $notifiable): MailMessage
|
||||
{
|
||||
return new MailMessage()
|
||||
->markdown('emails.owner.unknown-user', ['address' => $this->address])
|
||||
->subject((string) trans('email.unknown_user_subject'));
|
||||
->subject((string) trans('email.unknown_user_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -90,7 +90,8 @@ class UnknownUserLoginAttempt extends Notification
|
||||
public function toPushover(OwnerNotifiable $notifiable): PushoverMessage
|
||||
{
|
||||
return PushoverMessage::create((string) trans('email.unknown_user_message', ['address' => $this->address]))
|
||||
->title((string) trans('email.unknown_user_subject'));
|
||||
->title((string) trans('email.unknown_user_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
|
@ -83,7 +83,8 @@ class UserInvitation extends Notification
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.invitation-created', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email])
|
||||
->subject((string) trans('email.invitation_created_subject'));
|
||||
->subject((string) trans('email.invitation_created_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,7 +108,8 @@ class UserInvitation extends Notification
|
||||
Log::debug('Now in toPushover() for UserInvitation');
|
||||
|
||||
return PushoverMessage::create((string) trans('email.invitation_created_body', ['email' => $this->invitee->user->email, 'invitee' => $this->invitee->email]))
|
||||
->title((string) trans('email.invitation_created_subject'));
|
||||
->title((string) trans('email.invitation_created_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
|
@ -79,7 +79,8 @@ class UserRegistration extends Notification
|
||||
{
|
||||
return (new MailMessage())
|
||||
->markdown('emails.registered-admin', ['email' => $this->user->email, 'id' => $this->user->id])
|
||||
->subject((string) trans('email.registered_subject_admin'));
|
||||
->subject((string) trans('email.registered_subject_admin'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,7 +102,8 @@ class UserRegistration extends Notification
|
||||
Log::debug('Now in toPushover() for UserRegistration');
|
||||
|
||||
return PushoverMessage::create((string) trans('email.admin_new_user_registered', ['email' => $this->user->email, 'invitee' => $this->user->email]))
|
||||
->title((string) trans('email.registered_subject_admin'));
|
||||
->title((string) trans('email.registered_subject_admin'))
|
||||
;
|
||||
}
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
|
@ -27,7 +27,6 @@ namespace FireflyIII\Notifications\Admin;
|
||||
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
|
||||
use FireflyIII\Notifications\ReturnsAvailableChannels;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\Support\Notifications\UrlValidator;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Messages\SlackMessage;
|
||||
@ -108,7 +107,8 @@ class VersionCheckResult extends Notification
|
||||
Log::debug('Now in toPushover() for VersionCheckResult');
|
||||
|
||||
return PushoverMessage::create($this->message)
|
||||
->title((string) trans('email.new_version_email_subject'));
|
||||
->title((string) trans('email.new_version_email_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* AdminNotifiable.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -30,13 +31,13 @@ use NotificationChannels\Pushover\PushoverReceiver;
|
||||
|
||||
class OwnerNotifiable
|
||||
{
|
||||
|
||||
public function routeNotificationForSlack(): string
|
||||
{
|
||||
$res = app('fireflyconfig')->getEncrypted('slack_webhook_url', '')->data;
|
||||
if (is_array($res)) {
|
||||
$res = '';
|
||||
}
|
||||
|
||||
return (string) $res;
|
||||
}
|
||||
|
||||
@ -45,8 +46,10 @@ class OwnerNotifiable
|
||||
Log::debug('Return settings for routeNotificationForPushover');
|
||||
$pushoverAppToken = (string) app('fireflyconfig')->getEncrypted('pushover_app_token', '')->data;
|
||||
$pushoverUserToken = (string) app('fireflyconfig')->getEncrypted('pushover_user_token', '')->data;
|
||||
|
||||
return PushoverReceiver::withUserKey($pushoverUserToken)
|
||||
->withApplicationToken($pushoverAppToken);
|
||||
->withApplicationToken($pushoverAppToken)
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -62,6 +65,7 @@ class OwnerNotifiable
|
||||
$method = 'routeNotificationFor'.Str::studly($driver);
|
||||
if (method_exists($this, $method)) {
|
||||
Log::debug(sprintf('Redirect for settings to "%s".', $method));
|
||||
|
||||
return $this->{$method}($notification); // @phpstan-ignore-line
|
||||
}
|
||||
Log::debug(sprintf('No method "%s" found, return generic settings.', $method));
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ReturnsAvailableChannels.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -73,8 +74,8 @@ class ReturnsAvailableChannels
|
||||
}
|
||||
|
||||
Log::debug(sprintf('Final channel set in ReturnsAvailableChannels: %s ', implode(', ', $channels)));
|
||||
|
||||
// only the owner can get notifications over
|
||||
return $channels;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ReturnsSettings.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -34,6 +35,7 @@ class ReturnsSettings
|
||||
if ('ntfy' === $channel) {
|
||||
return self::getNtfySettings($type, $user);
|
||||
}
|
||||
|
||||
throw new FireflyException(sprintf('Cannot handle channel "%s"', $channel));
|
||||
}
|
||||
|
||||
@ -54,7 +56,7 @@ class ReturnsSettings
|
||||
$settings['ntfy_user'] = FireflyConfig::getEncrypted('ntfy_user', '')->data;
|
||||
$settings['ntfy_pass'] = FireflyConfig::getEncrypted('ntfy_pass', '')->data;
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -49,8 +49,6 @@ class TestNotificationEmail extends Notification
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return array
|
||||
@ -73,9 +71,11 @@ class TestNotificationEmail extends Notification
|
||||
public function toMail(OwnerNotifiable $notifiable)
|
||||
{
|
||||
$address = (string) config('firefly.site_owner');
|
||||
|
||||
return (new MailMessage())
|
||||
->markdown('emails.admin-test', ['email' => $address])
|
||||
->subject((string) trans('email.admin_test_subject'));
|
||||
->subject((string) trans('email.admin_test_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -26,7 +26,6 @@ namespace FireflyIII\Notifications\Test;
|
||||
|
||||
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
|
||||
use FireflyIII\Notifications\ReturnsSettings;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Ntfy\Message;
|
||||
@ -66,7 +65,6 @@ class TestNotificationNtfy extends Notification
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toNtfy(OwnerNotifiable $notifiable): Message
|
||||
{
|
||||
$settings = ReturnsSettings::getSettings('ntfy', 'owner', null);
|
||||
|
@ -25,15 +25,11 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Notifications\Test;
|
||||
|
||||
use FireflyIII\Notifications\Notifiables\OwnerNotifiable;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use NotificationChannels\Pushover\PushoverChannel;
|
||||
use NotificationChannels\Pushover\PushoverMessage;
|
||||
use Ntfy\Message;
|
||||
use Wijourdil\NtfyNotificationChannel\Channels\NtfyChannel;
|
||||
|
||||
// use Illuminate\Notifications\Slack\SlackMessage;
|
||||
|
||||
@ -57,8 +53,6 @@ class TestNotificationPushover extends Notification
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return array
|
||||
@ -69,16 +63,15 @@ class TestNotificationPushover extends Notification
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function toPushover(OwnerNotifiable $notifiable): PushoverMessage
|
||||
{
|
||||
Log::debug('Now in toPushover()');
|
||||
|
||||
return PushoverMessage::create((string)trans('email.admin_test_message', ['channel' => 'Pushover']))
|
||||
->title((string)trans('email.admin_test_subject'));
|
||||
->title((string)trans('email.admin_test_subject'))
|
||||
;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
|
@ -51,8 +51,6 @@ class TestNotificationSlack extends Notification
|
||||
/**
|
||||
* Get the array representation of the notification.
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @return array
|
||||
@ -66,10 +64,7 @@ class TestNotificationSlack extends Notification
|
||||
/**
|
||||
* Get the Slack representation of the notification.
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
*/
|
||||
public function toSlack(OwnerNotifiable $notifiable)
|
||||
{
|
||||
@ -82,8 +77,6 @@ class TestNotificationSlack extends Notification
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*
|
||||
* @param OwnerNotifiable $notifiable
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function via(OwnerNotifiable $notifiable)
|
||||
|
@ -25,7 +25,6 @@ namespace FireflyIII\Providers;
|
||||
|
||||
use FireflyIII\Events\ActuallyLoggedIn;
|
||||
use FireflyIII\Events\Admin\InvitationCreated;
|
||||
use FireflyIII\Events\AdminRequestedTestMessage;
|
||||
use FireflyIII\Events\DestroyedTransactionGroup;
|
||||
use FireflyIII\Events\DetectedNewIPAddress;
|
||||
use FireflyIII\Events\Model\BudgetLimit\Created;
|
||||
|
@ -68,7 +68,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d'));
|
||||
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
)
|
||||
;
|
||||
}
|
||||
)
|
||||
->orWhere(
|
||||
@ -77,13 +78,15 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d'));
|
||||
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
)
|
||||
;
|
||||
}
|
||||
)
|
||||
->where('budget_limits.transaction_currency_id', $currency->id)
|
||||
->whereNull('budgets.deleted_at')
|
||||
->where('budgets.active', true)
|
||||
->where('budgets.user_id', $this->user->id);
|
||||
->where('budgets.user_id', $this->user->id)
|
||||
;
|
||||
if (null !== $budgets && $budgets->count() > 0) {
|
||||
$query->whereIn('budget_limits.budget_id', $budgets->pluck('id')->toArray());
|
||||
}
|
||||
@ -138,14 +141,16 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
->with(['budget'])
|
||||
->where('budgets.user_id', $this->user->id)
|
||||
->whereNull('budgets.deleted_at')
|
||||
->get(['budget_limits.*']);
|
||||
->get(['budget_limits.*'])
|
||||
;
|
||||
}
|
||||
// one of the two is NULL.
|
||||
if (null === $start xor null === $end) {
|
||||
$query = BudgetLimit::leftJoin('budgets', 'budgets.id', '=', 'budget_limits.budget_id')
|
||||
->with(['budget'])
|
||||
->whereNull('budgets.deleted_at')
|
||||
->where('budgets.user_id', $this->user->id);
|
||||
->where('budgets.user_id', $this->user->id)
|
||||
;
|
||||
if (null !== $end) {
|
||||
// end date must be before $end.
|
||||
$query->where('end_date', '<=', $end->format('Y-m-d 00:00:00'));
|
||||
@ -178,7 +183,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d'));
|
||||
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
)
|
||||
;
|
||||
}
|
||||
)
|
||||
->orWhere(
|
||||
@ -187,9 +193,11 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d'));
|
||||
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d'));
|
||||
}
|
||||
);
|
||||
)
|
||||
;
|
||||
}
|
||||
)->get(['budget_limits.*']);
|
||||
)->get(['budget_limits.*'])
|
||||
;
|
||||
}
|
||||
|
||||
public function getBudgetLimits(Budget $budget, ?Carbon $start = null, ?Carbon $end = null): Collection
|
||||
@ -231,7 +239,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00'));
|
||||
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 23:59:59'));
|
||||
}
|
||||
);
|
||||
)
|
||||
;
|
||||
}
|
||||
)
|
||||
->orWhere(
|
||||
@ -240,9 +249,11 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 23:59:59'));
|
||||
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d 00:00:00'));
|
||||
}
|
||||
);
|
||||
)
|
||||
;
|
||||
}
|
||||
)->orderBy('budget_limits.start_date', 'DESC')->get(['budget_limits.*']);
|
||||
)->orderBy('budget_limits.start_date', 'DESC')->get(['budget_limits.*'])
|
||||
;
|
||||
}
|
||||
|
||||
public function setUser(null|Authenticatable|User $user): void
|
||||
@ -278,7 +289,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
->where('budget_limits.start_date', $data['start_date']->format('Y-m-d'))
|
||||
->where('budget_limits.end_date', $data['end_date']->format('Y-m-d'))
|
||||
->where('budget_limits.transaction_currency_id', $currency->id)
|
||||
->first(['budget_limits.*']);
|
||||
->first(['budget_limits.*'])
|
||||
;
|
||||
if (null !== $limit) {
|
||||
throw new FireflyException('200027: Budget limit already exists.');
|
||||
}
|
||||
@ -303,13 +315,13 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
return $limit;
|
||||
}
|
||||
|
||||
|
||||
public function find(Budget $budget, TransactionCurrency $currency, Carbon $start, Carbon $end): ?BudgetLimit
|
||||
{
|
||||
return $budget->budgetlimits()
|
||||
->where('transaction_currency_id', $currency->id)
|
||||
->where('start_date', $start->format('Y-m-d'))
|
||||
->where('end_date', $end->format('Y-m-d'))->first();
|
||||
->where('end_date', $end->format('Y-m-d'))->first()
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -362,7 +374,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$limits = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->count('budget_limits.*');
|
||||
->count('budget_limits.*')
|
||||
;
|
||||
app('log')->debug(sprintf('Found %d budget limits.', $limits));
|
||||
|
||||
// there might be a budget limit for these dates:
|
||||
@ -370,7 +383,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$limit = $budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->first(['budget_limits.*']);
|
||||
->first(['budget_limits.*'])
|
||||
;
|
||||
|
||||
// if more than 1 limit found, delete the others:
|
||||
if ($limits > 1 && null !== $limit) {
|
||||
@ -378,7 +392,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
$budget->budgetlimits()
|
||||
->where('budget_limits.start_date', $start->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.end_date', $end->format('Y-m-d 00:00:00'))
|
||||
->where('budget_limits.id', '!=', $limit->id)->delete();
|
||||
->where('budget_limits.id', '!=', $limit->id)->delete()
|
||||
;
|
||||
}
|
||||
|
||||
// delete if amount is zero.
|
||||
@ -413,12 +428,14 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
|
||||
return $limit;
|
||||
}
|
||||
|
||||
#[\Override] public function getNoteText(BudgetLimit $budgetLimit): string
|
||||
#[\Override]
|
||||
public function getNoteText(BudgetLimit $budgetLimit): string
|
||||
{
|
||||
return (string) $budgetLimit->notes()->first()?->text;
|
||||
}
|
||||
|
||||
#[\Override] public function setNoteText(BudgetLimit $budgetLimit, string $text): void
|
||||
#[\Override]
|
||||
public function setNoteText(BudgetLimit $budgetLimit, string $text): void
|
||||
{
|
||||
$dbNote = $budgetLimit->notes()->first();
|
||||
if ('' !== $text) {
|
||||
|
@ -49,6 +49,7 @@ interface BudgetLimitRepositoryInterface
|
||||
public function destroyAll(): void;
|
||||
|
||||
public function getNoteText(BudgetLimit $budgetLimit): string;
|
||||
|
||||
public function setNoteText(BudgetLimit $budgetLimit, string $text): void;
|
||||
|
||||
/**
|
||||
|
@ -106,7 +106,8 @@ class CurrencyRepository implements CurrencyRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
#[\Override] public function find(int $currencyId): ?TransactionCurrency
|
||||
#[\Override]
|
||||
public function find(int $currencyId): ?TransactionCurrency
|
||||
{
|
||||
return TransactionCurrency::find($currencyId);
|
||||
}
|
||||
|
@ -30,11 +30,9 @@ use FireflyIII\Factory\PiggyBankFactory;
|
||||
use FireflyIII\Models\Note;
|
||||
use FireflyIII\Models\PiggyBank;
|
||||
use FireflyIII\Models\PiggyBankRepetition;
|
||||
use FireflyIII\Models\TransactionCurrency;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Repositories\ObjectGroup\CreatesObjectGroups;
|
||||
use FireflyIII\Support\Facades\Amount;
|
||||
use Illuminate\Database\QueryException;
|
||||
|
||||
/**
|
||||
* Trait ModifiesPiggyBanks
|
||||
@ -184,10 +182,10 @@ trait ModifiesPiggyBanks
|
||||
{
|
||||
$factory = new PiggyBankFactory();
|
||||
$factory->user = $this->user;
|
||||
|
||||
return $factory->store($data);
|
||||
}
|
||||
|
||||
|
||||
public function setOrder(PiggyBank $piggyBank, int $newOrder): bool
|
||||
{
|
||||
$oldOrder = $piggyBank->order;
|
||||
@ -220,6 +218,7 @@ trait ModifiesPiggyBanks
|
||||
if ('' === $note) {
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
$dbNote?->delete();
|
||||
|
||||
return;
|
||||
}
|
||||
$dbNote = $piggyBank->notes()->first();
|
||||
|
@ -122,12 +122,14 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
$amount = '' === $amount ? '0' : $amount;
|
||||
$sum = bcadd($sum, $amount);
|
||||
}
|
||||
|
||||
return $sum;
|
||||
}
|
||||
|
||||
public function getRepetition(PiggyBank $piggyBank): ?PiggyBankRepetition
|
||||
{
|
||||
throw new FireflyException('[b] Piggy bank repetitions are EOL.');
|
||||
|
||||
return $piggyBank->piggyBankRepetitions()->first();
|
||||
}
|
||||
|
||||
@ -244,7 +246,6 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return note for piggy bank.
|
||||
*/
|
||||
@ -276,8 +277,7 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
|
||||
public function getPiggyBanks(): Collection
|
||||
{
|
||||
return PiggyBank
|
||||
::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
return PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||
->where('accounts.user_id', auth()->user()->id)
|
||||
->with(
|
||||
@ -286,7 +286,8 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
'objectGroups',
|
||||
]
|
||||
)
|
||||
->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*']);
|
||||
->orderBy('piggy_banks.order', 'ASC')->get(['piggy_banks.*'])
|
||||
;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -344,17 +345,20 @@ class PiggyBankRepository implements PiggyBankRepositoryInterface
|
||||
$search->whereLike('piggy_banks.name', sprintf('%%%s%%', $query));
|
||||
}
|
||||
$search->orderBy('piggy_banks.order', 'ASC')
|
||||
->orderBy('piggy_banks.name', 'ASC');
|
||||
->orderBy('piggy_banks.name', 'ASC')
|
||||
;
|
||||
|
||||
return $search->take($limit)->get();
|
||||
}
|
||||
|
||||
#[\Override] public function purgeAll(): void
|
||||
#[\Override]
|
||||
public function purgeAll(): void
|
||||
{
|
||||
throw new FireflyException('TODO Not implemented');
|
||||
}
|
||||
|
||||
#[\Override] public function resetOrder(): void
|
||||
#[\Override]
|
||||
public function resetOrder(): void
|
||||
{
|
||||
$factory = new PiggyBankFactory();
|
||||
$factory->user = $this->user;
|
||||
|
@ -289,6 +289,7 @@ class ExpandedForm
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws FireflyException
|
||||
*/
|
||||
|
@ -57,14 +57,18 @@ class FireflyConfig
|
||||
}
|
||||
if ('' === $result->data) {
|
||||
Log::warning(sprintf('Empty encrypted configuration value found: "%s"', $name));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
try {
|
||||
$result->data = decrypt($result->data);
|
||||
} catch (DecryptException $e) {
|
||||
Log::error(sprintf('Could not decrypt configuration value "%s": %s', $name, $e->getMessage()));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -106,8 +110,10 @@ class FireflyConfig
|
||||
$encrypted = encrypt($value);
|
||||
} catch (EncryptException $e) {
|
||||
Log::error(sprintf('Could not encrypt configuration value "%s": %s', $name, $e->getMessage()));
|
||||
|
||||
throw new FireflyException(sprintf('Could not encrypt configuration value "%s". Cowardly refuse to continue.', $name));
|
||||
}
|
||||
|
||||
return $this->set($name, $encrypted);
|
||||
}
|
||||
|
||||
|
@ -157,6 +157,7 @@ class AccountForm
|
||||
{
|
||||
$types = [AccountTypeEnum::ASSET->value, AccountTypeEnum::DEFAULT->value, AccountTypeEnum::MORTGAGE->value, AccountTypeEnum::DEBT->value, AccountTypeEnum::LOAN->value];
|
||||
$grouped = $this->getAccountsGrouped($types);
|
||||
|
||||
return $this->multiSelect($name, $grouped, $value, $options);
|
||||
}
|
||||
|
||||
|
@ -64,14 +64,18 @@ class Preferences
|
||||
}
|
||||
if ('' === $result->data) {
|
||||
Log::warning(sprintf('Empty encrypted preference found: "%s"', $name));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
try {
|
||||
$result->data = decrypt($result->data);
|
||||
} catch (DecryptException $e) {
|
||||
Log::error(sprintf('Could not decrypt preference "%s": %s', $name, $e->getMessage()));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
@ -81,12 +85,13 @@ class Preferences
|
||||
$encrypted = encrypt($value);
|
||||
} catch (EncryptException $e) {
|
||||
Log::error(sprintf('Could not encrypt preference "%s": %s', $name, $e->getMessage()));
|
||||
|
||||
throw new FireflyException(sprintf('Could not encrypt preference "%s". Cowardly refuse to continue.', $name));
|
||||
}
|
||||
|
||||
return $this->set($name, $encrypted);
|
||||
}
|
||||
|
||||
|
||||
public function get(string $name, null|array|bool|int|string $default = null): ?Preference
|
||||
{
|
||||
/** @var null|User $user */
|
||||
|
@ -140,6 +140,7 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
// TODO add balance, add left to save.
|
||||
];
|
||||
}
|
||||
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
@ -115,6 +115,7 @@ class PiggyBankTransformer extends AbstractTransformer
|
||||
|
||||
// grab repetitions (for current amount):
|
||||
$repetitions = PiggyBankRepetition::whereIn('piggy_bank_id', $piggyBanks)->get();
|
||||
|
||||
throw new FireflyException('[d] Piggy bank repetitions are EOL.');
|
||||
|
||||
/** @var PiggyBankRepetition $repetition */
|
||||
|
10
app/User.php
10
app/User.php
@ -49,10 +49,8 @@ use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Models\UserRole;
|
||||
use FireflyIII\Models\Webhook;
|
||||
use FireflyIII\Notifications\Admin\UserInvitation;
|
||||
use FireflyIII\Notifications\Admin\UserRegistration;
|
||||
use FireflyIII\Notifications\Admin\VersionCheckResult;
|
||||
use FireflyIII\Notifications\Test\TestNotificationDiscord;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
@ -400,9 +398,10 @@ class User extends Authenticatable
|
||||
$appToken = (string) app('fireflyconfig')->getEncrypted('pushover_app_token', '')->data;
|
||||
$userToken = (string) app('fireflyconfig')->getEncrypted('pushover_user_token', '')->data;
|
||||
|
||||
if (property_exists($notification, 'type') && $notification->type === 'owner') {
|
||||
if (property_exists($notification, 'type') && 'owner' === $notification->type) {
|
||||
return PushoverReceiver::withUserKey($userToken)
|
||||
->withApplicationToken($appToken);
|
||||
->withApplicationToken($appToken)
|
||||
;
|
||||
}
|
||||
|
||||
throw new FireflyException('No pushover token found.');
|
||||
@ -411,7 +410,6 @@ class User extends Authenticatable
|
||||
// return (string) config('services.pushover.token');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Route notifications for the Slack channel.
|
||||
*/
|
||||
@ -424,7 +422,7 @@ class User extends Authenticatable
|
||||
}
|
||||
$res = (string) $res;
|
||||
|
||||
if (property_exists($notification, 'type') && $notification->type === 'owner') {
|
||||
if (property_exists($notification, 'type') && 'owner' === $notification->type) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
@ -813,14 +813,15 @@ class FireflyValidator extends Validator
|
||||
public function validateUniquePiggyBankForUser($attribute, $value, $parameters): bool
|
||||
{
|
||||
$exclude = $parameters[0] ?? null;
|
||||
$query = PiggyBank
|
||||
::leftJoin('account_piggy_bank','account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
$query = PiggyBank::leftJoin('account_piggy_bank', 'account_piggy_bank.piggy_bank_id', '=', 'piggy_banks.id')
|
||||
->leftJoin('accounts', 'accounts.id', '=', 'account_piggy_bank.account_id')
|
||||
->where('accounts.user_id', auth()->user()->id);
|
||||
->where('accounts.user_id', auth()->user()->id)
|
||||
;
|
||||
if (null !== $exclude) {
|
||||
$query->where('piggy_banks.id', '!=', (int) $exclude);
|
||||
}
|
||||
$query->where('piggy_banks.name', $value);
|
||||
|
||||
return 0 === $query->get(['piggy_banks.*'])->count();
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* notifications.php
|
||||
* Copyright (c) 2024 james@firefly-iii.org.
|
||||
@ -20,14 +21,15 @@
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
return [
|
||||
'channels' => [
|
||||
'email' => ['enabled' => true, 'ui_configurable' => 0,],
|
||||
'slack' => ['enabled' => true, 'ui_configurable' => 1,],
|
||||
'ntfy' => ['enabled' => true, 'ui_configurable' => 1,],
|
||||
'pushover' => ['enabled' => true, 'ui_configurable' => 1,],
|
||||
'gotify' => ['enabled' => false, 'ui_configurable' => 0,],
|
||||
'pushbullet' => ['enabled' => false, 'ui_configurable' => 0,],
|
||||
'email' => ['enabled' => true, 'ui_configurable' => 0],
|
||||
'slack' => ['enabled' => true, 'ui_configurable' => 1],
|
||||
'ntfy' => ['enabled' => true, 'ui_configurable' => 1],
|
||||
'pushover' => ['enabled' => true, 'ui_configurable' => 1],
|
||||
'gotify' => ['enabled' => false, 'ui_configurable' => 0],
|
||||
'pushbullet' => ['enabled' => false, 'ui_configurable' => 0],
|
||||
],
|
||||
'notifications' => [
|
||||
'user' => [
|
||||
|
@ -1,5 +1,7 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
// config for Wijourdil/NtfyNotificationChannel
|
||||
return [
|
||||
|
||||
|
@ -1,31 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
return new class () extends Migration {
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
// make account_id nullable and the relation also nullable.
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 1. drop index
|
||||
$table->dropForeign('piggy_banks_account_id_foreign');
|
||||
});
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 2. make column nullable.
|
||||
$table->unsignedInteger('account_id')->nullable()->change();
|
||||
});
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 3. add currency
|
||||
$table->integer('transaction_currency_id', false, true)->after('account_id');
|
||||
$table->foreign('transaction_currency_id', 'unique_currency')->references('id')->on('transaction_currencies')->onDelete('cascade');
|
||||
});
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 4. rename columns
|
||||
$table->renameColumn('targetamount', 'target_amount');
|
||||
$table->renameColumn('startdate', 'start_date');
|
||||
@ -33,13 +34,13 @@ return new class extends Migration
|
||||
$table->renameColumn('startdate_tz', 'start_date_tz');
|
||||
$table->renameColumn('targetdate_tz', 'target_date_tz');
|
||||
});
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 5. add new index
|
||||
$table->foreign('account_id')->references('id')->on('accounts')->onDelete('set null');
|
||||
});
|
||||
|
||||
// rename some fields in piggy bank reps.
|
||||
Schema::table('piggy_bank_repetitions', static function (Blueprint $table) {
|
||||
Schema::table('piggy_bank_repetitions', static function (Blueprint $table): void {
|
||||
// 6. rename columns
|
||||
$table->renameColumn('currentamount', 'current_amount');
|
||||
$table->renameColumn('startdate', 'start_date');
|
||||
@ -49,7 +50,7 @@ return new class extends Migration
|
||||
});
|
||||
|
||||
// create table account_piggy_bank
|
||||
Schema::create('account_piggy_bank', static function (Blueprint $table) {
|
||||
Schema::create('account_piggy_bank', static function (Blueprint $table): void {
|
||||
$table->id();
|
||||
$table->integer('account_id', false, true);
|
||||
$table->integer('piggy_bank_id', false, true);
|
||||
@ -66,7 +67,7 @@ return new class extends Migration
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('piggy_banks', static function (Blueprint $table) {
|
||||
Schema::table('piggy_banks', static function (Blueprint $table): void {
|
||||
// 1. drop account index again.
|
||||
$table->dropForeign('piggy_banks_account_id_foreign');
|
||||
|
||||
@ -89,7 +90,7 @@ return new class extends Migration
|
||||
});
|
||||
|
||||
// rename some fields in piggy bank reps.
|
||||
Schema::table('piggy_bank_repetitions', static function (Blueprint $table) {
|
||||
Schema::table('piggy_bank_repetitions', static function (Blueprint $table): void {
|
||||
// 6. rename columns
|
||||
$table->renameColumn('current_amount', 'currentamount');
|
||||
$table->renameColumn('start_date', 'startdate');
|
||||
|
Loading…
Reference in New Issue
Block a user