-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Initial delete user and folder. * Apply php-cs-fixer changes * Small restructuring. * Add unit Tests. * Apply php-cs-fixer changes * Add line. * Use HttpResponseCode * Move IsGranted. * Controller should have throw tag for Exceptions. --------- Co-authored-by: martineiber <martineiber@users.noreply.github.com>
- Loading branch information
1 parent
65fdbaf
commit c7fdeb7
Showing
19 changed files
with
818 additions
and
2 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,30 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\Exception; | ||
|
||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ForbiddenException extends AbstractApiException | ||
{ | ||
public function __construct(string $message = 'Access Denied') | ||
{ | ||
parent::__construct(HttpResponseCodes::FORBIDDEN->value, $message); | ||
} | ||
} |
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
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,73 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Controller; | ||
|
||
use OpenApi\Attributes\Delete; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\DatabaseException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ForbiddenException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\User\Service\UserServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\PaginatedResponseTrait; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DeleteUserController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly UserServiceInterface $userService | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
|
||
/** | ||
* @throws NotFoundException|ForbiddenException|DatabaseException | ||
*/ | ||
#[Route('/user/{id}', name: 'pimcore_studio_api_user_delete', methods: ['DELETE'])] | ||
#[IsGranted(UserPermissions::USER_MANAGEMENT->value)] | ||
#[Delete( | ||
path: self::API_PATH . '/user/{id}', | ||
operationId: 'deleteUser', | ||
summary: 'Delete a specific user.', | ||
tags: [Tags::User->value] | ||
)] | ||
#[SuccessResponse] | ||
#[IdParameter(type: 'user')] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::NOT_FOUND, | ||
HttpResponseCodes::FORBIDDEN, | ||
])] | ||
public function cloneUser(int $id): Response | ||
{ | ||
$this->userService->deleteUser($id); | ||
return new Response(); | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Controller; | ||
|
||
use OpenApi\Attributes\Delete; | ||
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\DatabaseException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\ForbiddenException; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\NotFoundException; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Parameters\Path\IdParameter; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse; | ||
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags; | ||
use Pimcore\Bundle\StudioBackendBundle\User\Service\UserFolderServiceInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseCodes; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\UserPermissions; | ||
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\PaginatedResponseTrait; | ||
use Symfony\Component\HttpFoundation\Response; | ||
use Symfony\Component\Routing\Attribute\Route; | ||
use Symfony\Component\Security\Http\Attribute\IsGranted; | ||
use Symfony\Component\Serializer\SerializerInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class DeleteUserFolderController extends AbstractApiController | ||
{ | ||
use PaginatedResponseTrait; | ||
public function __construct( | ||
SerializerInterface $serializer, | ||
private readonly UserFolderServiceInterface $userFolderService | ||
) { | ||
parent::__construct($serializer); | ||
} | ||
|
||
|
||
/** | ||
* @throws ForbiddenException|NotFoundException|DatabaseException | ||
*/ | ||
#[Route('/user/folder/{id}', name: 'pimcore_studio_api_user_folder_delete', methods: ['DELETE'])] | ||
#[IsGranted(UserPermissions::PIMCORE_ADMIN->value)] | ||
#[Delete( | ||
path: self::API_PATH . '/user/folder/{id}', | ||
operationId: 'deleteUserFolder', | ||
summary: 'Delete a specific user folder with all users in this folder.', | ||
tags: [Tags::User->value] | ||
)] | ||
#[SuccessResponse] | ||
#[IdParameter(type: 'user-folder')] | ||
#[DefaultResponses([ | ||
HttpResponseCodes::NOT_FOUND | ||
])] | ||
public function deleteUserFolder(int $id): Response | ||
{ | ||
$this->userFolderService->deleteUserFolderById($id); | ||
return new Response(); | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Repository; | ||
|
||
use Exception; | ||
use Pimcore\Bundle\StaticResolverBundle\Models\User\FolderResolverInterface; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\NotFoundException; | ||
use Pimcore\Model\User\Folder; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class UserFolderRepository implements UserFolderRepositoryInterface | ||
{ | ||
|
||
public function __construct( | ||
private FolderResolverInterface $folderResolver | ||
) | ||
{ | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
public function deleteUserFolder(Folder $folder): void | ||
{ | ||
$folder->delete(); | ||
} | ||
|
||
/** | ||
* @throws NotFoundException | ||
*/ | ||
public function getUserFolderById(int $folderId): Folder | ||
{ | ||
$folder = $this->folderResolver->getById($folderId); | ||
|
||
if (!$folder instanceof Folder) { | ||
throw new NotFoundException(sprintf("User folder with ID %d not found", $folderId)); | ||
} | ||
|
||
return $folder; | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under two different licenses: | ||
* - GNU General Public License version 3 (GPLv3) | ||
* - Pimcore Commercial License (PCL) | ||
* Full copyright and license information is available in | ||
* LICENSE.md which is distributed with this source code. | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license GPLv3 and PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioBackendBundle\User\Repository; | ||
|
||
use Exception; | ||
use Pimcore\Bundle\StudioBackendBundle\Exception\NotFoundException; | ||
use Pimcore\Model\User\Folder; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface UserFolderRepositoryInterface | ||
{ | ||
/** | ||
* @throws Exception | ||
*/ | ||
public function deleteUserFolder(Folder $folder): void; | ||
|
||
/** | ||
* @throws NotFoundException | ||
*/ | ||
public function getUserFolderById(int $folderId): Folder; | ||
} |
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
Oops, something went wrong.