mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Add field to user management.
This commit is contained in:
parent
a08440aacf
commit
30d155a8e2
@ -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
|
||||
|
@ -32,5 +32,6 @@ return [
|
||||
UserRole::CHANGE_REPETITIONS => [],
|
||||
UserRole::VIEW_REPORTS => [],
|
||||
UserRole::FULL => [],
|
||||
UserRole::OWNER => [],
|
||||
],
|
||||
];
|
@ -2,6 +2,7 @@
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
/**
|
||||
* Class UserGroups
|
||||
@ -15,6 +16,17 @@ class UserGroups extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table(
|
||||
'users', function (Blueprint $table) {
|
||||
|
||||
$table->dropForeign('type_user_group_id');
|
||||
if (Schema::hasColumn('users', 'user_group_id')) {
|
||||
$table->dropColumn('user_group_id');
|
||||
}
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
Schema::dropIfExists('group_memberships');
|
||||
Schema::dropIfExists('user_roles');
|
||||
Schema::dropIfExists('user_groups');
|
||||
@ -69,6 +81,14 @@ class UserGroups extends Migration
|
||||
$table->unique(['user_id', 'user_group_id', 'user_role_id']);
|
||||
}
|
||||
);
|
||||
Schema::table(
|
||||
'users', function (Blueprint $table) {
|
||||
if (!Schema::hasColumn('users', 'user_group_id')) {
|
||||
$table->bigInteger('user_group_id', false, true)->nullable();
|
||||
$table->foreign('user_group_id', 'type_user_group_id')->references('id')->on('user_groups')->onDelete('set null');
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ class UserRoleSeeder extends Seeder
|
||||
UserRole::CHANGE_REPETITIONS,
|
||||
UserRole::VIEW_REPORTS,
|
||||
UserRole::FULL,
|
||||
UserRole::OWNER,
|
||||
];
|
||||
|
||||
/** @var string $role */
|
||||
|
Loading…
Reference in New Issue
Block a user