Merge pull request #15363 from owncloud/ext-ocp
Use OCP classes as much as possible in files_external
This commit is contained in:
commit
b476c125c0
|
@ -373,7 +373,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'rb':
|
case 'rb':
|
||||||
$tmpFile = \OC_Helper::tmpFile();
|
$tmpFile = \OCP\Files::tmpFile();
|
||||||
self::$tmpFiles[$tmpFile] = $path;
|
self::$tmpFiles[$tmpFile] = $path;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -405,7 +405,7 @@ class AmazonS3 extends \OC\Files\Storage\Common {
|
||||||
} else {
|
} else {
|
||||||
$ext = '';
|
$ext = '';
|
||||||
}
|
}
|
||||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||||
if ($this->file_exists($path)) {
|
if ($this->file_exists($path)) {
|
||||||
$source = $this->fopen($path, 'r');
|
$source = $this->fopen($path, 'r');
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Api {
|
||||||
*/
|
*/
|
||||||
public static function getUserMounts($params) {
|
public static function getUserMounts($params) {
|
||||||
$entries = array();
|
$entries = array();
|
||||||
$user = \OC_User::getUser();
|
$user = \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
|
|
||||||
$mounts = \OC_Mount_Config::getAbsoluteMountPoints($user);
|
$mounts = \OC_Mount_Config::getAbsoluteMountPoints($user);
|
||||||
foreach($mounts as $mountPoint => $mount) {
|
foreach($mounts as $mountPoint => $mount) {
|
||||||
|
|
|
@ -124,10 +124,9 @@ class OC_Mount_Config {
|
||||||
self::addStorageIdToConfig($data['user']);
|
self::addStorageIdToConfig($data['user']);
|
||||||
$user = \OC::$server->getUserManager()->get($data['user']);
|
$user = \OC::$server->getUserManager()->get($data['user']);
|
||||||
if (!$user) {
|
if (!$user) {
|
||||||
\OCP\Util::writeLog(
|
\OC::$server->getLogger()->warning(
|
||||||
'files_external',
|
|
||||||
'Cannot init external mount points for non-existant user "' . $data['user'] . '".',
|
'Cannot init external mount points for non-existant user "' . $data['user'] . '".',
|
||||||
\OCP\Util::WARN
|
['app' => 'files_external']
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -161,6 +160,9 @@ class OC_Mount_Config {
|
||||||
// Load system mount points
|
// Load system mount points
|
||||||
$mountConfig = self::readData();
|
$mountConfig = self::readData();
|
||||||
|
|
||||||
|
$userObject = \OC::$server->getUserManager()->get($user);
|
||||||
|
$groupManager = \OC::$server->getGroupManager();
|
||||||
|
|
||||||
// Global mount points (is this redundant?)
|
// Global mount points (is this redundant?)
|
||||||
if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
|
if (isset($mountConfig[self::MOUNT_TYPE_GLOBAL])) {
|
||||||
foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
|
foreach ($mountConfig[self::MOUNT_TYPE_GLOBAL] as $mountPoint => $options) {
|
||||||
|
@ -207,7 +209,7 @@ class OC_Mount_Config {
|
||||||
// Group mount points
|
// Group mount points
|
||||||
if (isset($mountConfig[self::MOUNT_TYPE_GROUP])) {
|
if (isset($mountConfig[self::MOUNT_TYPE_GROUP])) {
|
||||||
foreach ($mountConfig[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
|
foreach ($mountConfig[self::MOUNT_TYPE_GROUP] as $group => $mounts) {
|
||||||
if (\OC_Group::inGroup($user, $group)) {
|
if ($groupManager->get($group)->inGroup($userObject)) {
|
||||||
foreach ($mounts as $mountPoint => $options) {
|
foreach ($mounts as $mountPoint => $options) {
|
||||||
$mountPoint = self::setUserVars($user, $mountPoint);
|
$mountPoint = self::setUserVars($user, $mountPoint);
|
||||||
foreach ($options as &$option) {
|
foreach ($options as &$option) {
|
||||||
|
@ -581,7 +583,7 @@ class OC_Mount_Config {
|
||||||
|
|
||||||
$result = self::getBackendStatus($class, $classOptions, $isPersonal);
|
$result = self::getBackendStatus($class, $classOptions, $isPersonal);
|
||||||
if ($result === self::STATUS_SUCCESS && $isNew) {
|
if ($result === self::STATUS_SUCCESS && $isNew) {
|
||||||
\OC_Hook::emit(
|
\OCP\Util::emitHook(
|
||||||
\OC\Files\Filesystem::CLASSNAME,
|
\OC\Files\Filesystem::CLASSNAME,
|
||||||
\OC\Files\Filesystem::signal_create_mount,
|
\OC\Files\Filesystem::signal_create_mount,
|
||||||
array(
|
array(
|
||||||
|
@ -627,7 +629,7 @@ class OC_Mount_Config {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints);
|
self::writeData($isPersonal ? OCP\User::getUser() : null, $mountPoints);
|
||||||
\OC_Hook::emit(
|
\OCP\Util::emitHook(
|
||||||
\OC\Files\Filesystem::CLASSNAME,
|
\OC\Files\Filesystem::CLASSNAME,
|
||||||
\OC\Files\Filesystem::signal_delete_mount,
|
\OC\Files\Filesystem::signal_delete_mount,
|
||||||
array(
|
array(
|
||||||
|
@ -669,10 +671,11 @@ class OC_Mount_Config {
|
||||||
*/
|
*/
|
||||||
public static function readData($user = null) {
|
public static function readData($user = null) {
|
||||||
if (isset($user)) {
|
if (isset($user)) {
|
||||||
$jsonFile = OC_User::getHome($user) . '/mount.json';
|
$jsonFile = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json';
|
||||||
} else {
|
} else {
|
||||||
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
|
$config = \OC::$server->getConfig();
|
||||||
$jsonFile = \OC_Config::getValue('mount_file', $datadir . '/mount.json');
|
$datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
|
||||||
|
$jsonFile = $config->getSystemValue('mount_file', $datadir . '/mount.json');
|
||||||
}
|
}
|
||||||
if (is_file($jsonFile)) {
|
if (is_file($jsonFile)) {
|
||||||
$mountPoints = json_decode(file_get_contents($jsonFile), true);
|
$mountPoints = json_decode(file_get_contents($jsonFile), true);
|
||||||
|
@ -691,10 +694,11 @@ class OC_Mount_Config {
|
||||||
*/
|
*/
|
||||||
public static function writeData($user, $data) {
|
public static function writeData($user, $data) {
|
||||||
if (isset($user)) {
|
if (isset($user)) {
|
||||||
$file = OC_User::getHome($user) . '/mount.json';
|
$file = \OC::$server->getUserManager()->get($user)->getHome() . '/mount.json';
|
||||||
} else {
|
} else {
|
||||||
$datadir = \OC_Config::getValue('datadirectory', \OC::$SERVERROOT . '/data/');
|
$config = \OC::$server->getConfig();
|
||||||
$file = \OC_Config::getValue('mount_file', $datadir . '/mount.json');
|
$datadir = $config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data/');
|
||||||
|
$file = $config->getSystemValue('mount_file', $datadir . '/mount.json');
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as &$applicables) {
|
foreach ($data as &$applicables) {
|
||||||
|
@ -752,7 +756,7 @@ class OC_Mount_Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function generateDependencyMessage($dependencies) {
|
private static function generateDependencyMessage($dependencies) {
|
||||||
$l = new \OC_L10N('files_external');
|
$l = \OC::$server->getL10N('files_external');
|
||||||
$dependencyMessage = '';
|
$dependencyMessage = '';
|
||||||
foreach ($dependencies as $module => $backends) {
|
foreach ($dependencies as $module => $backends) {
|
||||||
$dependencyGroup = array();
|
$dependencyGroup = array();
|
||||||
|
@ -789,7 +793,7 @@ class OC_Mount_Config {
|
||||||
* @param string $backend
|
* @param string $backend
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
private static function getSingleDependencyMessage(OC_L10N $l, $module, $backend) {
|
private static function getSingleDependencyMessage(\OCP\IL10N $l, $module, $backend) {
|
||||||
switch (strtolower($module)) {
|
switch (strtolower($module)) {
|
||||||
case 'curl':
|
case 'curl':
|
||||||
return $l->t('<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
|
return $l->t('<b>Note:</b> The cURL support in PHP is not enabled or installed. Mounting of %s is not possible. Please ask your system administrator to install it.', $backend);
|
||||||
|
|
|
@ -243,7 +243,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'rb':
|
case 'rb':
|
||||||
$tmpFile = \OC_Helper::tmpFile();
|
$tmpFile = \OCP\Files::tmpFile();
|
||||||
try {
|
try {
|
||||||
$data = $this->dropbox->getFile($path);
|
$data = $this->dropbox->getFile($path);
|
||||||
file_put_contents($tmpFile, $data);
|
file_put_contents($tmpFile, $data);
|
||||||
|
@ -269,7 +269,7 @@ class Dropbox extends \OC\Files\Storage\Common {
|
||||||
} else {
|
} else {
|
||||||
$ext = '';
|
$ext = '';
|
||||||
}
|
}
|
||||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||||
if ($this->file_exists($path)) {
|
if ($this->file_exists($path)) {
|
||||||
$source = $this->fopen($path, 'r');
|
$source = $this->fopen($path, 'r');
|
||||||
|
|
|
@ -428,7 +428,7 @@ class Google extends \OC\Files\Storage\Common {
|
||||||
$request = new \Google_Http_Request($downloadUrl, 'GET', null, null);
|
$request = new \Google_Http_Request($downloadUrl, 'GET', null, null);
|
||||||
$httpRequest = $this->client->getAuth()->authenticatedRequest($request);
|
$httpRequest = $this->client->getAuth()->authenticatedRequest($request);
|
||||||
if ($httpRequest->getResponseHttpCode() == 200) {
|
if ($httpRequest->getResponseHttpCode() == 200) {
|
||||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||||
$data = $httpRequest->getResponseBody();
|
$data = $httpRequest->getResponseBody();
|
||||||
file_put_contents($tmpFile, $data);
|
file_put_contents($tmpFile, $data);
|
||||||
return fopen($tmpFile, $mode);
|
return fopen($tmpFile, $mode);
|
||||||
|
@ -448,7 +448,7 @@ class Google extends \OC\Files\Storage\Common {
|
||||||
case 'x+':
|
case 'x+':
|
||||||
case 'c':
|
case 'c':
|
||||||
case 'c+':
|
case 'c+':
|
||||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||||
if ($this->file_exists($path)) {
|
if ($this->file_exists($path)) {
|
||||||
$source = $this->fopen($path, 'rb');
|
$source = $this->fopen($path, 'rb');
|
||||||
|
|
|
@ -310,7 +310,7 @@ class Swift extends \OC\Files\Storage\Common {
|
||||||
switch ($mode) {
|
switch ($mode) {
|
||||||
case 'r':
|
case 'r':
|
||||||
case 'rb':
|
case 'rb':
|
||||||
$tmpFile = \OC_Helper::tmpFile();
|
$tmpFile = \OCP\Files::tmpFile();
|
||||||
self::$tmpFiles[$tmpFile] = $path;
|
self::$tmpFiles[$tmpFile] = $path;
|
||||||
try {
|
try {
|
||||||
$object = $this->getContainer()->getObject($path);
|
$object = $this->getContainer()->getObject($path);
|
||||||
|
@ -348,7 +348,7 @@ class Swift extends \OC\Files\Storage\Common {
|
||||||
} else {
|
} else {
|
||||||
$ext = '';
|
$ext = '';
|
||||||
}
|
}
|
||||||
$tmpFile = \OC_Helper::tmpFile($ext);
|
$tmpFile = \OCP\Files::tmpFile($ext);
|
||||||
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
\OC\Files\Stream\Close::registerCallback($tmpFile, array($this, 'writeBack'));
|
||||||
if ($this->file_exists($path)) {
|
if ($this->file_exists($path)) {
|
||||||
$source = $this->fopen($path, 'r');
|
$source = $this->fopen($path, 'r');
|
||||||
|
|
|
@ -306,7 +306,7 @@ abstract class StoragesService {
|
||||||
*/
|
*/
|
||||||
protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
|
protected function triggerApplicableHooks($signal, $mountPoint, $mountType, $applicableArray) {
|
||||||
foreach ($applicableArray as $applicable) {
|
foreach ($applicableArray as $applicable) {
|
||||||
\OC_Hook::emit(
|
\OCP\Util::emitHook(
|
||||||
Filesystem::CLASSNAME,
|
Filesystem::CLASSNAME,
|
||||||
$signal,
|
$signal,
|
||||||
[
|
[
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php $_['mounts'] = array_merge($_['mounts'], array('' => array('id' => ''))); ?>
|
<?php $_['mounts'] = array_merge($_['mounts'], array('' => array('id' => ''))); ?>
|
||||||
<?php foreach ($_['mounts'] as $mount): ?>
|
<?php foreach ($_['mounts'] as $mount): ?>
|
||||||
<tr <?php print_unescaped(isset($mount['mountpoint']) ? 'class="'.OC_Util::sanitizeHTML($mount['class']).'"' : 'id="addMountPoint"'); ?> data-id="<?php p($mount['id']) ?>">
|
<tr <?php print_unescaped(isset($mount['mountpoint']) ? 'class="'.\OCP\Util::sanitizeHTML($mount['class']).'"' : 'id="addMountPoint"'); ?> data-id="<?php p($mount['id']) ?>">
|
||||||
<td class="status">
|
<td class="status">
|
||||||
<span></span>
|
<span></span>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -131,6 +131,9 @@ class Test_Mount_Config extends \Test\TestCase {
|
||||||
const TEST_GROUP2 = 'group2';
|
const TEST_GROUP2 = 'group2';
|
||||||
const TEST_GROUP2B = 'group2b';
|
const TEST_GROUP2B = 'group2b';
|
||||||
|
|
||||||
|
private $users = [];
|
||||||
|
private $groups = [];
|
||||||
|
|
||||||
protected function setUp() {
|
protected function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
|
@ -147,32 +150,43 @@ class Test_Mount_Config extends \Test\TestCase {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
\OC_User::createUser(self::TEST_USER1, self::TEST_USER1);
|
$userManager = \OC::$server->getUserManager();
|
||||||
\OC_User::createUser(self::TEST_USER2, self::TEST_USER2);
|
$groupManager = \OC::$server->getGroupManager();
|
||||||
|
|
||||||
\OC_Group::createGroup(self::TEST_GROUP1);
|
$this->users[self::TEST_USER1] = $userManager->createUser(
|
||||||
\OC_Group::createGroup(self::TEST_GROUP1B);
|
self::TEST_USER1,
|
||||||
\OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1);
|
self::TEST_USER1
|
||||||
\OC_Group::addToGroup(self::TEST_USER1, self::TEST_GROUP1B);
|
);
|
||||||
\OC_Group::createGroup(self::TEST_GROUP2);
|
$this->users[self::TEST_USER2] = $userManager->createUser(
|
||||||
\OC_Group::createGroup(self::TEST_GROUP2B);
|
self::TEST_USER2,
|
||||||
\OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2);
|
self::TEST_USER2
|
||||||
\OC_Group::addToGroup(self::TEST_USER2, self::TEST_GROUP2B);
|
);
|
||||||
|
|
||||||
\OC_User::setUserId(self::TEST_USER1);
|
$this->groups[self::TEST_GROUP1] = $groupManager->createGroup(self::TEST_GROUP1);
|
||||||
$this->userHome = \OC_User::getHome(self::TEST_USER1);
|
$this->groups[self::TEST_GROUP1B] = $groupManager->createGroup(self::TEST_GROUP1B);
|
||||||
|
$this->groups[self::TEST_GROUP2] = $groupManager->createGroup(self::TEST_GROUP2);
|
||||||
|
$this->groups[self::TEST_GROUP2B] = $groupManager->createGroup(self::TEST_GROUP2B);
|
||||||
|
|
||||||
|
$this->groups[self::TEST_GROUP1]->addUser($this->users[self::TEST_USER1]);
|
||||||
|
$this->groups[self::TEST_GROUP1B]->addUser($this->users[self::TEST_USER1]);
|
||||||
|
$this->groups[self::TEST_GROUP2]->addUser($this->users[self::TEST_USER2]);
|
||||||
|
$this->groups[self::TEST_GROUP2B]->addUser($this->users[self::TEST_USER2]);
|
||||||
|
|
||||||
|
\OC::$server->getUserSession()->setUser($this->users[self::TEST_USER1]);
|
||||||
|
$this->userHome = $this->users[self::TEST_USER1]->getHome();
|
||||||
@mkdir($this->userHome);
|
@mkdir($this->userHome);
|
||||||
|
|
||||||
$this->dataDir = \OC_Config::getValue(
|
$config = \OC::$server->getConfig();
|
||||||
|
$this->dataDir = $config->getSystemValue(
|
||||||
'datadirectory',
|
'datadirectory',
|
||||||
\OC::$SERVERROOT . '/data/'
|
\OC::$SERVERROOT . '/data/'
|
||||||
);
|
);
|
||||||
$this->oldAllowedBackends = OCP\Config::getAppValue(
|
$this->oldAllowedBackends = $config->getAppValue(
|
||||||
'files_external',
|
'files_external',
|
||||||
'user_mounting_backends',
|
'user_mounting_backends',
|
||||||
''
|
''
|
||||||
);
|
);
|
||||||
OCP\Config::setAppValue(
|
$config->setAppValue(
|
||||||
'files_external',
|
'files_external',
|
||||||
'user_mounting_backends',
|
'user_mounting_backends',
|
||||||
'Test_Mount_Config_Dummy_Storage'
|
'Test_Mount_Config_Dummy_Storage'
|
||||||
|
@ -186,16 +200,19 @@ class Test_Mount_Config extends \Test\TestCase {
|
||||||
Test_Mount_Config_Hook_Test::clear();
|
Test_Mount_Config_Hook_Test::clear();
|
||||||
OC_Mount_Config::$skipTest = false;
|
OC_Mount_Config::$skipTest = false;
|
||||||
|
|
||||||
\OC_User::deleteUser(self::TEST_USER2);
|
foreach ($this->users as $user) {
|
||||||
\OC_User::deleteUser(self::TEST_USER1);
|
$user->delete();
|
||||||
\OC_Group::deleteGroup(self::TEST_GROUP1);
|
}
|
||||||
\OC_Group::deleteGroup(self::TEST_GROUP1B);
|
foreach ($this->groups as $group) {
|
||||||
\OC_Group::deleteGroup(self::TEST_GROUP2);
|
$group->delete();
|
||||||
\OC_Group::deleteGroup(self::TEST_GROUP2B);
|
}
|
||||||
|
$this->users = [];
|
||||||
|
$this->groups = [];
|
||||||
|
|
||||||
@unlink($this->dataDir . '/mount.json');
|
@unlink($this->dataDir . '/mount.json');
|
||||||
|
|
||||||
OCP\Config::setAppValue(
|
$config = \OC::$server->getConfig();
|
||||||
|
$config->setAppValue(
|
||||||
'files_external',
|
'files_external',
|
||||||
'user_mounting_backends',
|
'user_mounting_backends',
|
||||||
$this->oldAllowedBackends
|
$this->oldAllowedBackends
|
||||||
|
@ -778,7 +795,7 @@ class Test_Mount_Config extends \Test\TestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
// check mount points in the perspective of user $testUser
|
// check mount points in the perspective of user $testUser
|
||||||
\OC_User::setUserId($testUser);
|
\OC::$server->getUserSession()->setUser($this->users[$testUser]);
|
||||||
|
|
||||||
$mountPoints = OC_Mount_Config::getAbsoluteMountPoints($testUser);
|
$mountPoints = OC_Mount_Config::getAbsoluteMountPoints($testUser);
|
||||||
if ($expectVisible) {
|
if ($expectVisible) {
|
||||||
|
@ -1116,7 +1133,7 @@ class Test_Mount_Config extends \Test\TestCase {
|
||||||
);
|
);
|
||||||
|
|
||||||
// Ensure other user can read mount points
|
// Ensure other user can read mount points
|
||||||
\OC_User::setUserId(self::TEST_USER2);
|
\OC::$server->getUserSession()->setUser($this->users[self::TEST_USER2]);
|
||||||
$mountPointsMe = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER2);
|
$mountPointsMe = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER2);
|
||||||
$mountPointsOther = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
|
$mountPointsOther = OC_Mount_Config::getAbsoluteMountPoints(self::TEST_USER1);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue