Merge pull request #22416 from owncloud/fix_22402
Return proper error string if sharing for this user is disabled
This commit is contained in:
commit
c6fef52939
2 changed files with 15 additions and 42 deletions
|
@ -455,18 +455,16 @@ class Manager implements IManager {
|
||||||
* Check if the user that is sharing can actually share
|
* Check if the user that is sharing can actually share
|
||||||
*
|
*
|
||||||
* @param \OCP\Share\IShare $share
|
* @param \OCP\Share\IShare $share
|
||||||
* @return bool
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
protected function canShare(\OCP\Share\IShare $share) {
|
protected function canShare(\OCP\Share\IShare $share) {
|
||||||
if (!$this->shareApiEnabled()) {
|
if (!$this->shareApiEnabled()) {
|
||||||
return false;
|
throw new \Exception('The share API is disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->sharingDisabledForUser($share->getSharedBy())) {
|
if ($this->sharingDisabledForUser($share->getSharedBy())) {
|
||||||
return false;
|
throw new \Exception('You are not allowed to share');
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -479,9 +477,7 @@ class Manager implements IManager {
|
||||||
* TODO: handle link share permissions or check them
|
* TODO: handle link share permissions or check them
|
||||||
*/
|
*/
|
||||||
public function createShare(\OCP\Share\IShare $share) {
|
public function createShare(\OCP\Share\IShare $share) {
|
||||||
if (!$this->canShare($share)) {
|
$this->canShare($share);
|
||||||
throw new \Exception('The Share API is disabled');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->generalCreateChecks($share);
|
$this->generalCreateChecks($share);
|
||||||
|
|
||||||
|
@ -592,9 +588,7 @@ class Manager implements IManager {
|
||||||
public function updateShare(\OCP\Share\IShare $share) {
|
public function updateShare(\OCP\Share\IShare $share) {
|
||||||
$expirationDateUpdated = false;
|
$expirationDateUpdated = false;
|
||||||
|
|
||||||
if (!$this->canShare($share)) {
|
$this->canShare($share);
|
||||||
throw new \Exception('The Share API is disabled');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$originalShare = $this->getShareById($share->getFullId());
|
$originalShare = $this->getShareById($share->getFullId());
|
||||||
|
|
|
@ -1404,28 +1404,21 @@ class ManagerTest extends \Test\TestCase {
|
||||||
->setMethods(['sharingDisabledForUser'])
|
->setMethods(['sharingDisabledForUser'])
|
||||||
->getMock();
|
->getMock();
|
||||||
|
|
||||||
$manager->method('sharingDisabledForUser')->willReturn($disabledForUser);
|
$manager->method('sharingDisabledForUser')
|
||||||
|
->with('user')
|
||||||
|
->willReturn($disabledForUser);
|
||||||
|
|
||||||
$user = $this->getMock('\OCP\IUser');
|
|
||||||
$share = $this->manager->newShare();
|
$share = $this->manager->newShare();
|
||||||
$share->setSharedBy('user');
|
$share->setSharedBy('user');
|
||||||
|
|
||||||
$res = $this->invokePrivate($manager, 'canShare', [$share]);
|
$exception = false;
|
||||||
$this->assertEquals($expected, $res);
|
try {
|
||||||
}
|
$res = $this->invokePrivate($manager, 'canShare', [$share]);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$exception = true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
$this->assertEquals($expected, !$exception);
|
||||||
* @expectedException Exception
|
|
||||||
* @expectedExceptionMessage The Share API is disabled
|
|
||||||
*/
|
|
||||||
public function testCreateShareCantShare() {
|
|
||||||
$manager = $this->createManagerMock()
|
|
||||||
->setMethods(['canShare'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$manager->expects($this->once())->method('canShare')->willReturn(false);
|
|
||||||
$share = $this->manager->newShare();
|
|
||||||
$manager->createShare($share);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCreateShareUser() {
|
public function testCreateShareUser() {
|
||||||
|
@ -1943,20 +1936,6 @@ class ManagerTest extends \Test\TestCase {
|
||||||
$this->assertTrue($this->manager->checkPassword($share, 'password'));
|
$this->assertTrue($this->manager->checkPassword($share, 'password'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException Exception
|
|
||||||
* @expectedExceptionMessage The Share API is disabled
|
|
||||||
*/
|
|
||||||
public function testUpdateShareCantShare() {
|
|
||||||
$manager = $this->createManagerMock()
|
|
||||||
->setMethods(['canShare'])
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
$manager->expects($this->once())->method('canShare')->willReturn(false);
|
|
||||||
$share = $this->manager->newShare();
|
|
||||||
$manager->updateShare($share);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
* @expectedExceptionMessage Can't change share type
|
* @expectedExceptionMessage Can't change share type
|
||||||
|
|
Loading…
Reference in a new issue