mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 23:45:10 +00:00
Restore previous stuff
This commit is contained in:
@@ -40,17 +40,6 @@ class AccountRepository extends AbstractRepository implements QueriesAll
|
||||
*/
|
||||
public function __construct() {}
|
||||
|
||||
/**
|
||||
* Get the tags relationship
|
||||
*
|
||||
* @param Account $account
|
||||
* @return iterable
|
||||
*/
|
||||
public function getBalances(Account $account): iterable
|
||||
{
|
||||
die('here we are');
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\JsonApi\V3\Accounts;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use LaravelJsonApi\Core\Resources\JsonApiResource;
|
||||
|
||||
class AccountResource extends JsonApiResource
|
||||
@@ -54,11 +55,17 @@ class AccountResource extends JsonApiResource
|
||||
'name' => $this->resource->name,
|
||||
'iban' => '' === $this->resource->iban ? null : $this->resource->iban,
|
||||
'active' => $this->resource->active,
|
||||
// 'virtual_balance' => $this->resource->virtual_balance,
|
||||
'last_activity' => $this->resource->last_activity,
|
||||
// 'native_balance' => $this->resource->native_balance,
|
||||
'type' => $this->resource->type,
|
||||
'account_role' => $this->resource->account_role,
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// 'virtual_balance' => $this->resource->virtual_balance,
|
||||
// 'native_balance' => $this->resource->native_balance,
|
||||
//'user' => $this->resource->user_array,
|
||||
// 'balances' => []
|
||||
//
|
||||
@@ -152,9 +159,8 @@ class AccountResource extends JsonApiResource
|
||||
public function relationships($request): iterable
|
||||
{
|
||||
return [
|
||||
$this->relation('user')->withData($this->resource->user_array),
|
||||
$this->relation('balances')->withData([]),
|
||||
//$this->relation('tags')->withData($this->resource->getTags()),
|
||||
$this->relation('user')->withData($this->resource->user),
|
||||
$this->relation('balances')->withData($this->resource->balances),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,6 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\JsonApi\V3\Accounts\Capabilities;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Support\JsonApi\Concerns\UsergroupAware;
|
||||
use FireflyIII\Support\JsonApi\Enrichments\AccountEnrichment;
|
||||
use FireflyIII\Support\JsonApi\ExpandsQuery;
|
||||
@@ -48,6 +47,7 @@ class AccountQuery extends QueryAll implements HasPagination
|
||||
*/
|
||||
#[\Override] public function get(): iterable
|
||||
{
|
||||
|
||||
$filters = $this->queryParameters->filter();
|
||||
$sort = $this->queryParameters->sortFields();
|
||||
$pagination = $this->filtersPagination($this->queryParameters->page());
|
||||
|
@@ -3,6 +3,7 @@
|
||||
namespace FireflyIII\JsonApi\V3;
|
||||
|
||||
use FireflyIII\JsonApi\V3\Accounts\AccountSchema;
|
||||
use FireflyIII\JsonApi\V3\Balances\BalanceSchema;
|
||||
use FireflyIII\JsonApi\V3\Users\UserSchema;
|
||||
use LaravelJsonApi\Core\Server\Server as BaseServer;
|
||||
|
||||
@@ -36,6 +37,7 @@ class Server extends BaseServer
|
||||
return [
|
||||
AccountSchema::class,
|
||||
UserSchema::class,
|
||||
BalanceSchema::class,
|
||||
];
|
||||
}
|
||||
|
||||
|
@@ -7,6 +7,7 @@ use LaravelJsonApi\Eloquent\Contracts\Paginator;
|
||||
use LaravelJsonApi\Eloquent\Fields\DateTime;
|
||||
use LaravelJsonApi\Eloquent\Fields\ID;
|
||||
use LaravelJsonApi\Eloquent\Fields\Relations\HasMany;
|
||||
use LaravelJsonApi\Eloquent\Fields\Str;
|
||||
use LaravelJsonApi\Eloquent\Filters\WhereIdIn;
|
||||
use LaravelJsonApi\Eloquent\Pagination\PagePagination;
|
||||
use LaravelJsonApi\Eloquent\Schema;
|
||||
@@ -31,7 +32,8 @@ class UserSchema extends Schema
|
||||
return [
|
||||
ID::make(),
|
||||
DateTime::make('created_at')->sortable()->readOnly(),
|
||||
DateTime::make('created_at')->sortable()->readOnly(),
|
||||
DateTime::make('updated_at')->sortable()->readOnly(),
|
||||
Str::make('email'),
|
||||
HasMany::make('accounts'),
|
||||
];
|
||||
}
|
||||
|
@@ -51,4 +51,19 @@ class AccountPolicy
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
|
||||
/**
|
||||
* Everybody can do this, but selection should limit to user.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function viewUser(User $user, Account $account): bool
|
||||
{
|
||||
return $this->view($user, $account);
|
||||
}
|
||||
|
||||
public function viewBalances(User $user, Account $account): bool
|
||||
{
|
||||
return $this->view($user, $account);
|
||||
}
|
||||
}
|
||||
|
53
app/Policies/BalancePolicy.php
Normal file
53
app/Policies/BalancePolicy.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
/*
|
||||
* BalancePolicy.php
|
||||
* Copyright (c) 2024 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/.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Policies;
|
||||
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\User;
|
||||
|
||||
class BalancePolicy
|
||||
{
|
||||
/**
|
||||
* TODO needs better authentication.
|
||||
*
|
||||
* @param User $user
|
||||
* @param Account $account
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function view(User $user, Account $account): bool
|
||||
{
|
||||
return auth()->check() && $user->id === $account->user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Everybody can do this, but selection should limit to user.
|
||||
*
|
||||
* @return true
|
||||
*/
|
||||
public function viewAny(): bool
|
||||
{
|
||||
return auth()->check();
|
||||
}
|
||||
}
|
@@ -51,6 +51,11 @@ class AccountEnrichment implements EnrichmentInterface
|
||||
|
||||
$this->collection->transform(function (Account $account) {
|
||||
$account->user_array = ['id' => 1,'bla bla' => 'bla'];
|
||||
$account->balances = collect([
|
||||
['balance_id' => 1,'balance' => 5],
|
||||
['balance_id' => 2,'balance' => 5],
|
||||
['balance_id' => 3,'balance' => 5],
|
||||
]);
|
||||
return $account;
|
||||
});
|
||||
|
||||
|
@@ -23,14 +23,18 @@
|
||||
declare(strict_types=1);
|
||||
|
||||
use LaravelJsonApi\Laravel\Facades\JsonApiRoute;
|
||||
use LaravelJsonApi\Laravel\Routing\ResourceRegistrar;
|
||||
use LaravelJsonApi\Laravel\Http\Controllers\JsonApiController;
|
||||
use LaravelJsonApi\Laravel\Routing\Relationships;
|
||||
use LaravelJsonApi\Laravel\Routing\ResourceRegistrar;
|
||||
|
||||
|
||||
JsonApiRoute::server('v3')
|
||||
->prefix('v3')
|
||||
->resources(function (ResourceRegistrar $server) {
|
||||
$server->resource('accounts', JsonApiController::class);
|
||||
$server->resource('accounts', JsonApiController::class)->readOnly()->relationships(function (Relationships $relations) {
|
||||
$relations->hasOne('user')->readOnly();
|
||||
$relations->hasMany('balances')->readOnly();
|
||||
});
|
||||
$server->resource('users', JsonApiController::class);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user