Skip to content

Commit

Permalink
Add parameter to prepareConfiguration service to ignore permissions c…
Browse files Browse the repository at this point in the history
…heck (#171)

* Add parameter to prepareConfiguration service to ignore permissions check - resolves #165

* Apply php-cs-fixer changes

Co-authored-by: dvesh3 <[email protected]>
  • Loading branch information
dvesh3 and dvesh3 authored Feb 15, 2022
1 parent 2d83d94 commit d680110
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/Controller/PushImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public function pushAction(Request $request, ConfigurationPreparationService $co
{
try {
$configName = $request->get('config');
$config = $configurationLoaderService->prepareConfiguration($configName);
$config = $configurationLoaderService->prepareConfiguration($configName, null, true);

$loader = $dataLoaderFactory->loadDataLoader($config['loaderConfig']);

if (!$loader instanceof PushLoader) {
Expand Down
4 changes: 2 additions & 2 deletions src/Processing/ImportPreparationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function prepareImport(
throw new QueueNotEmptyException("Queue for `$configName` not empty. Not preparing new import, finish queue processing first.");
}

$config = $this->configLoader->prepareConfiguration($configName);
$config = $this->configLoader->prepareConfiguration($configName, null, true);

if (!$ignoreActiveFlag && !$this->isConfigurationActive($configName, $config)) {
return false;
Expand Down Expand Up @@ -168,7 +168,7 @@ public function prepareImport(

public function execute(string $configName)
{
$config = $this->configLoader->prepareConfiguration($configName);
$config = $this->configLoader->prepareConfiguration($configName, null, true);

if (!$this->isConfigurationActive($configName, $config)) {
return;
Expand Down
2 changes: 1 addition & 1 deletion src/Processing/ImportProcessingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public function processQueueItem(int $id)

//get config
$configName = $queueItem['configName'];
$config = $this->configLoader->prepareConfiguration($configName);
$config = $this->configLoader->prepareConfiguration($configName, null, true);

//init resolver and mapping
if (empty($this->mappingConfigurationCache[$configName])) {
Expand Down
19 changes: 11 additions & 8 deletions src/Settings/ConfigurationPreparationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

class ConfigurationPreparationService
{
public function prepareConfiguration(string $configName, $currentConfig = null)
public function prepareConfiguration(string $configName, $currentConfig = null, $ignorePermissions = false)
{
if ($currentConfig) {
if (is_string($currentConfig)) {
Expand All @@ -32,15 +32,18 @@ public function prepareConfiguration(string $configName, $currentConfig = null)
if (!$configuration) {
throw new \Exception('Configuration ' . $configName . ' does not exist.');
}
if (!$configuration->isAllowed('read')) {
throw new AccessDeniedHttpException('Access denied');
}

$config = $configuration->getConfiguration();
$config['userPermissions'] = [
'update' => $configuration->isAllowed('update'),
'delete' => $configuration->isAllowed('delete')
];
if (!$ignorePermissions) {
if (!$configuration->isAllowed('read')) {
throw new AccessDeniedHttpException('Access denied');
}

$config['userPermissions'] = [
'update' => $configuration->isAllowed('update'),
'delete' => $configuration->isAllowed('delete')
];
}
}

//init config array with default values
Expand Down

0 comments on commit d680110

Please sign in to comment.