Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.6' into 1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
dvesh3 committed Sep 14, 2023
2 parents dd78690 + 83c816e commit ce780dd
Show file tree
Hide file tree
Showing 14 changed files with 229 additions and 70 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -14,7 +14,7 @@
"minimum-stability": "dev",
"require": {
"php": "~8.0.0 || ~8.1.0 || ~8.2.0",
"pimcore/pimcore": "^10.6 || ^11.0",
"pimcore/pimcore": "^10.6.8 || ^11.0.7",
"pimcore/compatibility-bridge-v10": "^1.0",
"webonyx/graphql-php": "^15.2.3"
},
Expand Down
8 changes: 4 additions & 4 deletions doc/01_Installation_and_Upgrade/01_Upgrade_Notes.md
@@ -1,17 +1,17 @@
# Upgrade Notes

## 1.6.0
- [General] If you want to use data-hub 1.6 and Pimcore 11, please make sure to require the `pimcore/admin-ui-classic-bundle`.
- [General] If you want to use Datahub 1.6 and Pimcore 11, please make sure to require the `pimcore/admin-ui-classic-bundle`.
- [Config Location] Change default directory for configurations to `var/config/data_hub`
- When using Pimcore 11 configurations from `datahub-configurations.php` are no longer used. To migrate those configurations
- When using Pimcore 11, configurations from `datahub-configurations.php` are no longer used. To migrate those configurations
to the settings store, use the provided `datahub:configuration:migrate-legacy-config` command.
- Added the ability to import and export each type of data-hub configuration.
- Added the ability to import and export each type of Datahub configuration.
Be sure to include the `supported_types` configuration in any custom implementation to use the import functionality!
- Added possibility to disable the introspection for GraphQL via configuration tree.

## 1.5.0
- When "Skip Permission Check" is active in a GraphQL configuration, the "Workspaces" settings are also skipped
- It is possible to add more than one API-key per configuration now. Therefore, the API-key gets stored as an array
- It is possible to add more than one API key per configuration now. Therefore, the API keys get stored as an array
in the configuration. Configurations from previous versions are still supported, but they get converted to the new format
as soon as they get saved.
- Added "Translation Listing" and "Translation" to the Generic Types
21 changes: 10 additions & 11 deletions doc/02_Basic_Principle.md
@@ -1,23 +1,22 @@
# Basic Principle

Pimcore Datahub allows defining multiple endpoints that allow data delivery and consumption. These
endpoints are configured via so called configurations that can be added in Pimcore admin user interface:
Pimcore Datahub allows defining multiple endpoints that allow data delivery and consumption. These endpoints are configured via so called configurations that can be added in the Pimcore admin user interface:

## Adding a new configuration
## Adding a New Configuration

Open Datahub configuration panel
1. Open the Datahub configuration panel:

![Configuration Overview](./img/graphql/configuration3.png)


Choose endpoint technology
2. Choose an endpoint technology:

![Add Configuration](./img/add_config.png)

And get the configuration done by defining
- general settings
- schema configuration
- security definitions
- and additional settings
3. Get the configuration done by defining the followings:
- General settings
- Schema configuration
- Security definitions
- Additional settings

Example for [GraphQL](./10_GraphQL/README.md)
Here you can find an example for [GraphQL](./10_GraphQL/README.md).
33 changes: 29 additions & 4 deletions doc/10_GraphQL/01_Configuration/02_Schema_Settings.md
@@ -1,14 +1,39 @@
# Schema Settings

Schema settings define which data entities (Data Object classes, Assets, Documents) should be exposed via the endpoint. For Assets and Documents, default schemas are provided, for Data Object classes the schema can be defined in the field configuration.
Schema settings define which data entities (Data Object classes, Assets, Documents) should be exposed via the endpoint. For Assets and Documents, default schemas are provided, for Data Object classes the schema can be defined in the field configuration.

![Add](../../img/graphql/schema_add.png)

### Field Configuration
## Query Schema

Define all the fields that you want to make available. In addition, you can employ a set of operators.
Here you can configure which Data Objects Classes can be exposed.

### Available Fields Configuration

When adding a new entity with the `Add` button, you can access the `Available Fields Configuration` window with a right-click on the `Settings` icon. You can then define all the target Data Object Class fields you want to make available.

In addition, you can employ a set of operators.

![Schema Settings](../../img/graphql/schema.png)

Please note that not all data types are supported yet!
You will get a notice if you try to add an unsupported data type.
You will get a notice if you try to add an unsupported data type.

## Mutation Schema

Here you can decide if Data Objects for the selected class can be created, updated or deleted from the endpoint.

:::caution

Be aware that a Data Object deleted from an endpoint will be definitively deleted of Pimcore.

:::

### Available Fields Configuration

As for the `Query Schema` field, you can select the fields you want to expose and/or make available for changes in the `Available Fields Configuration` you can open by clicking on the `Settings` icon.

## Generic Types

Here you can define which data types can be created, read, updated or deleted from an endpoint.

2 changes: 1 addition & 1 deletion doc/10_GraphQL/01_Configuration/03_Security_Settings.md
Expand Up @@ -2,7 +2,7 @@

## Authentication

Defines how users are authenticated when accessing the endpoint.
Here you can define how users are authenticated when accessing the endpoint.

#### Supported Methods

Expand Down
4 changes: 1 addition & 3 deletions doc/10_GraphQL/01_Configuration/04_Custom_Permissions.md
@@ -1,8 +1,6 @@
# Custom Permissions

When creating custom queries or creating other custom extensions to Datahub, it might be useful to
add additional permissions to define access rules for certain data entities (like it is possible to
define access for documents, assets, etc.).
When creating custom queries or creating other custom extensions to Datahub, it might be useful to add additional permissions to define access rules for certain data entities (like it is possible to define access for Documents, Assets, etc.).

## Adding Custom Permissions

Expand Down
36 changes: 33 additions & 3 deletions doc/10_GraphQL/07_Mutation/04_Asset_Mutations.md
Expand Up @@ -2,13 +2,27 @@

## Create Asset

TODO add sample
This will create an Asset with uploading data provided:
```graphql
mutation {
createAsset(
parentId: 1,
filename: "foo.png",
type: "image",
input: {
data: "ewogICAgImZpZWxkY29sbGVjdGlvbiI6IFsKICAgICAgICB7CiAgICAgICAgICAgICJwYXJlbn...."
}) {
success
message
}
}
```

## Update Asset

This will rename the Asset and update the data.
Request:
```
```graphql
mutation {
updateAsset(id: 76, input: {filename:"newfilename",
data:"iVBORw0KGgoAAAANSUhEUg....."}) {
Expand All @@ -22,5 +36,21 @@ mutation {
```

## Delete Asset
```graphql
mutation {
deleteAsset(id: 533) {
success
message
}
}

or

mutation {
deleteAsset(fullpath: "/Sample Content/Background Images/foo.png") {
success
message
}
}

TODO add sample
```
4 changes: 2 additions & 2 deletions doc/20_Deployment.md
Expand Up @@ -11,11 +11,11 @@ When deploying configurations following steps are necessary:
- Rebuild workspaces by running `datahub:configuration:rebuild-workspaces`


Either call
Either call:
```bash
datahub:configuration:rebuild-workspaces
```
to do that for all definitions, or
to do that for all definitions, or:


```bash
Expand Down
Binary file modified doc/img/add_config.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion src/DependencyInjection/Configuration.php
Expand Up @@ -49,7 +49,10 @@ public function getConfigTreeBuilder()
$this->addSupportedTypes($rootNode);

/** @var ArrayNodeDefinition $rootNode */
ConfigurationHelper::addConfigLocationWithWriteTargetNodes($rootNode, ['data_hub' => '/var/config/data_hub']);
ConfigurationHelper::addConfigLocationWithWriteTargetNodes(
$rootNode,
['data_hub' => PIMCORE_CONFIGURATION_DIRECTORY . '/data_hub']
);

return $treeBuilder;
}
Expand Down
33 changes: 15 additions & 18 deletions src/DependencyInjection/PimcoreDataHubExtension.php
Expand Up @@ -16,6 +16,7 @@
namespace Pimcore\Bundle\DataHubBundle\DependencyInjection;

use Pimcore\Bundle\CoreBundle\DependencyInjection\ConfigurationHelper;
use Pimcore\Bundle\DataHubBundle\Configuration\Dao;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand Down Expand Up @@ -52,29 +53,25 @@ public function prepend(ContainerBuilder $container)
$loader->load('doctrine_migrations.yml');
}

$configDir = PIMCORE_CONFIGURATION_DIRECTORY . '/data_hub';

if (\Pimcore\Version::getMajorVersion() >= 11) {
$containerConfig = ConfigurationHelper::getConfigNodeFromSymfonyTree($container, 'pimcore_data_hub');
$configDir = $containerConfig['config_location']['data_hub']['write_target']['options']['directory'];
}
$containerConfig = ConfigurationHelper::getConfigNodeFromSymfonyTree($container, 'pimcore_data_hub');
$configDir = $containerConfig['config_location']['data_hub']['write_target']['options']['directory'];

$configLoader = new YamlFileLoader(
$container,
new FileLocator($configDir)
new FileLocator([$configDir, Dao::CONFIG_PATH])
);

//load datahub configs
if (\Pimcore\Version::getMajorVersion() >= 11) {
$configs = ConfigurationHelper::getSymfonyConfigFiles($configDir);
foreach ($configs as $config) {
$configLoader->load($config);
}
} else {
$configLocator = new \Pimcore\Bundle\DataHubBundle\Configuration\DatahubConfigLocator();
foreach ($configLocator->locate('config') as $config) {
$configLoader->load($config);
}
//TODO: remove as soon as Pimcore 10.6 isn´t supported anymore.
$configLocator = new \Pimcore\Bundle\DataHubBundle\Configuration\DatahubConfigLocator();
$configs =
[
...ConfigurationHelper::getSymfonyConfigFiles($configDir),
...ConfigurationHelper::getSymfonyConfigFiles($_SERVER['PIMCORE_CONFIG_STORAGE_DIR_DATA_HUB'] ?? ''),
...$configLocator->locate('config')
];

foreach ($configs as $config) {
$configLoader->load($config);
}
}
}
42 changes: 25 additions & 17 deletions src/GraphQL/Mutation/MutationType.php
Expand Up @@ -990,11 +990,13 @@ public function buildCreateAssetMutation(&$config, $context)
}

$type = $args['type'];
$filename = $args['filename'];

$className = 'Pimcore\\Model\\Asset\\' . ucfirst($type);
/** @var Concrete $newInstance */
/** @var Asset $newInstance */
$newInstance = new $className();
$newInstance->setParentId($parent->getId());
$newInstance->setFilename($filename);

$tags = [];
if (isset($args['input'])) {
Expand Down Expand Up @@ -1029,7 +1031,7 @@ public function buildCreateAssetMutation(&$config, $context)
} catch (\Exception $e) {
return [
'success' => false,
'message' => 'saving failed'
'message' => 'saving failed: ' . $e->getMessage()
];
}

Expand Down Expand Up @@ -1380,31 +1382,37 @@ public function buildDeleteElementMutation(&$config, $context, $type)
'args' => [
'id' => ['type' => Type::int()],
'fullpath' => ['type' => Type::string()],
], 'resolve' => static function ($value, $args, $context, ResolveInfo $info) use ($type, $omitPermissionCheck, $me) {
],
'resolve' => static function ($value, $args) use ($type, $omitPermissionCheck, $me) {
try {
$id = $args['id'];
/** @var Configuration $configuration */
$configuration = $context['configuration'];
$idOrPath = $args['id'] ?? ($args['fullpath'] ?? null);
if (!$idOrPath) {
return [
'success' => false,
'message' => 'Missing required field id or fullpath to delete the asset.'
];
}

$element = $me->getElementByTypeAndIdOrPath($args, $type);

if (!$omitPermissionCheck && !WorkspaceHelper::checkPermission($element, 'delete')) {
return [
'success' => false,
'message' => 'delete ' . $type . ' permission denied.'
];
'success' => false,
'message' => 'delete ' . $type . ' permission denied.'
];
}
$result = ['success' => false];
$element->delete();

return [
'success' => true,
'message' => $type . ' ' . $id . ' deleted'
];
$result = [
'success' => true,
'message' => $type . ' ' . $idOrPath . ' deleted'
];
} catch (\Exception $e) {
return [
'success' => false,
'message' => $e->getMessage()
];
$result['message'] = $e->getMessage();
}

return $result;
}
];

Expand Down
10 changes: 5 additions & 5 deletions src/Resources/public/js/configuration/graphql/configItem.js
Expand Up @@ -64,12 +64,12 @@ pimcore.plugin.datahub.configuration.graphql.configItem = Class.create(pimcore.e
url: '/admin/pimcoredatahub/config/get-explorer-url?name=' + this.data.general.name,

success: function (callbackFn, response, opts) {

var data = Ext.decode(response.responseText);
var securityValues = this.securityForm.getForm().getFieldValues();
var explorerUrl = window.location.origin + data.explorerUrl;
let data = Ext.decode(response.responseText);
let securityValues = this.securityForm.getForm().getFieldValues();
let explorerUrl = window.location.origin + data.explorerUrl;
if (securityValues && securityValues["method"] == "datahub_apikey") {
explorerUrl = explorerUrl + "?apikey=" + securityValues["apikey"];
let apiKeys = securityValues["apikey"].split("\n");
explorerUrl = explorerUrl + "?apikey=" + apiKeys[0];
}
callbackFn(explorerUrl);
}.bind(this, callbackFn)
Expand Down

0 comments on commit ce780dd

Please sign in to comment.