Skip to content

Commit

Permalink
Merge branch '1.x' into 110-auth-to-session
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/Version/Controller/PublishController.php
  • Loading branch information
martineiber committed Jun 11, 2024
2 parents 5caa6c5 + 0bbcc21 commit 1e29097
Show file tree
Hide file tree
Showing 33 changed files with 682 additions and 92 deletions.
4 changes: 2 additions & 2 deletions config/notes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ services:
Pimcore\Bundle\StudioBackendBundle\Note\Hydrator\NoteHydratorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Note\Hydrator\NoteHydrator

Pimcore\Bundle\StudioBackendBundle\Note\Extractor\NoteDataExtractorInterface:
class: Pimcore\Bundle\StudioBackendBundle\Note\Extractor\NoteDataExtractor
Pimcore\Bundle\StudioBackendBundle\Note\Resolver\NoteDataResolverInterface:
class: Pimcore\Bundle\StudioBackendBundle\Note\Resolver\NoteDataResolver

Pimcore\Bundle\StudioBackendBundle\Note\Repository\NoteRepositoryInterface:
class: Pimcore\Bundle\StudioBackendBundle\Note\Repository\NoteRepository
Expand Down
3 changes: 3 additions & 0 deletions config/versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ services:
arguments:
$versionHydratorLocator: '@listing.version_hydrator.service_locator'

Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionBinaryServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Version\Service\VersionBinaryService

#Service Locator
listing.version_hydrator.service_locator:
class: Symfony\Component\DependencyInjection\ServiceLocator
Expand Down
37 changes: 37 additions & 0 deletions src/Asset/Attributes/Response/Content/AssetMediaType.php
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\Asset\Attributes\Response\Content;

use OpenApi\Attributes\MediaType;
use OpenApi\Attributes\Schema;

/**
* @internal
*/
final class AssetMediaType extends MediaType
{
public function __construct(string $mimeType = 'application/*')
{
parent::__construct(
mediaType: $mimeType,
schema: new Schema(
type: 'string',
format: 'binary'
)
);
}
}
36 changes: 36 additions & 0 deletions src/Asset/Attributes/Response/Header/ContentDisposition.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?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\Asset\Attributes\Response\Header;

use OpenApi\Attributes\Header;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioBackendBundle\Util\Constants\HttpResponseHeaders;

/**
* @internal
*/
final class ContentDisposition extends Header
{
public function __construct(string $headerType = HttpResponseHeaders::ATTACHMENT_TYPE->value)
{
parent::__construct(
header: HttpResponseHeaders::HEADER_CONTENT_DISPOSITION->value,
description: 'Content-Disposition header',
schema: new Schema(type: 'string', example: $headerType . '; filename="example.jpg"'),
);
}
}
10 changes: 5 additions & 5 deletions src/Note/Hydrator/NoteHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace Pimcore\Bundle\StudioBackendBundle\Note\Hydrator;

use Pimcore\Bundle\StudioBackendBundle\Note\Extractor\NoteDataExtractorInterface;
use Pimcore\Bundle\StudioBackendBundle\Note\Resolver\NoteDataResolverInterface;
use Pimcore\Bundle\StudioBackendBundle\Note\Schema\Note;
use Pimcore\Model\Element\Note as CoreNote;

Expand All @@ -25,25 +25,25 @@
*/
final readonly class NoteHydrator implements NoteHydratorInterface
{
public function __construct(private NoteDataExtractorInterface $extractor)
public function __construct(private NoteDataResolverInterface $noteDataResolver)
{
}

public function hydrate(CoreNote $note): Note
{
$noteUser = $this->extractor->extractUserData($note);
$noteUser = $this->noteDataResolver->resolveUserData($note);

return new Note(
$note->getId(),
$note->getType(),
$note->getCid(),
$note->getCtype(),
$this->extractor->extractCPath($note),
$this->noteDataResolver->extractCPath($note),
$note->getDate(),
$note->getTitle(),
$note->getDescription(),
$note->getLocked(),
$this->extractor->extractData($note),
$this->noteDataResolver->resolveNoteData($note),
$noteUser->getId(),
$noteUser->getName(),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Note\Extractor;
namespace Pimcore\Bundle\StudioBackendBundle\Note\Resolver;

use Pimcore\Bundle\StaticResolverBundle\Models\Element\ServiceResolverInterface;
use Pimcore\Bundle\StaticResolverBundle\Models\User\UserResolverInterface;
Expand All @@ -25,7 +25,7 @@
/**
* @internal
*/
final readonly class NoteDataExtractor implements NoteDataExtractorInterface
final readonly class NoteDataResolver implements NoteDataResolverInterface
{
public function __construct(
private ServiceResolverInterface $serviceResolver,
Expand All @@ -39,26 +39,26 @@ public function extractCPath(CoreNote $note) : string
if (!$note->getCid() || !$note->getCtype()) {
return '';
}

$element = $this->serviceResolver->getElementById($note->getCtype(), $note->getCid());

if (!$element) {
return '';
}

return $element->getRealFullPath();
return $element->getFullPath();
}

public function extractUserData(CoreNote $note) : NoteUser
public function resolveUserData(CoreNote $note) : NoteUser
{
$emptyUser = new NoteUser();
if (!$note->getUser()) {
return $emptyUser;
return new NoteUser();
}

$user = $this->userResolver->getById($note->getUser());

if (!$user) {
return $emptyUser;
return new NoteUser();
}

return new NoteUser(
Expand All @@ -67,7 +67,7 @@ public function extractUserData(CoreNote $note) : NoteUser
);
}

public function extractData(CoreNote $note): array
public function resolveNoteData(CoreNote $note): array
{
// prepare key-values
$keyValues = [];
Expand All @@ -76,7 +76,7 @@ public function extractData(CoreNote $note): array
$type = $d['type'];

$data = match($type) {
'document', 'object', 'asset' => $this->extractElementData($d['data']),
'document', 'object', 'asset' => $this->resolveElementData($d['data']),
'date' => is_object($d['data']) ? $d['data']->getTimestamp() : $d['data'],
default => $d['data'],
};
Expand All @@ -93,7 +93,7 @@ public function extractData(CoreNote $note): array
return $keyValues;
}

private function extractElementData(?ElementInterface $element): array
private function resolveElementData(?ElementInterface $element): array
{
if (!$element) {
return [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Note\Extractor;
namespace Pimcore\Bundle\StudioBackendBundle\Note\Resolver;

use Pimcore\Bundle\StudioBackendBundle\Note\Schema\NoteUser;
use Pimcore\Model\Element\Note as CoreNote;

/**
* @internal
*/
interface NoteDataExtractorInterface
interface NoteDataResolverInterface
{
public function extractUserData(CoreNote $note): NoteUser;
public function resolveUserData(CoreNote $note): NoteUser;

public function extractCPath(CoreNote $note): string;

public function extractData(CoreNote $note): array;
public function resolveNoteData(CoreNote $note): array;
}
3 changes: 2 additions & 1 deletion src/OpenApi/Attributes/Response/SuccessResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@
#[Attribute(Attribute::TARGET_METHOD)]
final class SuccessResponse extends Response
{
public function __construct(string $description = 'Success', mixed $content = null)
public function __construct(string $description = 'Success', mixed $content = null, ?array $headers = null)
{
parent::__construct(
response: HttpResponseCodes::SUCCESS->value,
description: $description,
headers: $headers,
content: $content
);
}
Expand Down
35 changes: 35 additions & 0 deletions src/User/Event/UserTreeNodeEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?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\Event;

use Pimcore\Bundle\StudioBackendBundle\Event\AbstractPreResponseEvent;
use Pimcore\Bundle\StudioBackendBundle\User\Schema\UserTreeNode;

final class UserTreeNodeEvent extends AbstractPreResponseEvent
{
public const EVENT_NAME = 'pre_response.user_tree_node';

public function __construct(private readonly UserTreeNode $user)
{
parent::__construct($user);
}

public function getUserTreeNode(): UserTreeNode
{
return $this->user;
}
}
15 changes: 10 additions & 5 deletions src/User/Schema/UserTreeNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

use OpenApi\Attributes\Property;
use OpenApi\Attributes\Schema;
use Pimcore\Bundle\StudioBackendBundle\Util\Schema\AdditionalAttributesInterface;
use Pimcore\Bundle\StudioBackendBundle\Util\Traits\AdditionalAttributesTrait;

/**
* @internal
Expand All @@ -27,17 +29,20 @@
description: 'One node in the user tree',
type: 'object'
)]
final readonly class UserTreeNode
final class UserTreeNode implements AdditionalAttributesInterface
{

use AdditionalAttributesTrait;

public function __construct(
#[Property(description: 'Unique Identifier', type: 'integer', example: '1')]
private int $id,
private readonly int $id,
#[Property(description: 'Name of Folder or User', type: 'string', example: 'admin')]
private string $name,
private readonly string $name,
#[Property(description: 'Is ether user or folder', type: 'string', example: 'user')]
private string $type,
private readonly string $type,
#[Property(description: 'If a folder has sub items', type: 'bool', example: true)]
private bool $hasChildren,
private readonly bool $hasChildren,
) {
}

Expand Down
14 changes: 12 additions & 2 deletions src/User/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
use Pimcore\Bundle\StudioBackendBundle\Exception\RateLimitException;
use Pimcore\Bundle\StudioBackendBundle\Exception\SendMailException;
use Pimcore\Bundle\StudioBackendBundle\Response\Collection;
use Pimcore\Bundle\StudioBackendBundle\User\Event\UserTreeNodeEvent;
use Pimcore\Bundle\StudioBackendBundle\User\Hydrator\UserTreeNodeHydratorInterface;
use Pimcore\Bundle\StudioBackendBundle\User\MappedParameter\UserListParameter;
use Pimcore\Bundle\StudioBackendBundle\User\RateLimiter\RateLimiterInterface;
use Pimcore\Bundle\StudioBackendBundle\User\Repository\UserRepositoryInterface;
use Pimcore\Bundle\StudioBackendBundle\User\Schema\ResetPassword;
use Pimcore\Model\UserInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
* @internal
Expand All @@ -42,7 +44,8 @@ public function __construct(
private RateLimiterInterface $rateLimiter,
private LoggerInterface $pimcoreLogger,
private UserRepositoryInterface $userRepository,
private UserTreeNodeHydratorInterface $userTreeNodeHydrator
private UserTreeNodeHydratorInterface $userTreeNodeHydrator,
private EventDispatcherInterface $eventDispatcher
)
{
}
Expand Down Expand Up @@ -84,7 +87,14 @@ public function getUserTreeListing(UserListParameter $userListParameter): Collec
continue;
}

$users[] = $this->userTreeNodeHydrator->hydrate($user);
$userTreeNode = $this->userTreeNodeHydrator->hydrate($user);

$this->eventDispatcher->dispatch(
new UserTreeNodeEvent($userTreeNode),
UserTreeNodeEvent::EVENT_NAME
);

$users[] = $userTreeNode;
}

return new Collection(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Version\MappedParameter;
namespace Pimcore\Bundle\StudioBackendBundle\Util\Constants;

/**
* @internal
*/
final readonly class VersionCleanupParameters
enum HttpResponseHeaders: string
{
public function __construct(
private int $elementModificationDate
) {
}

public function getElementModificationDate(): int
{
return $this->elementModificationDate;
}
case HEADER_CONTENT_TYPE = 'Content-Type';
case HEADER_CONTENT_DISPOSITION = 'Content-Disposition';
case HEADER_CONTENT_LENGTH = 'Content-Length';
case ATTACHMENT_TYPE = 'attachment';
case INLINE_TYPE = 'inline';
}
Loading

0 comments on commit 1e29097

Please sign in to comment.