diff --git a/app/Console/Commands/Tools/Cron.php b/app/Console/Commands/Tools/Cron.php index 15d15832bf..d3c89667f9 100644 --- a/app/Console/Commands/Tools/Cron.php +++ b/app/Console/Commands/Tools/Cron.php @@ -27,6 +27,7 @@ namespace FireflyIII\Console\Commands\Tools; use Carbon\Carbon; use FireflyIII\Console\Commands\ShowsFriendlyMessages; use FireflyIII\Exceptions\FireflyException; +use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Support\Cronjobs\AutoBudgetCronjob; use FireflyIII\Support\Cronjobs\BillWarningCronjob; use FireflyIII\Support\Cronjobs\ExchangeRatesCronjob; @@ -34,6 +35,7 @@ use FireflyIII\Support\Cronjobs\RecurringCronjob; use FireflyIII\Support\Cronjobs\UpdateCheckCronjob; use FireflyIII\Support\Cronjobs\WebhookCronjob; use FireflyIII\Support\Facades\AppConfiguration; +use FireflyIII\User; use Illuminate\Console\Command; use Illuminate\Support\Facades\Log; use InvalidArgumentException; @@ -55,8 +57,18 @@ class Cron extends Command {--send-webhook-messages : Sends any stray webhook messages (with a maximum of 5).} '; + private User $admin; + public function handle(): int { + /** @var UserRepositoryInterface $repository */ + $repository = app(UserRepositoryInterface::class); + $admin = $repository->getUsersByRole('owner')?->first(); + if(null === $admin) { + $this->friendlyError('There is no user in the system with the "owner"-role, cannot continue.'); + return 1; + } + $this->admin = $admin; $doAll = !$this->option('download-cer') && !$this->option('create-recurring') @@ -147,6 +159,7 @@ class Cron extends Command { $autoBudget = new AutoBudgetCronjob(); $autoBudget->setForce($force); + $autoBudget->setUser($this->admin); // set date in cron job: if ($date instanceof Carbon) { $autoBudget->setDate($date); @@ -169,6 +182,7 @@ class Cron extends Command { $updateCheck = new UpdateCheckCronjob(); $updateCheck->setForce($force); + $updateCheck->setUser($this->admin); $updateCheck->fire(); if ($updateCheck->jobErrored) { @@ -187,6 +201,7 @@ class Cron extends Command Log::debug(sprintf('Created new ExchangeRateConverter in %s', __METHOD__)); $exchangeRates = new ExchangeRatesCronjob(); $exchangeRates->setForce($force); + $exchangeRates->setUser($this->admin); // set date in cron job: if ($date instanceof Carbon) { $exchangeRates->setDate($date); @@ -212,6 +227,7 @@ class Cron extends Command { $recurring = new RecurringCronjob(); $recurring->setForce($force); + $recurring->setUser($this->admin); // set date in cron job: if ($date instanceof Carbon) { @@ -237,6 +253,7 @@ class Cron extends Command { $subscriptionWarningJob = new BillWarningCronjob(); $subscriptionWarningJob->setForce($force); + $subscriptionWarningJob->setUser($this->admin); // set date in cron job: if ($date instanceof Carbon) { $subscriptionWarningJob->setDate($date); @@ -259,6 +276,7 @@ class Cron extends Command { $webhook = new WebhookCronjob(); $webhook->setForce($force); + $webhook->setUser($this->admin); // set date in cron job: if ($date instanceof Carbon) { $webhook->setDate($date); diff --git a/app/Repositories/User/UserRepository.php b/app/Repositories/User/UserRepository.php index 8943ff6862..5a2a54e4bd 100644 --- a/app/Repositories/User/UserRepository.php +++ b/app/Repositories/User/UserRepository.php @@ -417,4 +417,12 @@ class UserRepository implements UserRepositoryInterface return null !== $invitee; } + + public function getUsersByRole(string $role): Collection + { + return User::leftJoin('role_user','role_user.user_id','=','users.id') + ->leftJoin('roles','roles.id','role_user.role_id') + ->where('roles.name', $role) + ->get(); + } } diff --git a/app/Repositories/User/UserRepositoryInterface.php b/app/Repositories/User/UserRepositoryInterface.php index 392ee2f7dc..1f47641232 100644 --- a/app/Repositories/User/UserRepositoryInterface.php +++ b/app/Repositories/User/UserRepositoryInterface.php @@ -49,6 +49,8 @@ interface UserRepositoryInterface */ public function all(): Collection; + public function getUsersByRole(string $role): Collection; + /** * Gives a user a role. */ diff --git a/package-lock.json b/package-lock.json index 1fee2712f1..47c946cc05 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,5 +1,5 @@ { - "name": "firefly-iii", + "name": "release", "lockfileVersion": 3, "requires": true, "packages": { diff --git a/resources/assets/v3/js/api/model/link-type/get.js b/resources/assets/v3/js/api/model/link-type/get.js new file mode 100644 index 0000000000..fb417a8802 --- /dev/null +++ b/resources/assets/v3/js/api/model/link-type/get.js @@ -0,0 +1,35 @@ +/* + * get.js + * Copyright (c) 2023 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 . + */ + + +import {api} from "../../../boot/axios"; + +export default class Get { + + /** + * + * @param params + * @returns {Promise>} + */ + list(params) { + return api.get('/api/v1/link-types', {params: params}); + } + +} diff --git a/resources/assets/v3/js/pages/transactions/create.js b/resources/assets/v3/js/pages/transactions/create.js index 82ea8c038e..9df64d3dfc 100644 --- a/resources/assets/v3/js/pages/transactions/create.js +++ b/resources/assets/v3/js/pages/transactions/create.js @@ -53,6 +53,7 @@ import {onMapZoom} from "./shared/on-map-zoom.js"; import {clearLocation} from './shared/clear-location.js'; import bootstrap from "bootstrap/dist/js/bootstrap.bundle.js"; import {removeSplit} from "./shared/remove-split.js"; +import {loadTransactionLinks} from './shared/load-transaction-links.js'; let create = function () { @@ -65,6 +66,7 @@ let create = function () { // links are stored in "links" for each transaction journal. links: [], + preparedLinks: [], // maps are stored in this array so they can be referred to. maps: [], @@ -83,6 +85,7 @@ let create = function () { formStates: { loadingCurrencies: true, loadingBudgets: true, + loadingLinks: true, loadingPiggyBanks: true, loadingSubscriptions: true, isSubmitting: false, @@ -260,6 +263,7 @@ let create = function () { this.formData.foreignCurrencies = data.foreignCurrencies; }); + loadBudgets(false).then(data => { this.formData.budgets = data; this.formStates.loadingBudgets = false; @@ -276,6 +280,14 @@ let create = function () { // load custom field preference and enable/disable those fields. this.loadCustomFields().then(data => { this.formBehaviour.customFields = data; + // linked-transactions-search + if(true === data.links) { + loadTransactionLinks().then(data => { + //console.log(data); + this.formData.linkTypes = data; + this.formStates.loadingLinks = false; + }); + } }); diff --git a/resources/assets/v3/js/pages/transactions/shared/load-transaction-links.js b/resources/assets/v3/js/pages/transactions/shared/load-transaction-links.js new file mode 100644 index 0000000000..83d2cac002 --- /dev/null +++ b/resources/assets/v3/js/pages/transactions/shared/load-transaction-links.js @@ -0,0 +1,25 @@ +import Get from "../../../api/model/link-type/get.js"; + +export function loadTransactionLinks() { + let params = { + page: 1, limit: 1337 + }; + let getter = new Get(); + return getter.list(params).then((response) => { + let set = []; + for (let i in response.data.data) { + if (response.data.data.hasOwnProperty(i)) { + let current = response.data.data[i]; + let entry = { + id: current.id, + name: current.attributes.name, + inward: current.attributes.inward, + outward: current.attributes.outward, + editable: current.attributes.editable, + }; + set.push(entry); + } + } + return set; + }); +} diff --git a/resources/views/components/transaction/split.blade.php b/resources/views/components/transaction/split.blade.php index 9420bad0a6..ed63337901 100644 --- a/resources/views/components/transaction/split.blade.php +++ b/resources/views/components/transaction/split.blade.php @@ -138,11 +138,11 @@