mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 03:43:07 +00:00
Add field to user management.
This commit is contained in:
@@ -101,7 +101,7 @@ class CreateGroupMemberships extends Command
|
||||
private function createGroupMembership(User $user): void
|
||||
{
|
||||
$userGroup = UserGroup::create(['title' => $user->email]);
|
||||
$userRole = UserRole::where('title', UserRole::FULL)->first();
|
||||
$userRole = UserRole::where('title', UserRole::OWNER)->first();
|
||||
|
||||
if (null === $userRole) {
|
||||
throw new FireflyException('Firefly III could not find a user role. Please make sure all validations have run.');
|
||||
@@ -117,6 +117,9 @@ class CreateGroupMemberships extends Command
|
||||
if (null === $membership) {
|
||||
throw new FireflyException('Firefly III could not create user group management object. Please make sure all validations have run.');
|
||||
}
|
||||
$user->user_group_id = $userGroup->id;
|
||||
$user->save();
|
||||
|
||||
Log::debug(sprintf('User #%d now has main group.', $user->id));
|
||||
}
|
||||
|
||||
|
@@ -262,7 +262,7 @@ class UserEventHandler
|
||||
$user = $event->user;
|
||||
// create a new group.
|
||||
$group = UserGroup::create(['title' => $user->email]);
|
||||
$role = UserRole::where('title', UserRole::FULL)->first();
|
||||
$role = UserRole::where('title', UserRole::OWNER)->first();
|
||||
if (null === $role) {
|
||||
throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?');
|
||||
}
|
||||
@@ -273,6 +273,8 @@ class UserEventHandler
|
||||
'user_role_id' => $role->id,
|
||||
]
|
||||
);
|
||||
$user->user_group_id = $group->id;
|
||||
$user->save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -36,6 +36,7 @@ class UserRole extends Model
|
||||
public const CHANGE_REPETITIONS = 'change_reps';
|
||||
public const VIEW_REPORTS = 'view_reports';
|
||||
public const FULL = 'full';
|
||||
public const OWNER = 'owner';
|
||||
protected $fillable = ['title'];
|
||||
|
||||
/**
|
||||
|
10
app/User.php
10
app/User.php
@@ -46,8 +46,10 @@ use FireflyIII\Models\Tag;
|
||||
use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Models\TransactionGroup;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\UserGroup;
|
||||
use FireflyIII\Models\Webhook;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasManyThrough;
|
||||
@@ -311,6 +313,14 @@ class User extends Authenticatable
|
||||
return $this->hasMany(Category::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* @return BelongsTo
|
||||
*/
|
||||
public function userGroup(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(UserGroup::class,);
|
||||
}
|
||||
/**
|
||||
* @codeCoverageIgnore
|
||||
* Link to currency exchange rates
|
||||
|
Reference in New Issue
Block a user