Skip to content

Commit

Permalink
[PH-10][PH-11] Add option to disable SQL condition field (#831)
Browse files Browse the repository at this point in the history
* add option to disable sql condition and deprecate sql condition

* Apply php-cs-fixer changes

---------

Co-authored-by: lukmzig <[email protected]>
  • Loading branch information
lukmzig and lukmzig authored Jan 26, 2024
1 parent ed1a19e commit e66308a
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 55 deletions.
4 changes: 4 additions & 0 deletions doc/01_Installation_and_Upgrade/01_Upgrade_Notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade Notes

## 1.7.0
- [GraphQL] Deprecated SQL Condition.
- [GraphQL] Added the possibility to disable deprecated SQL Condition.

## 1.6.0
- [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`
Expand Down
12 changes: 10 additions & 2 deletions doc/10_GraphQL/01_Configuration/01_General_Settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,13 @@

#### Some Aspects:
* `Active`: You can temporarily disable the configuration using the checkbox.
* `SQL Condition`: You can add a condition all data object queries have to satisfy in addition to
the [workspace settings](./03_Security_Settings.md).
* `SQL Condition (Deprecated)`: You can add a condition all data object queries have to satisfy in addition to
the [workspace settings](./03_Security_Settings.md).

SQL Condition is currently deprecated but still enabled by default. If you want to disable it, you can do so in the symfony configuration tree:
```
pimcore_data_hub:
graphql:
allow_sqlObjectCondition: false
```
Please note that this option will be also removed in the next major version.
3 changes: 3 additions & 0 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ public function setGroup(?string $group): void
$this->group = $group;
}

/**
* @deprecated property sqlObjectCondition will be removed in the next major release
*/
public function getSqlObjectCondition(): ?string
{
return $this->configuration && $this->configuration['general'] ? $this->configuration['general']['sqlObjectCondition'] ?? null : null;
Expand Down
8 changes: 8 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ public function getConfigTreeBuilder()
->booleanNode('output_cache_enabled')->info('enables output cache for graphql responses. It is disabled by default')->defaultValue(false)->end()
->integerNode('output_cache_lifetime')->info('output cache in seconds. Default is 30 seconds')->defaultValue(30)->end()
->booleanNode('allow_introspection')->info('enables introspection for graphql. It is enabled by default')->defaultValue(true)->end()
->booleanNode('allow_sqlObjectCondition')
->setDeprecated(
'pimcore/data-hub',
'2.0.0'
)
->info('enables SQL Condition for graphql. It is enabled by default')
->defaultValue(true)
->end()
->end()
->end()
->end()
Expand Down
15 changes: 10 additions & 5 deletions src/EventListener/AdminListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,15 @@ public function __construct(array $config)
public function addIndexSettings(IndexActionSettingsEvent $event)
{
$event->addSetting('data-hub-writeable', (new \Pimcore\Bundle\DataHubBundle\Configuration(null, null))->isWriteable());
$allowIntrospection = true;
if (isset($this->config['graphql']) && isset($this->config['graphql']['allow_introspection'])) {
$allowIntrospection = $this->config['graphql']['allow_introspection'];
}
$event->addSetting('allow_introspection', $allowIntrospection);
$this->addEventSetting('allow_introspection', $event);
$this->addEventSetting('allow_sqlObjectCondition', $event);
}

private function addEventSetting(
string $key,
IndexActionSettingsEvent $event
): void {
$value = $this->config['graphql'][$key] ?? true;
$event->addSetting($key, $value);
}
}
6 changes: 6 additions & 0 deletions src/GraphQL/Resolver/QueryType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
namespace Pimcore\Bundle\DataHubBundle\GraphQL\Resolver;

use GraphQL\Type\Definition\ResolveInfo;
use Pimcore;
use Pimcore\Bundle\DataHubBundle\Configuration;
use Pimcore\Bundle\DataHubBundle\Event\GraphQL\ListingEvents;
use Pimcore\Bundle\DataHubBundle\Event\GraphQL\Model\ListingEvent;
Expand Down Expand Up @@ -301,6 +302,11 @@ public function resolveObjectGetter($value = null, $args = [], $context = [], Re
/** @var Configuration $configuration */
$configuration = $context['configuration'];
$sqlGetCondition = $configuration->getSqlObjectCondition();
$dataHubConfig = Pimcore::getContainer()?->getParameter('pimcore_data_hub');
if ($dataHubConfig && isset($dataHubConfig['graphql']['allow_sqlObjectCondition']) &&
!$dataHubConfig['graphql']['allow_sqlObjectCondition']) {
$sqlGetCondition = null;
}

if ($sqlGetCondition) {
$conditionParts[] = '(' . $sqlGetCondition . ')';
Expand Down
105 changes: 57 additions & 48 deletions src/Resources/public/js/configuration/graphql/configItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,66 +128,75 @@ pimcore.plugin.datahub.configuration.graphql.configItem = Class.create(pimcore.e
},

getGeneral: function () {


this.generalForm = new Ext.form.FormPanel({
bodyStyle: "padding:10px;",
autoScroll: true,
defaults: {
labelWidth: 200,
width: 600
const generalItems = [
{
xtype: "checkbox",
fieldLabel: t("active"),
name: "active",
value: this.data.general && this.data.general.hasOwnProperty("active") ? this.data.general.active : true
},
border: false,
title: t("plugin_pimcore_datahub_configpanel_item_general"),
items: [
{
xtype: "checkbox",
fieldLabel: t("active"),
name: "active",
value: this.data.general && this.data.general.hasOwnProperty("active") ? this.data.general.active : true
},
{
xtype: "textfield",
fieldLabel: t("type"),
name: "type",
value: t("plugin_pimcore_datahub_type_" + this.data.general.type),
readOnly: true
},
{
xtype: "textfield",
fieldLabel: t("name"),
name: "name",
value: this.data.general.name,
readOnly: true
},
{
name: "description",
fieldLabel: t("description"),
xtype: "textarea",
height: 100,
value: this.data.general.description
},
{
xtype: "textfield",
fieldLabel: t("group"),
name: "group",
value: this.data.general.group
},
{
{
xtype: "textfield",
fieldLabel: t("type"),
name: "type",
value: t("plugin_pimcore_datahub_type_" + this.data.general.type),
readOnly: true
},
{
xtype: "textfield",
fieldLabel: t("name"),
name: "name",
value: this.data.general.name,
readOnly: true
},
{
name: "description",
fieldLabel: t("description"),
xtype: "textarea",
height: 100,
value: this.data.general.description
},
{
xtype: "textfield",
fieldLabel: t("group"),
name: "group",
value: this.data.general.group
}
];

if (pimcore.settings.allow_sqlObjectCondition) {
generalItems.push({
xtype: "displayfield",
hideLabel: true,
value: t("plugin_pimcore_datahub_configpanel_condition_hint"),
readOnly: true,
disabled: true
},{
xtype: "displayfield",
hideLabel: true,
value: t("plugin_pimcore_datahub_configpanel_condition_deprecated"),
readOnly: true,
disabled: true
},
{
name: "sqlObjectCondition",
fieldLabel: t("plugin_pimcore_datahub_configpanel_sqlObjectCondition"),
fieldLabel: t("plugin_pimcore_datahub_configpanel_sqlObjectCondition") + ' (' + t("deprecated") + ')',
xtype: "textarea",
height: 100,
value: this.data.general.sqlObjectCondition
}
]
});
}

this.generalForm = new Ext.form.FormPanel({
bodyStyle: "padding:10px;",
autoScroll: true,
defaults: {
labelWidth: 200,
width: 600
},
border: false,
title: t("plugin_pimcore_datahub_configpanel_item_general"),
items: generalItems
});

return this.generalForm;
Expand Down
1 change: 1 addition & 0 deletions src/Resources/translations/admin.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ plugin_pimcore_datahub_configpanel_entity: "Entity"
plugin_pimcore_datahub_configpanel_root: "Root Node"
plugin_pimcore_datahub_fieldName: "Field Name"
plugin_pimcore_datahub_configpanel_condition_hint: "This is a global SQL condition in addition to the workspace settings that will be added to all queries"
plugin_pimcore_datahub_configpanel_condition_deprecated: "Warning: This feature is deprecated and will be removed in the next major release"
plugin_pimcore_datahub_configpanel_available_fields: "Available Fields"
plugin_pimcore_datahub_operator_thumbnail_config: "Configuration"
plugin_pimcore_datahub_operator_select_entity: "Select Entity"
Expand Down

0 comments on commit e66308a

Please sign in to comment.