James Cole 2023-09-23 10:34:49 +02:00
parent e003dcd596
commit f66dd259f0
No known key found for this signature in database
GPG Key ID: B49A324B7EAD6D80
2 changed files with 27 additions and 17 deletions

View File

@ -126,15 +126,13 @@ class OperationsRepository implements OperationsRepositoryInterface
/** /**
* @return Collection * @return Collection
* @throws FireflyException
*/ */
private function getBudgets(): Collection private function getBudgets(): Collection
{ {
/** @var BudgetRepositoryInterface $repos */ /** @var BudgetRepositoryInterface $repository */
$repos = app(BudgetRepositoryInterface::class); $repository = app(BudgetRepositoryInterface::class);
throw new FireflyException('uses old administration ID check, needs to be updated.F'); $repository->setUserGroup($this->getUserGroup());
$repos->setAdministrationId($this->getAdministrationId());
return $repos->getActiveBudgets(); return $repository->getActiveBudgets();
} }
} }

View File

@ -40,16 +40,11 @@ trait UserGroupTrait
protected UserGroup $userGroup; protected UserGroup $userGroup;
/** /**
* @param Authenticatable|User|null $user * @return UserGroup
*
* @return void
*/ */
public function setUser(Authenticatable | User | null $user): void public function getUserGroup(): UserGroup
{ {
if (null !== $user) { return $this->userGroup;
$this->user = $user;
$this->userGroup = $user->userGroup;
}
} }
/** /**
@ -64,6 +59,19 @@ trait UserGroupTrait
$this->userGroup = $userGroup; $this->userGroup = $userGroup;
} }
/**
* @param Authenticatable|User|null $user
*
* @return void
*/
public function setUser(Authenticatable | User | null $user): void
{
if (null !== $user) {
$this->user = $user;
$this->userGroup = $user->userGroup;
}
}
/** /**
* @param int $userGroupId * @param int $userGroupId
* *
@ -77,9 +85,13 @@ trait UserGroupTrait
if (0 === $memberships) { if (0 === $memberships) {
throw new FireflyException(sprintf('User #%d has no access to administration #%d', $this->user->id, $userGroupId)); throw new FireflyException(sprintf('User #%d has no access to administration #%d', $this->user->id, $userGroupId));
} }
$this->userGroup = UserGroup::find($userGroupId); /** @var UserGroup|null $userGroup */
if (null === $this->userGroup) { $userGroup = UserGroup::find($userGroupId);
throw new FireflyException(sprintf('Unfound administration for user #%d', $this->user->id)); if (null === $userGroup) {
throw new FireflyException(sprintf('Cannot find administration for user #%d', $this->user->id));
} }
$this->userGroup = $userGroup;
} }
} }