Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"league/flysystem-bundle": "^3.3",
"lexik/jwt-authentication-bundle": "^3.1",
"nelmio/cors-bundle": "^2.5",
"openspout/openspout": "^5.8",
"phpoffice/phpspreadsheet": "^4.3",
"runtime/frankenphp-symfony": "^0.2.0",
"symfony/asset": "7.2.*",
Expand Down
95 changes: 94 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion config/routes/admin/user.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ list:
controller: App\Controller\Web\Admin\UserAdminController::list
methods: ['GET']

export_links:
path: /exportar-vinculos
controller: App\Controller\Web\Admin\UserAdminController::exportLinks
methods: ['GET']

timeline:
path: /{id}/timeline
controller: App\Controller\Web\Admin\UserAdminController::timeline
Expand Down Expand Up @@ -32,4 +37,3 @@ edit_roles:
path: /{id}/edit-user-roles
controller: App\Controller\Web\Admin\UserAdminController::editUserRoles
methods: ['POST']

11 changes: 11 additions & 0 deletions src/Controller/Web/Admin/UserAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@
use App\Security\PasswordHasher;
use App\Service\Interface\AgentServiceInterface;
use App\Service\Interface\UserServiceInterface;
use App\Service\UserExportService;
use Exception;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\ExpressionLanguage\Expression;
use Symfony\Component\HttpFoundation\BinaryFileResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Security\Http\Attribute\IsGranted;
Expand Down Expand Up @@ -56,6 +58,15 @@ public function list(): Response
]);
}

#[IsGranted(new Expression(
'is_granted("'.UserRolesEnum::ROLE_ADMIN->value.'") or '.
'is_granted("'.UserRolesEnum::ROLE_MANAGER->value.'")'
), statusCode: self::ACCESS_DENIED_RESPONSE_CODE)]
public function exportLinks(UserExportService $service): BinaryFileResponse
{
return $service->export();
}

#[IsGranted(new Expression(
'is_granted("'.UserRolesEnum::ROLE_ADMIN->value.'") or '.
'is_granted("'.UserRolesEnum::ROLE_MANAGER->value.'")'
Expand Down
25 changes: 24 additions & 1 deletion src/Repository/Interface/UserRepositoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@

use App\Entity\User;

/**
* @phpstan-type UserExportRow array{
* user_id: string,
* user_name: string,
* social_name: ?string,
* email: string,
* status: string,
* roles: string,
* user_created_at: string,
* user_updated_at: ?string,
* agent_id: ?string,
* agent_name: ?string,
* agent_extra_fields: ?string,
* organization_id: ?string,
* organization_name: ?string,
* organization_type: ?string,
* organization_extra_fields: ?string,
* owner_id: ?string
* }
*/
interface UserRepositoryInterface
{
public function save(User $user): User;
Expand All @@ -18,5 +38,8 @@ public function rollback(): void;

public function findOneByRole(string $role): ?User;

public function findAllForExport(): array;
/**
* @return iterable<UserExportRow>
*/
public function findAllForExport(): iterable;
}
15 changes: 11 additions & 4 deletions src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use App\Repository\Interface\UserRepositoryInterface;
use Doctrine\Persistence\ManagerRegistry;

/**
* @phpstan-import-type UserExportRow from UserRepositoryInterface
*/
class UserRepository extends AbstractRepository implements UserRepositoryInterface
{
public function __construct(ManagerRegistry $registry)
Expand Down Expand Up @@ -58,7 +61,10 @@ public function findOneByRole(string $role): ?User
return $id ? $this->find($id) : null;
}

public function findAllForExport(): array
/**
* @return iterable<UserExportRow>
*/
public function findAllForExport(): iterable
{
$sql = <<<SQL
SELECT
Expand Down Expand Up @@ -106,9 +112,10 @@ public function findAllForExport(): array
organization_id
SQL;

return $this->getEntityManager()
$result = $this->getEntityManager()
->getConnection()
->executeQuery($sql)
->fetchAllAssociative();
->executeQuery($sql);

yield from $result->iterateAssociative();
}
}
Loading
Loading