-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(php): Create and use a UserFormatter
From the FileCSVController, I refactored all functions to get users data for the frontend in the new UserFormatter class. Signed-off-by: Baptiste Fotia <[email protected]>
- Loading branch information
Showing
2 changed files
with
58 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
namespace OCA\Workspace\Users; | ||
|
||
use OCP\IGroupManager; | ||
use OCP\IUser; | ||
|
||
class UserFormatter | ||
{ | ||
public function __construct(private IGroupManager $groupManager) | ||
{ | ||
} | ||
|
||
/** | ||
* @since 3.1.0|4.0.0 | ||
* | ||
* @param IUser $user | ||
* @param array $space | ||
* @param string $role admin|user | ||
* @return array users array valid for the frontend | ||
*/ | ||
public function formatUser(IUser $user, array $space, string $role): array { | ||
// Gets the workspace subgroups the user is member of | ||
$groups = []; | ||
foreach ($this->groupManager->getUserGroups($user) as $group) { | ||
if (in_array($group->getGID(), array_keys($space['groups']))) { | ||
array_push($groups, $group->getGID()); | ||
} | ||
} | ||
|
||
return array( | ||
'uid' => $user->getUID(), | ||
'name' => $user->getDisplayName(), | ||
'email' => $user->getEmailAddress(), | ||
'subtitle' => $user->getEmailAddress(), | ||
'groups' => $groups, | ||
'role' => $role | ||
); | ||
} | ||
} |