Skip to content

Commit

Permalink
Merge pull request #44860 from nextcloud/fix/remove-unicode-logs-user…
Browse files Browse the repository at this point in the history
…-ldap

fix(user_ldap): Remove unicode character from log lines
  • Loading branch information
come-nc committed Apr 22, 2024
2 parents aff3e65 + 9bf3d5a commit 7f0d2ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 23 deletions.
14 changes: 7 additions & 7 deletions apps/user_ldap/lib/LoginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function handle(Event $event): void {

public function onPostLogin(IUser $user): void {
$this->logger->info(
__CLASS__ . ' {user} postLogin',
__CLASS__ . ' - {user} postLogin',
[
'app' => 'user_ldap',
'user' => $user->getUID(),
Expand All @@ -84,7 +84,7 @@ private function updateGroups(IUser $userObject): void {
$groupObject = $this->groupManager->get($groupId);
if ($groupObject === null) {
$this->logger->error(
__CLASS__ . ' group {group} could not be found (user {user})',
__CLASS__ . ' - group {group} could not be found (user {user})',
[
'app' => 'user_ldap',
'user' => $userId,
Expand All @@ -98,7 +98,7 @@ private function updateGroups(IUser $userObject): void {
} catch (Exception $e) {
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
$this->logger->error(
__CLASS__ . ' group {group} membership failed to be added (user {user})',
__CLASS__ . ' - group {group} membership failed to be added (user {user})',
[
'app' => 'user_ldap',
'user' => $userId,
Expand All @@ -113,7 +113,7 @@ private function updateGroups(IUser $userObject): void {
$this->groupBackend->addRelationshipToCaches($userId, null, $groupId);
$this->dispatcher->dispatchTyped(new UserAddedEvent($groupObject, $userObject));
$this->logger->info(
__CLASS__ . ' {user} added to {group}',
__CLASS__ . ' - {user} added to {group}',
[
'app' => 'user_ldap',
'user' => $userId,
Expand All @@ -127,7 +127,7 @@ private function updateGroups(IUser $userObject): void {
} catch (Exception $e) {
if ($e->getReason() !== Exception::REASON_DATABASE_OBJECT_NOT_FOUND) {
$this->logger->error(
__CLASS__ . ' group {group} membership failed to be removed (user {user})',
__CLASS__ . ' - group {group} membership failed to be removed (user {user})',
[
'app' => 'user_ldap',
'user' => $userId,
Expand All @@ -142,7 +142,7 @@ private function updateGroups(IUser $userObject): void {
$groupObject = $this->groupManager->get($groupId);
if ($groupObject === null) {
$this->logger->error(
__CLASS__ . ' group {group} could not be found (user {user})',
__CLASS__ . ' - group {group} could not be found (user {user})',
[
'app' => 'user_ldap',
'user' => $userId,
Expand All @@ -153,7 +153,7 @@ private function updateGroups(IUser $userObject): void {
}
$this->dispatcher->dispatchTyped(new UserRemovedEvent($groupObject, $userObject));
$this->logger->info(
'service "updateGroups" {user} removed from {group}',
'service "updateGroups" - {user} removed from {group}',
[
'user' => $userId,
'group' => $groupId
Expand Down
32 changes: 16 additions & 16 deletions apps/user_ldap/lib/Service/UpdateGroupsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function updateGroups(): void {

if (empty($actualGroups) && empty($knownGroups)) {
$this->logger->info(
'service "updateGroups" groups do not seem to be configured properly, aborting.',
'service "updateGroups" - groups do not seem to be configured properly, aborting.',
);
return;
}
Expand All @@ -75,18 +75,18 @@ public function updateGroups(): void {
$this->handleCreatedGroups(array_diff($actualGroups, $knownGroups));
$this->handleRemovedGroups(array_diff($knownGroups, $actualGroups));

$this->logger->debug('service "updateGroups" Finished.');
$this->logger->debug('service "updateGroups" - Finished.');
}

/**
* @param string[] $groups
* @throws Exception
*/
public function handleKnownGroups(array $groups): void {
$this->logger->debug('service "updateGroups" Dealing with known Groups.');
$this->logger->debug('service "updateGroups" - Dealing with known Groups.');

foreach ($groups as $group) {
$this->logger->debug('service "updateGroups" Dealing with {group}.', ['group' => $group]);
$this->logger->debug('service "updateGroups" - Dealing with {group}.', ['group' => $group]);
$groupMemberships = $this->groupMembershipMapper->findGroupMemberships($group);
$knownUsers = array_map(
static fn (GroupMembership $groupMembership): string => $groupMembership->getUserid(),
Expand All @@ -99,7 +99,7 @@ public function handleKnownGroups(array $groups): void {
if ($groupObject === null) {
/* We are not expecting the group to not be found since it was returned by $this->groupBackend->getGroups() */
$this->logger->error(
'service "updateGroups" Failed to get group {group} for update',
'service "updateGroups" - Failed to get group {group} for update',
[
'group' => $group
]
Expand All @@ -113,7 +113,7 @@ public function handleKnownGroups(array $groups): void {
if ($e->getReason() !== Exception::REASON_DATABASE_OBJECT_NOT_FOUND) {
/* If reason is not found something else removed the membership, that’s fine */
$this->logger->error(
__CLASS__ . ' group {group} membership failed to be removed (user {user})',
__CLASS__ . ' - group {group} membership failed to be removed (user {user})',
[
'app' => 'user_ldap',
'user' => $removedUser,
Expand All @@ -130,7 +130,7 @@ public function handleKnownGroups(array $groups): void {
$this->dispatcher->dispatchTyped(new UserRemovedEvent($groupObject, $userObject));
}
$this->logger->info(
'service "updateGroups" {user} removed from {group}',
'service "updateGroups" - {user} removed from {group}',
[
'user' => $removedUser,
'group' => $group
Expand All @@ -144,7 +144,7 @@ public function handleKnownGroups(array $groups): void {
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
/* If reason is unique constraint something else added the membership, that’s fine */
$this->logger->error(
__CLASS__ . ' group {group} membership failed to be added (user {user})',
__CLASS__ . ' - group {group} membership failed to be added (user {user})',
[
'app' => 'user_ldap',
'user' => $addedUser,
Expand All @@ -161,26 +161,26 @@ public function handleKnownGroups(array $groups): void {
$this->dispatcher->dispatchTyped(new UserAddedEvent($groupObject, $userObject));
}
$this->logger->info(
'service "updateGroups" {user} added to {group}',
'service "updateGroups" - {user} added to {group}',
[
'user' => $addedUser,
'group' => $group
]
);
}
}
$this->logger->debug('service "updateGroups" FINISHED dealing with known Groups.');
$this->logger->debug('service "updateGroups" - FINISHED dealing with known Groups.');
}

/**
* @param string[] $createdGroups
* @throws Exception
*/
public function handleCreatedGroups(array $createdGroups): void {
$this->logger->debug('service "updateGroups" dealing with created Groups.');
$this->logger->debug('service "updateGroups" - dealing with created Groups.');

foreach ($createdGroups as $createdGroup) {
$this->logger->info('service "updateGroups" new group "' . $createdGroup . '" found.');
$this->logger->info('service "updateGroups" - new group "' . $createdGroup . '" found.');

$users = $this->groupBackend->usersInGroup($createdGroup);
$groupObject = $this->groupManager->get($createdGroup);
Expand All @@ -190,7 +190,7 @@ public function handleCreatedGroups(array $createdGroups): void {
} catch (Exception $e) {
if ($e->getReason() !== Exception::REASON_UNIQUE_CONSTRAINT_VIOLATION) {
$this->logger->error(
__CLASS__ . ' group {group} membership failed to be added (user {user})',
__CLASS__ . ' - group {group} membership failed to be added (user {user})',
[
'app' => 'user_ldap',
'user' => $user,
Expand All @@ -210,15 +210,15 @@ public function handleCreatedGroups(array $createdGroups): void {
}
}
}
$this->logger->debug('service "updateGroups" FINISHED dealing with created Groups.');
$this->logger->debug('service "updateGroups" - FINISHED dealing with created Groups.');
}

/**
* @param string[] $removedGroups
* @throws Exception
*/
public function handleRemovedGroups(array $removedGroups): void {
$this->logger->debug('service "updateGroups" dealing with removed groups.');
$this->logger->debug('service "updateGroups" - dealing with removed groups.');

$this->groupMembershipMapper->deleteGroups($removedGroups);
foreach ($removedGroups as $group) {
Expand All @@ -235,7 +235,7 @@ public function handleRemovedGroups(array $removedGroups): void {
}

$this->logger->info(
'service "updateGroups" groups {removedGroups} were removed.',
'service "updateGroups" - groups {removedGroups} were removed.',
[
'removedGroups' => $removedGroups
]
Expand Down

0 comments on commit 7f0d2ad

Please sign in to comment.