mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Expand API with better user group management.
This commit is contained in:
@@ -25,23 +25,26 @@ declare(strict_types=1);
|
||||
namespace FireflyIII\Models;
|
||||
|
||||
use Eloquent;
|
||||
use FireflyIII\Enums\UserRoleEnum;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
|
||||
/**
|
||||
* Class UserGroup
|
||||
*
|
||||
* @property int $id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property string|null $deleted_at
|
||||
* @property string $title
|
||||
* @property-read Collection|GroupMembership[] $groupMemberships
|
||||
* @property-read int|null $group_memberships_count
|
||||
* @property int $id
|
||||
* @property Carbon|null $created_at
|
||||
* @property Carbon|null $updated_at
|
||||
* @property string|null $deleted_at
|
||||
* @property string $title
|
||||
* @property-read Collection|GroupMembership[] $groupMemberships
|
||||
* @property-read int|null $group_memberships_count
|
||||
* @method static Builder|UserGroup newModelQuery()
|
||||
* @method static Builder|UserGroup newQuery()
|
||||
* @method static Builder|UserGroup query()
|
||||
@@ -50,24 +53,52 @@ use Illuminate\Support\Carbon;
|
||||
* @method static Builder|UserGroup whereId($value)
|
||||
* @method static Builder|UserGroup whereTitle($value)
|
||||
* @method static Builder|UserGroup whereUpdatedAt($value)
|
||||
* @property-read Collection<int, Account> $accounts
|
||||
* @property-read int|null $accounts_count
|
||||
* @property-read Collection<int, \FireflyIII\Models\AvailableBudget> $availableBudgets
|
||||
* @property-read int|null $available_budgets_count
|
||||
* @property-read Collection<int, \FireflyIII\Models\Bill> $bills
|
||||
* @property-read int|null $bills_count
|
||||
* @property-read Collection<int, \FireflyIII\Models\Budget> $budgets
|
||||
* @property-read int|null $budgets_count
|
||||
* @property-read Collection<int, \FireflyIII\Models\PiggyBank> $piggyBanks
|
||||
* @property-read int|null $piggy_banks_count
|
||||
* @property-read Collection<int, \FireflyIII\Models\TransactionJournal> $transactionJournals
|
||||
* @property-read int|null $transaction_journals_count
|
||||
* @property-read Collection<int, Account> $accounts
|
||||
* @property-read int|null $accounts_count
|
||||
* @property-read Collection<int, AvailableBudget> $availableBudgets
|
||||
* @property-read int|null $available_budgets_count
|
||||
* @property-read Collection<int, Bill> $bills
|
||||
* @property-read int|null $bills_count
|
||||
* @property-read Collection<int, Budget> $budgets
|
||||
* @property-read int|null $budgets_count
|
||||
* @property-read Collection<int, PiggyBank> $piggyBanks
|
||||
* @property-read int|null $piggy_banks_count
|
||||
* @property-read Collection<int, TransactionJournal> $transactionJournals
|
||||
* @property-read int|null $transaction_journals_count
|
||||
* @mixin Eloquent
|
||||
*/
|
||||
class UserGroup extends Model
|
||||
{
|
||||
protected $fillable = ['title'];
|
||||
|
||||
/**
|
||||
* Route binder. Converts the key in the URL to the specified object (or throw 404).
|
||||
*
|
||||
* @param string $value
|
||||
*
|
||||
* @return UserGroup
|
||||
* @throws NotFoundHttpException
|
||||
*/
|
||||
public static function routeBinder(string $value): UserGroup
|
||||
{
|
||||
if (auth()->check()) {
|
||||
$userGroupId = (int)$value;
|
||||
/** @var User $user */
|
||||
$user = auth()->user();
|
||||
/** @var UserGroup $userGroup */
|
||||
$userGroup = UserGroup::find($userGroupId);
|
||||
if (null === $userGroup) {
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
// need at least ready only to be aware of the user group's existence,
|
||||
// but owner/full role (in the group) or global owner role may overrule this.
|
||||
if ($user->hasRoleInGroup($userGroup, UserRoleEnum::READ_ONLY, true, true)) {
|
||||
return $userGroup;
|
||||
}
|
||||
}
|
||||
throw new NotFoundHttpException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Link to accounts.
|
||||
*
|
||||
|
Reference in New Issue
Block a user