mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-12-17 11:59:05 +00:00
Fix code quality with rector [skip ci]
This commit is contained in:
@@ -24,6 +24,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace FireflyIII\Repositories\UserGroup;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use FireflyIII\Enums\UserRoleEnum;
|
||||
use FireflyIII\Exceptions\FireflyException;
|
||||
use FireflyIII\Factory\UserGroupFactory;
|
||||
@@ -47,7 +48,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
|
||||
public function destroy(UserGroup $userGroup): void
|
||||
{
|
||||
app('log')->debug(sprintf('Going to destroy user group #%d ("%s").', $userGroup->id, $userGroup->title));
|
||||
Log::debug(sprintf('Going to destroy user group #%d ("%s").', $userGroup->id, $userGroup->title));
|
||||
$memberships = $userGroup->groupMemberships()->get();
|
||||
|
||||
/** @var GroupMembership $membership */
|
||||
@@ -57,19 +58,19 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
if (null === $user) {
|
||||
continue;
|
||||
}
|
||||
app('log')->debug(sprintf('Processing membership #%d (user #%d "%s")', $membership->id, $user->id, $user->email));
|
||||
Log::debug(sprintf('Processing membership #%d (user #%d "%s")', $membership->id, $user->id, $user->email));
|
||||
// user has memberships of other groups?
|
||||
$count = $user->groupMemberships()->where('user_group_id', '!=', $userGroup->id)->count();
|
||||
if (0 === $count) {
|
||||
app('log')->debug('User has no other memberships and needs a new user group.');
|
||||
Log::debug('User has no other memberships and needs a new user group.');
|
||||
$newUserGroup = $this->createNewUserGroup($user);
|
||||
$user->user_group_id = $newUserGroup->id;
|
||||
$user->save();
|
||||
app('log')->debug(sprintf('Make new group #%d ("%s")', $newUserGroup->id, $newUserGroup->title));
|
||||
Log::debug(sprintf('Make new group #%d ("%s")', $newUserGroup->id, $newUserGroup->title));
|
||||
}
|
||||
// user has other memberships, select one at random and assign it to the user.
|
||||
if ($count > 0) {
|
||||
app('log')->debug('User has other memberships and will be assigned a new administration.');
|
||||
Log::debug('User has other memberships and will be assigned a new administration.');
|
||||
|
||||
/** @var GroupMembership $first */
|
||||
$first = $user->groupMemberships()->where('user_group_id', '!=', $userGroup->id)->inRandomOrder()->first();
|
||||
@@ -91,7 +92,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
}
|
||||
}
|
||||
$userGroup->delete();
|
||||
app('log')->debug('Done!');
|
||||
Log::debug('Done!');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,23 +217,23 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
public function updateMembership(UserGroup $userGroup, array $data): UserGroup
|
||||
{
|
||||
$owner = UserRole::whereTitle(UserRoleEnum::OWNER)->first();
|
||||
app('log')->debug('in update membership');
|
||||
Log::debug('in update membership');
|
||||
|
||||
/** @var null|User $user */
|
||||
$user = null;
|
||||
if (array_key_exists('id', $data)) {
|
||||
/** @var null|User $user */
|
||||
$user = User::find($data['id']);
|
||||
app('log')->debug('Found user by ID');
|
||||
Log::debug('Found user by ID');
|
||||
}
|
||||
if (array_key_exists('email', $data) && '' !== (string)$data['email']) {
|
||||
/** @var null|User $user */
|
||||
$user = User::whereEmail($data['email'])->first();
|
||||
app('log')->debug('Found user by email');
|
||||
Log::debug('Found user by email');
|
||||
}
|
||||
if (null === $user) {
|
||||
// should throw error, but validator already catches this.
|
||||
app('log')->debug('No user found');
|
||||
Log::debug('No user found');
|
||||
|
||||
return $userGroup;
|
||||
}
|
||||
@@ -244,13 +245,13 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
$lastUserId = $userGroup->groupMemberships()->distinct()->first(['group_memberships.user_id'])->user_id;
|
||||
// if this is also the user we're editing right now, and we remove all of their roles:
|
||||
if ($lastUserId === (int)$user->id && 0 === count($data['roles'])) {
|
||||
app('log')->debug('User is last in this group, refuse to act');
|
||||
Log::debug('User is last in this group, refuse to act');
|
||||
|
||||
throw new FireflyException('You cannot remove the last member from this user group. Delete the user group instead.');
|
||||
}
|
||||
// if this is also the user we're editing right now, and do not grant them the owner role:
|
||||
if ($lastUserId === (int)$user->id && count($data['roles']) > 0 && !in_array(UserRoleEnum::OWNER->value, $data['roles'], true)) {
|
||||
app('log')->debug('User needs to have owner role in this group, refuse to act');
|
||||
Log::debug('User needs to have owner role in this group, refuse to act');
|
||||
|
||||
throw new FireflyException('The last member in this user group must get or keep the "owner" role.');
|
||||
}
|
||||
@@ -267,7 +268,7 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
&& (0 === count($data['roles'])
|
||||
|| (count($data['roles']) > 0 // @phpstan-ignore-line
|
||||
&& !in_array(UserRoleEnum::OWNER->value, $data['roles'], true)))) {
|
||||
app('log')->debug('User needs to keep owner role in this group, refuse to act');
|
||||
Log::debug('User needs to keep owner role in this group, refuse to act');
|
||||
|
||||
throw new FireflyException('The last owner in this user group must keep the "owner" role.');
|
||||
}
|
||||
@@ -294,12 +295,12 @@ class UserGroupRepository implements UserGroupRepositoryInterface, UserGroupInte
|
||||
private function simplifyListByName(array $roles): array
|
||||
{
|
||||
if (in_array(UserRoleEnum::OWNER->value, $roles, true)) {
|
||||
app('log')->debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::OWNER->value));
|
||||
Log::debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::OWNER->value));
|
||||
|
||||
return [UserRoleEnum::OWNER->value];
|
||||
}
|
||||
if (in_array(UserRoleEnum::FULL->value, $roles, true)) {
|
||||
app('log')->debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::FULL->value));
|
||||
Log::debug(sprintf('List of roles is [%1$s] but this includes "%2$s", so return [%2$s]', implode(',', $roles), UserRoleEnum::FULL->value));
|
||||
|
||||
return [UserRoleEnum::FULL->value];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user