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 @@ -97,6 +97,7 @@
"Api\\User\\": "src/User/src/",
"Core\\Admin\\": "src/Core/src/Admin/src/",
"Core\\App\\": "src/Core/src/App/src/",
"Core\\Security\\": "src/Core/src/Security/src/",
"Core\\User\\": "src/Core/src/User/src/"
}
},
Expand Down
2 changes: 1 addition & 1 deletion config/autoload/cors.local.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ return [
* Leaving this line here makes your application accessible by any origin.
*
* To restrict, replace this line with a list of origins that should have access to your application.
* Example: "domain1.com", "domain2.com"
* Example: 'domain1.com', 'domain2.com'
*/
ConfigurationInterface::ANY_ORIGIN,
],
Expand Down
63 changes: 25 additions & 38 deletions config/autoload/dependencies.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,66 +3,53 @@
declare(strict_types=1);

use Api\App\Factory\ErrorResponseGeneratorFactory;
use Api\App\Factory\OAuthAccessTokenRepositoryFactory;
use Api\App\Factory\OAuthAuthCodeRepositoryFactory;
use Api\App\Factory\OAuthClientRepositoryFactory;
use Api\App\Factory\OAuthRefreshTokenRepositoryFactory;
use Api\App\Factory\OAuthScopeRepositoryFactory;
use Api\App\Factory\UserIdentityFactory;
use Api\App\Factory\UserRepositoryFactory;
use Core\App\Repository\OAuthAccessTokenRepository;
use Core\App\Repository\OAuthAuthCodeRepository;
use Core\App\Repository\OAuthClientRepository;
use Core\App\Repository\OAuthRefreshTokenRepository;
use Core\App\Repository\OAuthScopeRepository;
use Core\Security\Repository\OAuthAccessTokenRepository;
use Core\Security\Repository\OAuthAuthCodeRepository;
use Core\Security\Repository\OAuthClientRepository;
use Core\Security\Repository\OAuthRefreshTokenRepository;
use Core\Security\Repository\OAuthScopeRepository;
use Core\User\Repository\UserRepository;
use Core\User\UserIdentity;
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;
use Dot\ErrorHandler\ErrorHandlerInterface;
use Dot\ErrorHandler\LogErrorHandler;
use League\OAuth2\Server\Repositories\AccessTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\AuthCodeRepositoryInterface;
use League\OAuth2\Server\Repositories\ClientRepositoryInterface;
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\ScopeRepositoryInterface;
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use Mezzio\Authentication\UserInterface;
use Mezzio\Authorization\AuthorizationInterface;
use Mezzio\Authorization\Rbac\LaminasRbac;
use Mezzio\Middleware\ErrorResponseGenerator;
use Roave\PsrContainerDoctrine\Migrations\CommandFactory;

return [
// Provides application-wide services.
// We recommend using fully-qualified class names whenever possible as
// service names.
// We recommend using fully-qualified class names whenever possible as service names.
'dependencies' => [
// Use 'aliases' to alias a service name to another service. The
// key is the alias name, the value is the service to which it points.
// Use 'aliases' to alias a service name to another service.
// The key is the alias name, the value is the service to which it points.
'aliases' => [
AccessTokenRepositoryInterface::class => OAuthAccessTokenRepository::class,
AuthCodeRepositoryInterface::class => OAuthAuthCodeRepository::class,
ClientRepositoryInterface::class => OAuthClientRepository::class,
RefreshTokenRepositoryInterface::class => OAuthRefreshTokenRepository::class,
ScopeRepositoryInterface::class => OAuthScopeRepository::class,
Mezzio\Authentication\UserInterface::class => UserIdentity::class,
ErrorHandlerInterface::class => LogErrorHandler::class,
Mezzio\Authorization\AuthorizationInterface::class => Mezzio\Authorization\Rbac\LaminasRbac::class,
UserRepositoryInterface::class => UserRepository::class,
AccessTokenRepositoryInterface::class => OAuthAccessTokenRepository::class,
AuthCodeRepositoryInterface::class => OAuthAuthCodeRepository::class,
ClientRepositoryInterface::class => OAuthClientRepository::class,
UserInterface::class => UserIdentity::class,
AuthorizationInterface::class => LaminasRbac::class,
RefreshTokenRepositoryInterface::class => OAuthRefreshTokenRepository::class,
ScopeRepositoryInterface::class => OAuthScopeRepository::class,
UserRepositoryInterface::class => UserRepository::class,
],
// Use 'invokables' for constructor-less services, or services that do
// not require arguments to the constructor. Map a service name to the
// class name.
// Use 'invokables' for constructor-less services, or services that do not require arguments to the constructor.
// Map a service name to the class name.
'invokables' => [
// Fully\Qualified\InterfaceName::class => Fully\Qualified\ClassName::class,
],
// Use 'factories' for services provided by callbacks/factory classes.
'factories' => [
ExecuteCommand::class => CommandFactory::class,
Mezzio\Middleware\ErrorResponseGenerator::class => ErrorResponseGeneratorFactory::class,
OAuthAccessTokenRepository::class => OAuthAccessTokenRepositoryFactory::class,
OAuthAuthCodeRepository::class => OAuthAuthCodeRepositoryFactory::class,
OAuthClientRepository::class => OAuthClientRepositoryFactory::class,
OAuthRefreshTokenRepository::class => OAuthRefreshTokenRepositoryFactory::class,
OAuthScopeRepository::class => OAuthScopeRepositoryFactory::class,
UserRepository::class => UserRepositoryFactory::class,
UserIdentity::class => UserIdentityFactory::class,
ExecuteCommand::class => CommandFactory::class,
ErrorResponseGenerator::class => ErrorResponseGeneratorFactory::class,
UserIdentity::class => UserIdentityFactory::class,
],
],
];
17 changes: 0 additions & 17 deletions config/autoload/mezzio-tooling-factories.global.php

This file was deleted.

2 changes: 1 addition & 1 deletion config/autoload/templates.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
'globals' => [],
'optimizations' => -1,
'runtime_loaders' => [],
// 'timezone' => '',
'timezone' => 'UTC',
],
];
1 change: 1 addition & 0 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class_exists(Mezzio\Tooling\ConfigProvider::class)
// Default App module config
Core\Admin\ConfigProvider::class,
Core\App\ConfigProvider::class,
Core\Security\ConfigProvider::class,
Core\User\ConfigProvider::class,
Api\Admin\ConfigProvider::class,
Api\App\ConfigProvider::class,
Expand Down
6 changes: 3 additions & 3 deletions documentation/command/admin-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ after replacing:

If the submitted data is valid, the outputted response is:

```text
Admin account has been created.
```
>
> [INFO] Admin account has been created.
>

The new admin account is ready to use.

Expand Down
4 changes: 4 additions & 0 deletions documentation/command/token-generate.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ The output should look similar to this:
Error reporting token:

0123456789abcdef0123456789abcdef01234567

* copy the generated token
* open config/autoload/error-handling.global.php
* paste the copied string inside the tokens array found under the ErrorReportServiceInterface::class key.
```

Copy the generated token.
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ includes:
parameters:
level: 5
paths:
- bin
- config
- public
- src
- test
treatPhpDocTypesAsCertain: false
Expand Down
29 changes: 19 additions & 10 deletions src/Admin/src/Command/AdminCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,20 @@
namespace Api\Admin\Command;

use Api\Admin\InputFilter\CreateAdminInputFilter;
use Api\Admin\Service\AdminRoleService;
use Api\Admin\Service\AdminService;
use Api\App\Exception\BadRequestException;
use Api\App\Exception\ConflictException;
use Api\App\Exception\NotFoundException;
use Core\Admin\Entity\AdminRole;
use Core\Admin\Service\AdminRoleServiceInterface;
use Core\Admin\Service\AdminServiceInterface;
use Core\App\Exception\BadRequestException;
use Core\App\Exception\ConflictException;
use Core\App\Exception\NotFoundException;
use Core\App\Message;
use Dot\DependencyInjection\Attribute\Inject;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

use function implode;
use function sprintf;
Expand All @@ -32,9 +34,13 @@
/** @var string $defaultName */
protected static $defaultName = 'admin:create';

#[Inject(

Check warning on line 37 in src/Admin/src/Command/AdminCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Command/AdminCreateCommand.php#L37

Added line #L37 was not covered by tests
AdminServiceInterface::class,
AdminRoleServiceInterface::class,
)]
public function __construct(
protected AdminService $adminService,
protected AdminRoleService $adminRoleService,
protected AdminServiceInterface $adminService,
protected AdminRoleServiceInterface $adminRoleService,
) {
parent::__construct(self::$defaultName);
}
Expand Down Expand Up @@ -74,7 +80,7 @@

$this->adminService->createAdmin($inputFilter->getValues());

$output->writeln(Message::ADMIN_CREATED);
(new SymfonyStyle($input, $output))->info(Message::ADMIN_CREATED);

Check warning on line 83 in src/Admin/src/Command/AdminCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Command/AdminCreateCommand.php#L83

Added line #L83 was not covered by tests

return Command::SUCCESS;
}
Expand All @@ -84,7 +90,10 @@
*/
private function getData(InputInterface $input): array
{
$role = $this->adminRoleService->findOneBy(['name' => AdminRole::ROLE_ADMIN]);
$adminRole = $this->adminRoleService->getAdminRoleRepository()->findOneBy(['name' => AdminRole::ROLE_ADMIN]);
if (! $adminRole instanceof AdminRole) {
throw new NotFoundException(Message::ROLE_NOT_FOUND);

Check warning on line 95 in src/Admin/src/Command/AdminCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Command/AdminCreateCommand.php#L93-L95

Added lines #L93 - L95 were not covered by tests
}

return [
'identity' => $input->getOption('identity'),
Expand All @@ -93,7 +102,7 @@
'firstName' => $input->getOption('firstName'),
'lastName' => $input->getOption('lastName'),
'roles' => [
['uuid' => $role->getUuid()->toString()],
['uuid' => $adminRole->getUuid()->toString()],

Check warning on line 105 in src/Admin/src/Command/AdminCreateCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Admin/src/Command/AdminCreateCommand.php#L105

Added line #L105 was not covered by tests
],
];
}
Expand Down
22 changes: 3 additions & 19 deletions src/Admin/src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Api\Admin\Collection\AdminCollection;
use Api\Admin\Collection\AdminRoleCollection;
use Api\Admin\Command\AdminCreateCommand;
use Api\Admin\Factory\AdminCreateCommandFactory;
use Api\Admin\Handler\Account\GetAdminAccountResourceHandler;
use Api\Admin\Handler\Account\PatchAdminAccountResourceHandler;
use Api\Admin\Handler\Admin\DeleteAdminResourceHandler;
Expand All @@ -17,17 +16,10 @@
use Api\Admin\Handler\Admin\PostAdminResourceHandler;
use Api\Admin\Handler\Admin\Role\GetAdminRoleCollectionHandler;
use Api\Admin\Handler\Admin\Role\GetAdminRoleResourceHandler;
use Api\Admin\Service\AdminRoleService;
use Api\Admin\Service\AdminRoleServiceInterface;
use Api\Admin\Service\AdminService;
use Api\Admin\Service\AdminServiceInterface;
use Api\App\ConfigProvider as AppConfigProvider;
use Api\App\Factory\HandlerDelegatorFactory;
use Core\Admin\Entity\Admin;
use Core\Admin\Entity\AdminRole;
use Core\Admin\Repository\AdminRepository;
use Core\Admin\Repository\AdminRoleRepository;
use Dot\DependencyInjection\Factory\AttributedRepositoryFactory;
use Dot\DependencyInjection\Factory\AttributedServiceFactory;
use Mezzio\Application;
use Mezzio\Hal\Metadata\MetadataMap;
Expand All @@ -42,7 +34,7 @@ public function __invoke(): array
];
}

public function getDependencies(): array
private function getDependencies(): array
{
return [
'delegators' => [
Expand All @@ -58,11 +50,7 @@ public function getDependencies(): array
PostAdminResourceHandler::class => [HandlerDelegatorFactory::class],
],
'factories' => [
AdminCreateCommand::class => AdminCreateCommandFactory::class,
AdminRepository::class => AttributedRepositoryFactory::class,
AdminRoleRepository::class => AttributedRepositoryFactory::class,
AdminRoleService::class => AttributedServiceFactory::class,
AdminService::class => AttributedServiceFactory::class,
AdminCreateCommand::class => AttributedServiceFactory::class,
DeleteAdminResourceHandler::class => AttributedServiceFactory::class,
GetAdminAccountResourceHandler::class => AttributedServiceFactory::class,
GetAdminCollectionHandler::class => AttributedServiceFactory::class,
Expand All @@ -73,14 +61,10 @@ public function getDependencies(): array
PatchAdminResourceHandler::class => AttributedServiceFactory::class,
PostAdminResourceHandler::class => AttributedServiceFactory::class,
],
'aliases' => [
AdminRoleServiceInterface::class => AdminRoleService::class,
AdminServiceInterface::class => AdminService::class,
],
];
}

public function getHalConfig(): array
private function getHalConfig(): array
{
return [
AppConfigProvider::getCollection(AdminCollection::class, 'admin::list-admin', 'admins'),
Expand Down
32 changes: 0 additions & 32 deletions src/Admin/src/Factory/AdminCreateCommandFactory.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
namespace Api\Admin\Handler\Account;

use Api\Admin\InputFilter\UpdateAdminInputFilter;
use Api\Admin\Service\AdminServiceInterface;
use Api\App\Exception\BadRequestException;
use Api\App\Exception\ConflictException;
use Api\App\Exception\NotFoundException;
use Api\App\Handler\AbstractHandler;
use Core\Admin\Entity\Admin;
use Core\Admin\Service\AdminServiceInterface;
use Core\App\Exception\BadRequestException;
use Core\App\Exception\ConflictException;
use Core\App\Exception\NotFoundException;
use Dot\DependencyInjection\Attribute\Inject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand Down
10 changes: 5 additions & 5 deletions src/Admin/src/Handler/Admin/DeleteAdminResourceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Api\Admin\Handler\Admin;

use Api\Admin\Service\AdminServiceInterface;
use Api\App\Exception\NotFoundException;
use Api\App\Handler\AbstractHandler;
use Core\Admin\Service\AdminServiceInterface;
use Core\App\Exception\NotFoundException;
use Dot\DependencyInjection\Attribute\Inject;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -26,9 +26,9 @@ public function __construct(
*/
public function handle(ServerRequestInterface $request): ResponseInterface
{
$admin = $this->adminService->findOneBy(['uuid' => $request->getAttribute('uuid')]);

$this->adminService->deleteAdmin($admin);
$this->adminService->getAdminRepository()->deleteAdmin(
$this->adminService->find($request->getAttribute('uuid'))
);

return $this->noContentResponse();
}
Expand Down
Loading