@@ -41,7 +41,7 @@ |
||
| 41 | 41 | $application->registerRoutes($this, [ |
| 42 | 42 | 'ocs' => [ |
| 43 | 43 | ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], |
| 44 | - ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 44 | + ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 45 | 45 | ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], |
| 46 | 46 | ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], |
| 47 | 47 | ] |
@@ -23,36 +23,36 @@ |
||
| 23 | 23 | |
| 24 | 24 | /** @var $this \OCP\Route\IRouter */ |
| 25 | 25 | $this->create('user_ldap_ajax_clearMappings', 'ajax/clearMappings.php') |
| 26 | - ->actionInclude('user_ldap/ajax/clearMappings.php'); |
|
| 26 | + ->actionInclude('user_ldap/ajax/clearMappings.php'); |
|
| 27 | 27 | $this->create('user_ldap_ajax_deleteConfiguration', 'ajax/deleteConfiguration.php') |
| 28 | - ->actionInclude('user_ldap/ajax/deleteConfiguration.php'); |
|
| 28 | + ->actionInclude('user_ldap/ajax/deleteConfiguration.php'); |
|
| 29 | 29 | $this->create('user_ldap_ajax_getConfiguration', 'ajax/getConfiguration.php') |
| 30 | - ->actionInclude('user_ldap/ajax/getConfiguration.php'); |
|
| 30 | + ->actionInclude('user_ldap/ajax/getConfiguration.php'); |
|
| 31 | 31 | $this->create('user_ldap_ajax_getNewServerConfigPrefix', 'ajax/getNewServerConfigPrefix.php') |
| 32 | - ->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php'); |
|
| 32 | + ->actionInclude('user_ldap/ajax/getNewServerConfigPrefix.php'); |
|
| 33 | 33 | $this->create('user_ldap_ajax_setConfiguration', 'ajax/setConfiguration.php') |
| 34 | - ->actionInclude('user_ldap/ajax/setConfiguration.php'); |
|
| 34 | + ->actionInclude('user_ldap/ajax/setConfiguration.php'); |
|
| 35 | 35 | $this->create('user_ldap_ajax_testConfiguration', 'ajax/testConfiguration.php') |
| 36 | - ->actionInclude('user_ldap/ajax/testConfiguration.php'); |
|
| 36 | + ->actionInclude('user_ldap/ajax/testConfiguration.php'); |
|
| 37 | 37 | $this->create('user_ldap_ajax_wizard', 'ajax/wizard.php') |
| 38 | - ->actionInclude('user_ldap/ajax/wizard.php'); |
|
| 38 | + ->actionInclude('user_ldap/ajax/wizard.php'); |
|
| 39 | 39 | |
| 40 | 40 | $application = new \OCP\AppFramework\App('user_ldap'); |
| 41 | 41 | $application->registerRoutes($this, [ |
| 42 | - 'ocs' => [ |
|
| 43 | - ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], |
|
| 44 | - ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 45 | - ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], |
|
| 46 | - ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], |
|
| 47 | - ] |
|
| 42 | + 'ocs' => [ |
|
| 43 | + ['name' => 'ConfigAPI#create', 'url' => '/api/v1/config', 'verb' => 'POST'], |
|
| 44 | + ['name' => 'ConfigAPI#show', 'url' => '/api/v1/config/{configID}', 'verb' => 'GET'], |
|
| 45 | + ['name' => 'ConfigAPI#modify', 'url' => '/api/v1/config/{configID}', 'verb' => 'PUT'], |
|
| 46 | + ['name' => 'ConfigAPI#delete', 'url' => '/api/v1/config/{configID}', 'verb' => 'DELETE'], |
|
| 47 | + ] |
|
| 48 | 48 | ]); |
| 49 | 49 | |
| 50 | 50 | $application = new OCA\User_LDAP\AppInfo\Application(); |
| 51 | 51 | $application->registerRoutes($this, [ |
| 52 | - 'routes' => [ |
|
| 53 | - ['name' => 'renewPassword#tryRenewPassword', 'url' => '/renewpassword', 'verb' => 'POST'], |
|
| 54 | - ['name' => 'renewPassword#showRenewPasswordForm', 'url' => '/renewpassword/{user}', 'verb' => 'GET'], |
|
| 55 | - ['name' => 'renewPassword#cancel', 'url' => '/renewpassword/cancel', 'verb' => 'GET'], |
|
| 56 | - ['name' => 'renewPassword#showLoginFormInvalidPassword', 'url' => '/renewpassword/invalidlogin/{user}', 'verb' => 'GET'], |
|
| 57 | - ] |
|
| 52 | + 'routes' => [ |
|
| 53 | + ['name' => 'renewPassword#tryRenewPassword', 'url' => '/renewpassword', 'verb' => 'POST'], |
|
| 54 | + ['name' => 'renewPassword#showRenewPasswordForm', 'url' => '/renewpassword/{user}', 'verb' => 'GET'], |
|
| 55 | + ['name' => 'renewPassword#cancel', 'url' => '/renewpassword/cancel', 'verb' => 'GET'], |
|
| 56 | + ['name' => 'renewPassword#showLoginFormInvalidPassword', 'url' => '/renewpassword/invalidlogin/{user}', 'verb' => 'GET'], |
|
| 57 | + ] |
|
| 58 | 58 | ]); |
@@ -41,44 +41,44 @@ |
||
| 41 | 41 | $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
| 42 | 42 | |
| 43 | 43 | switch ($parameter->getType()) { |
| 44 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
| 45 | - <?php if ($is_optional) { $classes[] = 'optional'; } ?> |
|
| 46 | - <input type="password" |
|
| 44 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
| 45 | + <?php if ($is_optional) { $classes[] = 'optional'; } ?> |
|
| 46 | + <input type="password" |
|
| 47 | 47 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 48 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
| 48 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
| 49 | 49 | value="<?php p($value); ?>" |
| 50 | 50 | placeholder="<?php p($placeholder); ?>" |
| 51 | 51 | /> |
| 52 | 52 | <?php |
| 53 | - break; |
|
| 54 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
| 55 | - <?php $checkboxId = uniqid("checkbox_"); ?> |
|
| 53 | + break; |
|
| 54 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
| 55 | + <?php $checkboxId = uniqid("checkbox_"); ?> |
|
| 56 | 56 | <div> |
| 57 | 57 | <label> |
| 58 | 58 | <input type="checkbox" |
| 59 | 59 | id="<?php p($checkboxId); ?>" |
| 60 | 60 | <?php if (!empty($classes)): ?> class="checkbox <?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 61 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
| 61 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
| 62 | 62 | <?php if ($value === true): ?> checked="checked"<?php endif; ?> |
| 63 | - /> |
|
| 63 | + /> |
|
| 64 | 64 | <?php p($placeholder); ?> |
| 65 | 65 | </label> |
| 66 | 66 | </div> |
| 67 | 67 | <?php |
| 68 | - break; |
|
| 69 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
| 70 | - <input type="hidden" |
|
| 68 | + break; |
|
| 69 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
| 70 | + <input type="hidden" |
|
| 71 | 71 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 72 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
| 72 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
| 73 | 73 | value="<?php p($value); ?>" |
| 74 | 74 | /> |
| 75 | 75 | <?php |
| 76 | - break; |
|
| 77 | - default: ?> |
|
| 78 | - <?php if ($is_optional) { $classes[] = 'optional'; } ?> |
|
| 79 | - <input type="text" |
|
| 76 | + break; |
|
| 77 | + default: ?> |
|
| 78 | + <?php if ($is_optional) { $classes[] = 'optional'; } ?> |
|
| 79 | + <input type="text" |
|
| 80 | 80 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 81 | - data-parameter="<?php p($parameter->getName()); ?>" |
|
| 81 | + data-parameter="<?php p($parameter->getName()); ?>" |
|
| 82 | 82 | value="<?php p($value); ?>" |
| 83 | 83 | placeholder="<?php p($placeholder); ?>" |
| 84 | 84 | /> |
@@ -92,7 +92,7 @@ |
||
| 92 | 92 | <h2><?php p($l->t('No external storage configured or you don\'t have the permission to configure them')); ?></h2> |
| 93 | 93 | </div> |
| 94 | 94 | |
| 95 | -<form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
|
| 95 | +<form data-can-create="<?php echo $canCreateMounts ? 'true' : 'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled'] ? 'true' : 'false'; ?>"> |
|
| 96 | 96 | <h2 data-anchor-name="external-storage"><?php p($l->t('External storages')); ?></h2> |
| 97 | 97 | <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) print_unescaped(''.$_['dependencies'].''); ?> |
| 98 | 98 | <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'> |
@@ -94,7 +94,10 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | <form data-can-create="<?php echo $canCreateMounts?'true':'false' ?>" id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>"> |
| 96 | 96 | <h2 data-anchor-name="external-storage"><?php p($l->t('External storages')); ?></h2> |
| 97 | - <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) print_unescaped(''.$_['dependencies'].''); ?> |
|
| 97 | + <?php if (isset($_['dependencies']) and ($_['dependencies'] !== '') and $canCreateMounts) { |
|
| 98 | + print_unescaped(''.$_['dependencies'].''); |
|
| 99 | +} |
|
| 100 | +?> |
|
| 98 | 101 | <table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'> |
| 99 | 102 | <thead> |
| 100 | 103 | <tr> |
@@ -103,7 +106,10 @@ discard block |
||
| 103 | 106 | <th><?php p($l->t('External storage')); ?></th> |
| 104 | 107 | <th><?php p($l->t('Authentication')); ?></th> |
| 105 | 108 | <th><?php p($l->t('Configuration')); ?></th> |
| 106 | - <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) print_unescaped('<th>'.$l->t('Available for').'</th>'); ?> |
|
| 109 | + <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) { |
|
| 110 | + print_unescaped('<th>'.$l->t('Available for').'</th>'); |
|
| 111 | +} |
|
| 112 | +?> |
|
| 107 | 113 | <th> </th> |
| 108 | 114 | <th> </th> |
| 109 | 115 | <th> </th> |
@@ -136,7 +142,10 @@ discard block |
||
| 136 | 142 | }); |
| 137 | 143 | ?> |
| 138 | 144 | <?php foreach ($sortedBackends as $backend): ?> |
| 139 | - <?php if ($backend->getDeprecateTo()) continue; // ignore deprecated backends ?> |
|
| 145 | + <?php if ($backend->getDeprecateTo()) { |
|
| 146 | + continue; |
|
| 147 | +} |
|
| 148 | +// ignore deprecated backends ?> |
|
| 140 | 149 | <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option> |
| 141 | 150 | <?php endforeach; ?> |
| 142 | 151 | </select> |
@@ -164,7 +173,10 @@ discard block |
||
| 164 | 173 | |
| 165 | 174 | <?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?> |
| 166 | 175 | <input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox" |
| 167 | - value="1" <?php if ($_['allowUserMounting']) print_unescaped(' checked="checked"'); ?> /> |
|
| 176 | + value="1" <?php if ($_['allowUserMounting']) { |
|
| 177 | + print_unescaped(' checked="checked"'); |
|
| 178 | +} |
|
| 179 | +?> /> |
|
| 168 | 180 | <label for="allowUserMounting"><?php p($l->t('Allow users to mount external storage')); ?></label> <span id="userMountingMsg" class="msg"></span> |
| 169 | 181 | |
| 170 | 182 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
@@ -177,8 +189,14 @@ discard block |
||
| 177 | 189 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
| 178 | 190 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
| 179 | 191 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
| 180 | - <?php else: ?> |
|
| 181 | - <input type="checkbox" id="allowUserMountingBackends<?php p($i); ?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) print_unescaped(' checked="checked"'); ?> /> |
|
| 192 | + <?php else { |
|
| 193 | + : ?> |
|
| 194 | + <input type="checkbox" id="allowUserMountingBackends<?php p($i); |
|
| 195 | +} |
|
| 196 | +?>" class="checkbox" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" <?php if ($backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL)) { |
|
| 197 | + print_unescaped(' checked="checked"'); |
|
| 198 | +} |
|
| 199 | +?> /> |
|
| 182 | 200 | <label for="allowUserMountingBackends<?php p($i); ?>"><?php p($backend->getText()); ?></label> <br /> |
| 183 | 201 | <?php endif; ?> |
| 184 | 202 | <?php $i++; ?> |
@@ -1,48 +1,48 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | - use \OCA\Files_External\Lib\Backend\Backend; |
|
| 3 | - use \OCA\Files_External\Lib\Auth\AuthMechanism; |
|
| 4 | - use \OCA\Files_External\Lib\DefinitionParameter; |
|
| 5 | - use \OCA\Files_External\Service\BackendService; |
|
| 2 | + use \OCA\Files_External\Lib\Backend\Backend; |
|
| 3 | + use \OCA\Files_External\Lib\Auth\AuthMechanism; |
|
| 4 | + use \OCA\Files_External\Lib\DefinitionParameter; |
|
| 5 | + use \OCA\Files_External\Service\BackendService; |
|
| 6 | 6 | |
| 7 | - $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting']; |
|
| 7 | + $canCreateMounts = $_['visibilityType'] === BackendService::VISIBILITY_ADMIN || $_['allowUserMounting']; |
|
| 8 | 8 | |
| 9 | - $l->t("Enable encryption"); |
|
| 10 | - $l->t("Enable previews"); |
|
| 11 | - $l->t("Enable sharing"); |
|
| 12 | - $l->t("Check for changes"); |
|
| 13 | - $l->t("Never"); |
|
| 14 | - $l->t("Once every direct access"); |
|
| 15 | - $l->t('Read only'); |
|
| 9 | + $l->t("Enable encryption"); |
|
| 10 | + $l->t("Enable previews"); |
|
| 11 | + $l->t("Enable sharing"); |
|
| 12 | + $l->t("Check for changes"); |
|
| 13 | + $l->t("Never"); |
|
| 14 | + $l->t("Once every direct access"); |
|
| 15 | + $l->t('Read only'); |
|
| 16 | 16 | |
| 17 | - script('files_external', 'settings'); |
|
| 18 | - style('files_external', 'settings'); |
|
| 17 | + script('files_external', 'settings'); |
|
| 18 | + style('files_external', 'settings'); |
|
| 19 | 19 | |
| 20 | - // load custom JS |
|
| 21 | - foreach ($_['backends'] as $backend) { |
|
| 22 | - /** @var Backend $backend */ |
|
| 23 | - $scripts = $backend->getCustomJs(); |
|
| 24 | - foreach ($scripts as $script) { |
|
| 25 | - script('files_external', $script); |
|
| 26 | - } |
|
| 27 | - } |
|
| 28 | - foreach ($_['authMechanisms'] as $authMechanism) { |
|
| 29 | - /** @var AuthMechanism $authMechanism */ |
|
| 30 | - $scripts = $authMechanism->getCustomJs(); |
|
| 31 | - foreach ($scripts as $script) { |
|
| 32 | - script('files_external', $script); |
|
| 33 | - } |
|
| 34 | - } |
|
| 20 | + // load custom JS |
|
| 21 | + foreach ($_['backends'] as $backend) { |
|
| 22 | + /** @var Backend $backend */ |
|
| 23 | + $scripts = $backend->getCustomJs(); |
|
| 24 | + foreach ($scripts as $script) { |
|
| 25 | + script('files_external', $script); |
|
| 26 | + } |
|
| 27 | + } |
|
| 28 | + foreach ($_['authMechanisms'] as $authMechanism) { |
|
| 29 | + /** @var AuthMechanism $authMechanism */ |
|
| 30 | + $scripts = $authMechanism->getCustomJs(); |
|
| 31 | + foreach ($scripts as $script) { |
|
| 32 | + script('files_external', $script); |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - function writeParameterInput($parameter, $options, $classes = []) { |
|
| 37 | - $value = ''; |
|
| 38 | - if (isset($options[$parameter->getName()])) { |
|
| 39 | - $value = $options[$parameter->getName()]; |
|
| 40 | - } |
|
| 41 | - $placeholder = $parameter->getText(); |
|
| 42 | - $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
| 36 | + function writeParameterInput($parameter, $options, $classes = []) { |
|
| 37 | + $value = ''; |
|
| 38 | + if (isset($options[$parameter->getName()])) { |
|
| 39 | + $value = $options[$parameter->getName()]; |
|
| 40 | + } |
|
| 41 | + $placeholder = $parameter->getText(); |
|
| 42 | + $is_optional = $parameter->isFlagSet(DefinitionParameter::FLAG_OPTIONAL); |
|
| 43 | 43 | |
| 44 | - switch ($parameter->getType()) { |
|
| 45 | - case DefinitionParameter::VALUE_PASSWORD: ?> |
|
| 44 | + switch ($parameter->getType()) { |
|
| 45 | + case DefinitionParameter::VALUE_PASSWORD: ?> |
|
| 46 | 46 | <?php if ($is_optional) { $classes[] = 'optional'; } ?> |
| 47 | 47 | <input type="password" |
| 48 | 48 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
@@ -51,8 +51,8 @@ discard block |
||
| 51 | 51 | placeholder="<?php p($placeholder); ?>" |
| 52 | 52 | /> |
| 53 | 53 | <?php |
| 54 | - break; |
|
| 55 | - case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
| 54 | + break; |
|
| 55 | + case DefinitionParameter::VALUE_BOOLEAN: ?> |
|
| 56 | 56 | <?php $checkboxId = uniqid("checkbox_"); ?> |
| 57 | 57 | <div> |
| 58 | 58 | <label> |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | </label> |
| 67 | 67 | </div> |
| 68 | 68 | <?php |
| 69 | - break; |
|
| 70 | - case DefinitionParameter::VALUE_HIDDEN: ?> |
|
| 69 | + break; |
|
| 70 | + case DefinitionParameter::VALUE_HIDDEN: ?> |
|
| 71 | 71 | <input type="hidden" |
| 72 | 72 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
| 73 | 73 | data-parameter="<?php p($parameter->getName()); ?>" |
| 74 | 74 | value="<?php p($value); ?>" |
| 75 | 75 | /> |
| 76 | 76 | <?php |
| 77 | - break; |
|
| 78 | - default: ?> |
|
| 77 | + break; |
|
| 78 | + default: ?> |
|
| 79 | 79 | <?php if ($is_optional) { $classes[] = 'optional'; } ?> |
| 80 | 80 | <input type="text" |
| 81 | 81 | <?php if (!empty($classes)): ?> class="<?php p(implode(' ', $classes)); ?>"<?php endif; ?> |
@@ -84,8 +84,8 @@ discard block |
||
| 84 | 84 | placeholder="<?php p($placeholder); ?>" |
| 85 | 85 | /> |
| 86 | 86 | <?php |
| 87 | - } |
|
| 88 | - } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | ?> |
| 90 | 90 | |
| 91 | 91 | <div id="emptycontent" class="hidden"> |
@@ -129,13 +129,13 @@ discard block |
||
| 129 | 129 | <?php p($l->t('Add storage')); ?> |
| 130 | 130 | </option> |
| 131 | 131 | <?php |
| 132 | - $sortedBackends = array_filter($_['backends'], function($backend) use ($_) { |
|
| 133 | - return $backend->isVisibleFor($_['visibilityType']); |
|
| 134 | - }); |
|
| 135 | - uasort($sortedBackends, function($a, $b) { |
|
| 136 | - return strcasecmp($a->getText(), $b->getText()); |
|
| 137 | - }); |
|
| 138 | - ?> |
|
| 132 | + $sortedBackends = array_filter($_['backends'], function($backend) use ($_) { |
|
| 133 | + return $backend->isVisibleFor($_['visibilityType']); |
|
| 134 | + }); |
|
| 135 | + uasort($sortedBackends, function($a, $b) { |
|
| 136 | + return strcasecmp($a->getText(), $b->getText()); |
|
| 137 | + }); |
|
| 138 | + ?> |
|
| 139 | 139 | <?php foreach ($sortedBackends as $backend): ?> |
| 140 | 140 | <?php if ($backend->getDeprecateTo()) continue; // ignore deprecated backends ?> |
| 141 | 141 | <option value="<?php p($backend->getIdentifier()); ?>"><?php p($backend->getText()); ?></option> |
@@ -170,10 +170,10 @@ discard block |
||
| 170 | 170 | |
| 171 | 171 | <p id="userMountingBackends"<?php if (!$_['allowUserMounting']): ?> class="hidden"<?php endif; ?>> |
| 172 | 172 | <?php |
| 173 | - $userBackends = array_filter($_['backends'], function($backend) { |
|
| 174 | - return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
| 175 | - }); |
|
| 176 | - ?> |
|
| 173 | + $userBackends = array_filter($_['backends'], function($backend) { |
|
| 174 | + return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL); |
|
| 175 | + }); |
|
| 176 | + ?> |
|
| 177 | 177 | <?php $i = 0; foreach ($userBackends as $backend): ?> |
| 178 | 178 | <?php if ($deprecateTo = $backend->getDeprecateTo()): ?> |
| 179 | 179 | <input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" /> |
@@ -30,23 +30,23 @@ |
||
| 30 | 30 | $limit = null; |
| 31 | 31 | $offset = null; |
| 32 | 32 | if (isset($_GET['pattern'])) { |
| 33 | - $pattern = (string)$_GET['pattern']; |
|
| 33 | + $pattern = (string)$_GET['pattern']; |
|
| 34 | 34 | } |
| 35 | 35 | if (isset($_GET['limit'])) { |
| 36 | - $limit = (int)$_GET['limit']; |
|
| 36 | + $limit = (int)$_GET['limit']; |
|
| 37 | 37 | } |
| 38 | 38 | if (isset($_GET['offset'])) { |
| 39 | - $offset = (int)$_GET['offset']; |
|
| 39 | + $offset = (int)$_GET['offset']; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $groups = []; |
| 43 | 43 | foreach (\OC::$server->getGroupManager()->search($pattern, $limit, $offset) as $group) { |
| 44 | - $groups[$group->getGID()] = $group->getGID(); |
|
| 44 | + $groups[$group->getGID()] = $group->getGID(); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | $users = []; |
| 48 | 48 | foreach (\OC::$server->getUserManager()->searchDisplayName($pattern, $limit, $offset) as $user) { |
| 49 | - $users[$user->getUID()] = $user->getDisplayName(); |
|
| 49 | + $users[$user->getUID()] = $user->getDisplayName(); |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | $results = array('groups' => $groups, 'users' => $users); |
@@ -30,13 +30,13 @@ |
||
| 30 | 30 | $limit = null; |
| 31 | 31 | $offset = null; |
| 32 | 32 | if (isset($_GET['pattern'])) { |
| 33 | - $pattern = (string)$_GET['pattern']; |
|
| 33 | + $pattern = (string) $_GET['pattern']; |
|
| 34 | 34 | } |
| 35 | 35 | if (isset($_GET['limit'])) { |
| 36 | - $limit = (int)$_GET['limit']; |
|
| 36 | + $limit = (int) $_GET['limit']; |
|
| 37 | 37 | } |
| 38 | 38 | if (isset($_GET['offset'])) { |
| 39 | - $offset = (int)$_GET['offset']; |
|
| 39 | + $offset = (int) $_GET['offset']; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | $groups = []; |
@@ -24,25 +24,25 @@ |
||
| 24 | 24 | namespace OCA\Files_External\Service; |
| 25 | 25 | |
| 26 | 26 | class ImportLegacyStoragesService extends LegacyStoragesService { |
| 27 | - private $data; |
|
| 27 | + private $data; |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @param BackendService $backendService |
|
| 31 | - */ |
|
| 32 | - public function __construct(BackendService $backendService) { |
|
| 33 | - $this->backendService = $backendService; |
|
| 34 | - } |
|
| 29 | + /** |
|
| 30 | + * @param BackendService $backendService |
|
| 31 | + */ |
|
| 32 | + public function __construct(BackendService $backendService) { |
|
| 33 | + $this->backendService = $backendService; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - public function setData($data) { |
|
| 37 | - $this->data = $data; |
|
| 38 | - } |
|
| 36 | + public function setData($data) { |
|
| 37 | + $this->data = $data; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * Read legacy config data |
|
| 42 | - * |
|
| 43 | - * @return array list of mount configs |
|
| 44 | - */ |
|
| 45 | - protected function readLegacyConfig() { |
|
| 46 | - return $this->data; |
|
| 47 | - } |
|
| 40 | + /** |
|
| 41 | + * Read legacy config data |
|
| 42 | + * |
|
| 43 | + * @return array list of mount configs |
|
| 44 | + */ |
|
| 45 | + protected function readLegacyConfig() { |
|
| 46 | + return $this->data; |
|
| 47 | + } |
|
| 48 | 48 | } |
@@ -34,167 +34,167 @@ |
||
| 34 | 34 | */ |
| 35 | 35 | class UserGlobalStoragesService extends GlobalStoragesService { |
| 36 | 36 | |
| 37 | - use UserTrait; |
|
| 38 | - |
|
| 39 | - /** @var IGroupManager */ |
|
| 40 | - protected $groupManager; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @param BackendService $backendService |
|
| 44 | - * @param DBConfigService $dbConfig |
|
| 45 | - * @param IUserSession $userSession |
|
| 46 | - * @param IGroupManager $groupManager |
|
| 47 | - * @param IUserMountCache $userMountCache |
|
| 48 | - */ |
|
| 49 | - public function __construct( |
|
| 50 | - BackendService $backendService, |
|
| 51 | - DBConfigService $dbConfig, |
|
| 52 | - IUserSession $userSession, |
|
| 53 | - IGroupManager $groupManager, |
|
| 54 | - IUserMountCache $userMountCache |
|
| 55 | - ) { |
|
| 56 | - parent::__construct($backendService, $dbConfig, $userMountCache); |
|
| 57 | - $this->userSession = $userSession; |
|
| 58 | - $this->groupManager = $groupManager; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Replace config hash ID with real IDs, for migrating legacy storages |
|
| 63 | - * |
|
| 64 | - * @param StorageConfig[] $storages Storages with real IDs |
|
| 65 | - * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs |
|
| 66 | - */ |
|
| 67 | - protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { |
|
| 68 | - // as a read-only view, storage IDs don't need to be real |
|
| 69 | - foreach ($storagesWithConfigHash as $storage) { |
|
| 70 | - $storages[$storage->getId()] = $storage; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - protected function readDBConfig() { |
|
| 75 | - $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
| 76 | - $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 77 | - $groups = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 78 | - if (is_array($groups) && count($groups) !== 0) { |
|
| 79 | - $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); |
|
| 80 | - } else { |
|
| 81 | - $groupMounts = []; |
|
| 82 | - } |
|
| 83 | - return array_merge($userMounts, $groupMounts, $globalMounts); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function addStorage(StorageConfig $newStorage) { |
|
| 87 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - public function updateStorage(StorageConfig $updatedStorage) { |
|
| 91 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param integer $id |
|
| 96 | - */ |
|
| 97 | - public function removeStorage($id) { |
|
| 98 | - throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Get unique storages, in case two are defined with the same mountpoint |
|
| 103 | - * Higher priority storages take precedence |
|
| 104 | - * |
|
| 105 | - * @return StorageConfig[] |
|
| 106 | - */ |
|
| 107 | - public function getUniqueStorages() { |
|
| 108 | - $storages = $this->getStorages(); |
|
| 109 | - |
|
| 110 | - $storagesByMountpoint = []; |
|
| 111 | - foreach ($storages as $storage) { |
|
| 112 | - $storagesByMountpoint[$storage->getMountPoint()][] = $storage; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - $result = []; |
|
| 116 | - foreach ($storagesByMountpoint as $storageList) { |
|
| 117 | - $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 118 | - if (isset($carry)) { |
|
| 119 | - $carryPriorityType = $this->getPriorityType($carry); |
|
| 120 | - $itemPriorityType = $this->getPriorityType($item); |
|
| 121 | - if ($carryPriorityType > $itemPriorityType) { |
|
| 122 | - return $carry; |
|
| 123 | - } elseif ($carryPriorityType === $itemPriorityType) { |
|
| 124 | - if ($carry->getPriority() > $item->getPriority()) { |
|
| 125 | - return $carry; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - return $item; |
|
| 130 | - }); |
|
| 131 | - $result[$storage->getID()] = $storage; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $result; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Get a priority 'type', where a bigger number means higher priority |
|
| 139 | - * user applicable > group applicable > 'all' |
|
| 140 | - * |
|
| 141 | - * @param StorageConfig $storage |
|
| 142 | - * @return int |
|
| 143 | - */ |
|
| 144 | - protected function getPriorityType(StorageConfig $storage) { |
|
| 145 | - $applicableUsers = $storage->getApplicableUsers(); |
|
| 146 | - $applicableGroups = $storage->getApplicableGroups(); |
|
| 147 | - |
|
| 148 | - if ($applicableUsers && $applicableUsers[0] !== 'all') { |
|
| 149 | - return 2; |
|
| 150 | - } |
|
| 151 | - if ($applicableGroups) { |
|
| 152 | - return 1; |
|
| 153 | - } |
|
| 154 | - return 0; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - protected function isApplicable(StorageConfig $config) { |
|
| 158 | - $applicableUsers = $config->getApplicableUsers(); |
|
| 159 | - $applicableGroups = $config->getApplicableGroups(); |
|
| 160 | - |
|
| 161 | - if (count($applicableUsers) === 0 && count($applicableGroups) === 0) { |
|
| 162 | - return true; |
|
| 163 | - } |
|
| 164 | - if (in_array($this->getUser()->getUID(), $applicableUsers, true)) { |
|
| 165 | - return true; |
|
| 166 | - } |
|
| 167 | - $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 168 | - foreach ($groupIds as $groupId) { |
|
| 169 | - if (in_array($groupId, $applicableGroups, true)) { |
|
| 170 | - return true; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Gets all storages for the user, admin, personal, global, etc |
|
| 179 | - * |
|
| 180 | - * @return StorageConfig[] array of storage configs |
|
| 181 | - */ |
|
| 182 | - public function getAllStoragesForUser() { |
|
| 183 | - if (is_null($this->getUser())) { |
|
| 184 | - return []; |
|
| 185 | - } |
|
| 186 | - $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 187 | - $mounts = $this->dbConfig->getMountsForUser($this->getUser()->getUID(), $groupIds); |
|
| 188 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 189 | - $configs = array_filter($configs, function ($config) { |
|
| 190 | - return $config instanceof StorageConfig; |
|
| 191 | - }); |
|
| 192 | - |
|
| 193 | - $keys = array_map(function (StorageConfig $config) { |
|
| 194 | - return $config->getId(); |
|
| 195 | - }, $configs); |
|
| 196 | - |
|
| 197 | - $storages = array_combine($keys, $configs); |
|
| 198 | - return array_filter($storages, [$this, 'validateStorage']); |
|
| 199 | - } |
|
| 37 | + use UserTrait; |
|
| 38 | + |
|
| 39 | + /** @var IGroupManager */ |
|
| 40 | + protected $groupManager; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @param BackendService $backendService |
|
| 44 | + * @param DBConfigService $dbConfig |
|
| 45 | + * @param IUserSession $userSession |
|
| 46 | + * @param IGroupManager $groupManager |
|
| 47 | + * @param IUserMountCache $userMountCache |
|
| 48 | + */ |
|
| 49 | + public function __construct( |
|
| 50 | + BackendService $backendService, |
|
| 51 | + DBConfigService $dbConfig, |
|
| 52 | + IUserSession $userSession, |
|
| 53 | + IGroupManager $groupManager, |
|
| 54 | + IUserMountCache $userMountCache |
|
| 55 | + ) { |
|
| 56 | + parent::__construct($backendService, $dbConfig, $userMountCache); |
|
| 57 | + $this->userSession = $userSession; |
|
| 58 | + $this->groupManager = $groupManager; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Replace config hash ID with real IDs, for migrating legacy storages |
|
| 63 | + * |
|
| 64 | + * @param StorageConfig[] $storages Storages with real IDs |
|
| 65 | + * @param StorageConfig[] $storagesWithConfigHash Storages with config hash IDs |
|
| 66 | + */ |
|
| 67 | + protected function setRealStorageIds(array &$storages, array $storagesWithConfigHash) { |
|
| 68 | + // as a read-only view, storage IDs don't need to be real |
|
| 69 | + foreach ($storagesWithConfigHash as $storage) { |
|
| 70 | + $storages[$storage->getId()] = $storage; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + protected function readDBConfig() { |
|
| 75 | + $userMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_USER, $this->getUser()->getUID()); |
|
| 76 | + $globalMounts = $this->dbConfig->getAdminMountsFor(DBConfigService::APPLICABLE_TYPE_GLOBAL, null); |
|
| 77 | + $groups = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 78 | + if (is_array($groups) && count($groups) !== 0) { |
|
| 79 | + $groupMounts = $this->dbConfig->getAdminMountsForMultiple(DBConfigService::APPLICABLE_TYPE_GROUP, $groups); |
|
| 80 | + } else { |
|
| 81 | + $groupMounts = []; |
|
| 82 | + } |
|
| 83 | + return array_merge($userMounts, $groupMounts, $globalMounts); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function addStorage(StorageConfig $newStorage) { |
|
| 87 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + public function updateStorage(StorageConfig $updatedStorage) { |
|
| 91 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param integer $id |
|
| 96 | + */ |
|
| 97 | + public function removeStorage($id) { |
|
| 98 | + throw new \DomainException('UserGlobalStoragesService writing disallowed'); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Get unique storages, in case two are defined with the same mountpoint |
|
| 103 | + * Higher priority storages take precedence |
|
| 104 | + * |
|
| 105 | + * @return StorageConfig[] |
|
| 106 | + */ |
|
| 107 | + public function getUniqueStorages() { |
|
| 108 | + $storages = $this->getStorages(); |
|
| 109 | + |
|
| 110 | + $storagesByMountpoint = []; |
|
| 111 | + foreach ($storages as $storage) { |
|
| 112 | + $storagesByMountpoint[$storage->getMountPoint()][] = $storage; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + $result = []; |
|
| 116 | + foreach ($storagesByMountpoint as $storageList) { |
|
| 117 | + $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 118 | + if (isset($carry)) { |
|
| 119 | + $carryPriorityType = $this->getPriorityType($carry); |
|
| 120 | + $itemPriorityType = $this->getPriorityType($item); |
|
| 121 | + if ($carryPriorityType > $itemPriorityType) { |
|
| 122 | + return $carry; |
|
| 123 | + } elseif ($carryPriorityType === $itemPriorityType) { |
|
| 124 | + if ($carry->getPriority() > $item->getPriority()) { |
|
| 125 | + return $carry; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + return $item; |
|
| 130 | + }); |
|
| 131 | + $result[$storage->getID()] = $storage; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $result; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Get a priority 'type', where a bigger number means higher priority |
|
| 139 | + * user applicable > group applicable > 'all' |
|
| 140 | + * |
|
| 141 | + * @param StorageConfig $storage |
|
| 142 | + * @return int |
|
| 143 | + */ |
|
| 144 | + protected function getPriorityType(StorageConfig $storage) { |
|
| 145 | + $applicableUsers = $storage->getApplicableUsers(); |
|
| 146 | + $applicableGroups = $storage->getApplicableGroups(); |
|
| 147 | + |
|
| 148 | + if ($applicableUsers && $applicableUsers[0] !== 'all') { |
|
| 149 | + return 2; |
|
| 150 | + } |
|
| 151 | + if ($applicableGroups) { |
|
| 152 | + return 1; |
|
| 153 | + } |
|
| 154 | + return 0; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + protected function isApplicable(StorageConfig $config) { |
|
| 158 | + $applicableUsers = $config->getApplicableUsers(); |
|
| 159 | + $applicableGroups = $config->getApplicableGroups(); |
|
| 160 | + |
|
| 161 | + if (count($applicableUsers) === 0 && count($applicableGroups) === 0) { |
|
| 162 | + return true; |
|
| 163 | + } |
|
| 164 | + if (in_array($this->getUser()->getUID(), $applicableUsers, true)) { |
|
| 165 | + return true; |
|
| 166 | + } |
|
| 167 | + $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 168 | + foreach ($groupIds as $groupId) { |
|
| 169 | + if (in_array($groupId, $applicableGroups, true)) { |
|
| 170 | + return true; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Gets all storages for the user, admin, personal, global, etc |
|
| 179 | + * |
|
| 180 | + * @return StorageConfig[] array of storage configs |
|
| 181 | + */ |
|
| 182 | + public function getAllStoragesForUser() { |
|
| 183 | + if (is_null($this->getUser())) { |
|
| 184 | + return []; |
|
| 185 | + } |
|
| 186 | + $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
|
| 187 | + $mounts = $this->dbConfig->getMountsForUser($this->getUser()->getUID(), $groupIds); |
|
| 188 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 189 | + $configs = array_filter($configs, function ($config) { |
|
| 190 | + return $config instanceof StorageConfig; |
|
| 191 | + }); |
|
| 192 | + |
|
| 193 | + $keys = array_map(function (StorageConfig $config) { |
|
| 194 | + return $config->getId(); |
|
| 195 | + }, $configs); |
|
| 196 | + |
|
| 197 | + $storages = array_combine($keys, $configs); |
|
| 198 | + return array_filter($storages, [$this, 'validateStorage']); |
|
| 199 | + } |
|
| 200 | 200 | } |
@@ -114,7 +114,7 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | $result = []; |
| 116 | 116 | foreach ($storagesByMountpoint as $storageList) { |
| 117 | - $storage = array_reduce($storageList, function ($carry, $item) { |
|
| 117 | + $storage = array_reduce($storageList, function($carry, $item) { |
|
| 118 | 118 | if (isset($carry)) { |
| 119 | 119 | $carryPriorityType = $this->getPriorityType($carry); |
| 120 | 120 | $itemPriorityType = $this->getPriorityType($item); |
@@ -186,11 +186,11 @@ discard block |
||
| 186 | 186 | $groupIds = $this->groupManager->getUserGroupIds($this->getUser()); |
| 187 | 187 | $mounts = $this->dbConfig->getMountsForUser($this->getUser()->getUID(), $groupIds); |
| 188 | 188 | $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
| 189 | - $configs = array_filter($configs, function ($config) { |
|
| 189 | + $configs = array_filter($configs, function($config) { |
|
| 190 | 190 | return $config instanceof StorageConfig; |
| 191 | 191 | }); |
| 192 | 192 | |
| 193 | - $keys = array_map(function (StorageConfig $config) { |
|
| 193 | + $keys = array_map(function(StorageConfig $config) { |
|
| 194 | 194 | return $config->getId(); |
| 195 | 195 | }, $configs); |
| 196 | 196 | |
@@ -35,151 +35,151 @@ |
||
| 35 | 35 | * Service class to manage global external storages |
| 36 | 36 | */ |
| 37 | 37 | class GlobalStoragesService extends StoragesService { |
| 38 | - /** |
|
| 39 | - * Triggers $signal for all applicable users of the given |
|
| 40 | - * storage |
|
| 41 | - * |
|
| 42 | - * @param StorageConfig $storage storage data |
|
| 43 | - * @param string $signal signal to trigger |
|
| 44 | - */ |
|
| 45 | - protected function triggerHooks(StorageConfig $storage, $signal) { |
|
| 46 | - // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 47 | - $applicableUsers = $storage->getApplicableUsers(); |
|
| 48 | - $applicableGroups = $storage->getApplicableGroups(); |
|
| 49 | - if (empty($applicableUsers) && empty($applicableGroups)) { |
|
| 50 | - // raise for user "all" |
|
| 51 | - $this->triggerApplicableHooks( |
|
| 52 | - $signal, |
|
| 53 | - $storage->getMountPoint(), |
|
| 54 | - \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 55 | - ['all'] |
|
| 56 | - ); |
|
| 57 | - return; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $this->triggerApplicableHooks( |
|
| 61 | - $signal, |
|
| 62 | - $storage->getMountPoint(), |
|
| 63 | - \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 64 | - $applicableUsers |
|
| 65 | - ); |
|
| 66 | - $this->triggerApplicableHooks( |
|
| 67 | - $signal, |
|
| 68 | - $storage->getMountPoint(), |
|
| 69 | - \OC_Mount_Config::MOUNT_TYPE_GROUP, |
|
| 70 | - $applicableGroups |
|
| 71 | - ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Triggers signal_create_mount or signal_delete_mount to |
|
| 76 | - * accommodate for additions/deletions in applicableUsers |
|
| 77 | - * and applicableGroups fields. |
|
| 78 | - * |
|
| 79 | - * @param StorageConfig $oldStorage old storage config |
|
| 80 | - * @param StorageConfig $newStorage new storage config |
|
| 81 | - */ |
|
| 82 | - protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) { |
|
| 83 | - // if mount point changed, it's like a deletion + creation |
|
| 84 | - if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { |
|
| 85 | - $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); |
|
| 86 | - $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
| 87 | - return; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $userAdditions = array_diff($newStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
| 91 | - $userDeletions = array_diff($oldStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
| 92 | - $groupAdditions = array_diff($newStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
| 93 | - $groupDeletions = array_diff($oldStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
| 94 | - |
|
| 95 | - // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 96 | - // if no applicable were set, raise a signal for "all" |
|
| 97 | - $oldApplicableUsers = $oldStorage->getApplicableUsers(); |
|
| 98 | - $oldApplicableGroups = $oldStorage->getApplicableGroups(); |
|
| 99 | - if (empty($oldApplicableUsers) && empty($oldApplicableGroups)) { |
|
| 100 | - $this->triggerApplicableHooks( |
|
| 101 | - Filesystem::signal_delete_mount, |
|
| 102 | - $oldStorage->getMountPoint(), |
|
| 103 | - \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 104 | - ['all'] |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // trigger delete for removed users |
|
| 109 | - $this->triggerApplicableHooks( |
|
| 110 | - Filesystem::signal_delete_mount, |
|
| 111 | - $oldStorage->getMountPoint(), |
|
| 112 | - \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 113 | - $userDeletions |
|
| 114 | - ); |
|
| 115 | - |
|
| 116 | - // trigger delete for removed groups |
|
| 117 | - $this->triggerApplicableHooks( |
|
| 118 | - Filesystem::signal_delete_mount, |
|
| 119 | - $oldStorage->getMountPoint(), |
|
| 120 | - \OC_Mount_Config::MOUNT_TYPE_GROUP, |
|
| 121 | - $groupDeletions |
|
| 122 | - ); |
|
| 123 | - |
|
| 124 | - // and now add the new users |
|
| 125 | - $this->triggerApplicableHooks( |
|
| 126 | - Filesystem::signal_create_mount, |
|
| 127 | - $newStorage->getMountPoint(), |
|
| 128 | - \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 129 | - $userAdditions |
|
| 130 | - ); |
|
| 131 | - |
|
| 132 | - // and now add the new groups |
|
| 133 | - $this->triggerApplicableHooks( |
|
| 134 | - Filesystem::signal_create_mount, |
|
| 135 | - $newStorage->getMountPoint(), |
|
| 136 | - \OC_Mount_Config::MOUNT_TYPE_GROUP, |
|
| 137 | - $groupAdditions |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 141 | - // if no applicable, raise a signal for "all" |
|
| 142 | - $newApplicableUsers = $newStorage->getApplicableUsers(); |
|
| 143 | - $newApplicableGroups = $newStorage->getApplicableGroups(); |
|
| 144 | - if (empty($newApplicableUsers) && empty($newApplicableGroups)) { |
|
| 145 | - $this->triggerApplicableHooks( |
|
| 146 | - Filesystem::signal_create_mount, |
|
| 147 | - $newStorage->getMountPoint(), |
|
| 148 | - \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 149 | - ['all'] |
|
| 150 | - ); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - /** |
|
| 155 | - * Get the visibility type for this controller, used in validation |
|
| 156 | - * |
|
| 157 | - * @return string BackendService::VISIBILITY_* constants |
|
| 158 | - */ |
|
| 159 | - public function getVisibilityType() { |
|
| 160 | - return BackendService::VISIBILITY_ADMIN; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - protected function isApplicable(StorageConfig $config) { |
|
| 164 | - return true; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Get all configured admin and personal mounts |
|
| 169 | - * |
|
| 170 | - * @return array map of storage id to storage config |
|
| 171 | - */ |
|
| 172 | - public function getStorageForAllUsers() { |
|
| 173 | - $mounts = $this->dbConfig->getAllMounts(); |
|
| 174 | - $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 175 | - $configs = array_filter($configs, function ($config) { |
|
| 176 | - return $config instanceof StorageConfig; |
|
| 177 | - }); |
|
| 178 | - |
|
| 179 | - $keys = array_map(function (StorageConfig $config) { |
|
| 180 | - return $config->getId(); |
|
| 181 | - }, $configs); |
|
| 182 | - |
|
| 183 | - return array_combine($keys, $configs); |
|
| 184 | - } |
|
| 38 | + /** |
|
| 39 | + * Triggers $signal for all applicable users of the given |
|
| 40 | + * storage |
|
| 41 | + * |
|
| 42 | + * @param StorageConfig $storage storage data |
|
| 43 | + * @param string $signal signal to trigger |
|
| 44 | + */ |
|
| 45 | + protected function triggerHooks(StorageConfig $storage, $signal) { |
|
| 46 | + // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 47 | + $applicableUsers = $storage->getApplicableUsers(); |
|
| 48 | + $applicableGroups = $storage->getApplicableGroups(); |
|
| 49 | + if (empty($applicableUsers) && empty($applicableGroups)) { |
|
| 50 | + // raise for user "all" |
|
| 51 | + $this->triggerApplicableHooks( |
|
| 52 | + $signal, |
|
| 53 | + $storage->getMountPoint(), |
|
| 54 | + \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 55 | + ['all'] |
|
| 56 | + ); |
|
| 57 | + return; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $this->triggerApplicableHooks( |
|
| 61 | + $signal, |
|
| 62 | + $storage->getMountPoint(), |
|
| 63 | + \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 64 | + $applicableUsers |
|
| 65 | + ); |
|
| 66 | + $this->triggerApplicableHooks( |
|
| 67 | + $signal, |
|
| 68 | + $storage->getMountPoint(), |
|
| 69 | + \OC_Mount_Config::MOUNT_TYPE_GROUP, |
|
| 70 | + $applicableGroups |
|
| 71 | + ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Triggers signal_create_mount or signal_delete_mount to |
|
| 76 | + * accommodate for additions/deletions in applicableUsers |
|
| 77 | + * and applicableGroups fields. |
|
| 78 | + * |
|
| 79 | + * @param StorageConfig $oldStorage old storage config |
|
| 80 | + * @param StorageConfig $newStorage new storage config |
|
| 81 | + */ |
|
| 82 | + protected function triggerChangeHooks(StorageConfig $oldStorage, StorageConfig $newStorage) { |
|
| 83 | + // if mount point changed, it's like a deletion + creation |
|
| 84 | + if ($oldStorage->getMountPoint() !== $newStorage->getMountPoint()) { |
|
| 85 | + $this->triggerHooks($oldStorage, Filesystem::signal_delete_mount); |
|
| 86 | + $this->triggerHooks($newStorage, Filesystem::signal_create_mount); |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $userAdditions = array_diff($newStorage->getApplicableUsers(), $oldStorage->getApplicableUsers()); |
|
| 91 | + $userDeletions = array_diff($oldStorage->getApplicableUsers(), $newStorage->getApplicableUsers()); |
|
| 92 | + $groupAdditions = array_diff($newStorage->getApplicableGroups(), $oldStorage->getApplicableGroups()); |
|
| 93 | + $groupDeletions = array_diff($oldStorage->getApplicableGroups(), $newStorage->getApplicableGroups()); |
|
| 94 | + |
|
| 95 | + // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 96 | + // if no applicable were set, raise a signal for "all" |
|
| 97 | + $oldApplicableUsers = $oldStorage->getApplicableUsers(); |
|
| 98 | + $oldApplicableGroups = $oldStorage->getApplicableGroups(); |
|
| 99 | + if (empty($oldApplicableUsers) && empty($oldApplicableGroups)) { |
|
| 100 | + $this->triggerApplicableHooks( |
|
| 101 | + Filesystem::signal_delete_mount, |
|
| 102 | + $oldStorage->getMountPoint(), |
|
| 103 | + \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 104 | + ['all'] |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // trigger delete for removed users |
|
| 109 | + $this->triggerApplicableHooks( |
|
| 110 | + Filesystem::signal_delete_mount, |
|
| 111 | + $oldStorage->getMountPoint(), |
|
| 112 | + \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 113 | + $userDeletions |
|
| 114 | + ); |
|
| 115 | + |
|
| 116 | + // trigger delete for removed groups |
|
| 117 | + $this->triggerApplicableHooks( |
|
| 118 | + Filesystem::signal_delete_mount, |
|
| 119 | + $oldStorage->getMountPoint(), |
|
| 120 | + \OC_Mount_Config::MOUNT_TYPE_GROUP, |
|
| 121 | + $groupDeletions |
|
| 122 | + ); |
|
| 123 | + |
|
| 124 | + // and now add the new users |
|
| 125 | + $this->triggerApplicableHooks( |
|
| 126 | + Filesystem::signal_create_mount, |
|
| 127 | + $newStorage->getMountPoint(), |
|
| 128 | + \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 129 | + $userAdditions |
|
| 130 | + ); |
|
| 131 | + |
|
| 132 | + // and now add the new groups |
|
| 133 | + $this->triggerApplicableHooks( |
|
| 134 | + Filesystem::signal_create_mount, |
|
| 135 | + $newStorage->getMountPoint(), |
|
| 136 | + \OC_Mount_Config::MOUNT_TYPE_GROUP, |
|
| 137 | + $groupAdditions |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + // FIXME: Use as expression in empty once PHP 5.4 support is dropped |
|
| 141 | + // if no applicable, raise a signal for "all" |
|
| 142 | + $newApplicableUsers = $newStorage->getApplicableUsers(); |
|
| 143 | + $newApplicableGroups = $newStorage->getApplicableGroups(); |
|
| 144 | + if (empty($newApplicableUsers) && empty($newApplicableGroups)) { |
|
| 145 | + $this->triggerApplicableHooks( |
|
| 146 | + Filesystem::signal_create_mount, |
|
| 147 | + $newStorage->getMountPoint(), |
|
| 148 | + \OC_Mount_Config::MOUNT_TYPE_USER, |
|
| 149 | + ['all'] |
|
| 150 | + ); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + /** |
|
| 155 | + * Get the visibility type for this controller, used in validation |
|
| 156 | + * |
|
| 157 | + * @return string BackendService::VISIBILITY_* constants |
|
| 158 | + */ |
|
| 159 | + public function getVisibilityType() { |
|
| 160 | + return BackendService::VISIBILITY_ADMIN; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + protected function isApplicable(StorageConfig $config) { |
|
| 164 | + return true; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Get all configured admin and personal mounts |
|
| 169 | + * |
|
| 170 | + * @return array map of storage id to storage config |
|
| 171 | + */ |
|
| 172 | + public function getStorageForAllUsers() { |
|
| 173 | + $mounts = $this->dbConfig->getAllMounts(); |
|
| 174 | + $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
|
| 175 | + $configs = array_filter($configs, function ($config) { |
|
| 176 | + return $config instanceof StorageConfig; |
|
| 177 | + }); |
|
| 178 | + |
|
| 179 | + $keys = array_map(function (StorageConfig $config) { |
|
| 180 | + return $config->getId(); |
|
| 181 | + }, $configs); |
|
| 182 | + |
|
| 183 | + return array_combine($keys, $configs); |
|
| 184 | + } |
|
| 185 | 185 | } |
@@ -172,11 +172,11 @@ |
||
| 172 | 172 | public function getStorageForAllUsers() { |
| 173 | 173 | $mounts = $this->dbConfig->getAllMounts(); |
| 174 | 174 | $configs = array_map([$this, 'getStorageConfigFromDBMount'], $mounts); |
| 175 | - $configs = array_filter($configs, function ($config) { |
|
| 175 | + $configs = array_filter($configs, function($config) { |
|
| 176 | 176 | return $config instanceof StorageConfig; |
| 177 | 177 | }); |
| 178 | 178 | |
| 179 | - $keys = array_map(function (StorageConfig $config) { |
|
| 179 | + $keys = array_map(function(StorageConfig $config) { |
|
| 180 | 180 | return $config->getId(); |
| 181 | 181 | }, $configs); |
| 182 | 182 | |
@@ -29,28 +29,28 @@ |
||
| 29 | 29 | * Read user defined mounts from the legacy mount.json |
| 30 | 30 | */ |
| 31 | 31 | class UserLegacyStoragesService extends LegacyStoragesService { |
| 32 | - /** |
|
| 33 | - * @var IUserSession |
|
| 34 | - */ |
|
| 35 | - private $userSession; |
|
| 32 | + /** |
|
| 33 | + * @var IUserSession |
|
| 34 | + */ |
|
| 35 | + private $userSession; |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param BackendService $backendService |
|
| 39 | - * @param IUserSession $userSession |
|
| 40 | - */ |
|
| 41 | - public function __construct(BackendService $backendService, IUserSession $userSession) { |
|
| 42 | - $this->backendService = $backendService; |
|
| 43 | - $this->userSession = $userSession; |
|
| 44 | - } |
|
| 37 | + /** |
|
| 38 | + * @param BackendService $backendService |
|
| 39 | + * @param IUserSession $userSession |
|
| 40 | + */ |
|
| 41 | + public function __construct(BackendService $backendService, IUserSession $userSession) { |
|
| 42 | + $this->backendService = $backendService; |
|
| 43 | + $this->userSession = $userSession; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Read legacy config data |
|
| 48 | - * |
|
| 49 | - * @return array list of storage configs |
|
| 50 | - */ |
|
| 51 | - protected function readLegacyConfig() { |
|
| 52 | - // read user config |
|
| 53 | - $user = $this->userSession->getUser()->getUID(); |
|
| 54 | - return \OC_Mount_Config::readData($user); |
|
| 55 | - } |
|
| 46 | + /** |
|
| 47 | + * Read legacy config data |
|
| 48 | + * |
|
| 49 | + * @return array list of storage configs |
|
| 50 | + */ |
|
| 51 | + protected function readLegacyConfig() { |
|
| 52 | + // read user config |
|
| 53 | + $user = $this->userSession->getUser()->getUID(); |
|
| 54 | + return \OC_Mount_Config::readData($user); |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | */ |
| 179 | 179 | public function getAdminMountsForMultiple($type, array $values) { |
| 180 | 180 | $builder = $this->connection->getQueryBuilder(); |
| 181 | - $params = array_map(function ($value) use ($builder) { |
|
| 181 | + $params = array_map(function($value) use ($builder) { |
|
| 182 | 182 | return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR); |
| 183 | 183 | }, $values); |
| 184 | 184 | |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | 'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT) |
| 232 | 232 | ]); |
| 233 | 233 | $query->execute(); |
| 234 | - return (int)$this->connection->lastInsertId('*PREFIX*external_mounts'); |
|
| 234 | + return (int) $this->connection->lastInsertId('*PREFIX*external_mounts'); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | } |
| 368 | 368 | $uniqueMounts = array_values($uniqueMounts); |
| 369 | 369 | |
| 370 | - $mountIds = array_map(function ($mount) { |
|
| 370 | + $mountIds = array_map(function($mount) { |
|
| 371 | 371 | return $mount['mount_id']; |
| 372 | 372 | }, $uniqueMounts); |
| 373 | 373 | $mountIds = array_values(array_unique($mountIds)); |
@@ -376,9 +376,9 @@ discard block |
||
| 376 | 376 | $config = $this->getConfigForMounts($mountIds); |
| 377 | 377 | $options = $this->getOptionsForMounts($mountIds); |
| 378 | 378 | |
| 379 | - return array_map(function ($mount, $applicable, $config, $options) { |
|
| 380 | - $mount['type'] = (int)$mount['type']; |
|
| 381 | - $mount['priority'] = (int)$mount['priority']; |
|
| 379 | + return array_map(function($mount, $applicable, $config, $options) { |
|
| 380 | + $mount['type'] = (int) $mount['type']; |
|
| 381 | + $mount['priority'] = (int) $mount['priority']; |
|
| 382 | 382 | $mount['applicable'] = $applicable; |
| 383 | 383 | $mount['config'] = $config; |
| 384 | 384 | $mount['options'] = $options; |
@@ -400,7 +400,7 @@ discard block |
||
| 400 | 400 | } |
| 401 | 401 | $builder = $this->connection->getQueryBuilder(); |
| 402 | 402 | $fields[] = 'mount_id'; |
| 403 | - $placeHolders = array_map(function ($id) use ($builder) { |
|
| 403 | + $placeHolders = array_map(function($id) use ($builder) { |
|
| 404 | 404 | return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT); |
| 405 | 405 | }, $mountIds); |
| 406 | 406 | $query = $builder->select($fields) |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | } |
| 415 | 415 | foreach ($rows as $row) { |
| 416 | 416 | if (isset($row['type'])) { |
| 417 | - $row['type'] = (int)$row['type']; |
|
| 417 | + $row['type'] = (int) $row['type']; |
|
| 418 | 418 | } |
| 419 | 419 | $result[$row['mount_id']][] = $row; |
| 420 | 420 | } |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | public function getOptionsForMounts($mountIds) { |
| 446 | 446 | $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds); |
| 447 | 447 | $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions); |
| 448 | - return array_map(function (array $options) { |
|
| 449 | - return array_map(function ($option) { |
|
| 448 | + return array_map(function(array $options) { |
|
| 449 | + return array_map(function($option) { |
|
| 450 | 450 | return json_decode($option); |
| 451 | 451 | }, $options); |
| 452 | 452 | }, $optionsMap); |
@@ -457,16 +457,16 @@ discard block |
||
| 457 | 457 | * @return array ['key1' => $value1, ...] |
| 458 | 458 | */ |
| 459 | 459 | private function createKeyValueMap(array $keyValuePairs) { |
| 460 | - $decryptedPairts = array_map(function ($pair) { |
|
| 460 | + $decryptedPairts = array_map(function($pair) { |
|
| 461 | 461 | if ($pair['key'] === 'password') { |
| 462 | 462 | $pair['value'] = $this->decryptValue($pair['value']); |
| 463 | 463 | } |
| 464 | 464 | return $pair; |
| 465 | 465 | }, $keyValuePairs); |
| 466 | - $keys = array_map(function ($pair) { |
|
| 466 | + $keys = array_map(function($pair) { |
|
| 467 | 467 | return $pair['key']; |
| 468 | 468 | }, $decryptedPairts); |
| 469 | - $values = array_map(function ($pair) { |
|
| 469 | + $values = array_map(function($pair) { |
|
| 470 | 470 | return $pair['value']; |
| 471 | 471 | }, $decryptedPairts); |
| 472 | 472 | |
@@ -32,460 +32,460 @@ |
||
| 32 | 32 | * Stores the mount config in the database |
| 33 | 33 | */ |
| 34 | 34 | class DBConfigService { |
| 35 | - const MOUNT_TYPE_ADMIN = 1; |
|
| 36 | - const MOUNT_TYPE_PERSONAl = 2; |
|
| 37 | - |
|
| 38 | - const APPLICABLE_TYPE_GLOBAL = 1; |
|
| 39 | - const APPLICABLE_TYPE_GROUP = 2; |
|
| 40 | - const APPLICABLE_TYPE_USER = 3; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @var IDBConnection |
|
| 44 | - */ |
|
| 45 | - private $connection; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @var ICrypto |
|
| 49 | - */ |
|
| 50 | - private $crypto; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * DBConfigService constructor. |
|
| 54 | - * |
|
| 55 | - * @param IDBConnection $connection |
|
| 56 | - * @param ICrypto $crypto |
|
| 57 | - */ |
|
| 58 | - public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
| 59 | - $this->connection = $connection; |
|
| 60 | - $this->crypto = $crypto; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @param int $mountId |
|
| 65 | - * @return array |
|
| 66 | - */ |
|
| 67 | - public function getMountById($mountId) { |
|
| 68 | - $builder = $this->connection->getQueryBuilder(); |
|
| 69 | - $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 70 | - ->from('external_mounts', 'm') |
|
| 71 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 72 | - $mounts = $this->getMountsFromQuery($query); |
|
| 73 | - if (count($mounts) > 0) { |
|
| 74 | - return $mounts[0]; |
|
| 75 | - } else { |
|
| 76 | - return null; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Get all configured mounts |
|
| 82 | - * |
|
| 83 | - * @return array |
|
| 84 | - */ |
|
| 85 | - public function getAllMounts() { |
|
| 86 | - $builder = $this->connection->getQueryBuilder(); |
|
| 87 | - $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 88 | - ->from('external_mounts'); |
|
| 89 | - return $this->getMountsFromQuery($query); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - public function getMountsForUser($userId, $groupIds) { |
|
| 93 | - $builder = $this->connection->getQueryBuilder(); |
|
| 94 | - $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 95 | - ->from('external_mounts', 'm') |
|
| 96 | - ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 97 | - ->where($builder->expr()->orX( |
|
| 98 | - $builder->expr()->andX( // global mounts |
|
| 99 | - $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)), |
|
| 100 | - $builder->expr()->isNull('a.value') |
|
| 101 | - ), |
|
| 102 | - $builder->expr()->andX( // mounts for user |
|
| 103 | - $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)), |
|
| 104 | - $builder->expr()->eq('a.value', $builder->createNamedParameter($userId)) |
|
| 105 | - ), |
|
| 106 | - $builder->expr()->andX( // mounts for group |
|
| 107 | - $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)), |
|
| 108 | - $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)) |
|
| 109 | - ) |
|
| 110 | - )); |
|
| 111 | - |
|
| 112 | - return $this->getMountsFromQuery($query); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Get admin defined mounts |
|
| 117 | - * |
|
| 118 | - * @return array |
|
| 119 | - * @suppress SqlInjectionChecker |
|
| 120 | - */ |
|
| 121 | - public function getAdminMounts() { |
|
| 122 | - $builder = $this->connection->getQueryBuilder(); |
|
| 123 | - $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 124 | - ->from('external_mounts') |
|
| 125 | - ->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 126 | - return $this->getMountsFromQuery($query); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - protected function getForQuery(IQueryBuilder $builder, $type, $value) { |
|
| 130 | - $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 131 | - ->from('external_mounts', 'm') |
|
| 132 | - ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 133 | - ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))); |
|
| 134 | - |
|
| 135 | - if (is_null($value)) { |
|
| 136 | - $query = $query->andWhere($builder->expr()->isNull('a.value')); |
|
| 137 | - } else { |
|
| 138 | - $query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value))); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - return $query; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Get mounts by applicable |
|
| 146 | - * |
|
| 147 | - * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 148 | - * @param string|null $value user_id, group_id or null for global mounts |
|
| 149 | - * @return array |
|
| 150 | - */ |
|
| 151 | - public function getMountsFor($type, $value) { |
|
| 152 | - $builder = $this->connection->getQueryBuilder(); |
|
| 153 | - $query = $this->getForQuery($builder, $type, $value); |
|
| 154 | - |
|
| 155 | - return $this->getMountsFromQuery($query); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Get admin defined mounts by applicable |
|
| 160 | - * |
|
| 161 | - * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 162 | - * @param string|null $value user_id, group_id or null for global mounts |
|
| 163 | - * @return array |
|
| 164 | - * @suppress SqlInjectionChecker |
|
| 165 | - */ |
|
| 166 | - public function getAdminMountsFor($type, $value) { |
|
| 167 | - $builder = $this->connection->getQueryBuilder(); |
|
| 168 | - $query = $this->getForQuery($builder, $type, $value); |
|
| 169 | - $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 170 | - |
|
| 171 | - return $this->getMountsFromQuery($query); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * Get admin defined mounts for multiple applicable |
|
| 176 | - * |
|
| 177 | - * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 178 | - * @param string[] $values user_ids or group_ids |
|
| 179 | - * @return array |
|
| 180 | - * @suppress SqlInjectionChecker |
|
| 181 | - */ |
|
| 182 | - public function getAdminMountsForMultiple($type, array $values) { |
|
| 183 | - $builder = $this->connection->getQueryBuilder(); |
|
| 184 | - $params = array_map(function ($value) use ($builder) { |
|
| 185 | - return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR); |
|
| 186 | - }, $values); |
|
| 187 | - |
|
| 188 | - $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 189 | - ->from('external_mounts', 'm') |
|
| 190 | - ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 191 | - ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))) |
|
| 192 | - ->andWhere($builder->expr()->in('a.value', $params)); |
|
| 193 | - $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 194 | - |
|
| 195 | - return $this->getMountsFromQuery($query); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Get user defined mounts by applicable |
|
| 200 | - * |
|
| 201 | - * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 202 | - * @param string|null $value user_id, group_id or null for global mounts |
|
| 203 | - * @return array |
|
| 204 | - * @suppress SqlInjectionChecker |
|
| 205 | - */ |
|
| 206 | - public function getUserMountsFor($type, $value) { |
|
| 207 | - $builder = $this->connection->getQueryBuilder(); |
|
| 208 | - $query = $this->getForQuery($builder, $type, $value); |
|
| 209 | - $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT))); |
|
| 210 | - |
|
| 211 | - return $this->getMountsFromQuery($query); |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - /** |
|
| 215 | - * Add a mount to the database |
|
| 216 | - * |
|
| 217 | - * @param string $mountPoint |
|
| 218 | - * @param string $storageBackend |
|
| 219 | - * @param string $authBackend |
|
| 220 | - * @param int $priority |
|
| 221 | - * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL |
|
| 222 | - * @return int the id of the new mount |
|
| 223 | - */ |
|
| 224 | - public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) { |
|
| 225 | - if (!$priority) { |
|
| 226 | - $priority = 100; |
|
| 227 | - } |
|
| 228 | - $builder = $this->connection->getQueryBuilder(); |
|
| 229 | - $query = $builder->insert('external_mounts') |
|
| 230 | - ->values([ |
|
| 231 | - 'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR), |
|
| 232 | - 'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR), |
|
| 233 | - 'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR), |
|
| 234 | - 'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT), |
|
| 235 | - 'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT) |
|
| 236 | - ]); |
|
| 237 | - $query->execute(); |
|
| 238 | - return (int)$this->connection->lastInsertId('*PREFIX*external_mounts'); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Remove a mount from the database |
|
| 243 | - * |
|
| 244 | - * @param int $mountId |
|
| 245 | - */ |
|
| 246 | - public function removeMount($mountId) { |
|
| 247 | - $builder = $this->connection->getQueryBuilder(); |
|
| 248 | - $query = $builder->delete('external_mounts') |
|
| 249 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 250 | - $query->execute(); |
|
| 251 | - |
|
| 252 | - $query = $builder->delete('external_applicable') |
|
| 253 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 254 | - $query->execute(); |
|
| 255 | - |
|
| 256 | - $query = $builder->delete('external_config') |
|
| 257 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 258 | - $query->execute(); |
|
| 259 | - |
|
| 260 | - $query = $builder->delete('external_options') |
|
| 261 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 262 | - $query->execute(); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * @param int $mountId |
|
| 267 | - * @param string $newMountPoint |
|
| 268 | - */ |
|
| 269 | - public function setMountPoint($mountId, $newMountPoint) { |
|
| 270 | - $builder = $this->connection->getQueryBuilder(); |
|
| 271 | - |
|
| 272 | - $query = $builder->update('external_mounts') |
|
| 273 | - ->set('mount_point', $builder->createNamedParameter($newMountPoint)) |
|
| 274 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 275 | - |
|
| 276 | - $query->execute(); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @param int $mountId |
|
| 281 | - * @param string $newAuthBackend |
|
| 282 | - */ |
|
| 283 | - public function setAuthBackend($mountId, $newAuthBackend) { |
|
| 284 | - $builder = $this->connection->getQueryBuilder(); |
|
| 285 | - |
|
| 286 | - $query = $builder->update('external_mounts') |
|
| 287 | - ->set('auth_backend', $builder->createNamedParameter($newAuthBackend)) |
|
| 288 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 289 | - |
|
| 290 | - $query->execute(); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * @param int $mountId |
|
| 295 | - * @param string $key |
|
| 296 | - * @param string $value |
|
| 297 | - */ |
|
| 298 | - public function setConfig($mountId, $key, $value) { |
|
| 299 | - if ($key === 'password') { |
|
| 300 | - $value = $this->encryptValue($value); |
|
| 301 | - } |
|
| 302 | - $count = $this->connection->insertIfNotExist('*PREFIX*external_config', [ |
|
| 303 | - 'mount_id' => $mountId, |
|
| 304 | - 'key' => $key, |
|
| 305 | - 'value' => $value |
|
| 306 | - ], ['mount_id', 'key']); |
|
| 307 | - if ($count === 0) { |
|
| 308 | - $builder = $this->connection->getQueryBuilder(); |
|
| 309 | - $query = $builder->update('external_config') |
|
| 310 | - ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)) |
|
| 311 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 312 | - ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))); |
|
| 313 | - $query->execute(); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * @param int $mountId |
|
| 319 | - * @param string $key |
|
| 320 | - * @param string $value |
|
| 321 | - */ |
|
| 322 | - public function setOption($mountId, $key, $value) { |
|
| 323 | - |
|
| 324 | - $count = $this->connection->insertIfNotExist('*PREFIX*external_options', [ |
|
| 325 | - 'mount_id' => $mountId, |
|
| 326 | - 'key' => $key, |
|
| 327 | - 'value' => json_encode($value) |
|
| 328 | - ], ['mount_id', 'key']); |
|
| 329 | - if ($count === 0) { |
|
| 330 | - $builder = $this->connection->getQueryBuilder(); |
|
| 331 | - $query = $builder->update('external_options') |
|
| 332 | - ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR)) |
|
| 333 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 334 | - ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))); |
|
| 335 | - $query->execute(); |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - public function addApplicable($mountId, $type, $value) { |
|
| 340 | - $this->connection->insertIfNotExist('*PREFIX*external_applicable', [ |
|
| 341 | - 'mount_id' => $mountId, |
|
| 342 | - 'type' => $type, |
|
| 343 | - 'value' => $value |
|
| 344 | - ], ['mount_id', 'type', 'value']); |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - public function removeApplicable($mountId, $type, $value) { |
|
| 348 | - $builder = $this->connection->getQueryBuilder(); |
|
| 349 | - $query = $builder->delete('external_applicable') |
|
| 350 | - ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 351 | - ->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))); |
|
| 352 | - |
|
| 353 | - if (is_null($value)) { |
|
| 354 | - $query = $query->andWhere($builder->expr()->isNull('value')); |
|
| 355 | - } else { |
|
| 356 | - $query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - $query->execute(); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - private function getMountsFromQuery(IQueryBuilder $query) { |
|
| 363 | - $result = $query->execute(); |
|
| 364 | - $mounts = $result->fetchAll(); |
|
| 365 | - $uniqueMounts = []; |
|
| 366 | - foreach ($mounts as $mount) { |
|
| 367 | - $id = $mount['mount_id']; |
|
| 368 | - if (!isset($uniqueMounts[$id])) { |
|
| 369 | - $uniqueMounts[$id] = $mount; |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - $uniqueMounts = array_values($uniqueMounts); |
|
| 373 | - |
|
| 374 | - $mountIds = array_map(function ($mount) { |
|
| 375 | - return $mount['mount_id']; |
|
| 376 | - }, $uniqueMounts); |
|
| 377 | - $mountIds = array_values(array_unique($mountIds)); |
|
| 378 | - |
|
| 379 | - $applicable = $this->getApplicableForMounts($mountIds); |
|
| 380 | - $config = $this->getConfigForMounts($mountIds); |
|
| 381 | - $options = $this->getOptionsForMounts($mountIds); |
|
| 382 | - |
|
| 383 | - return array_map(function ($mount, $applicable, $config, $options) { |
|
| 384 | - $mount['type'] = (int)$mount['type']; |
|
| 385 | - $mount['priority'] = (int)$mount['priority']; |
|
| 386 | - $mount['applicable'] = $applicable; |
|
| 387 | - $mount['config'] = $config; |
|
| 388 | - $mount['options'] = $options; |
|
| 389 | - return $mount; |
|
| 390 | - }, $uniqueMounts, $applicable, $config, $options); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - /** |
|
| 394 | - * Get mount options from a table grouped by mount id |
|
| 395 | - * |
|
| 396 | - * @param string $table |
|
| 397 | - * @param string[] $fields |
|
| 398 | - * @param int[] $mountIds |
|
| 399 | - * @return array [$mountId => [['field1' => $value1, ...], ...], ...] |
|
| 400 | - */ |
|
| 401 | - private function selectForMounts($table, array $fields, array $mountIds) { |
|
| 402 | - if (count($mountIds) === 0) { |
|
| 403 | - return []; |
|
| 404 | - } |
|
| 405 | - $builder = $this->connection->getQueryBuilder(); |
|
| 406 | - $fields[] = 'mount_id'; |
|
| 407 | - $placeHolders = array_map(function ($id) use ($builder) { |
|
| 408 | - return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT); |
|
| 409 | - }, $mountIds); |
|
| 410 | - $query = $builder->select($fields) |
|
| 411 | - ->from($table) |
|
| 412 | - ->where($builder->expr()->in('mount_id', $placeHolders)); |
|
| 413 | - $rows = $query->execute()->fetchAll(); |
|
| 414 | - |
|
| 415 | - $result = []; |
|
| 416 | - foreach ($mountIds as $mountId) { |
|
| 417 | - $result[$mountId] = []; |
|
| 418 | - } |
|
| 419 | - foreach ($rows as $row) { |
|
| 420 | - if (isset($row['type'])) { |
|
| 421 | - $row['type'] = (int)$row['type']; |
|
| 422 | - } |
|
| 423 | - $result[$row['mount_id']][] = $row; |
|
| 424 | - } |
|
| 425 | - return $result; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - /** |
|
| 429 | - * @param int[] $mountIds |
|
| 430 | - * @return array [$id => [['type' => $type, 'value' => $value], ...], ...] |
|
| 431 | - */ |
|
| 432 | - public function getApplicableForMounts($mountIds) { |
|
| 433 | - return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * @param int[] $mountIds |
|
| 438 | - * @return array [$id => ['key1' => $value1, ...], ...] |
|
| 439 | - */ |
|
| 440 | - public function getConfigForMounts($mountIds) { |
|
| 441 | - $mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds); |
|
| 442 | - return array_map([$this, 'createKeyValueMap'], $mountConfigs); |
|
| 443 | - } |
|
| 444 | - |
|
| 445 | - /** |
|
| 446 | - * @param int[] $mountIds |
|
| 447 | - * @return array [$id => ['key1' => $value1, ...], ...] |
|
| 448 | - */ |
|
| 449 | - public function getOptionsForMounts($mountIds) { |
|
| 450 | - $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds); |
|
| 451 | - $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions); |
|
| 452 | - return array_map(function (array $options) { |
|
| 453 | - return array_map(function ($option) { |
|
| 454 | - return json_decode($option); |
|
| 455 | - }, $options); |
|
| 456 | - }, $optionsMap); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...] |
|
| 461 | - * @return array ['key1' => $value1, ...] |
|
| 462 | - */ |
|
| 463 | - private function createKeyValueMap(array $keyValuePairs) { |
|
| 464 | - $decryptedPairts = array_map(function ($pair) { |
|
| 465 | - if ($pair['key'] === 'password') { |
|
| 466 | - $pair['value'] = $this->decryptValue($pair['value']); |
|
| 467 | - } |
|
| 468 | - return $pair; |
|
| 469 | - }, $keyValuePairs); |
|
| 470 | - $keys = array_map(function ($pair) { |
|
| 471 | - return $pair['key']; |
|
| 472 | - }, $decryptedPairts); |
|
| 473 | - $values = array_map(function ($pair) { |
|
| 474 | - return $pair['value']; |
|
| 475 | - }, $decryptedPairts); |
|
| 476 | - |
|
| 477 | - return array_combine($keys, $values); |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - private function encryptValue($value) { |
|
| 481 | - return $this->crypto->encrypt($value); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - private function decryptValue($value) { |
|
| 485 | - try { |
|
| 486 | - return $this->crypto->decrypt($value); |
|
| 487 | - } catch (\Exception $e) { |
|
| 488 | - return $value; |
|
| 489 | - } |
|
| 490 | - } |
|
| 35 | + const MOUNT_TYPE_ADMIN = 1; |
|
| 36 | + const MOUNT_TYPE_PERSONAl = 2; |
|
| 37 | + |
|
| 38 | + const APPLICABLE_TYPE_GLOBAL = 1; |
|
| 39 | + const APPLICABLE_TYPE_GROUP = 2; |
|
| 40 | + const APPLICABLE_TYPE_USER = 3; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @var IDBConnection |
|
| 44 | + */ |
|
| 45 | + private $connection; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @var ICrypto |
|
| 49 | + */ |
|
| 50 | + private $crypto; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * DBConfigService constructor. |
|
| 54 | + * |
|
| 55 | + * @param IDBConnection $connection |
|
| 56 | + * @param ICrypto $crypto |
|
| 57 | + */ |
|
| 58 | + public function __construct(IDBConnection $connection, ICrypto $crypto) { |
|
| 59 | + $this->connection = $connection; |
|
| 60 | + $this->crypto = $crypto; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @param int $mountId |
|
| 65 | + * @return array |
|
| 66 | + */ |
|
| 67 | + public function getMountById($mountId) { |
|
| 68 | + $builder = $this->connection->getQueryBuilder(); |
|
| 69 | + $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 70 | + ->from('external_mounts', 'm') |
|
| 71 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 72 | + $mounts = $this->getMountsFromQuery($query); |
|
| 73 | + if (count($mounts) > 0) { |
|
| 74 | + return $mounts[0]; |
|
| 75 | + } else { |
|
| 76 | + return null; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Get all configured mounts |
|
| 82 | + * |
|
| 83 | + * @return array |
|
| 84 | + */ |
|
| 85 | + public function getAllMounts() { |
|
| 86 | + $builder = $this->connection->getQueryBuilder(); |
|
| 87 | + $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 88 | + ->from('external_mounts'); |
|
| 89 | + return $this->getMountsFromQuery($query); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + public function getMountsForUser($userId, $groupIds) { |
|
| 93 | + $builder = $this->connection->getQueryBuilder(); |
|
| 94 | + $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 95 | + ->from('external_mounts', 'm') |
|
| 96 | + ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 97 | + ->where($builder->expr()->orX( |
|
| 98 | + $builder->expr()->andX( // global mounts |
|
| 99 | + $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GLOBAL, IQueryBuilder::PARAM_INT)), |
|
| 100 | + $builder->expr()->isNull('a.value') |
|
| 101 | + ), |
|
| 102 | + $builder->expr()->andX( // mounts for user |
|
| 103 | + $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_USER, IQueryBuilder::PARAM_INT)), |
|
| 104 | + $builder->expr()->eq('a.value', $builder->createNamedParameter($userId)) |
|
| 105 | + ), |
|
| 106 | + $builder->expr()->andX( // mounts for group |
|
| 107 | + $builder->expr()->eq('a.type', $builder->createNamedParameter(self::APPLICABLE_TYPE_GROUP, IQueryBuilder::PARAM_INT)), |
|
| 108 | + $builder->expr()->in('a.value', $builder->createNamedParameter($groupIds, IQueryBuilder::PARAM_STR_ARRAY)) |
|
| 109 | + ) |
|
| 110 | + )); |
|
| 111 | + |
|
| 112 | + return $this->getMountsFromQuery($query); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Get admin defined mounts |
|
| 117 | + * |
|
| 118 | + * @return array |
|
| 119 | + * @suppress SqlInjectionChecker |
|
| 120 | + */ |
|
| 121 | + public function getAdminMounts() { |
|
| 122 | + $builder = $this->connection->getQueryBuilder(); |
|
| 123 | + $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) |
|
| 124 | + ->from('external_mounts') |
|
| 125 | + ->where($builder->expr()->eq('type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 126 | + return $this->getMountsFromQuery($query); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + protected function getForQuery(IQueryBuilder $builder, $type, $value) { |
|
| 130 | + $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 131 | + ->from('external_mounts', 'm') |
|
| 132 | + ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 133 | + ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))); |
|
| 134 | + |
|
| 135 | + if (is_null($value)) { |
|
| 136 | + $query = $query->andWhere($builder->expr()->isNull('a.value')); |
|
| 137 | + } else { |
|
| 138 | + $query = $query->andWhere($builder->expr()->eq('a.value', $builder->createNamedParameter($value))); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + return $query; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Get mounts by applicable |
|
| 146 | + * |
|
| 147 | + * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 148 | + * @param string|null $value user_id, group_id or null for global mounts |
|
| 149 | + * @return array |
|
| 150 | + */ |
|
| 151 | + public function getMountsFor($type, $value) { |
|
| 152 | + $builder = $this->connection->getQueryBuilder(); |
|
| 153 | + $query = $this->getForQuery($builder, $type, $value); |
|
| 154 | + |
|
| 155 | + return $this->getMountsFromQuery($query); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Get admin defined mounts by applicable |
|
| 160 | + * |
|
| 161 | + * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 162 | + * @param string|null $value user_id, group_id or null for global mounts |
|
| 163 | + * @return array |
|
| 164 | + * @suppress SqlInjectionChecker |
|
| 165 | + */ |
|
| 166 | + public function getAdminMountsFor($type, $value) { |
|
| 167 | + $builder = $this->connection->getQueryBuilder(); |
|
| 168 | + $query = $this->getForQuery($builder, $type, $value); |
|
| 169 | + $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 170 | + |
|
| 171 | + return $this->getMountsFromQuery($query); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * Get admin defined mounts for multiple applicable |
|
| 176 | + * |
|
| 177 | + * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 178 | + * @param string[] $values user_ids or group_ids |
|
| 179 | + * @return array |
|
| 180 | + * @suppress SqlInjectionChecker |
|
| 181 | + */ |
|
| 182 | + public function getAdminMountsForMultiple($type, array $values) { |
|
| 183 | + $builder = $this->connection->getQueryBuilder(); |
|
| 184 | + $params = array_map(function ($value) use ($builder) { |
|
| 185 | + return $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR); |
|
| 186 | + }, $values); |
|
| 187 | + |
|
| 188 | + $query = $builder->select(['m.mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'm.type']) |
|
| 189 | + ->from('external_mounts', 'm') |
|
| 190 | + ->innerJoin('m', 'external_applicable', 'a', $builder->expr()->eq('m.mount_id', 'a.mount_id')) |
|
| 191 | + ->where($builder->expr()->eq('a.type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))) |
|
| 192 | + ->andWhere($builder->expr()->in('a.value', $params)); |
|
| 193 | + $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_ADMIN, IQueryBuilder::PARAM_INT))); |
|
| 194 | + |
|
| 195 | + return $this->getMountsFromQuery($query); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Get user defined mounts by applicable |
|
| 200 | + * |
|
| 201 | + * @param int $type any of the self::APPLICABLE_TYPE_ constants |
|
| 202 | + * @param string|null $value user_id, group_id or null for global mounts |
|
| 203 | + * @return array |
|
| 204 | + * @suppress SqlInjectionChecker |
|
| 205 | + */ |
|
| 206 | + public function getUserMountsFor($type, $value) { |
|
| 207 | + $builder = $this->connection->getQueryBuilder(); |
|
| 208 | + $query = $this->getForQuery($builder, $type, $value); |
|
| 209 | + $query->andWhere($builder->expr()->eq('m.type', $builder->expr()->literal(self::MOUNT_TYPE_PERSONAl, IQueryBuilder::PARAM_INT))); |
|
| 210 | + |
|
| 211 | + return $this->getMountsFromQuery($query); |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + /** |
|
| 215 | + * Add a mount to the database |
|
| 216 | + * |
|
| 217 | + * @param string $mountPoint |
|
| 218 | + * @param string $storageBackend |
|
| 219 | + * @param string $authBackend |
|
| 220 | + * @param int $priority |
|
| 221 | + * @param int $type self::MOUNT_TYPE_ADMIN or self::MOUNT_TYPE_PERSONAL |
|
| 222 | + * @return int the id of the new mount |
|
| 223 | + */ |
|
| 224 | + public function addMount($mountPoint, $storageBackend, $authBackend, $priority, $type) { |
|
| 225 | + if (!$priority) { |
|
| 226 | + $priority = 100; |
|
| 227 | + } |
|
| 228 | + $builder = $this->connection->getQueryBuilder(); |
|
| 229 | + $query = $builder->insert('external_mounts') |
|
| 230 | + ->values([ |
|
| 231 | + 'mount_point' => $builder->createNamedParameter($mountPoint, IQueryBuilder::PARAM_STR), |
|
| 232 | + 'storage_backend' => $builder->createNamedParameter($storageBackend, IQueryBuilder::PARAM_STR), |
|
| 233 | + 'auth_backend' => $builder->createNamedParameter($authBackend, IQueryBuilder::PARAM_STR), |
|
| 234 | + 'priority' => $builder->createNamedParameter($priority, IQueryBuilder::PARAM_INT), |
|
| 235 | + 'type' => $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT) |
|
| 236 | + ]); |
|
| 237 | + $query->execute(); |
|
| 238 | + return (int)$this->connection->lastInsertId('*PREFIX*external_mounts'); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Remove a mount from the database |
|
| 243 | + * |
|
| 244 | + * @param int $mountId |
|
| 245 | + */ |
|
| 246 | + public function removeMount($mountId) { |
|
| 247 | + $builder = $this->connection->getQueryBuilder(); |
|
| 248 | + $query = $builder->delete('external_mounts') |
|
| 249 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 250 | + $query->execute(); |
|
| 251 | + |
|
| 252 | + $query = $builder->delete('external_applicable') |
|
| 253 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 254 | + $query->execute(); |
|
| 255 | + |
|
| 256 | + $query = $builder->delete('external_config') |
|
| 257 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 258 | + $query->execute(); |
|
| 259 | + |
|
| 260 | + $query = $builder->delete('external_options') |
|
| 261 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 262 | + $query->execute(); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * @param int $mountId |
|
| 267 | + * @param string $newMountPoint |
|
| 268 | + */ |
|
| 269 | + public function setMountPoint($mountId, $newMountPoint) { |
|
| 270 | + $builder = $this->connection->getQueryBuilder(); |
|
| 271 | + |
|
| 272 | + $query = $builder->update('external_mounts') |
|
| 273 | + ->set('mount_point', $builder->createNamedParameter($newMountPoint)) |
|
| 274 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 275 | + |
|
| 276 | + $query->execute(); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @param int $mountId |
|
| 281 | + * @param string $newAuthBackend |
|
| 282 | + */ |
|
| 283 | + public function setAuthBackend($mountId, $newAuthBackend) { |
|
| 284 | + $builder = $this->connection->getQueryBuilder(); |
|
| 285 | + |
|
| 286 | + $query = $builder->update('external_mounts') |
|
| 287 | + ->set('auth_backend', $builder->createNamedParameter($newAuthBackend)) |
|
| 288 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))); |
|
| 289 | + |
|
| 290 | + $query->execute(); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * @param int $mountId |
|
| 295 | + * @param string $key |
|
| 296 | + * @param string $value |
|
| 297 | + */ |
|
| 298 | + public function setConfig($mountId, $key, $value) { |
|
| 299 | + if ($key === 'password') { |
|
| 300 | + $value = $this->encryptValue($value); |
|
| 301 | + } |
|
| 302 | + $count = $this->connection->insertIfNotExist('*PREFIX*external_config', [ |
|
| 303 | + 'mount_id' => $mountId, |
|
| 304 | + 'key' => $key, |
|
| 305 | + 'value' => $value |
|
| 306 | + ], ['mount_id', 'key']); |
|
| 307 | + if ($count === 0) { |
|
| 308 | + $builder = $this->connection->getQueryBuilder(); |
|
| 309 | + $query = $builder->update('external_config') |
|
| 310 | + ->set('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR)) |
|
| 311 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 312 | + ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))); |
|
| 313 | + $query->execute(); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * @param int $mountId |
|
| 319 | + * @param string $key |
|
| 320 | + * @param string $value |
|
| 321 | + */ |
|
| 322 | + public function setOption($mountId, $key, $value) { |
|
| 323 | + |
|
| 324 | + $count = $this->connection->insertIfNotExist('*PREFIX*external_options', [ |
|
| 325 | + 'mount_id' => $mountId, |
|
| 326 | + 'key' => $key, |
|
| 327 | + 'value' => json_encode($value) |
|
| 328 | + ], ['mount_id', 'key']); |
|
| 329 | + if ($count === 0) { |
|
| 330 | + $builder = $this->connection->getQueryBuilder(); |
|
| 331 | + $query = $builder->update('external_options') |
|
| 332 | + ->set('value', $builder->createNamedParameter(json_encode($value), IQueryBuilder::PARAM_STR)) |
|
| 333 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 334 | + ->andWhere($builder->expr()->eq('key', $builder->createNamedParameter($key, IQueryBuilder::PARAM_STR))); |
|
| 335 | + $query->execute(); |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + public function addApplicable($mountId, $type, $value) { |
|
| 340 | + $this->connection->insertIfNotExist('*PREFIX*external_applicable', [ |
|
| 341 | + 'mount_id' => $mountId, |
|
| 342 | + 'type' => $type, |
|
| 343 | + 'value' => $value |
|
| 344 | + ], ['mount_id', 'type', 'value']); |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + public function removeApplicable($mountId, $type, $value) { |
|
| 348 | + $builder = $this->connection->getQueryBuilder(); |
|
| 349 | + $query = $builder->delete('external_applicable') |
|
| 350 | + ->where($builder->expr()->eq('mount_id', $builder->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
| 351 | + ->andWhere($builder->expr()->eq('type', $builder->createNamedParameter($type, IQueryBuilder::PARAM_INT))); |
|
| 352 | + |
|
| 353 | + if (is_null($value)) { |
|
| 354 | + $query = $query->andWhere($builder->expr()->isNull('value')); |
|
| 355 | + } else { |
|
| 356 | + $query = $query->andWhere($builder->expr()->eq('value', $builder->createNamedParameter($value, IQueryBuilder::PARAM_STR))); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + $query->execute(); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + private function getMountsFromQuery(IQueryBuilder $query) { |
|
| 363 | + $result = $query->execute(); |
|
| 364 | + $mounts = $result->fetchAll(); |
|
| 365 | + $uniqueMounts = []; |
|
| 366 | + foreach ($mounts as $mount) { |
|
| 367 | + $id = $mount['mount_id']; |
|
| 368 | + if (!isset($uniqueMounts[$id])) { |
|
| 369 | + $uniqueMounts[$id] = $mount; |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + $uniqueMounts = array_values($uniqueMounts); |
|
| 373 | + |
|
| 374 | + $mountIds = array_map(function ($mount) { |
|
| 375 | + return $mount['mount_id']; |
|
| 376 | + }, $uniqueMounts); |
|
| 377 | + $mountIds = array_values(array_unique($mountIds)); |
|
| 378 | + |
|
| 379 | + $applicable = $this->getApplicableForMounts($mountIds); |
|
| 380 | + $config = $this->getConfigForMounts($mountIds); |
|
| 381 | + $options = $this->getOptionsForMounts($mountIds); |
|
| 382 | + |
|
| 383 | + return array_map(function ($mount, $applicable, $config, $options) { |
|
| 384 | + $mount['type'] = (int)$mount['type']; |
|
| 385 | + $mount['priority'] = (int)$mount['priority']; |
|
| 386 | + $mount['applicable'] = $applicable; |
|
| 387 | + $mount['config'] = $config; |
|
| 388 | + $mount['options'] = $options; |
|
| 389 | + return $mount; |
|
| 390 | + }, $uniqueMounts, $applicable, $config, $options); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + /** |
|
| 394 | + * Get mount options from a table grouped by mount id |
|
| 395 | + * |
|
| 396 | + * @param string $table |
|
| 397 | + * @param string[] $fields |
|
| 398 | + * @param int[] $mountIds |
|
| 399 | + * @return array [$mountId => [['field1' => $value1, ...], ...], ...] |
|
| 400 | + */ |
|
| 401 | + private function selectForMounts($table, array $fields, array $mountIds) { |
|
| 402 | + if (count($mountIds) === 0) { |
|
| 403 | + return []; |
|
| 404 | + } |
|
| 405 | + $builder = $this->connection->getQueryBuilder(); |
|
| 406 | + $fields[] = 'mount_id'; |
|
| 407 | + $placeHolders = array_map(function ($id) use ($builder) { |
|
| 408 | + return $builder->createPositionalParameter($id, IQueryBuilder::PARAM_INT); |
|
| 409 | + }, $mountIds); |
|
| 410 | + $query = $builder->select($fields) |
|
| 411 | + ->from($table) |
|
| 412 | + ->where($builder->expr()->in('mount_id', $placeHolders)); |
|
| 413 | + $rows = $query->execute()->fetchAll(); |
|
| 414 | + |
|
| 415 | + $result = []; |
|
| 416 | + foreach ($mountIds as $mountId) { |
|
| 417 | + $result[$mountId] = []; |
|
| 418 | + } |
|
| 419 | + foreach ($rows as $row) { |
|
| 420 | + if (isset($row['type'])) { |
|
| 421 | + $row['type'] = (int)$row['type']; |
|
| 422 | + } |
|
| 423 | + $result[$row['mount_id']][] = $row; |
|
| 424 | + } |
|
| 425 | + return $result; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + /** |
|
| 429 | + * @param int[] $mountIds |
|
| 430 | + * @return array [$id => [['type' => $type, 'value' => $value], ...], ...] |
|
| 431 | + */ |
|
| 432 | + public function getApplicableForMounts($mountIds) { |
|
| 433 | + return $this->selectForMounts('external_applicable', ['type', 'value'], $mountIds); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * @param int[] $mountIds |
|
| 438 | + * @return array [$id => ['key1' => $value1, ...], ...] |
|
| 439 | + */ |
|
| 440 | + public function getConfigForMounts($mountIds) { |
|
| 441 | + $mountConfigs = $this->selectForMounts('external_config', ['key', 'value'], $mountIds); |
|
| 442 | + return array_map([$this, 'createKeyValueMap'], $mountConfigs); |
|
| 443 | + } |
|
| 444 | + |
|
| 445 | + /** |
|
| 446 | + * @param int[] $mountIds |
|
| 447 | + * @return array [$id => ['key1' => $value1, ...], ...] |
|
| 448 | + */ |
|
| 449 | + public function getOptionsForMounts($mountIds) { |
|
| 450 | + $mountOptions = $this->selectForMounts('external_options', ['key', 'value'], $mountIds); |
|
| 451 | + $optionsMap = array_map([$this, 'createKeyValueMap'], $mountOptions); |
|
| 452 | + return array_map(function (array $options) { |
|
| 453 | + return array_map(function ($option) { |
|
| 454 | + return json_decode($option); |
|
| 455 | + }, $options); |
|
| 456 | + }, $optionsMap); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * @param array $keyValuePairs [['key'=>$key, 'value=>$value], ...] |
|
| 461 | + * @return array ['key1' => $value1, ...] |
|
| 462 | + */ |
|
| 463 | + private function createKeyValueMap(array $keyValuePairs) { |
|
| 464 | + $decryptedPairts = array_map(function ($pair) { |
|
| 465 | + if ($pair['key'] === 'password') { |
|
| 466 | + $pair['value'] = $this->decryptValue($pair['value']); |
|
| 467 | + } |
|
| 468 | + return $pair; |
|
| 469 | + }, $keyValuePairs); |
|
| 470 | + $keys = array_map(function ($pair) { |
|
| 471 | + return $pair['key']; |
|
| 472 | + }, $decryptedPairts); |
|
| 473 | + $values = array_map(function ($pair) { |
|
| 474 | + return $pair['value']; |
|
| 475 | + }, $decryptedPairts); |
|
| 476 | + |
|
| 477 | + return array_combine($keys, $values); |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + private function encryptValue($value) { |
|
| 481 | + return $this->crypto->encrypt($value); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + private function decryptValue($value) { |
|
| 485 | + try { |
|
| 486 | + return $this->crypto->decrypt($value); |
|
| 487 | + } catch (\Exception $e) { |
|
| 488 | + return $value; |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | 491 | } |
@@ -30,46 +30,46 @@ |
||
| 30 | 30 | */ |
| 31 | 31 | trait UserTrait { |
| 32 | 32 | |
| 33 | - /** @var IUserSession */ |
|
| 34 | - protected $userSession; |
|
| 33 | + /** @var IUserSession */ |
|
| 34 | + protected $userSession; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * User override |
|
| 38 | - * |
|
| 39 | - * @var IUser|null |
|
| 40 | - */ |
|
| 41 | - private $user = null; |
|
| 36 | + /** |
|
| 37 | + * User override |
|
| 38 | + * |
|
| 39 | + * @var IUser|null |
|
| 40 | + */ |
|
| 41 | + private $user = null; |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * @return IUser|null |
|
| 45 | - */ |
|
| 46 | - protected function getUser() { |
|
| 47 | - if ($this->user) { |
|
| 48 | - return $this->user; |
|
| 49 | - } |
|
| 50 | - return $this->userSession->getUser(); |
|
| 51 | - } |
|
| 43 | + /** |
|
| 44 | + * @return IUser|null |
|
| 45 | + */ |
|
| 46 | + protected function getUser() { |
|
| 47 | + if ($this->user) { |
|
| 48 | + return $this->user; |
|
| 49 | + } |
|
| 50 | + return $this->userSession->getUser(); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Override the user from the session |
|
| 55 | - * Unset with ->resetUser() when finished! |
|
| 56 | - * |
|
| 57 | - * @param IUser |
|
| 58 | - * @return self |
|
| 59 | - */ |
|
| 60 | - public function setUser(IUser $user) { |
|
| 61 | - $this->user = $user; |
|
| 62 | - return $this; |
|
| 63 | - } |
|
| 53 | + /** |
|
| 54 | + * Override the user from the session |
|
| 55 | + * Unset with ->resetUser() when finished! |
|
| 56 | + * |
|
| 57 | + * @param IUser |
|
| 58 | + * @return self |
|
| 59 | + */ |
|
| 60 | + public function setUser(IUser $user) { |
|
| 61 | + $this->user = $user; |
|
| 62 | + return $this; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Reset the user override |
|
| 67 | - * |
|
| 68 | - * @return self |
|
| 69 | - */ |
|
| 70 | - public function resetUser() { |
|
| 71 | - $this->user = null; |
|
| 72 | - return $this; |
|
| 73 | - } |
|
| 65 | + /** |
|
| 66 | + * Reset the user override |
|
| 67 | + * |
|
| 68 | + * @return self |
|
| 69 | + */ |
|
| 70 | + public function resetUser() { |
|
| 71 | + $this->user = null; |
|
| 72 | + return $this; |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | |