mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-11 17:39:41 +00:00
Basic check for user's administration ID
This commit is contained in:
15
app/User.php
15
app/User.php
@@ -27,6 +27,7 @@ namespace FireflyIII;
|
||||
use Eloquent;
|
||||
use Exception;
|
||||
use FireflyIII\Events\RequestedNewPassword;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Models\Account;
|
||||
use FireflyIII\Models\Attachment;
|
||||
use FireflyIII\Models\AvailableBudget;
|
||||
@@ -361,6 +362,20 @@ class User extends Authenticatable
|
||||
return $this->hasMany(GroupMembership::class)->with(['userGroup', 'userRole']);
|
||||
}
|
||||
|
||||
/**
|
||||
* A safe method that returns the user's current administration ID (group ID).
|
||||
*
|
||||
* @return int
|
||||
* @throws FireflyException
|
||||
*/
|
||||
public function getAdministrationId(): int {
|
||||
$groupId = (int)$this->user_group_id;
|
||||
if(0 === $groupId) {
|
||||
throw new FireflyException('User has no administration ID.');
|
||||
}
|
||||
return $groupId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Link to object groups.
|
||||
|
||||
Reference in New Issue
Block a user