Merge branch 'v6.2' of github.com:firefly-iii/firefly-iii into v6.2

# Conflicts:
#	app/Api/V2/Controllers/Model/ExchangeRate/ShowController.php
#	app/Repositories/UserGroups/ExchangeRate/ExchangeRateRepository.php
#	routes/api.php
This commit is contained in:
James Cole
2024-12-22 08:28:44 +01:00
66 changed files with 234 additions and 195 deletions

View File

@@ -35,8 +35,8 @@ use Illuminate\Pagination\LengthAwarePaginator;
*/
class IndexController extends Controller
{
public const string RESOURCE_KEY = 'exchange-rates';
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
private ExchangeRateRepositoryInterface $repository;
@@ -55,11 +55,11 @@ class IndexController extends Controller
public function index(): JsonResponse
{
$piggies = $this->repository->getAll();
$pageSize = $this->parameters->get('limit');
$count = $piggies->count();
$piggies = $piggies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($piggies, $count, $pageSize, $this->parameters->get('page'));
$piggies = $this->repository->getAll();
$pageSize = $this->parameters->get('limit');
$count = $piggies->count();
$piggies = $piggies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($piggies, $count, $pageSize, $this->parameters->get('page'));
var_dump('here we are');
@@ -68,6 +68,7 @@ class IndexController extends Controller
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -37,8 +37,8 @@ use Illuminate\Pagination\LengthAwarePaginator;
*/
class ShowController extends Controller
{
public const string RESOURCE_KEY = 'exchange-rates';
use ValidatesUserGroupTrait;
public const string RESOURCE_KEY = 'exchange-rates';
private ExchangeRateRepositoryInterface $repository;
@@ -61,7 +61,6 @@ class ShowController extends Controller
$page = $this->parameters->get('page');
$rates = $this->repository->getRates($from, $to);
$count = $rates->count();
$rates = $rates->slice(($page - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($rates, $count, $pageSize, $page);
@@ -70,6 +69,7 @@ class ShowController extends Controller
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -34,7 +34,7 @@ use Illuminate\Pagination\LengthAwarePaginator;
class IndexController extends Controller
{
public const string RESOURCE_KEY = 'transaction-currencies';
public const string RESOURCE_KEY = 'transaction-currencies';
private CurrencyRepositoryInterface $repository;
protected array $acceptedRoles = [UserRoleEnum::READ_ONLY];
@@ -46,7 +46,7 @@ class IndexController extends Controller
function ($request, $next) {
$this->repository = app(CurrencyRepositoryInterface::class);
// new way of user group validation
$userGroup = $this->validateUserGroup($request);
$userGroup = $this->validateUserGroup($request);
$this->repository->setUserGroup($userGroup);
return $next($request);
@@ -56,20 +56,20 @@ class IndexController extends Controller
public function index(IndexRequest $request): JsonResponse
{
$settings = $request->getAll();
if(true === $settings['enabled']) {
$settings = $request->getAll();
if (true === $settings['enabled']) {
$currencies = $this->repository->get();
}
if(true !== $settings['enabled']) {
if (true !== $settings['enabled']) {
$currencies = $this->repository->getAll();
}
$pageSize = $this->parameters->get('limit');
$count = $currencies->count();
$pageSize = $this->parameters->get('limit');
$count = $currencies->count();
// depending on the sort parameters, this list must not be split, because the
// order is calculated in the account transformer and by that time it's too late.
$accounts = $currencies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$accounts = $currencies->slice(($this->parameters->get('page') - 1) * $pageSize, $pageSize);
$paginator = new LengthAwarePaginator($accounts, $count, $pageSize, $this->parameters->get('page'));
$transformer = new CurrencyTransformer();
@@ -78,6 +78,7 @@ class IndexController extends Controller
return response()
->json($this->jsonApiList(self::RESOURCE_KEY, $paginator, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -47,7 +47,7 @@ class ShowController extends Controller
function ($request, $next) {
$this->repository = app(CurrencyRepositoryInterface::class);
// new way of user group validation
$userGroup = $this->validateUserGroup($request);
$userGroup = $this->validateUserGroup($request);
$this->repository->setUserGroup($userGroup);
return $next($request);
@@ -57,9 +57,10 @@ class ShowController extends Controller
public function show(TransactionCurrency $currency): JsonResponse
{
$groups = $currency->userGroups()->where('user_groups.id', $this->repository->getUserGroup()->id)->get();
$enabled = $groups->count() > 0;
$default = false;
$groups = $currency->userGroups()->where('user_groups.id', $this->repository->getUserGroup()->id)->get();
$enabled = $groups->count() > 0;
$default = false;
/** @var UserGroup $group */
foreach ($groups as $group) {
$default = 1 === $group->pivot->group_default;
@@ -68,11 +69,12 @@ class ShowController extends Controller
$currency->userGroupDefault = $default;
$transformer = new CurrencyTransformer();
$transformer = new CurrencyTransformer();
$transformer->setParameters($this->parameters);
return response()
->api($this->jsonApiObject(self::RESOURCE_KEY, $currency, $transformer))
->header('Content-Type', self::CONTENT_TYPE);
->header('Content-Type', self::CONTENT_TYPE)
;
}
}

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Api\V2\Request\Model\TransactionCurrency;
use Carbon\Carbon;
use FireflyIII\Support\Http\Api\AccountFilter;
use FireflyIII\Support\Request\ChecksLogin;
use FireflyIII\Support\Request\ConvertsDataTypes;

View File

@@ -151,7 +151,6 @@ class CorrectAmounts extends Command
/**
* Foreach loop is unavoidable here.
* @return void
*/
private function fixRuleTriggers(): void
{
@@ -162,7 +161,7 @@ class CorrectAmounts extends Command
foreach ($set as $item) {
$result = $this->fixRuleTrigger($item);
if (true === $result) {
$fixed++;
++$fixed;
}
}
if (0 === $fixed) {
@@ -182,13 +181,16 @@ class CorrectAmounts extends Command
$item->rule->active = false;
$item->rule->save();
$item->forceDelete();
return false;
}
if (-1 === $check) {
$item->trigger_value = app('steam')->positive($item->trigger_value);
$item->save();
return true;
}
return false;
}
}

View File

@@ -69,7 +69,7 @@ class CorrectDatabase extends Command
'firefly-iii:fix-long-descriptions',
'firefly-iii:fix-recurring-transactions',
'firefly-iii:upgrade-group-information',
//'firefly-iii:fix-transaction-types', // very resource heavy.
// 'firefly-iii:fix-transaction-types', // very resource heavy.
'firefly-iii:fix-frontpage-accounts',
// new!
'firefly-iii:unify-group-accounts',

View File

@@ -52,6 +52,7 @@ class FixTransactionTypes extends Command
$count = 0;
$journals = $this->collectJournals();
Log::debug(sprintf('In FixTransactionTypes, found %d journals.', $journals->count()));
/** @var TransactionJournal $journal */
foreach ($journals as $journal) {
$fixed = $this->fixJournal($journal);

View File

@@ -41,6 +41,6 @@ class DetectedNewIPAddress extends Event
*/
public function __construct(User $user)
{
$this->user = $user;
$this->user = $user;
}
}

View File

@@ -187,13 +187,13 @@ class UserEventHandler
*/
public function notifyNewIPAddress(DetectedNewIPAddress $event): void
{
$user = $event->user;
$user = $event->user;
if ($user->hasRole('demo')) {
return; // do not email demo user.
}
$list = app('preferences')->getForUser($user, 'login_ip_history', [])->data;
$list = app('preferences')->getForUser($user, 'login_ip_history', [])->data;
if (!is_array($list)) {
$list = [];
}

View File

@@ -1,4 +1,5 @@
<?php
/*
* IndexController.php
* Copyright (c) 2024 james@firefly-iii.org.
@@ -25,7 +26,6 @@ namespace FireflyIII\Http\Controllers\ExchangeRates;
use FireflyIII\Http\Controllers\Controller;
use FireflyIII\Models\TransactionCurrency;
use Illuminate\View\Factory;
use Illuminate\View\View;
class IndexController extends Controller
@@ -42,6 +42,7 @@ class IndexController extends Controller
function ($request, $next) {
app('view')->share('mainTitleIcon', 'fa-exchange');
app('view')->share('title', (string) trans('firefly.header_exchange_rates'));
return $next($request);
}
);
@@ -56,5 +57,4 @@ class IndexController extends Controller
{
return view('exchange-rates.rates', compact('from', 'to'));
}
}

View File

@@ -43,7 +43,7 @@ class TransactionCurrency extends Model
public ?bool $userGroupDefault = null;
public ?bool $userGroupEnabled = null;
protected $casts
= [
= [
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
@@ -51,7 +51,7 @@ class TransactionCurrency extends Model
'enabled' => 'bool',
];
protected $fillable = ['name', 'code', 'symbol', 'decimal_places', 'enabled'];
protected $fillable = ['name', 'code', 'symbol', 'decimal_places', 'enabled'];
/**
* Route binder. Converts the key in the URL to the specified object (or throw 404).

View File

@@ -68,7 +68,8 @@ class UnknownUserLoginAttempt extends Notification
return new MailMessage()
->markdown('emails.owner.unknown-user', ['address' => $this->address, 'ip' => $ip, 'host' => $host, 'userAgent' => $userAgent, 'time' => $time])
->subject((string) trans('email.unknown_user_subject'));
->subject((string) trans('email.unknown_user_subject'))
;
}
/**
@@ -91,7 +92,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'))
;
}
/**

View File

@@ -61,7 +61,7 @@ class DisabledMFANotification extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.disabled_mfa_subject');
$subject = (string) trans('email.disabled_mfa_subject');
$ip = Request::ip();
$host = Steam::getHostName($ip);
$userAgent = Request::userAgent();

View File

@@ -61,7 +61,7 @@ class EnabledMFANotification extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.enabled_mfa_subject');
$subject = (string) trans('email.enabled_mfa_subject');
$ip = Request::ip();
$host = Steam::getHostName($ip);
$userAgent = Request::userAgent();

View File

@@ -63,7 +63,7 @@ class MFABackupFewLeftNotification extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.mfa_few_backups_left_subject', ['count' => $this->count]);
$subject = (string) trans('email.mfa_few_backups_left_subject', ['count' => $this->count]);
$ip = Request::ip();
$host = Steam::getHostName($ip);
$userAgent = Request::userAgent();

View File

@@ -61,7 +61,7 @@ class MFABackupNoLeftNotification extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.mfa_no_backups_left_subject');
$subject = (string) trans('email.mfa_no_backups_left_subject');
$ip = Request::ip();
$host = Steam::getHostName($ip);
$userAgent = Request::userAgent();

View File

@@ -60,7 +60,7 @@ class MFAManyFailedAttemptsNotification extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.mfa_many_failed_subject', ['count' => $this->count]);
$subject = (string) trans('email.mfa_many_failed_subject', ['count' => $this->count]);
$ip = Request::ip();
$host = Steam::getHostName($ip);
$userAgent = Request::userAgent();

View File

@@ -61,7 +61,7 @@ class MFAUsedBackupCodeNotification extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.used_backup_code_subject');
$subject = (string) trans('email.used_backup_code_subject');
$ip = Request::ip();
$host = Steam::getHostName($ip);
$userAgent = Request::userAgent();

View File

@@ -61,7 +61,7 @@ class NewBackupCodesNotification extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.new_backup_codes_subject');
$subject = (string) trans('email.new_backup_codes_subject');
$ip = Request::ip();
$host = Steam::getHostName($ip);
$userAgent = Request::userAgent();

View File

@@ -58,7 +58,7 @@ class UserFailedLoginAttempt extends Notification
*/
public function toMail(User $notifiable)
{
$subject = (string) trans('email.failed_login_subject');
$subject = (string) trans('email.failed_login_subject');
$ip = Request::ip();
$host = Steam::getHostName($ip);
$userAgent = Request::userAgent();

View File

@@ -24,7 +24,6 @@ declare(strict_types=1);
namespace FireflyIII\Notifications\User;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Notifications\ReturnsAvailableChannels;
use FireflyIII\Notifications\ReturnsSettings;
use FireflyIII\Support\Facades\Steam;
@@ -68,13 +67,13 @@ class UserLogin extends Notification
public function toNtfy(User $notifiable): Message
{
$ip = Request::ip();
$host = Steam::getHostName($ip);
$ip = Request::ip();
$host = Steam::getHostName($ip);
$settings = ReturnsSettings::getSettings('ntfy', 'user', $notifiable);
$message = new Message();
$message->topic($settings['ntfy_topic']);
$message->title((string) trans('email.login_from_new_ip'));
$message->body((string) trans('email.slack_login_from_new_ip', ['ip' => $ip, 'host' => $host, ]));
$message->body((string) trans('email.slack_login_from_new_ip', ['ip' => $ip, 'host' => $host]));
return $message;
}
@@ -84,9 +83,10 @@ class UserLogin extends Notification
*/
public function toPushover(User $notifiable): PushoverMessage
{
$ip = Request::ip();
$host = Steam::getHostName($ip);
return PushoverMessage::create((string) trans('email.slack_login_from_new_ip', ['ip' => $ip, 'host' => $host, ]))
$ip = Request::ip();
$host = Steam::getHostName($ip);
return PushoverMessage::create((string) trans('email.slack_login_from_new_ip', ['ip' => $ip, 'host' => $host]))
->title((string) trans('email.login_from_new_ip'))
;
}
@@ -96,9 +96,10 @@ class UserLogin extends Notification
*/
public function toSlack(User $notifiable)
{
$ip = Request::ip();
$host = Steam::getHostName($ip);
return new SlackMessage()->content((string) trans('email.slack_login_from_new_ip', ['ip' => $ip, 'host' => $host, ]));
$ip = Request::ip();
$host = Steam::getHostName($ip);
return new SlackMessage()->content((string) trans('email.slack_login_from_new_ip', ['ip' => $ip, 'host' => $host]));
}
/**
@@ -108,6 +109,4 @@ class UserLogin extends Notification
{
return ReturnsAvailableChannels::returnChannels('user', $notifiable);
}
}

View File

@@ -77,7 +77,7 @@ class CurrencyServiceProvider extends ServiceProvider
$this->app->bind(
ExchangeRateRepositoryInterface::class,
static function (Application $app) {
/** @var ExchangeRateRepository $repository */
// @var ExchangeRateRepository $repository
return app(ExchangeRateRepository::class);
}
);

View File

@@ -1,4 +1,5 @@
<?php
/*
* ExchangeRateRepository.php
* Copyright (c) 2024 james@firefly-iii.org.
@@ -32,8 +33,8 @@ class ExchangeRateRepository implements ExchangeRateRepositoryInterface
{
use UserGroupTrait;
#[\Override] public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection
#[\Override]
public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection
{
// orderBy('date', 'DESC')->toRawSql();
return

View File

@@ -1,4 +1,5 @@
<?php
/*
* ExchangeRateRepositoryInterface.php
* Copyright (c) 2024 james@firefly-iii.org.
@@ -28,7 +29,5 @@ use Illuminate\Support\Collection;
interface ExchangeRateRepositoryInterface
{
public function getRates(TransactionCurrency $from, TransactionCurrency $to): Collection;
}

View File

@@ -32,8 +32,6 @@ use Illuminate\Support\Collection;
*/
class ExchangeRateTransformer extends AbstractTransformer
{
/**
* This method collects meta-data for one or all accounts in the transformer's collection.
*/
@@ -48,23 +46,23 @@ class ExchangeRateTransformer extends AbstractTransformer
public function transform(CurrencyExchangeRate $rate): array
{
return [
'id' => (string) $rate->id,
'created_at' => $rate->created_at->toAtomString(),
'updated_at' => $rate->updated_at->toAtomString(),
'id' => (string) $rate->id,
'created_at' => $rate->created_at->toAtomString(),
'updated_at' => $rate->updated_at->toAtomString(),
'from_currency_id' => (string) $rate->fromCurrency->id,
'from_currency_code' => $rate->fromCurrency->code,
'from_currency_symbol' => $rate->fromCurrency->symbol,
'from_currency_decimal_places' => $rate->fromCurrency->decimal_places,
'to_currency_id' => (string) $rate->toCurrency->id,
'to_currency_code' => $rate->toCurrency->code,
'to_currency_symbol' => $rate->toCurrency->symbol,
'to_currency_decimal_places' => $rate->toCurrency->decimal_places,
'to_currency_id' => (string) $rate->toCurrency->id,
'to_currency_code' => $rate->toCurrency->code,
'to_currency_symbol' => $rate->toCurrency->symbol,
'to_currency_decimal_places' => $rate->toCurrency->decimal_places,
'rate' => $rate->rate,
'date' => $rate->date->toAtomString(),
'links' => [
'rate' => $rate->rate,
'date' => $rate->date->toAtomString(),
'links' => [
[
'rel' => 'self',
'uri' => sprintf('/exchange-rates/%s', $rate->id),