Display applicable global storages in personal mount list
This commit is contained in:
parent
a1704c8623
commit
28876bf463
6 changed files with 187 additions and 57 deletions
|
@ -36,6 +36,7 @@ namespace OCA\Files_External\AppInfo;
|
|||
'resources' => array(
|
||||
'global_storages' => array('url' => '/globalstorages'),
|
||||
'user_storages' => array('url' => '/userstorages'),
|
||||
'user_global_storages' => array('url' => '/userglobalstorages'),
|
||||
),
|
||||
'routes' => array(
|
||||
array(
|
||||
|
|
121
apps/files_external/controller/userglobalstoragescontroller.php
Normal file
121
apps/files_external/controller/userglobalstoragescontroller.php
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Robin McCorkell <rmccorkell@owncloud.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2015, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_External\Controller;
|
||||
|
||||
use \OCP\IRequest;
|
||||
use \OCP\IL10N;
|
||||
use \OCP\AppFramework\Http\DataResponse;
|
||||
use \OCP\AppFramework\Controller;
|
||||
use \OCP\AppFramework\Http;
|
||||
use \OCA\Files_external\Service\UserGlobalStoragesService;
|
||||
use \OCA\Files_external\NotFoundException;
|
||||
use \OCA\Files_external\Lib\StorageConfig;
|
||||
use \OCA\Files_External\Lib\Backend\Backend;
|
||||
|
||||
/**
|
||||
* User global storages controller
|
||||
*/
|
||||
class UserGlobalStoragesController extends StoragesController {
|
||||
/**
|
||||
* Creates a new user global storages controller.
|
||||
*
|
||||
* @param string $AppName application name
|
||||
* @param IRequest $request request object
|
||||
* @param IL10N $l10n l10n service
|
||||
* @param UserGlobalStoragesService $userGlobalStoragesService storage service
|
||||
*/
|
||||
public function __construct(
|
||||
$AppName,
|
||||
IRequest $request,
|
||||
IL10N $l10n,
|
||||
UserGlobalStoragesService $userGlobalStoragesService
|
||||
) {
|
||||
parent::__construct(
|
||||
$AppName,
|
||||
$request,
|
||||
$l10n,
|
||||
$userGlobalStoragesService
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all storage entries
|
||||
*
|
||||
* @return DataResponse
|
||||
*
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function index() {
|
||||
$storages = $this->service->getAllStorages();
|
||||
|
||||
// remove configuration data, this must be kept private
|
||||
foreach ($storages as $storage) {
|
||||
$this->sanitizeStorage($storage);
|
||||
}
|
||||
|
||||
return new DataResponse(
|
||||
$storages,
|
||||
Http::STATUS_OK
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an external storage entry.
|
||||
*
|
||||
* @param int $id storage id
|
||||
* @return DataResponse
|
||||
*
|
||||
* @NoAdminRequired
|
||||
*/
|
||||
public function show($id) {
|
||||
try {
|
||||
$storage = $this->service->getStorage($id);
|
||||
|
||||
$this->updateStorageStatus($storage);
|
||||
} catch (NotFoundException $e) {
|
||||
return new DataResponse(
|
||||
[
|
||||
'message' => (string)$this->l10n->t('Storage with id "%i" not found', array($id))
|
||||
],
|
||||
Http::STATUS_NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
$this->sanitizeStorage($storage);
|
||||
|
||||
return new DataResponse(
|
||||
$storage,
|
||||
Http::STATUS_OK
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove sensitive data from a StorageConfig before returning it to the user
|
||||
*
|
||||
* @param StorageConfig $storage
|
||||
*/
|
||||
protected function sanitizeStorage(StorageConfig $storage) {
|
||||
$storage->setBackendOptions([]);
|
||||
$storage->setMountOptions([]);
|
||||
}
|
||||
|
||||
}
|
|
@ -820,6 +820,37 @@ MountConfigListView.prototype = _.extend({
|
|||
loadStorages: function() {
|
||||
var self = this;
|
||||
|
||||
if (this._isPersonal) {
|
||||
// load userglobal storages
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: OC.generateUrl('apps/files_external/userglobalstorages'),
|
||||
contentType: 'application/json',
|
||||
success: function(result) {
|
||||
$.each(result, function(i, storageParams) {
|
||||
storageParams.mountPoint = storageParams.mountPoint.substr(1); // trim leading slash
|
||||
var storageConfig = new self._storageConfigClass();
|
||||
_.extend(storageConfig, storageParams);
|
||||
var $tr = self.newStorage(storageConfig);
|
||||
|
||||
// userglobal storages must be at the top of the list
|
||||
$tr.detach();
|
||||
self.$el.prepend($tr);
|
||||
|
||||
var $authentication = $tr.find('.authentication');
|
||||
$authentication.text($authentication.find('select option:selected').text());
|
||||
|
||||
// userglobal storages do not expose configuration data
|
||||
$tr.find('.configuration').text(t('files_external', 'Admin defined'));
|
||||
|
||||
// disable any other inputs
|
||||
$tr.find('.mountOptionsToggle, .remove').empty();
|
||||
$tr.find('input, select, button').attr('disabled', 'disabled');
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var url = this._storageConfigClass.prototype._url;
|
||||
|
||||
$.ajax({
|
||||
|
|
|
@ -32,31 +32,11 @@ $appContainer = \OC_Mount_Config::$app->getContainer();
|
|||
$backendService = $appContainer->query('OCA\Files_External\Service\BackendService');
|
||||
$userStoragesService = $appContainer->query('OCA\Files_external\Service\UserStoragesService');
|
||||
|
||||
OCP\Util::addScript('files_external', 'settings');
|
||||
OCP\Util::addStyle('files_external', 'settings');
|
||||
|
||||
$backends = array_filter($backendService->getAvailableBackends(), function($backend) {
|
||||
return $backend->isVisibleFor(BackendService::VISIBILITY_PERSONAL);
|
||||
});
|
||||
$authMechanisms = array_filter($backendService->getAuthMechanisms(), function($authMechanism) {
|
||||
return $authMechanism->isVisibleFor(BackendService::VISIBILITY_PERSONAL);
|
||||
});
|
||||
foreach ($backends as $backend) {
|
||||
if ($backend->getCustomJs()) {
|
||||
\OCP\Util::addScript('files_external', $backend->getCustomJs());
|
||||
}
|
||||
}
|
||||
foreach ($authMechanisms as $authMechanism) {
|
||||
if ($authMechanism->getCustomJs()) {
|
||||
\OCP\Util::addScript('files_external', $authMechanism->getCustomJs());
|
||||
}
|
||||
}
|
||||
|
||||
$tmpl = new OCP\Template('files_external', 'settings');
|
||||
$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
|
||||
$tmpl->assign('isAdminPage', false);
|
||||
$tmpl->assign('visibilityType', BackendService::VISIBILITY_PERSONAL);
|
||||
$tmpl->assign('storages', $userStoragesService->getStorages());
|
||||
$tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends()));
|
||||
$tmpl->assign('backends', $backends);
|
||||
$tmpl->assign('authMechanisms', $authMechanisms);
|
||||
$tmpl->assign('backends', $backendService->getAvailableBackends());
|
||||
$tmpl->assign('authMechanisms', $backendService->getAuthMechanisms());
|
||||
return $tmpl->fetchPage();
|
||||
|
|
|
@ -35,40 +35,15 @@ $appContainer = \OC_Mount_Config::$app->getContainer();
|
|||
$backendService = $appContainer->query('OCA\Files_External\Service\BackendService');
|
||||
$globalStoragesService = $appContainer->query('OCA\Files_external\Service\GlobalStoragesService');
|
||||
|
||||
OCP\Util::addScript('files_external', 'settings');
|
||||
OCP\Util::addStyle('files_external', 'settings');
|
||||
|
||||
\OC_Util::addVendorScript('select2/select2');
|
||||
\OC_Util::addVendorStyle('select2/select2');
|
||||
|
||||
$backends = array_filter($backendService->getAvailableBackends(), function($backend) {
|
||||
return $backend->isVisibleFor(BackendService::VISIBILITY_ADMIN);
|
||||
});
|
||||
$authMechanisms = array_filter($backendService->getAuthMechanisms(), function($authMechanism) {
|
||||
return $authMechanism->isVisibleFor(BackendService::VISIBILITY_ADMIN);
|
||||
});
|
||||
foreach ($backends as $backend) {
|
||||
if ($backend->getCustomJs()) {
|
||||
\OCP\Util::addScript('files_external', $backend->getCustomJs());
|
||||
}
|
||||
}
|
||||
foreach ($authMechanisms as $authMechanism) {
|
||||
if ($authMechanism->getCustomJs()) {
|
||||
\OCP\Util::addScript('files_external', $authMechanism->getCustomJs());
|
||||
}
|
||||
}
|
||||
|
||||
$userBackends = array_filter($backendService->getAvailableBackends(), function($backend) {
|
||||
return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL);
|
||||
});
|
||||
|
||||
$tmpl = new OCP\Template('files_external', 'settings');
|
||||
$tmpl->assign('encryptionEnabled', \OC::$server->getEncryptionManager()->isEnabled());
|
||||
$tmpl->assign('isAdminPage', true);
|
||||
$tmpl->assign('visibilityType', BackendService::VISIBILITY_ADMIN);
|
||||
$tmpl->assign('storages', $globalStoragesService->getStorages());
|
||||
$tmpl->assign('backends', $backends);
|
||||
$tmpl->assign('authMechanisms', $authMechanisms);
|
||||
$tmpl->assign('userBackends', $userBackends);
|
||||
$tmpl->assign('backends', $backendService->getAvailableBackends());
|
||||
$tmpl->assign('authMechanisms', $backendService->getAuthMechanisms());
|
||||
$tmpl->assign('dependencies', OC_Mount_Config::dependencyMessage($backendService->getBackends()));
|
||||
$tmpl->assign('allowUserMounting', $backendService->isUserMountingAllowed());
|
||||
return $tmpl->fetchPage();
|
||||
|
|
|
@ -3,6 +3,21 @@
|
|||
use \OCA\Files_External\Lib\DefinitionParameter;
|
||||
use \OCA\Files_External\Service\BackendService;
|
||||
|
||||
script('files_external', 'settings');
|
||||
style('files_external', 'settings');
|
||||
|
||||
// load custom JS
|
||||
foreach ($_['backends'] as $backend) {
|
||||
if ($backend->getCustomJs()) {
|
||||
script('files_external', $backend->getCustomJs());
|
||||
}
|
||||
}
|
||||
foreach ($_['authMechanisms'] as $authMechanism) {
|
||||
if ($authMechanism->getCustomJs()) {
|
||||
script('files_external', $authMechanism->getCustomJs());
|
||||
}
|
||||
}
|
||||
|
||||
function writeParameterInput($parameter, $options, $classes = []) {
|
||||
$value = '';
|
||||
if (isset($options[$parameter->getName()])) {
|
||||
|
@ -56,7 +71,7 @@
|
|||
<form id="files_external" class="section" data-encryption-enabled="<?php echo $_['encryptionEnabled']?'true': 'false'; ?>">
|
||||
<h2><?php p($l->t('External Storage')); ?></h2>
|
||||
<?php if (isset($_['dependencies']) and ($_['dependencies']<>'')) print_unescaped(''.$_['dependencies'].''); ?>
|
||||
<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['isAdminPage'])); ?>'>
|
||||
<table id="externalStorage" class="grid" data-admin='<?php print_unescaped(json_encode($_['visibilityType'] === BackendService::VISIBILITY_ADMIN)); ?>'>
|
||||
<thead>
|
||||
<tr>
|
||||
<th></th>
|
||||
|
@ -64,7 +79,7 @@
|
|||
<th><?php p($l->t('External storage')); ?></th>
|
||||
<th><?php p($l->t('Authentication')); ?></th>
|
||||
<th><?php p($l->t('Configuration')); ?></th>
|
||||
<?php if ($_['isAdminPage']) print_unescaped('<th>'.$l->t('Available for').'</th>'); ?>
|
||||
<?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN) print_unescaped('<th>'.$l->t('Available for').'</th>'); ?>
|
||||
<th> </th>
|
||||
<th> </th>
|
||||
</tr>
|
||||
|
@ -84,7 +99,9 @@
|
|||
<?php p($l->t('Add storage')); ?>
|
||||
</option>
|
||||
<?php
|
||||
$sortedBackends = $_['backends'];
|
||||
$sortedBackends = array_filter($_['backends'], function($backend) use ($_) {
|
||||
return $backend->isVisibleFor($_['visibilityType']);
|
||||
});
|
||||
uasort($sortedBackends, function($a, $b) {
|
||||
return strcasecmp($a->getText(), $b->getText());
|
||||
});
|
||||
|
@ -97,7 +114,7 @@
|
|||
</td>
|
||||
<td class="authentication" data-mechanisms='<?php p(json_encode($_['authMechanisms'])); ?>'></td>
|
||||
<td class="configuration"></td>
|
||||
<?php if ($_['isAdminPage']): ?>
|
||||
<?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
|
||||
<td class="applicable" align="right">
|
||||
<input type="hidden" class="applicableUsers" style="width:20em;" value="" />
|
||||
</td>
|
||||
|
@ -122,7 +139,7 @@
|
|||
</table>
|
||||
<br />
|
||||
|
||||
<?php if ($_['isAdminPage']): ?>
|
||||
<?php if ($_['visibilityType'] === BackendService::VISIBILITY_ADMIN): ?>
|
||||
<br />
|
||||
<input type="checkbox" name="allowUserMounting" id="allowUserMounting" class="checkbox"
|
||||
value="1" <?php if ($_['allowUserMounting'] == 'yes') print_unescaped(' checked="checked"'); ?> />
|
||||
|
@ -130,7 +147,12 @@
|
|||
|
||||
<p id="userMountingBackends"<?php if ($_['allowUserMounting'] != 'yes'): ?> class="hidden"<?php endif; ?>>
|
||||
<?php p($l->t('Allow users to mount the following external storage')); ?><br />
|
||||
<?php $i = 0; foreach ($_['userBackends'] as $backend): ?>
|
||||
<?php
|
||||
$userBackends = array_filter($_['backends'], function($backend) {
|
||||
return $backend->isAllowedVisibleFor(BackendService::VISIBILITY_PERSONAL);
|
||||
});
|
||||
?>
|
||||
<?php $i = 0; foreach ($userBackends as $backend): ?>
|
||||
<?php if ($deprecateTo = $backend->getDeprecateTo()): ?>
|
||||
<input type="hidden" id="allowUserMountingBackends<?php p($i); ?>" name="allowUserMountingBackends[]" value="<?php p($backend->getIdentifier()); ?>" data-deprecate-to="<?php p($deprecateTo->getIdentifier()); ?>" />
|
||||
<?php else: ?>
|
||||
|
|
Loading…
Reference in a new issue