\OC::$server->getSecureRandom(),
\OC::$server->getHasher(),
\OC::$server->getMountManager(),
- \OC::$server->getGroupManager()
+ \OC::$server->getGroupManager(),
+ \OC::$server->getL10N('core')
),
\OC::$server->getGroupManager(),
\OC::$server->getUserManager(),
}
$share->setPermissions(
- \OCP\Constants::PERMISSION_READ |
- \OCP\Constants::PERMISSION_CREATE |
- \OCP\Constants::PERMISSION_UPDATE
+ \OCP\Constants::PERMISSION_READ |
+ \OCP\Constants::PERMISSION_CREATE |
+ \OCP\Constants::PERMISSION_UPDATE
);
} else {
$share->setPermissions(\OCP\Constants::PERMISSION_READ);
try {
$share = $this->shareManager->createShare($share);
- } catch (\Exception $e) {
+ } catch (\OC\HintException $e) {
+ $code = $e->getCode() === 0 ? 403 : $e->getCode();
+ return new \OC_OCS_Result(null, $code, $e->getHint());
+ }catch (\Exception $e) {
return new \OC_OCS_Result(null, 403, $e->getMessage());
}
use OCP\IConfig;
+use OCP\IL10N;
use OCP\ILogger;
use OCP\Security\ISecureRandom;
use OCP\Security\IHasher;
use OCP\Files\Mount\IMountManager;
use OCP\IGroupManager;
+use OCP\Files\File;
+use OCP\Files\Folder;
+use OCP\IUser;
use OC\Share20\Exception\ShareNotFound;
*/
class Manager {
- /**
- * @var IShareProvider[]
- */
+ /** @var IShareProvider[] */
private $defaultProvider;
/** @var ILogger */
/** @var IGroupManager */
private $groupManager;
+ /** @var IL10N */
+ private $l;
+
/**
* Manager constructor.
*
* @param IHasher $hasher
* @param IMountManager $mountManager
* @param IGroupManager $groupManager
+ * @param IL10N $l
*/
public function __construct(
ILogger $logger,
ISecureRandom $secureRandom,
IHasher $hasher,
IMountManager $mountManager,
- IGroupManager $groupManager
+ IGroupManager $groupManager,
+ IL10N $l
) {
$this->logger = $logger;
$this->config = $config;
$this->hasher = $hasher;
$this->mountManager = $mountManager;
$this->groupManager = $groupManager;
+ $this->l = $l;
// TEMP SOLUTION JUST TO GET STARTED
$this->defaultProvider = $defaultProvider;
*
* @param \DateTime $expireDate The current expiration date (can be null)
* @return \DateTime|null The expiration date or null if $expireDate was null and it is not required
+ * @throws \OC\HintException
*/
protected function validateExpiredate($expireDate) {
$date = new \DateTime();
$date->setTime(0, 0, 0);
if ($date >= $expireDate) {
- throw new \InvalidArgumentException('Expiration date is in the past');
+ $message = $this->l->t('Expiration date is in the past');
+ throw new \OC\HintException($message, $message, 404);
}
}
$date->setTime(0, 0, 0);
$date->add(new \DateInterval('P' . $this->shareApiLinkDefaultExpireDays() . 'D'));
if ($date < $expireDate) {
- throw new \InvalidArgumentException('Cannot set expiration date more than ' . $this->shareApiLinkDefaultExpireDays() . ' in the future');
+ $message = $this->l->t('Cannot set expiration date more than %s days in the future', [$this->shareApiLinkDefaultExpireDays()]);
+ throw new \OC\HintException($message, $message, 404);
}
return $expireDate;
* For now ignore a set token.
*/
$share->setToken(
- $this->secureRandom->getMediumStrengthGenerator()->generate(
+ $this->secureRandom->generate(
\OC\Share\Constants::TOKEN_LENGTH,
\OCP\Security\ISecureRandom::CHAR_LOWER.
\OCP\Security\ISecureRandom::CHAR_UPPER.
use OC\Share20\Manager;
use OC\Share20\Exception;
+use OCP\IL10N;
use OCP\ILogger;
use OCP\IConfig;
use OC\Share20\IShareProvider;
/** @var IGroupManager */
protected $groupManager;
+ /** @var IL10N */
+ protected $l;
+
public function setUp() {
$this->logger = $this->getMock('\OCP\ILogger');
$this->mountManager = $this->getMock('\OCP\Files\Mount\IMountManager');
$this->groupManager = $this->getMock('\OCP\IGroupManager');
+ $this->l = $this->getMock('\OCP\IL10N');
+ $this->l->method('t')
+ ->will($this->returnCallback(function($text, $parameters = []) {
+ return vsprintf($text, $parameters);
+ }));
+
$this->manager = new Manager(
$this->logger,
$this->config,
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l
);
}
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l
])
->setMethods(['getShareById', 'deleteChildren'])
->getMock();
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l,
])
->setMethods(['getShareById'])
->getMock();
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l,
])
->setMethods(['deleteShare'])
->getMock();
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException \OC\HintException
* @expectedExceptionMessage Expiration date is in the past
*/
public function testValidateExpiredateInPast() {
$this->invokePrivate($this->manager, 'validateExpiredate', [null]);
}
- /**
- * @expectedException InvalidArgumentException
- * @expectedExceptionMessage Cannot set expiration date more than 3 in the future
- */
public function testValidateExpiredateEnforceToFarIntoFuture() {
// Expire date in the past
$future = new \DateTime();
['core', 'shareapi_expire_after_n_days', '7', '3'],
]));
- $this->invokePrivate($this->manager, 'validateExpiredate', [$future]);
+ try {
+ $this->invokePrivate($this->manager, 'validateExpiredate', [$future]);
+ } catch (\OC\HintException $e) {
+ $this->assertEquals('Cannot set expiration date more than 3 days in the future', $e->getMessage());
+ $this->assertEquals('Cannot set expiration date more than 3 days in the future', $e->getHint());
+ $this->assertEquals(404, $e->getCode());
+ }
}
public function testValidateExpiredateEnforceValid() {
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l,
])
->setMethods(['isSharingDisabledForUser'])
->getMock();
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l,
])
->setMethods(['canShare'])
->getMock();
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l,
])
->setMethods(['canShare', 'generalCreateChecks', 'userCreateChecks', 'pathCreateChecks'])
->getMock();
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l,
])
->setMethods(['canShare', 'generalCreateChecks', 'groupCreateChecks', 'pathCreateChecks'])
->getMock();
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l,
])
->setMethods([
'canShare',
$this->secureRandom,
$this->hasher,
$this->mountManager,
- $this->groupManager
+ $this->groupManager,
+ $this->l,
])
->setMethods([
'canShare',