Fix account list and remove sanctum

This commit is contained in:
James Cole
2025-05-08 20:22:01 +02:00
parent ee96dd3ab6
commit 07ff2305fd
9 changed files with 73 additions and 44 deletions

View File

@@ -296,13 +296,6 @@ STATIC_CRON_TOKEN=
# However if you know what you're doing you can significantly speed up container start times.
# Set each value to true to enable, or false to disable.
# Set this to true to build all locales supported by Firefly III.
# This may take quite some time (several minutes) and is generally not recommended.
# If you wish to change or alter the list of locales, start your Docker container with
# `docker run -v locale.gen:/etc/locale.gen -e DKR_BUILD_LOCALE=true`
# and make sure your preferred locales are in your own locale.gen.
DKR_BUILD_LOCALE=false
# Check if the SQLite database exists. Can be skipped if you're not using SQLite.
# Won't significantly speed up things.
DKR_CHECK_SQLITE=true

View File

@@ -177,7 +177,7 @@ class Kernel extends HttpKernel
// full API authentication
'api' => [
AcceptHeaders::class,
EnsureFrontendRequestsAreStateful::class,
// EnsureFrontendRequestsAreStateful::class,
'auth:api,sanctum',
'bindings',
],

View File

@@ -59,6 +59,7 @@ class AccountEnrichment implements EnrichmentInterface
private array $openingBalances;
private User $user;
private UserGroup $userGroup;
private array $lastActivities;
public function __construct()
{
@@ -69,6 +70,7 @@ class AccountEnrichment implements EnrichmentInterface
$this->accountTypes = [];
$this->meta = [];
$this->notes = [];
$this->lastActivities = [];
$this->locations = [];
// $this->repository = app(AccountRepositoryInterface::class);
// $this->currencyRepository = app(CurrencyRepositoryInterface::class);
@@ -100,6 +102,7 @@ class AccountEnrichment implements EnrichmentInterface
$this->getAccountTypes();
$this->collectMetaData();
$this->collectNotes();
$this->collectLastActivities();
$this->collectLocations();
$this->collectOpeningBalances();
$this->appendCollectedData();
@@ -132,8 +135,7 @@ class AccountEnrichment implements EnrichmentInterface
{
$set = AccountMeta::whereIn('name', ['is_multi_currency', 'include_net_worth', 'currency_id', 'account_role', 'account_number', 'BIC', 'liability_direction', 'interest', 'interest_period', 'current_debt'])
->whereIn('account_id', $this->accountIds)
->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])->toArray()
;
->get(['account_meta.id', 'account_meta.account_id', 'account_meta.name', 'account_meta.data'])->toArray();
/** @var array $entry */
foreach ($set as $entry) {
@@ -159,8 +161,7 @@ class AccountEnrichment implements EnrichmentInterface
$notes = Note::query()->whereIn('noteable_id', $this->accountIds)
->whereNotNull('notes.text')
->where('notes.text', '!=', '')
->where('noteable_type', Account::class)->get(['notes.noteable_id', 'notes.text'])->toArray()
;
->where('noteable_type', Account::class)->get(['notes.noteable_id', 'notes.text'])->toArray();
foreach ($notes as $note) {
$this->notes[(int) $note['noteable_id']] = (string) $note['text'];
}
@@ -170,8 +171,7 @@ class AccountEnrichment implements EnrichmentInterface
private function collectLocations(): void
{
$locations = Location::query()->whereIn('locatable_id', $this->accountIds)
->where('locatable_type', Account::class)->get(['locations.locatable_id', 'locations.latitude', 'locations.longitude', 'locations.zoom_level'])->toArray()
;
->where('locatable_type', Account::class)->get(['locations.locatable_id', 'locations.latitude', 'locations.longitude', 'locations.zoom_level'])->toArray();
foreach ($locations as $location) {
$this->locations[(int) $location['locatable_id']]
= [
@@ -193,8 +193,7 @@ class AccountEnrichment implements EnrichmentInterface
->setUserGroup($this->userGroup)
->setAccounts($this->collection)
->withAccountInformation()
->setTypes([TransactionTypeEnum::OPENING_BALANCE->value])
;
->setTypes([TransactionTypeEnum::OPENING_BALANCE->value]);
$journals = $collector->getExtractedJournals();
foreach ($journals as $journal) {
$this->openingBalances[(int) $journal['source_account_id']]
@@ -229,7 +228,8 @@ class AccountEnrichment implements EnrichmentInterface
$notes = $this->notes;
$openingBalances = $this->openingBalances;
$locations = $this->locations;
$this->collection = $this->collection->map(function (Account $item) use ($accountTypes, $meta, $currencies, $notes, $openingBalances, $locations) {
$lastActivities = $this->lastActivities;
$this->collection = $this->collection->map(function (Account $item) use ($accountTypes, $meta, $currencies, $notes, $openingBalances, $locations, $lastActivities) {
$item->full_account_type = $accountTypes[(int) $item->account_type_id] ?? null;
$accountMeta = [
'currency' => null,
@@ -264,6 +264,9 @@ class AccountEnrichment implements EnrichmentInterface
if (array_key_exists($item->id, $locations)) {
$accountMeta['location'] = $locations[$item->id];
}
if (array_key_exists($item->id, $lastActivities)) {
$accountMeta['last_activity'] = $lastActivities[$item->id];
}
$item->meta = $accountMeta;
return $item;
@@ -274,4 +277,9 @@ class AccountEnrichment implements EnrichmentInterface
{
$this->native = $native;
}
private function collectLastActivities(): void
{
$this->lastActivities = Steam::getLastActivities($this->accountIds);
}
}

View File

@@ -152,6 +152,7 @@ class AccountTransformer extends AbstractTransformer
'longitude' => $longitude,
'latitude' => $latitude,
'zoom_level' => $zoomLevel,
'last_activity' => array_key_exists('last_activity', $account->meta) ? $account->meta['last_activity']->toAtomString() : null,
'links' => [
[
'rel' => 'self',

6
package-lock.json generated
View File

@@ -4416,9 +4416,9 @@
}
},
"node_modules/caniuse-lite": {
"version": "1.0.30001716",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001716.tgz",
"integrity": "sha512-49/c1+x3Kwz7ZIWt+4DvK3aMJy9oYXXG6/97JKsnjdCk/6n9vVyWL8NAwVt95Lwt9eigI10Hl782kDfZUUlRXw==",
"version": "1.0.30001717",
"resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001717.tgz",
"integrity": "sha512-auPpttCq6BDEG8ZAuHJIplGw6GODhjw+/11e7IjpnYCxZcW/ONgPs0KVBJ0d1bY3e2+7PRe5RCLyP+PfwVgkYw==",
"dev": true,
"funding": [
{

View File

@@ -20,6 +20,7 @@
import {api} from "../../../../boot/axios";
import format from "date-fns/format";
import {getCacheKey} from "../../../../support/get-cache-key.js";
export default class Get {
@@ -37,6 +38,31 @@ export default class Get {
return api.get('/api/v1/accounts/' + identifier, {params: params});
}
/**
*
* @param params
* @returns {Promise<AxiosResponse<any>>}
*/
index(params) {
// first, check API in some consistent manner.
// then, load if necessary.
const cacheKey = getCacheKey('/api/v1/accounts', params);
const cacheValid = window.store.get('cacheValid');
let cachedData = window.store.get(cacheKey);
if (cacheValid && typeof cachedData !== 'undefined') {
console.log('Cache is valid, return cache.');
return Promise.resolve(cachedData);
}
// if not, store in cache and then return res.
return api.get('/api/v1/accounts', {params: params}).then(response => {
console.log('Cache is invalid, return fresh.');
window.store.set(cacheKey, response.data);
return Promise.resolve({data: response.data.data, meta: response.data.meta});
});
}
/**
*

View File

@@ -383,7 +383,8 @@ let index = function () {
// one page only.o
(new Get()).index(params).then(response => {
console.log(response);
this.totalPages = response.meta.lastPage;
this.totalPages = response.meta.pagination.total_pages;
console.log('a');
for (let i = 0; i < response.data.length; i++) {
if (response.data.hasOwnProperty(i)) {
let current = response.data[i];

View File

@@ -9,7 +9,7 @@
<div class="card">
<div class="card-header">
<h3 class="card-title">
<a :href="'{{ route('accounts.show', '') }}/' + account.id"
<a :href="'{{ route('accounts.show', '0') }}/' + account.id"
x-text="account.name"></a>
<span class="small">
@@ -42,7 +42,7 @@
<template x-if="group.transactions[0].type === 'transfer'">
<span class="text-muted fa-solid fa-arrows-rotate fa-fw"></span>
</template>
<a :href="'{{route('transactions.show', '') }}/' + group.id" x-text="group.title"></a><br/></span>
<a :href="'{{route('transactions.show', '0') }}/' + group.id" x-text="group.title"></a><br/></span>
</template>
<ul class="list-unstyled list-no-margin">
<template x-for="transaction in group.transactions">
@@ -61,7 +61,7 @@
<template x-if="transaction.type == 'transfer'">
<span class="text-muted fa-solid fa-arrows-rotate fa-fw"></span>
</template>
<a :href="'{{route('transactions.show', '') }}/' + group.id" x-text="transaction.description"></a>
<a :href="'{{route('transactions.show', '0') }}/' + group.id" x-text="transaction.description"></a>
</span>
</template>
</li>

View File

@@ -30,7 +30,7 @@
<template x-for="bill in group.bills">
<tr>
<td>
<a :href="'{{ route('subscriptions.show',['']) }}/' + bill.id" :title="bill.name">
<a :href="'{{ route('subscriptions.show',['0']) }}/' + bill.id" :title="bill.name">
<span x-text="bill.name"></span>
</a>
<template x-if="bill.paid">