Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0x first prototype #2

Closed
wants to merge 12 commits into from
Closed
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
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
"minimum-stability": "dev",
"require": {
"php": "~8.1.0 || ~8.2.0",
"pimcore/static-resolver-bundle": "^1.3",
"pimcore/generic-data-index-bundle": "1.x-dev",
"pimcore/pimcore": "^11.0",
"api-platform/core": "^3.2"
},
Expand Down
26 changes: 26 additions & 0 deletions config/api_platform/resources/asset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
resources:
Pimcore\Bundle\StudioApiBundle\Dto\Asset:
operations:
ApiPlatform\Metadata\GetCollection:
filters: [ Pimcore\Bundle\StudioApiBundle\Filter\AssetParentIdFilter ]
paginationClientItemsPerPage: true
ApiPlatform\Metadata\Get:
normalizationContext:
groups: [ 'asset:read', 'asset:item:get', 'dependency:read', 'property:read']
ApiPlatform\Metadata\Put:
ApiPlatform\Metadata\Post:
ApiPlatform\Metadata\Delete:
ApiPlatform\Metadata\Patch:
provider: Pimcore\Bundle\StudioApiBundle\State\AssetProvider
normalizationContext:
groups: ['asset:read', 'dependency:read', 'property:read']
denormalizationContext:
groups: ['asset:write']
properties:
id:
identifier: true

properties:
Pimcore\Bundle\StudioApiBundle\Dto\Asset:
dependencies:
genId: false
10 changes: 10 additions & 0 deletions config/api_platform/resources/asset/image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resources:
Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image:
provider: Pimcore\Bundle\StudioApiBundle\State\AssetProvider
properties:
id:
identifier: true
normalizationContext:
groups: ['image:read', 'asset:read', 'task:read', 'dependency:read', 'property:read', 'version:read']
denormalizationContext:
groups: ['image:write', 'asset:write']
10 changes: 10 additions & 0 deletions config/api_platform/resources/schedule/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
resources:
Pimcore\Bundle\StudioApiBundle\Dto\Task:
provider: Pimcore\Bundle\StudioApiBundle\State\ScheduledTaskProvider
normalizationContext:
groups: ['task:read']
denormalizationContext:
groups: ['task:write']
properties:
id:
identifier: true
14 changes: 14 additions & 0 deletions config/api_platform/resources/user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
resources:
Pimcore\Model\User:
operations:
ApiPlatform\Metadata\Post:
status: 202
processor: Pimcore\Bundle\StudioApiBundle\State\ResetPasswordProcessor
input: Pimcore\Bundle\StudioApiBundle\Dto\ResetPasswordRequest
output: false
uriTemplate: '/users/reset-password'

normalizationContext:
groups: [ 'get' ]
denormalizationContext:
groups: [ 'set' ]
16 changes: 16 additions & 0 deletions config/api_platform/resources/version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
resources:
Pimcore\Bundle\StudioApiBundle\Dto\Version:
operations:
ApiPlatform\Metadata\Get:
ApiPlatform\Metadata\Put:
ApiPlatform\Metadata\Post:
ApiPlatform\Metadata\Delete:
ApiPlatform\Metadata\Patch:
provider: Pimcore\Bundle\StudioApiBundle\State\VersionProvider
normalizationContext:
groups: ['version:read']
denormalizationContext:
groups: ['version:write']
properties:
id:
identifier: true
4 changes: 4 additions & 0 deletions config/pimcore/routing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
api_platform:
resource: .
type: api_platform
prefix: /api
48 changes: 48 additions & 0 deletions config/serialization/asset.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
Pimcore\Bundle\StudioApiBundle\Dto\Asset:
attributes:
id:
groups: ['asset:read']
parentId:
groups: ['asset:read']
permissions:
groups: [ 'asset:read' ]
type:
groups: ['asset:read']
children:
groups: ['asset:read']
filename:
groups: ['asset:read']
path:
groups: ['asset:read']
mimetype:
groups: ['asset:read']
creationDate:
groups: ['asset:read']
modificationDate:
groups: ['asset:read']
userOwner:
groups: ['asset:read']
userModification:
groups: ['asset:read']
properties:
groups: ['asset:item:get']
versions:
groups: ['asset:read']
metadata:
groups: ['asset:read']
locked:
groups: ['asset:read']
lock:
groups: ['asset:read']
customSettings:
groups: ['asset:item:get']
hasMetaData:
groups: ['asset:read']
dependencies:
groups: ['asset:item:get']
scheduledTasks:
groups: ['asset:item:get']
versionCount:
groups: ['asset:item:get']
fullPath:
groups: ['asset:read']
20 changes: 20 additions & 0 deletions config/serialization/asset/image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pimcore\Bundle\StudioApiBundle\Dto\Asset\Image:
attributes:
thumbnail:
groups: ['image:read']
format:
groups: ['image:read']
dimensions:
groups: ['image:read']
width:
groups: ['image:read']
height:
groups: ['image:read']
animated:
groups: ['image:read']
vectorGraphic:
groups: ['image:read']
lowQualityPreviewDataUri:
groups: ['image:read']
lowQualityPreviewPath:
groups: ['image:read']
20 changes: 20 additions & 0 deletions config/serialization/asset/permissions.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Pimcore\Bundle\StudioApiBundle\Dto\Asset\Permissions:
attributes:
list:
groups: ['asset:read']
view:
groups: ['asset:read']
publish:
groups: ['asset:read']
delete:
groups: ['asset:read']
rename:
groups: ['asset:read']
create:
groups: ['asset:read']
settings:
groups: ['asset:read']
versions:
groups: ['asset:read']
properties:
groups: ['asset:read']
16 changes: 16 additions & 0 deletions config/serialization/dependency.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Pimcore\Model\Dependency:
attributes:
sourceId:
groups: ['dependency:read']
sourceType:
groups: ['dependency:read']
required:
groups: ['dependency:read']
requiredByTotalCount:
groups: ['dependency:read']
requiresTotalCount:
groups: ['dependency:read']
requires:
groups: ['dependency:read']
requiredBy:
groups: ['dependency:read']
18 changes: 18 additions & 0 deletions config/serialization/property.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Pimcore\Bundle\StudioApiBundle\Dto\Property:
attributes:
name:
groups: ['property:read']
data:
groups: ['property:read']
type:
groups: ['property:read']
ctype:
groups: ['property:read']
cpath:
groups: ['property:read']
cid:
groups: ['property:read']
inheritable:
groups: ['property:read']
inherited:
groups: ['property:read']
18 changes: 18 additions & 0 deletions config/serialization/schedule/task.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Pimcore\Bundle\StudioApiBundle\Dto\Task:
attributes:
id:
groups: ['task:read', 'task:write']
cid:
groups: ['task:read', 'task:write']
ctype:
groups: ['task:read', 'task:write']
date:
groups: ['task:read', 'task:write']
action:
groups: ['task:read', 'task:write']
version:
groups: ['task:read', 'task:write']
active:
groups: ['task:read', 'task:write']
userId:
groups: ['task:read', 'task:write']
4 changes: 4 additions & 0 deletions config/serialization/user.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Pimcore\Bundle\StudioApiBundle\Dto\ResetPasswordRequest:
attributes:
username:
groups: ['get', 'set']
32 changes: 32 additions & 0 deletions config/serialization/version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
Pimcore\Bundle\StudioApiBundle\Dto\Version:
attributes:
id:
groups: ['version:read', 'asset:item:get']
cid:
groups: ['version:read', 'asset:item:get']
ctype:
groups: ['version:read', 'asset:item:get']
userId:
groups: ['version:read', 'asset:item:get']
user:
groups: ['version:read', 'asset:item:get']
note:
groups: ['version:read', 'asset:item:get']
date:
groups: ['version:read', 'asset:item:get']
data:
groups: ['version:read']
public:
groups: ['version:read', 'asset:item:get']
serialized:
groups: ['version:read', 'asset:item:get']
versionCount:
groups: ['version:read', 'asset:item:get']
binaryFileHash:
groups: ['version:read', 'asset:item:get']
binaryFileId:
groups: ['version:read', 'asset:item:get']
autosave:
groups: ['version:read', 'asset:item:get']
storageType:
groups: ['version:read', 'asset:item:get']
19 changes: 18 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,21 @@ services:
Pimcore\Bundle\StudioApiBundle\Controller\:
resource: '../src/Controller'
public: true
tags: [ 'controller.service_arguments' ]
tags: [ 'controller.service_arguments' ]

# Providers
Pimcore\Bundle\StudioApiBundle\State\AssetProvider: ~
Pimcore\Bundle\StudioApiBundle\State\ScheduledTaskProvider: ~
Pimcore\Bundle\StudioApiBundle\State\VersionProvider: ~

# Processors
Pimcore\Bundle\StudioApiBundle\State\ResetPasswordProcessor: ~

# Filters
Pimcore\Bundle\StudioApiBundle\Filter\AssetParentIdFilter:
tags: [ 'api_platform.filter' ]

# Normalizers
Pimcore\Bundle\StudioApiBundle\Serializer\AssetNormalizer:
tags:
- { name: 'serializer.normalizer' }
71 changes: 71 additions & 0 deletions src/DependencyInjection/PimcoreStudioApiExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\DependencyInjection;

use Exception;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
*
* @link http://symfony.com/doc/current/cookbook/bundles/extension.html
*/

/**
* @internal
*/
class PimcoreStudioApiExtension extends Extension implements PrependExtensionInterface
{
/**
* {@inheritdoc}
*
* @throws Exception
*/
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

// Load services and configuration
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../config'));
$loader->load('services.yaml');

// Set default serializer mapping if not provided in the app's config
if (!isset($config['serializer']['mapping']['paths'])) {
$config['serializer']['mapping']['paths'] = [__DIR__ . '/../../config/serialization'];
}

// Pass the configuration to the custom normalizer
$container->setParameter(
'pimcore_studio_api.serializer.mapping.paths',
$config['serializer']['mapping']['paths']
);
}

public function prepend(ContainerBuilder $container): void
{
$apiPlatformConfig = [
'mapping'=>[
'paths'=> [
__DIR__ . '/../../config/api_platform/',
],
],
];
$container->prependExtensionConfig('api_platform', $apiPlatformConfig);
}
}
Loading
Loading