$shareWith = (string) $_POST['shareWith']; } $return = OCP\Share::unshare((string) $_POST['itemType'], (string) $_POST['itemSource'], (int) $_POST['shareType'], $shareWith); $return ? OC_JSON::success() : OC_JSON::error(); } break; case 'setPermissions': if (isset($_POST['shareType']) && isset($_POST['shareWith']) && isset($_POST['permissions'])) { $return = OCP\Share::setPermissions((string) $_POST['itemType'], (string) $_POST['itemSource'], (int) $_POST['shareType'], (string) $_POST['shareWith'], (int) $_POST['permissions']); $return ? OC_JSON::success() : OC_JSON::error(); } break; case 'setExpirationDate': if (isset($_POST['date'])) { try { $return = OCP\Share::setExpirationDate((string) $_POST['itemType'], (string) $_POST['itemSource'], (string) $_POST['date']); $return ? OC_JSON::success() : OC_JSON::error(); } catch (\Exception $e) { OC_JSON::error(array('data' => array('message' => $e->getMessage()))); } } break; case 'informRecipients': $l = \OC::$server->getL10N('core'); $shareType = (int) $_POST['shareType']; $itemType = (string) $_POST['itemType']; $itemSource = (string) $_POST['itemSource']; $recipient = (string) $_POST['recipient']; if ($shareType === \OCP\Share::SHARE_TYPE_USER) { $recipientList[] = $recipient; } elseif ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
public function testShareItemWithLink() { OC_User::setUserId($this->user1); $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); $this->assertInternalType('string', $token, 'Failed asserting that user 1 successfully shared text.txt as link with token.'); // testGetShareByTokenNoExpiration $row = $this->getShareByValidToken($token); $this->assertEmpty($row['expiration'], 'Failed asserting that the returned row does not have an expiration date.'); // testGetShareByTokenExpirationValid $this->assertTrue(OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture, ''), 'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.'); $row = $this->getShareByValidToken($token); $this->assertNotEmpty($row['expiration'], 'Failed asserting that the returned row has an expiration date.'); // manipulate share table and set expire date to the past $query = \OC_DB::prepare('UPDATE `*PREFIX*share` SET `expiration` = ? WHERE `item_type` = ? AND `item_source` = ? AND `uid_owner` = ? AND `share_type` = ?'); $query->bindValue(1, new \DateTime($this->dateInPast), 'datetime'); $query->bindValue(2, 'test'); $query->bindValue(3, 'test.txt'); $query->bindValue(4, $this->user1); $query->bindValue(5, \OCP\Share::SHARE_TYPE_LINK); $query->execute(); $this->assertFalse(OCP\Share::getShareByToken($token), 'Failed asserting that an expired share could not be found.'); }
/** * Ensure that we do not allow removing a an expiration date from a link share if this * is enforced by the settings. */ public function testClearExpireDateWhileEnforced() { OC_User::setUserId($this->user1); \OC::$server->getAppConfig()->setValue('core', 'shareapi_default_expire_date', 'yes'); \OC::$server->getAppConfig()->setValue('core', 'shareapi_expire_after_n_days', '2'); \OC::$server->getAppConfig()->setValue('core', 'shareapi_enforce_expire_date', 'yes'); $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, \OCP\Constants::PERMISSION_READ); $this->assertInternalType('string', $token, 'Failed asserting that user 1 successfully shared text.txt as link with token.'); $setExpireDateFailed = false; try { $this->assertTrue(OCP\Share::setExpirationDate('test', 'test.txt', '', ''), 'Failed asserting that user 1 successfully set an expiration date for the test.txt share.'); } catch (\Exception $e) { $setExpireDateFailed = true; } $this->assertTrue($setExpireDateFailed); \OC::$server->getAppConfig()->deleteKey('core', 'shareapi_default_expire_date'); \OC::$server->getAppConfig()->deleteKey('core', 'shareapi_expire_after_n_days'); \OC::$server->getAppConfig()->deleteKey('core', 'shareapi_enforce_expire_date'); }
public function testShareItemWithLink() { OC_User::setUserId($this->user1); $token = OCP\Share::shareItem('test', 'test.txt', OCP\Share::SHARE_TYPE_LINK, null, OCP\PERMISSION_READ); $this->assertInternalType('string', $token, 'Failed asserting that user 1 successfully shared text.txt as link with token.'); // testGetShareByTokenNoExpiration $row = $this->getShareByValidToken($token); $this->assertEmpty($row['expiration'], 'Failed asserting that the returned row does not have an expiration date.'); // testGetShareByTokenExpirationValid $this->assertTrue(OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInFuture), 'Failed asserting that user 1 successfully set a future expiration date for the test.txt share.'); $row = $this->getShareByValidToken($token); $this->assertNotEmpty($row['expiration'], 'Failed asserting that the returned row has an expiration date.'); // testGetShareByTokenExpirationExpired $this->assertTrue(OCP\Share::setExpirationDate('test', 'test.txt', $this->dateInPast), 'Failed asserting that user 1 successfully set a past expiration date for the test.txt share.'); $this->assertFalse(OCP\Share::getShareByToken($token), 'Failed asserting that an expired share could not be found.'); }