Skip to content

Commit

Permalink
Store user bucket in preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
rullzer committed May 23, 2016
1 parent e03e492 commit abe338f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 20 deletions.
4 changes: 0 additions & 4 deletions .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,3 @@ Options -Indexes
<IfModule pagespeed_module>
ModPagespeed Off
</IfModule>
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 /core/templates/403.php
ErrorDocument 404 /core/templates/404.php
24 changes: 16 additions & 8 deletions lib/private/Files/Mount/ObjectHomeMountProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,23 @@ private function getMultiBucketObjectStoreConfig(IUser $user) {
}
$config['arguments']['user'] = $user;

/*
* Use any provided bucket argument as prefix
* and add the mapping from username => bucket
*/
if (!isset($config['arguments']['bucket'])) {
$config['arguments']['bucket'] = '';
$bucket = $this->config->getUserValue($user->getUID(), 'homeobjectstore', 'bucket', null);

if ($bucket === null) {
/*
* Use any provided bucket argument as prefix
* and add the mapping from username => bucket
*/
if (!isset($config['arguments']['bucket'])) {
$config['arguments']['bucket'] = '';
}
$mapper = new \OC\Files\ObjectStore\Mapper($user);
$config['arguments']['bucket'] .= $mapper->getBucket();

$this->config->setUserValue($user->getUID(), 'homeobjectstore', 'bucket', $config['arguments']['bucket']);
} else {
$config['arguments']['bucket'] = $bucket;
}
$mapper = new \OC\Files\ObjectStore\Mapper($user);
$config['arguments']['bucket'] .= $mapper->getBucket();

// instantiate object store implementation
$config['arguments']['objectstore'] = new $config['class']($config['arguments']);
Expand Down
90 changes: 82 additions & 8 deletions tests/lib/Files/Mount/ObjectHomeMountProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,29 @@ public function testMultiBucket() {
'class' => 'Test\Files\Mount\FakeObjectStore',
]);

$this->user->expects($this->once())
->method('getUID')
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());

$this->config->expects($this->once())
->method('getUserValue')
->with(
$this->equalTo('uid'),
$this->equalTo('homeobjectstore'),
$this->equalTo('bucket'),
$this->equalTo(null)
)->willReturn(null);

$this->config->expects($this->once())
->method('setUserValue')
->with(
$this->equalTo('uid'),
$this->equalTo('homeobjectstore'),
$this->equalTo('bucket'),
$this->equalTo('987'),
$this->equalTo(null)
);

$config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);

$this->assertArrayHasKey('class', $config);
Expand All @@ -90,11 +108,29 @@ public function testMultiBucketWithPrefix() {
],
]);

$this->user->expects($this->once())
->method('getUID')
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());

$this->config->expects($this->once())
->method('getUserValue')
->with(
$this->equalTo('uid'),
$this->equalTo('homeobjectstore'),
$this->equalTo('bucket'),
$this->equalTo(null)
)->willReturn(null);

$this->config->expects($this->once())
->method('setUserValue')
->with(
$this->equalTo('uid'),
$this->equalTo('homeobjectstore'),
$this->equalTo('bucket'),
$this->equalTo('myBucketPrefix987'),
$this->equalTo(null)
);

$config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);

$this->assertArrayHasKey('class', $config);
Expand All @@ -108,6 +144,46 @@ public function testMultiBucketWithPrefix() {
$this->assertEquals('myBucketPrefix987', $config['arguments']['bucket']);
}

public function testMultiBucketBucketAlreadySet() {
$this->config->expects($this->once())
->method('getSystemValue')
->with($this->equalTo('objectstore_multibucket'), '')
->willReturn([
'class' => 'Test\Files\Mount\FakeObjectStore',
'arguments' => [
'bucket' => 'myBucketPrefix',
],
]);

$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());

$this->config->expects($this->once())
->method('getUserValue')
->with(
$this->equalTo('uid'),
$this->equalTo('homeobjectstore'),
$this->equalTo('bucket'),
$this->equalTo(null)
)->willReturn('awesomeBucket1');

$this->config->expects($this->never())
->method('setUserValue');

$config = $this->invokePrivate($this->provider, 'getMultiBucketObjectStoreConfig', [$this->user, $this->loader]);

$this->assertArrayHasKey('class', $config);
$this->assertEquals($config['class'], 'Test\Files\Mount\FakeObjectStore');
$this->assertArrayHasKey('arguments', $config);
$this->assertArrayHasKey('user', $config['arguments']);
$this->assertSame($this->user, $config['arguments']['user']);
$this->assertArrayHasKey('objectstore', $config['arguments']);
$this->assertInstanceOf('Test\Files\Mount\FakeObjectStore', $config['arguments']['objectstore']);
$this->assertArrayHasKey('bucket', $config['arguments']);
$this->assertEquals('awesomeBucket1', $config['arguments']['bucket']);
}

public function testMultiBucketConfigFirst() {
$this->config->expects($this->once())
->method('getSystemValue')
Expand All @@ -116,8 +192,7 @@ public function testMultiBucketConfigFirst() {
'class' => 'Test\Files\Mount\FakeObjectStore',
]);

$this->user->expects($this->exactly(2))
->method('getUID')
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());

Expand All @@ -138,8 +213,7 @@ public function testMultiBucketConfigFirstFallBackSingle() {
'class' => 'Test\Files\Mount\FakeObjectStore',
]);

$this->user->expects($this->once())
->method('getUID')
$this->user->method('getUID')
->willReturn('uid');
$this->loader->expects($this->never())->method($this->anything());

Expand Down

0 comments on commit abe338f

Please sign in to comment.