Merge branch 'develop' into 5.8-dev

This commit is contained in:
James Cole
2022-10-01 19:06:55 +02:00
25 changed files with 367 additions and 122 deletions

View File

@@ -0,0 +1,93 @@
<?php
/*
* PurgeController.php
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Api\V1\Controllers\Data;
use FireflyIII\Api\V1\Controllers\Controller;
use FireflyIII\Models\Account;
use FireflyIII\Models\Bill;
use FireflyIII\Models\Budget;
use FireflyIII\Models\Category;
use FireflyIII\Models\ObjectGroup;
use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\Recurrence;
use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\Tag;
use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal;
use Illuminate\Http\JsonResponse;
class PurgeController extends Controller
{
/**
* @return JsonResponse
*/
public function purge(): JsonResponse
{
$user = auth()->user();
// some manual code, too lazy to call all repositories.
//,transactions,withdrawals,deposits,transfers';
// budgets:
Budget::whereUserId($user->id)->onlyTrashed()->forceDelete();
// bills
Bill::whereUserId($user->id)->onlyTrashed()->forceDelete();
// piggies
$set = PiggyBank::leftJoin('accounts','accounts.id','piggy_banks.account_id')
->where('accounts.user_id', $user->id)->onlyTrashed()->get(['piggy_banks.*']);
/** @var PiggyBank $piggy */
foreach($set as $piggy) {
$piggy->forceDelete();
}
// rule group
RuleGroup::whereUserId($user->id)->onlyTrashed()->forceDelete();
// rules
Rule::whereUserId($user->id)->onlyTrashed()->forceDelete();
// recurring transactions
Recurrence::whereUserId($user->id)->onlyTrashed()->forceDelete();
// categories
Category::whereUserId($user->id)->onlyTrashed()->forceDelete();
// tags
Tag::whereUserId($user->id)->onlyTrashed()->forceDelete();
// accounts
Account::whereUserId($user->id)->onlyTrashed()->forceDelete();
// transaction groups
TransactionGroup::whereUserId($user->id)->onlyTrashed()->forceDelete();
// transaction journals
TransactionJournal::whereUserId($user->id)->onlyTrashed()->forceDelete();
return response()->json([], 204);
}
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* InvitationCreated.php
* Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* NewVersionAvailable.php
* Copyright (c) 2022 james@firefly-iii.org

View File

@@ -27,12 +27,14 @@ use Carbon\Carbon;
use Database\Seeders\ExchangeRateSeeder;
use Exception;
use FireflyIII\Events\ActuallyLoggedIn;
use FireflyIII\Events\Admin\InvitationCreated;
use FireflyIII\Events\DetectedNewIPAddress;
use FireflyIII\Events\RegisteredUser;
use FireflyIII\Events\RequestedNewPassword;
use FireflyIII\Events\UserChangedEmail;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Mail\ConfirmEmailChangeMail;
use FireflyIII\Mail\InvitationMail;
use FireflyIII\Mail\UndoEmailChangeMail;
use FireflyIII\Models\GroupMembership;
use FireflyIII\Models\UserGroup;
@@ -77,6 +79,23 @@ class UserEventHandler
}
}
/**
* @param InvitationCreated $event
* @return void
*/
public function sendRegistrationInvite(InvitationCreated $event): void
{
$invitee = $event->invitee->email;
$admin = $event->invitee->user->email;
$url = route('invite', [$event->invitee->invite_code]);
try {
Mail::to($invitee)->send(new InvitationMail($invitee, $admin, $url));
} catch (Exception $e) { // @phpstan-ignore-line
Log::error($e->getMessage());
}
}
/**
* @param RegisteredUser $event
* @return bool

View File

@@ -237,9 +237,6 @@ trait MetaCollection
return $this;
}
/**
* @param string $url
* @return GroupCollectorInterface
@@ -269,9 +266,6 @@ trait MetaCollection
return $this;
}
/**
* @param string $url
* @return GroupCollectorInterface

View File

@@ -411,9 +411,6 @@ interface GroupCollectorInterface
* @return GroupCollectorInterface
*/
public function externalIdDoesNotContain(string $externalId): GroupCollectorInterface;
/**
* @param string $externalId
* @return GroupCollectorInterface
@@ -437,9 +434,6 @@ interface GroupCollectorInterface
* @return GroupCollectorInterface
*/
public function externalIdDoesNotStart(string $externalId): GroupCollectorInterface;
/**
* @param string $url
* @return GroupCollectorInterface
@@ -1038,9 +1032,6 @@ interface GroupCollectorInterface
* @return GroupCollectorInterface
*/
public function excludeInternalReference(string $externalId): GroupCollectorInterface;
/**
* Limit the result to a set of specific transaction journals.
*

View File

@@ -151,10 +151,14 @@ class BudgetLimitController extends Controller
// sanity check on amount:
if ((float) $amount === 0.0) {
$amount = '1';
if (null !== $limit) {
$this->blRepository->destroyBudgetLimit($limit);
}
// return empty=ish array:
return response()->json([]);
}
if ((int) $amount > 65536) {
$amount = '65536';
if ((int) $amount > 16777216) {
$amount = '16777216';
}
if (null !== $limit) {
@@ -175,7 +179,7 @@ class BudgetLimitController extends Controller
if ($request->expectsJson()) {
$array = $limit->toArray();
// add some extra meta data:
// add some extra metadata:
$spentArr = $this->opsRepository->sumExpenses($limit->start_date, $limit->end_date, null, new Collection([$budget]), $currency);
$array['spent'] = $spentArr[$currency->id]['sum'] ?? '0';
$array['left_formatted'] = app('amount')->formatAnything($limit->transactionCurrency, bcadd($array['spent'], $array['amount']));
@@ -208,10 +212,19 @@ class BudgetLimitController extends Controller
// sanity check on amount:
if ((float) $amount === 0.0) {
$amount = '1';
$budgetId = $budgetLimit->budget_id;
$currency = $budgetLimit->transactionCurrency;
$this->blRepository->destroyBudgetLimit($budgetLimit);
$array = [
'budget_id' => $budgetId,
'left_formatted' => app('amount')->formatAnything($currency, '0'),
'left_per_day_formatted' => app('amount')->formatAnything($currency, '0'),
'transaction_currency_id' => $currency->id,
];
return response()->json($array);
}
if ((int) $amount > 65536) {
$amount = '65536';
if ((int) $amount > 16777216) { // 16 million
$amount = '16777216';
}
$limit = $this->blRepository->update($budgetLimit, ['amount' => $amount]);

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* InviteUserFormRequest.php
* Copyright (c) 2022 james@firefly-iii.org

View File

@@ -99,7 +99,7 @@ class RecurrenceFormRequest extends FormRequest
];
// fill in foreign currency data
if (null !== $this->float('foreign_amount')) {
if (null !== $this->convertFloat('foreign_amount')) {
$return['transactions'][0]['foreign_amount'] = $this->convertString('foreign_amount');
$return['transactions'][0]['foreign_currency_id'] = $this->convertInteger('foreign_currency_id');
}
@@ -228,7 +228,7 @@ class RecurrenceFormRequest extends FormRequest
$rules['repetitions'] = 'required|numeric|between:0,254';
}
// if foreign amount, currency must be different.
if (null !== $this->float('foreign_amount')) {
if (null !== $this->convertFloat('foreign_amount')) {
$rules['foreign_currency_id'] = 'exists:transaction_currencies,id|different:transaction_currency_id';
}

View File

@@ -0,0 +1,61 @@
<?php
/*
* InvitationMail.php
* Copyright (c) 2022 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace FireflyIII\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class InvitationMail extends Mailable
{
use Queueable, SerializesModels;
public string $invitee;
public string $admin;
public string $url;
public string $host;
/**
* OAuthTokenCreatedMail constructor.
*
* @param string $ipAddress
*/
public function __construct(string $invitee, string $admin, string $url)
{
$this->invitee = $invitee;
$this->admin = $admin;
$this->url = $url;
$this->host = parse_url($url, PHP_URL_HOST);
}
/**
* Build the message.
*
* @return $this
*/
public function build(): self
{
return $this
->markdown('emails.invitation')
->subject((string) trans('email.invite_user_subject'));
}
}

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* InvitedUser.php
* Copyright (c) 2022 james@firefly-iii.org

View File

@@ -116,7 +116,7 @@ class EventServiceProvider extends ServiceProvider
],
InvitationCreated::class => [
'FireflyIII\Handlers\Events\AdminEventHandler@sendInvitationNotification',
//'FireflyIII\Handlers\Events\UserEventHandler@sendRegistrationInvite',
'FireflyIII\Handlers\Events\UserEventHandler@sendRegistrationInvite',
],
// is a Transaction Journal related event.

View File

@@ -451,7 +451,7 @@ class UserRepository implements UserRepositoryInterface
public function validateInviteCode(string $code): bool
{
$now = Carbon::now();
$invitee = InvitedUser::where('invite_code', $code)->where('expires', '<=', $now)->where('redeemed', 0)->first();
$invitee = InvitedUser::where('invite_code', $code)->where('expires', '>', $now->format('Y-m-d H:i:s'))->where('redeemed', 0)->first();
return null !== $invitee;
}

View File

@@ -219,7 +219,7 @@ trait ConvertsDataTypes
*
* @return float|null
*/
protected function float(string $field): ?float
protected function convertFloat(string $field): ?float
{
$res = $this->get($field);
if (null === $res) {

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* AppendDescriptionToNotes.php
* Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* AppendNotesToDescription.php
* Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* MoveDescriptionToNotes.php
* Copyright (c) 2022 james@firefly-iii.org

View File

@@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/*
* MoveNotesToDescription.php
* Copyright (c) 2022 james@firefly-iii.org