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
* @throws FireflyException
*/
private function getBudgets(): Collection
{
/** @var BudgetRepositoryInterface $repos */
$repos = app(BudgetRepositoryInterface::class);
throw new FireflyException('uses old administration ID check, needs to be updated.F');
$repos->setAdministrationId($this->getAdministrationId());
/** @var BudgetRepositoryInterface $repository */
$repository = app(BudgetRepositoryInterface::class);
$repository->setUserGroup($this->getUserGroup());
return $repos->getActiveBudgets();
return $repository->getActiveBudgets();
}
}

View File

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