Merge pull request #9949 from firefly-iii/missing-phpstan-methods

Missing phpstan methods
This commit is contained in:
James Cole
2025-03-08 15:58:27 +01:00
committed by GitHub
43 changed files with 675 additions and 24 deletions

View File

@@ -69,7 +69,7 @@ class AccountController extends Controller
public function accounts(AutocompleteRequest $request): JsonResponse public function accounts(AutocompleteRequest $request): JsonResponse
{ {
$params = $request->getParameters(); $params = $request->getParameters();
$result = $this->repository->searchAccount($params['query'], $params['account_types'], $params['page'], $params['size']); $result = $this->repository->searchAccount($params['query'], $params['account_types'], $params['size']);
$return = []; $return = [];
/** @var Account $account */ /** @var Account $account */

View File

@@ -59,7 +59,7 @@ class TagController extends Controller
public function tags(AutocompleteRequest $request): JsonResponse public function tags(AutocompleteRequest $request): JsonResponse
{ {
$queryParameters = $request->getParameters(); $queryParameters = $request->getParameters();
$result = $this->repository->searchTag($queryParameters['query'], $queryParameters['size']); $result = $this->repository->searchTag($queryParameters['query']);
$filtered = $result->map( $filtered = $result->map(
static function (Tag $item) { static function (Tag $item) {
return [ return [

View File

@@ -67,7 +67,7 @@ class IndexController extends Controller
$types = $request->getAccountTypes(); $types = $request->getAccountTypes();
$sorting = $request->getSortInstructions('accounts'); $sorting = $request->getSortInstructions('accounts');
$filters = $request->getFilterInstructions('accounts'); $filters = $request->getFilterInstructions('accounts');
$accounts = $this->repository->getAccountsByType($types, $sorting, $filters); $accounts = $this->repository->getAccountsByType($types, $sorting);
$pageSize = $this->parameters->get('limit'); $pageSize = $this->parameters->get('limit');
$count = $accounts->count(); $count = $accounts->count();

View File

@@ -122,8 +122,7 @@ class CorrectsUnevenAmount extends Command
$journals = DB::table('transactions') $journals = DB::table('transactions')
->groupBy('transaction_journal_id') ->groupBy('transaction_journal_id')
->whereNull('deleted_at') ->whereNull('deleted_at')
->get(['transaction_journal_id', DB::raw('SUM(amount) AS the_sum')]) // @phpstan-ignore-line ->get(['transaction_journal_id', DB::raw('SUM(amount) AS the_sum')]);
;
/** @var \stdClass $entry */ /** @var \stdClass $entry */
foreach ($journals as $entry) { foreach ($journals as $entry) {

View File

@@ -27,6 +27,7 @@ use Illuminate\Console\Command;
class ValidatesEnvironmentVariables extends Command class ValidatesEnvironmentVariables extends Command
{ {
use ShowsFriendlyMessages; use ShowsFriendlyMessages;
/** /**
* The name and signature of the console command. * The name and signature of the console command.
* *
@@ -37,7 +38,7 @@ class ValidatesEnvironmentVariables extends Command
/** /**
* The console command description. * The console command description.
* *
* @var string * @var string|null
*/ */
protected $description = 'Makes sure you use the correct variables.'; protected $description = 'Makes sure you use the correct variables.';
@@ -54,17 +55,18 @@ class ValidatesEnvironmentVariables extends Command
private function validateLanguage(): void private function validateLanguage(): void
{ {
$language = env('DEFAULT_LANGUAGE', 'en_US'); $language = config('firefly.default_language');
$locale = env('DEFAULT_LOCALE', 'equal'); $locale = config('firefly.default_locale');
$options = array_keys(config('firefly.languages')); $options = array_keys(config('firefly.languages'));
if (!in_array($language, $options)) {
if (!in_array($language, $options, true)) {
$this->friendlyError(sprintf('DEFAULT_LANGUAGE "%s" is not a valid language for Firefly III.', $language)); $this->friendlyError(sprintf('DEFAULT_LANGUAGE "%s" is not a valid language for Firefly III.', $language));
$this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError('Please check your .env file and make sure you use a valid setting.');
$this->friendlyError(sprintf('Valid languages are: %s', implode(', ', $options))); $this->friendlyError(sprintf('Valid languages are: %s', implode(', ', $options)));
exit(1); exit(1);
} }
$options[] = 'equal'; $options[] = 'equal';
if (!in_array($locale, $options)) { if (!in_array($locale, $options, true)) {
$this->friendlyError(sprintf('DEFAULT_LOCALE "%s" is not a valid local for Firefly III.', $locale)); $this->friendlyError(sprintf('DEFAULT_LOCALE "%s" is not a valid local for Firefly III.', $locale));
$this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError('Please check your .env file and make sure you use a valid setting.');
$this->friendlyError(sprintf('Valid locales are: %s', implode(', ', $options))); $this->friendlyError(sprintf('Valid locales are: %s', implode(', ', $options)));
@@ -72,9 +74,10 @@ class ValidatesEnvironmentVariables extends Command
} }
} }
private function validateGuard(): void { private function validateGuard(): void
$guard = env('AUTHENTICATION_GUARD','web'); {
if('web' !== $guard && 'remote_user_guard' !== $guard) { $guard = env('AUTHENTICATION_GUARD', 'web');
if ('web' !== $guard && 'remote_user_guard' !== $guard) {
$this->friendlyError(sprintf('AUTHENTICATION_GUARD "%s" is not a valid guard for Firefly III.', $guard)); $this->friendlyError(sprintf('AUTHENTICATION_GUARD "%s" is not a valid guard for Firefly III.', $guard));
$this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError('Please check your .env file and make sure you use a valid setting.');
$this->friendlyError('Valid guards are: web, remote_user_guard'); $this->friendlyError('Valid guards are: web, remote_user_guard');
@@ -82,9 +85,10 @@ class ValidatesEnvironmentVariables extends Command
} }
} }
private function validateStaticToken(): void { private function validateStaticToken(): void
$token = (string) env('STATIC_CRON_TOKEN',''); {
if(0 !== strlen($token) && 32 !== strlen($token)) { $token = (string) env('STATIC_CRON_TOKEN', '');
if (0 !== strlen($token) && 32 !== strlen($token)) {
$this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.'); $this->friendlyError('STATIC_CRON_TOKEN must be empty or a 32-character string.');
$this->friendlyError('Please check your .env file and make sure you use a valid setting.'); $this->friendlyError('Please check your .env file and make sure you use a valid setting.');
exit(1); exit(1);

View File

@@ -65,6 +65,12 @@ class AccountRepository implements AccountRepositoryInterface, UserGroupInterfac
return true; return true;
} }
#[\Override]
public function getAccountBalances(Account $account): Collection
{
return $account->accountBalances;
}
/** /**
* Find account with same name OR same IBAN or both, but not the same type or ID. * Find account with same name OR same IBAN or both, but not the same type or ID.
*/ */

View File

@@ -24,16 +24,27 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Account; namespace FireflyIII\Repositories\Account;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\AccountType; use FireflyIII\Models\AccountType;
use FireflyIII\Models\Location; use FireflyIII\Models\Location;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface AccountRepositoryInterface. * Interface AccountRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface AccountRepositoryInterface interface AccountRepositoryInterface
{ {
@@ -41,6 +52,7 @@ interface AccountRepositoryInterface
* Moved here from account CRUD. * Moved here from account CRUD.
*/ */
public function count(array $types): int; public function count(array $types): int;
public function getAccountBalances(Account $account): Collection;
/** /**
* Moved here from account CRUD. * Moved here from account CRUD.

View File

@@ -24,10 +24,21 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Account; namespace FireflyIII\Repositories\Account;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface AccountTaskerInterface. * Interface AccountTaskerInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface AccountTaskerInterface interface AccountTaskerInterface
{ {

View File

@@ -25,11 +25,22 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Account; namespace FireflyIII\Repositories\Account;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface OperationsRepositoryInterface * Interface OperationsRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface OperationsRepositoryInterface interface OperationsRepositoryInterface
{ {

View File

@@ -23,12 +23,23 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Attachment; namespace FireflyIII\Repositories\Attachment;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Attachment; use FireflyIII\Models\Attachment;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface AttachmentRepositoryInterface. * Interface AttachmentRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface AttachmentRepositoryInterface interface AttachmentRepositoryInterface
{ {

View File

@@ -24,12 +24,23 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\AuditLogEntry; namespace FireflyIII\Repositories\AuditLogEntry;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\AuditLogEntry; use FireflyIII\Models\AuditLogEntry;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface ALERepositoryInterface * Interface ALERepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface ALERepositoryInterface interface ALERepositoryInterface
{ {

View File

@@ -24,13 +24,24 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Bill; namespace FireflyIII\Repositories\Bill;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Bill; use FireflyIII\Models\Bill;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface BillRepositoryInterface. * Interface BillRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface BillRepositoryInterface interface BillRepositoryInterface
{ {

View File

@@ -25,12 +25,23 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Budget; namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\AvailableBudget; use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface AvailableBudgetRepositoryInterface * Interface AvailableBudgetRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface AvailableBudgetRepositoryInterface interface AvailableBudgetRepositoryInterface
{ {

View File

@@ -25,13 +25,24 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Budget; namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\BudgetLimit; use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface BudgetLimitRepositoryInterface * Interface BudgetLimitRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface BudgetLimitRepositoryInterface interface BudgetLimitRepositoryInterface
{ {

View File

@@ -24,13 +24,25 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Budget; namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\AutoBudget; use FireflyIII\Models\AutoBudget;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface BudgetRepositoryInterface. * Interface BudgetRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface BudgetRepositoryInterface interface BudgetRepositoryInterface
{ {

View File

@@ -25,11 +25,23 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Budget; namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface NoBudgetRepositoryInterface * Interface NoBudgetRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface NoBudgetRepositoryInterface interface NoBudgetRepositoryInterface
{ {

View File

@@ -25,12 +25,24 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Budget; namespace FireflyIII\Repositories\Budget;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Budget; use FireflyIII\Models\Budget;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface OperationsRepositoryInterface * Interface OperationsRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface OperationsRepositoryInterface interface OperationsRepositoryInterface
{ {

View File

@@ -24,12 +24,24 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Category; namespace FireflyIII\Repositories\Category;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Category; use FireflyIII\Models\Category;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface CategoryRepositoryInterface. * Interface CategoryRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface CategoryRepositoryInterface interface CategoryRepositoryInterface
{ {

View File

@@ -25,10 +25,22 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Category; namespace FireflyIII\Repositories\Category;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface NoCategoryRepositoryInterface * Interface NoCategoryRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface NoCategoryRepositoryInterface interface NoCategoryRepositoryInterface
{ {

View File

@@ -25,10 +25,22 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Category; namespace FireflyIII\Repositories\Category;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface OperationsRepositoryInterface * Interface OperationsRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface OperationsRepositoryInterface interface OperationsRepositoryInterface
{ {

View File

@@ -24,12 +24,25 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Currency; namespace FireflyIII\Repositories\Currency;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Events\Preferences\UserGroupChangedDefaultCurrency;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Factory\TransactionCurrencyFactory;
use FireflyIII\Models\AccountMeta;
use FireflyIII\Models\AvailableBudget;
use FireflyIII\Models\Bill;
use FireflyIII\Models\BudgetLimit;
use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\Services\Internal\Destroy\CurrencyDestroyService;
use FireflyIII\Services\Internal\Update\CurrencyUpdateService;
use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface; use FireflyIII\Support\Repositories\UserGroup\UserGroupInterface;
use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait; use FireflyIII\Support\Repositories\UserGroup\UserGroupTrait;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
/** /**
* Class CurrencyRepository. * Class CurrencyRepository.
@@ -38,6 +51,243 @@ class CurrencyRepository implements CurrencyRepositoryInterface, UserGroupInterf
{ {
use UserGroupTrait; use UserGroupTrait;
/**
* @throws FireflyException
*/
public function currencyInUse(TransactionCurrency $currency): bool
{
$result = $this->currencyInUseAt($currency);
return null !== $result;
}
public function disable(TransactionCurrency $currency): void
{
$this->userGroup->currencies()->detach($currency->id);
$currency->enabled = false;
$currency->save();
}
public function enable(TransactionCurrency $currency): void
{
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id]);
$currency->enabled = false;
$currency->save();
}
public function update(TransactionCurrency $currency, array $data): TransactionCurrency
{
app('log')->debug('Now in update()');
// can be true, false, null
$enabled = array_key_exists('enabled', $data) ? $data['enabled'] : null;
// can be true, false, but method only responds to "true".
$default = array_key_exists('default', $data) ? $data['default'] : false;
// remove illegal combo's:
if (false === $enabled && true === $default) {
$enabled = true;
}
// update currency with current user specific settings
$currency->refreshForUser($this->user);
// currency is enabled, must be disabled.
if (false === $enabled) {
app('log')->debug(sprintf('Disabled currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
}
// currency must be enabled
if (true === $enabled) {
app('log')->debug(sprintf('Enabled currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => false]]);
}
// currency must be made default.
if (true === $default) {
$this->makeDefault($currency);
}
/** @var CurrencyUpdateService $service */
$service = app(CurrencyUpdateService::class);
return $service->update($currency, $data);
}
public function destroy(TransactionCurrency $currency): bool
{
/** @var UserRepositoryInterface $repository */
$repository = app(UserRepositoryInterface::class);
if ($repository->hasRole($this->user, 'owner')) {
/** @var CurrencyDestroyService $service */
$service = app(CurrencyDestroyService::class);
$service->destroy($currency);
}
return true;
}
/**
* @throws FireflyException
*/
public function store(array $data): TransactionCurrency
{
/** @var TransactionCurrencyFactory $factory */
$factory = app(TransactionCurrencyFactory::class);
$result = $factory->create($data);
if (true === $data['enabled']) {
$this->userGroup->currencies()->attach($result->id);
}
return $result;
}
public function makeDefault(TransactionCurrency $currency): void
{
$current = app('amount')->getNativeCurrencyByUserGroup($this->userGroup);
app('log')->debug(sprintf('Enabled + made default currency %s for user #%d', $currency->code, $this->userGroup->id));
$this->userGroup->currencies()->detach($currency->id);
foreach ($this->userGroup->currencies()->get() as $item) {
$this->userGroup->currencies()->updateExistingPivot($item->id, ['group_default' => false]);
}
$this->userGroup->currencies()->syncWithoutDetaching([$currency->id => ['group_default' => true]]);
if ($current->id !== $currency->id) {
Log::debug('Trigger on a different default currency.');
// clear all native amounts through an event.
event(new UserGroupChangedDefaultCurrency($this->userGroup));
}
}
public function isFallbackCurrency(TransactionCurrency $currency): bool
{
return $currency->code === config('firefly.default_currency', 'EUR');
}
/**
* Returns ALL currencies, regardless of whether they are enabled or not.
*/
public function getAll(): Collection
{
$all = TransactionCurrency::orderBy('code', 'ASC')->get();
$local = $this->get();
return $all->map(static function (TransactionCurrency $current) use ($local) {
$hasId = $local->contains(static function (TransactionCurrency $entry) use ($current) {
return $entry->id === $current->id;
});
$isNative = $local->contains(static function (TransactionCurrency $entry) use ($current) {
return 1 === (int) $entry->pivot->group_default && $entry->id === $current->id;
});
$current->userGroupEnabled = $hasId;
$current->userGroupNative = $isNative;
return $current;
});
}
private function countJournals(TransactionCurrency $currency): int
{
$count = $currency->transactions()->whereNull('deleted_at')->count() + $currency->transactionJournals()->whereNull('deleted_at')->count();
// also count foreign:
return $count + Transaction::where('foreign_currency_id', $currency->id)->count();
}
/**
* @throws FireflyException
*/
public function currencyInUseAt(TransactionCurrency $currency): ?string
{
app('log')->debug(sprintf('Now in currencyInUse() for #%d ("%s")', $currency->id, $currency->code));
$countJournals = $this->countJournals($currency);
if ($countJournals > 0) {
app('log')->info(sprintf('Count journals is %d, return true.', $countJournals));
return 'journals';
}
// is the only currency left
if (1 === $this->getAll()->count()) {
app('log')->info('Is the last currency in the system, return true. ');
return 'last_left';
}
// is being used in accounts:
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((string) $currency->id))->count();
if ($meta > 0) {
app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
return 'account_meta';
}
// second search using integer check.
$meta = AccountMeta::where('name', 'currency_id')->where('data', json_encode((int) $currency->id))->count();
if ($meta > 0) {
app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
return 'account_meta';
}
// is being used in bills:
$bills = Bill::where('transaction_currency_id', $currency->id)->count();
if ($bills > 0) {
app('log')->info(sprintf('Used in %d bills as currency, return true. ', $bills));
return 'bills';
}
// is being used in recurring transactions
$recurringAmount = RecurrenceTransaction::where('transaction_currency_id', $currency->id)->count();
$recurringForeign = RecurrenceTransaction::where('foreign_currency_id', $currency->id)->count();
if ($recurringAmount > 0 || $recurringForeign > 0) {
app('log')->info(sprintf('Used in %d recurring transactions as (foreign) currency id, return true. ', $recurringAmount + $recurringForeign));
return 'recurring';
}
// is being used in accounts (as integer)
$meta = AccountMeta::leftJoin('accounts', 'accounts.id', '=', 'account_meta.account_id')
->whereNull('accounts.deleted_at')
->where('account_meta.name', 'currency_id')->where('account_meta.data', json_encode($currency->id))->count()
;
if ($meta > 0) {
app('log')->info(sprintf('Used in %d accounts as currency_id, return true. ', $meta));
return 'account_meta';
}
// is being used in available budgets
$availableBudgets = AvailableBudget::where('transaction_currency_id', $currency->id)->count();
if ($availableBudgets > 0) {
app('log')->info(sprintf('Used in %d available budgets as currency, return true. ', $availableBudgets));
return 'available_budgets';
}
// is being used in budget limits
$budgetLimit = BudgetLimit::where('transaction_currency_id', $currency->id)->count();
if ($budgetLimit > 0) {
app('log')->info(sprintf('Used in %d budget limits as currency, return true. ', $budgetLimit));
return 'budget_limits';
}
// is the default currency for the user or the system
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
if ($count > 0) {
app('log')->info('Is the default currency of the user, return true.');
return 'current_default';
}
// is the default currency for the user or the system
$count = $this->userGroup->currencies()->where('transaction_currencies.id', $currency->id)->wherePivot('group_default', 1)->count();
if ($count > 0) {
app('log')->info('Is the default currency of the user group, return true.');
return 'current_default';
}
app('log')->debug('Currency is not used, return false.');
return null;
}
public function searchCurrency(string $search, int $limit): Collection public function searchCurrency(string $search, int $limit): Collection
{ {
$query = TransactionCurrency::where('enabled', true); $query = TransactionCurrency::where('enabled', true);

View File

@@ -24,17 +24,47 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Currency; namespace FireflyIII\Repositories\Currency;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface CurrencyRepositoryInterface. * Interface CurrencyRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface CurrencyRepositoryInterface interface CurrencyRepositoryInterface
{ {
public function find(int $currencyId): ?TransactionCurrency; public function find(int $currencyId): ?TransactionCurrency;
public function searchCurrency(string $search, int $limit): Collection; public function searchCurrency(string $search, int $limit): Collection;
public function isFallbackCurrency(TransactionCurrency $currency): bool;
public function getAll(): Collection;
public function store(array $data): TransactionCurrency;
public function makeDefault(TransactionCurrency $currency): void;
public function destroy(TransactionCurrency $currency): bool;
public function enable(TransactionCurrency $currency): void;
public function disable(TransactionCurrency $currency): void;
public function update(TransactionCurrency $currency, array $data): TransactionCurrency;
/**
* @throws FireflyException
*/
public function currencyInUse(TransactionCurrency $currency);
/**
* @throws FireflyException
*/
public function currencyInUseAt(TransactionCurrency $currency): ?string;
/** /**
* Find by currency code, return NULL if unfound. * Find by currency code, return NULL if unfound.

View File

@@ -24,10 +24,25 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\ExchangeRate; namespace FireflyIII\Repositories\ExchangeRate;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\CurrencyExchangeRate; use FireflyIII\Models\CurrencyExchangeRate;
use FireflyIII\Models\TransactionCurrency; use FireflyIII\Models\TransactionCurrency;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/**
* Interface ExchangeRateRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/
interface ExchangeRateRepositoryInterface interface ExchangeRateRepositoryInterface
{ {
public function deleteRate(CurrencyExchangeRate $rate): void; public function deleteRate(CurrencyExchangeRate $rate): void;

View File

@@ -24,12 +24,24 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal; namespace FireflyIII\Repositories\Journal;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Transaction; use FireflyIII\Models\Transaction;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface JournalAPIRepositoryInterface * Interface JournalAPIRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface JournalAPIRepositoryInterface interface JournalAPIRepositoryInterface
{ {

View File

@@ -25,11 +25,22 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal; namespace FireflyIII\Repositories\Journal;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface JournalCLIRepositoryInterface * Interface JournalCLIRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*/ */
interface JournalCLIRepositoryInterface interface JournalCLIRepositoryInterface
{ {

View File

@@ -24,15 +24,27 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Journal; namespace FireflyIII\Repositories\Journal;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalLink; use FireflyIII\Models\TransactionJournalLink;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface JournalRepositoryInterface. * Interface JournalRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface JournalRepositoryInterface interface JournalRepositoryInterface
{ {

View File

@@ -23,13 +23,25 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\LinkType; namespace FireflyIII\Repositories\LinkType;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\LinkType; use FireflyIII\Models\LinkType;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\TransactionJournalLink; use FireflyIII\Models\TransactionJournalLink;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface LinkTypeRepositoryInterface. * Interface LinkTypeRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface LinkTypeRepositoryInterface interface LinkTypeRepositoryInterface
{ {

View File

@@ -24,11 +24,23 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\ObjectGroup; namespace FireflyIII\Repositories\ObjectGroup;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\ObjectGroup; use FireflyIII\Models\ObjectGroup;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface ObjectGroupRepositoryInterface * Interface ObjectGroupRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface ObjectGroupRepositoryInterface interface ObjectGroupRepositoryInterface
{ {

View File

@@ -24,15 +24,27 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\PiggyBank; namespace FireflyIII\Repositories\PiggyBank;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Account; use FireflyIII\Models\Account;
use FireflyIII\Models\PiggyBank; use FireflyIII\Models\PiggyBank;
use FireflyIII\Models\PiggyBankRepetition; use FireflyIII\Models\PiggyBankRepetition;
use FireflyIII\Models\TransactionJournal; use FireflyIII\Models\TransactionJournal;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface PiggyBankRepositoryInterface. * Interface PiggyBankRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface PiggyBankRepositoryInterface interface PiggyBankRepositoryInterface
{ {

View File

@@ -25,15 +25,27 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Recurring; namespace FireflyIII\Repositories\Recurring;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Recurrence; use FireflyIII\Models\Recurrence;
use FireflyIII\Models\RecurrenceRepetition; use FireflyIII\Models\RecurrenceRepetition;
use FireflyIII\Models\RecurrenceTransaction; use FireflyIII\Models\RecurrenceTransaction;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface RecurringRepositoryInterface * Interface RecurringRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface RecurringRepositoryInterface interface RecurringRepositoryInterface
{ {

View File

@@ -23,14 +23,26 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Rule; namespace FireflyIII\Repositories\Rule;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Rule; use FireflyIII\Models\Rule;
use FireflyIII\Models\RuleAction; use FireflyIII\Models\RuleAction;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\RuleTrigger; use FireflyIII\Models\RuleTrigger;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface RuleRepositoryInterface. * Interface RuleRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface RuleRepositoryInterface interface RuleRepositoryInterface
{ {

View File

@@ -23,11 +23,23 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\RuleGroup; namespace FireflyIII\Repositories\RuleGroup;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\RuleGroup; use FireflyIII\Models\RuleGroup;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface RuleGroupRepositoryInterface. * Interface RuleGroupRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface RuleGroupRepositoryInterface interface RuleGroupRepositoryInterface
{ {

View File

@@ -25,10 +25,22 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Tag; namespace FireflyIII\Repositories\Tag;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface OperationsRepositoryInterface * Interface OperationsRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface OperationsRepositoryInterface interface OperationsRepositoryInterface
{ {

View File

@@ -24,12 +24,24 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Tag; namespace FireflyIII\Repositories\Tag;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\Location; use FireflyIII\Models\Location;
use FireflyIII\Models\Tag; use FireflyIII\Models\Tag;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface TagRepositoryInterface. * Interface TagRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface TagRepositoryInterface interface TagRepositoryInterface
{ {

View File

@@ -24,15 +24,27 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\TransactionGroup; namespace FireflyIII\Repositories\TransactionGroup;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Exceptions\DuplicateTransactionException; use FireflyIII\Exceptions\DuplicateTransactionException;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Models\Location; use FireflyIII\Models\Location;
use FireflyIII\Models\TransactionGroup; use FireflyIII\Models\TransactionGroup;
use FireflyIII\Models\UserGroup;
use FireflyIII\Support\NullArrayObject; use FireflyIII\Support\NullArrayObject;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface TransactionGroupRepositoryInterface * Interface TransactionGroupRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface TransactionGroupRepositoryInterface interface TransactionGroupRepositoryInterface
{ {

View File

@@ -24,11 +24,23 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\TransactionType; namespace FireflyIII\Repositories\TransactionType;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\TransactionType; use FireflyIII\Models\TransactionType;
use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface TransactionTypeRepositoryInterface * Interface TransactionTypeRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface TransactionTypeRepositoryInterface interface TransactionTypeRepositoryInterface
{ {

View File

@@ -23,14 +23,24 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\User; namespace FireflyIII\Repositories\User;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\InvitedUser; use FireflyIII\Models\InvitedUser;
use FireflyIII\Models\Role; use FireflyIII\Models\Role;
use FireflyIII\Models\UserGroup;
use FireflyIII\User; use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable; use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface UserRepositoryInterface. * Interface UserRepositoryInterface.
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface UserRepositoryInterface interface UserRepositoryInterface
{ {

View File

@@ -24,11 +24,22 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\UserGroup; namespace FireflyIII\Repositories\UserGroup;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\UserGroup; use FireflyIII\Models\UserGroup;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface UserGroupRepositoryInterface * Interface UserGroupRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface UserGroupRepositoryInterface interface UserGroupRepositoryInterface
{ {

View File

@@ -88,8 +88,6 @@ interface CurrencyRepositoryInterface
public function getByIds(array $ids): Collection; public function getByIds(array $ids): Collection;
public function getUserGroup(): UserGroup;
public function isFallbackCurrency(TransactionCurrency $currency): bool; public function isFallbackCurrency(TransactionCurrency $currency): bool;
public function makeDefault(TransactionCurrency $currency): void; public function makeDefault(TransactionCurrency $currency): void;

View File

@@ -24,13 +24,25 @@ declare(strict_types=1);
namespace FireflyIII\Repositories\Webhook; namespace FireflyIII\Repositories\Webhook;
use FireflyIII\Enums\UserRoleEnum;
use FireflyIII\Models\UserGroup;
use FireflyIII\Models\Webhook; use FireflyIII\Models\Webhook;
use FireflyIII\Models\WebhookAttempt; use FireflyIII\Models\WebhookAttempt;
use FireflyIII\Models\WebhookMessage; use FireflyIII\Models\WebhookMessage;
use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
/** /**
* Interface WebhookRepositoryInterface * Interface WebhookRepositoryInterface
*
* @method setUserGroup(UserGroup $group)
* @method getUserGroup()
* @method getUser()
* @method checkUserGroupAccess(UserRoleEnum $role)
* @method setUser(null|Authenticatable|User $user)
* @method setUserGroupById(int $userGroupId)
*
*/ */
interface WebhookRepositoryInterface interface WebhookRepositoryInterface
{ {

View File

@@ -126,7 +126,7 @@ trait DepositValidation
// if the user submits an ID, but that ID is not of the correct type, // if the user submits an ID, but that ID is not of the correct type,
// return false. // return false.
if (null !== $accountId) { if (null !== $accountId) {
$search = $this->getRepository()->find($accountId); $search = $this->accountRepository->find($accountId);
if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) { if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) {
app('log')->debug(sprintf('User submitted an ID (#%d), which is a "%s", so this is not a valid source.', $accountId, $search->accountType->type)); app('log')->debug(sprintf('User submitted an ID (#%d), which is a "%s", so this is not a valid source.', $accountId, $search->accountType->type));
app('log')->debug(sprintf('Firefly III accepts ID #%d as valid account data.', $accountId)); app('log')->debug(sprintf('Firefly III accepts ID #%d as valid account data.', $accountId));
@@ -140,7 +140,7 @@ trait DepositValidation
// if user submits an IBAN: // if user submits an IBAN:
if (null !== $accountIban) { if (null !== $accountIban) {
$search = $this->getRepository()->findByIbanNull($accountIban, $validTypes); $search = $this->accountRepository->findByIbanNull($accountIban, $validTypes);
if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) { if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) {
app('log')->debug(sprintf('User submitted IBAN ("%s"), which is a "%s", so this is not a valid source.', $accountIban, $search->accountType->type)); app('log')->debug(sprintf('User submitted IBAN ("%s"), which is a "%s", so this is not a valid source.', $accountIban, $search->accountType->type));
$result = false; $result = false;
@@ -154,7 +154,7 @@ trait DepositValidation
// if user submits a number: // if user submits a number:
if (null !== $accountNumber && '' !== $accountNumber) { if (null !== $accountNumber && '' !== $accountNumber) {
$search = $this->getRepository()->findByAccountNumber($accountNumber, $validTypes); $search = $this->accountRepository->findByAccountNumber($accountNumber, $validTypes);
if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) { if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) {
app('log')->debug( app('log')->debug(
sprintf('User submitted number ("%s"), which is a "%s", so this is not a valid source.', $accountNumber, $search->accountType->type) sprintf('User submitted number ("%s"), which is a "%s", so this is not a valid source.', $accountNumber, $search->accountType->type)

View File

@@ -101,7 +101,7 @@ trait OBValidation
// return false. // return false.
if (null !== $accountId && null === $accountName) { if (null !== $accountId && null === $accountName) {
app('log')->debug('Source ID is not null, but name is null.'); app('log')->debug('Source ID is not null, but name is null.');
$search = $this->getRepository()->find($accountId); $search = $this->accountRepository->find($accountId);
// the source resulted in an account, but it's not of a valid type. // the source resulted in an account, but it's not of a valid type.
if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) { if (null !== $search && !in_array($search->accountType->type, $validTypes, true)) {

View File

@@ -87,7 +87,7 @@ trait WithdrawalValidation
// if there's an ID it must be of the "validTypes". // if there's an ID it must be of the "validTypes".
if (null !== $accountId && 0 !== $accountId) { if (null !== $accountId && 0 !== $accountId) {
$found = $this->getRepository()->find($accountId); $found = $this->accountRepository->find($accountId);
if (null !== $found) { if (null !== $found) {
$type = $found->accountType->type; $type = $found->accountType->type;
if (in_array($type, $validTypes, true)) { if (in_array($type, $validTypes, true)) {