New user groups and memberships

This commit is contained in:
James Cole
2021-08-28 15:47:33 +02:00
parent a14c9438ad
commit 10787aada8
12 changed files with 483 additions and 8 deletions

View File

@@ -35,6 +35,9 @@ use FireflyIII\Mail\NewIPAddressWarningMail;
use FireflyIII\Mail\RegisteredUser as RegisteredUserMail;
use FireflyIII\Mail\RequestedNewPassword as RequestedNewPasswordMail;
use FireflyIII\Mail\UndoEmailChangeMail;
use FireflyIII\Models\GroupMembership;
use FireflyIII\Models\UserGroup;
use FireflyIII\Models\UserRole;
use FireflyIII\Repositories\User\UserRepositoryInterface;
use FireflyIII\User;
use Illuminate\Auth\Events\Login;
@@ -248,6 +251,32 @@ class UserEventHandler
return true;
}
/**
* @param RegisteredUser $event
*
* @return bool
* @throws FireflyException
*/
public function createGroupMembership(RegisteredUser $event): bool
{
$user = $event->user;
// create a new group.
$group = UserGroup::create(['title' => $user->email]);
$role = UserRole::where('title', UserRole::FULL)->first();
if (null === $role) {
throw new FireflyException('The user role is unexpectedly empty. Did you run all migrations?');
}
GroupMembership::create(
[
'user_id' => $user->id,
'user_group_id' => $group->id,
'user_role_id' => $role->id,
]
);
return true;
}
/**
* This method will send the user a registration mail, welcoming him or her to Firefly III.
* This message is only sent when the configuration of Firefly III says so.