'uid_owner' => $share->getSharedBy()->getUID(),
'displayname_owner' => $share->getSharedBy()->getDisplayName(),
'permissions' => $share->getPermissions(),
- 'stime' => $share->getShareTime(),
- 'parent' => $share->getParent(),
+ 'stime' => $share->getShareTime()->getTimestamp(),
+ 'parent' => null,
'expiration' => null,
'token' => null,
'uid_file_owner' => $share->getShareOwner()->getUID(),
'displayname_file_owner' => $share->getShareOwner()->getDisplayName(),
];
- $path = $share->getPath();
- $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID())->getRelativePath($path->getPath());
- if ($path instanceOf \OCP\Files\Folder) {
+ $node = $share->getNode();
+ $result['path'] = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID())->getRelativePath($node->getPath());
+ if ($node instanceOf \OCP\Files\Folder) {
$result['item_type'] = 'folder';
} else {
$result['item_type'] = 'file';
}
- $result['storage_id'] = $path->getStorage()->getId();
- $result['storage'] = $path->getStorage()->getCache()->getNumericStorageId();
- $result['item_source'] = $path->getId();
- $result['file_source'] = $path->getId();
- $result['file_parent'] = $path->getParent()->getId();
+ $result['storage_id'] = $node->getStorage()->getId();
+ $result['storage'] = $node->getStorage()->getCache()->getNumericStorageId();
+ $result['item_source'] = $node->getId();
+ $result['file_source'] = $node->getId();
+ $result['file_parent'] = $node->getParent()->getId();
$result['file_target'] = $share->getTarget();
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
return new \OC_OCS_Result(null, 404, 'wrong path, file/folder doesn\'t exist');
}
- $share->setPath($path);
+ $share->setNode($path);
// Parse permissions (if available)
$permissions = $this->request->getParam('permissions', null);
}
// We can't get the path of a file share
- if ($share->getPath() instanceof \OCP\Files\File && $path !== '') {
+ if ($share->getNode() instanceof \OCP\Files\File && $path !== '') {
throw new NotFoundException();
}
$rootFolder = null;
- if ($share->getPath() instanceof \OCP\Files\Folder) {
+ if ($share->getNode() instanceof \OCP\Files\Folder) {
/** @var \OCP\Files\Folder $rootFolder */
- $rootFolder = $share->getPath();
+ $rootFolder = $share->getNode();
try {
$path = $rootFolder->get($path);
$shareTmpl = [];
$shareTmpl['displayName'] = $share->getShareOwner()->getDisplayName();
$shareTmpl['owner'] = $share->getShareOwner()->getUID();
- $shareTmpl['filename'] = $share->getPath()->getName();
+ $shareTmpl['filename'] = $share->getNode()->getName();
$shareTmpl['directory_path'] = $share->getTarget();
- $shareTmpl['mimetype'] = $share->getPath()->getMimetype();
- $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getPath()->getMimetype());
+ $shareTmpl['mimetype'] = $share->getNode()->getMimetype();
+ $shareTmpl['previewSupported'] = $this->previewManager->isMimeSupported($share->getNode()->getMimetype());
$shareTmpl['dirToken'] = $token;
$shareTmpl['sharingToken'] = $token;
$shareTmpl['server2serversharing'] = Helper::isOutgoingServer2serverShareEnabled();
$shareTmpl['protected'] = $share->getPassword() !== null ? 'true' : 'false';
$shareTmpl['dir'] = '';
- $shareTmpl['nonHumanFileSize'] = $share->getPath()->getSize();
- $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getPath()->getSize());
+ $shareTmpl['nonHumanFileSize'] = $share->getNode()->getSize();
+ $shareTmpl['fileSize'] = \OCP\Util::humanFileSize($share->getNode()->getSize());
// Show file list
- if ($share->getPath() instanceof \OCP\Files\Folder) {
+ if ($share->getNode() instanceof \OCP\Files\Folder) {
$shareTmpl['dir'] = $rootFolder->getRelativePath($path->getPath());
/*
* The OC_Util methods require a view. This just uses the node API
*/
- $freeSpace = $share->getPath()->getStorage()->free_space($share->getPath()->getInternalPath());
+ $freeSpace = $share->getNode()->getStorage()->free_space($share->getNode()->getInternalPath());
if ($freeSpace !== \OCP\Files\FileInfo::SPACE_UNKNOWN) {
$freeSpace = max($freeSpace, 0);
} else {
}
$userFolder = $this->rootFolder->getUserFolder($share->getShareOwner()->getUID());
- $originalSharePath = $userFolder->getRelativePath($share->getPath()->getPath());
+ $originalSharePath = $userFolder->getRelativePath($share->getNode()->getPath());
// Single file share
- if ($share->getPath() instanceof \OCP\Files\File) {
+ if ($share->getNode() instanceof \OCP\Files\File) {
// Single file download
$event = $this->activityManager->generateEvent();
$event->setApp('files_sharing')
->setType(Activity::TYPE_PUBLIC_LINKS)
- ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($share->getPath()->getPath())])
+ ->setSubject(Activity::SUBJECT_PUBLIC_SHARED_FILE_DOWNLOADED, [$userFolder->getRelativePath($share->getNode()->getPath())])
->setAffectedUser($share->getShareOwner()->getUID())
- ->setObject('files', $share->getPath()->getId(), $userFolder->getRelativePath($share->getPath()->getPath()));
+ ->setObject('files', $share->getNode()->getId(), $userFolder->getRelativePath($share->getNode()->getPath()));
$this->activityManager->publish($event);
}
// Directory share
else {
/** @var \OCP\Files\Folder $node */
- $node = $share->getPath();
+ $node = $share->getNode();
// Try to get the path
if ($path !== '') {
$share->method('getSharedWith')->willReturn($sharedWith);
$share->method('getSharedBy')->willReturn($sharedBy);
$share->method('getShareOwner')->willReturn($shareOwner);
- $share->method('getPath')->willReturn($path);
+ $share->method('getNode')->willReturn($path);
$share->method('getPermissions')->willReturn($permissions);
- $share->method('getShareTime')->willReturn($shareTime);
+ $time = new \DateTime();
+ $time->setTimestamp($shareTime);
+ $share->method('getShareTime')->willReturn($time);
$share->method('getExpirationDate')->willReturn($expiration);
- $share->method('getParent')->willReturn($parent);
$share->method('getTarget')->willReturn($target);
$share->method('getMailSend')->willReturn($mail_send);
$share->method('getToken')->willReturn($token);
'expiration' => null,
'permissions' => 4,
'stime' => 5,
- 'parent' => 6,
+ 'parent' => null,
'storage_id' => 'STORAGE',
'path' => 'file',
'storage' => 101,
'expiration' => null,
'permissions' => 4,
'stime' => 5,
- 'parent' => 6,
+ 'parent' => null,
'storage_id' => 'STORAGE',
'path' => 'folder',
'storage' => 101,
'expiration' => '2000-01-02 00:00:00',
'permissions' => 4,
'stime' => 5,
- 'parent' => 6,
+ 'parent' => null,
'storage_id' => 'STORAGE',
'path' => 'folder',
'storage' => 101,
$share->method('getId')->willReturn('42');
$share->method('getPassword')->willReturn('password');
$share->method('getShareOwner')->willReturn($owner);
- $share->method('getPath')->willReturn($file);
+ $share->method('getNode')->willReturn($file);
$share->method('getTarget')->willReturn('/file1.txt');
$this->session->method('exists')->with('public_link_authenticated')->willReturn(true);
// Set what is shares
$qb->setValue('item_type', $qb->createParameter('itemType'));
- if ($share->getPath() instanceof \OCP\Files\File) {
+ if ($share->getNode() instanceof \OCP\Files\File) {
$qb->setParameter('itemType', 'file');
} else {
$qb->setParameter('itemType', 'folder');
}
// Set the file id
- $qb->setValue('item_source', $qb->createNamedParameter($share->getPath()->getId()));
- $qb->setValue('file_source', $qb->createNamedParameter($share->getPath()->getId()));
+ $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
+ $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
// set the permissions
$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
- ->set('item_source', $qb->createNamedParameter($share->getPath()->getId()))
- ->set('file_source', $qb->createNamedParameter($share->getPath()->getId()))
+ ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
+ ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->execute();
} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
$qb = $this->dbConn->getQueryBuilder();
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
- ->set('item_source', $qb->createNamedParameter($share->getPath()->getId()))
- ->set('file_source', $qb->createNamedParameter($share->getPath()->getId()))
+ ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
+ ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->execute();
/*
->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
- ->set('item_source', $qb->createNamedParameter($share->getPath()->getId()))
- ->set('file_source', $qb->createNamedParameter($share->getPath()->getId()))
+ ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
+ ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->execute();
/*
->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()->getUID()))
->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()->getUID()))
->set('permissions', $qb->createNamedParameter($share->getPermissions()))
- ->set('item_source', $qb->createNamedParameter($share->getPath()->getId()))
- ->set('file_source', $qb->createNamedParameter($share->getPath()->getId()))
+ ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
+ ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
->set('token', $qb->createNamedParameter($share->getToken()))
->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
->execute();
if ($data === false) {
$qb = $this->dbConn->getQueryBuilder();
- $type = $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder';
+ $type = $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder';
//Insert new share
$qb->insert('share')
'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()->getUID()),
'parent' => $qb->createNamedParameter($share->getId()),
'item_type' => $qb->createNamedParameter($type),
- 'item_source' => $qb->createNamedParameter($share->getPath()->getId()),
- 'file_source' => $qb->createNamedParameter($share->getPath()->getId()),
+ 'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
+ 'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
'file_target' => $qb->createNamedParameter($share->getTarget()),
'permissions' => $qb->createNamedParameter(0),
- 'stime' => $qb->createNamedParameter($share->getShareTime()),
+ 'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
])->execute();
} else if ($data['permissions'] !== 0) {
* Get share by id
*
* @param int $id
- * @return IShare
+ * @return \OCP\Share\IShare
* @throws ShareNotFound
*/
public function getShareById($id) {
* Create a share object from an database row
*
* @param mixed[] $data
- * @return Share
+ * @return \OCP\Share\IShare
* @throws InvalidShare
*/
private function createShare($data) {
->setShareType((int)$data['share_type'])
->setPermissions((int)$data['permissions'])
->setTarget($data['file_target'])
- ->setShareTime((int)$data['stime'])
->setMailSend((bool)$data['mail_send']);
+ $shareTime = new \DateTime();
+ $shareTime->setTimestamp((int)$data['stime']);
+ $share->setShareTime($shareTime);
+
if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
$sharedWith = $this->userManager->get($data['share_with']);
if ($sharedWith === null) {
}
$path = $this->getNode($share->getShareOwner(), (int)$data['file_source']);
- $share->setPath($path);
+ $share->setNode($path);
if ($data['expiration'] !== null) {
$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
}
// The path should be set
- if ($share->getPath() === null) {
+ if ($share->getNode() === null) {
throw new \InvalidArgumentException('Path should be set');
}
// And it should be a file or a folder
- if (!($share->getPath() instanceof \OCP\Files\File) &&
- !($share->getPath() instanceof \OCP\Files\Folder)) {
+ if (!($share->getNode() instanceof \OCP\Files\File) &&
+ !($share->getNode() instanceof \OCP\Files\Folder)) {
throw new \InvalidArgumentException('Path should be either a file or a folder');
}
// Check if we actually have share permissions
- if (!$share->getPath()->isShareable()) {
- $message_t = $this->l->t('You are not allowed to share %s', [$share->getPath()->getPath()]);
+ if (!$share->getNode()->isShareable()) {
+ $message_t = $this->l->t('You are not allowed to share %s', [$share->getNode()->getPath()]);
throw new HintException($message_t, $message_t, 404);
}
}
// Check that we do not share with more permissions than we have
- if ($share->getPermissions() & ~$share->getPath()->getPermissions()) {
- $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getPath()->getPath()]);
+ if ($share->getPermissions() & ~$share->getNode()->getPermissions()) {
+ $message_t = $this->l->t('Cannot increase permissions of %s', [$share->getNode()->getPath()]);
throw new HintException($message_t, $message_t, 404);
}
* Also this is not what we want in the future.. then we want to squash identical shares.
*/
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_USER);
- $existingShares = $provider->getSharesByPath($share->getPath());
+ $existingShares = $provider->getSharesByPath($share->getNode());
foreach($existingShares as $existingShare) {
// Ignore if it is the same share
if ($existingShare->getFullId() === $share->getFullId()) {
* Also this is not what we want in the future.. then we want to squash identical shares.
*/
$provider = $this->factory->getProviderForType(\OCP\Share::SHARE_TYPE_GROUP);
- $existingShares = $provider->getSharesByPath($share->getPath());
+ $existingShares = $provider->getSharesByPath($share->getNode());
foreach($existingShares as $existingShare) {
if ($existingShare->getFullId() === $share->getFullId()) {
continue;
return false;
}
- if ($this->isSharingDisabledForUser($share->getSharedBy())) {
+ if ($this->sharingDisabledForUser($share->getSharedBy())) {
return false;
}
}
// Verify if there are any issues with the path
- $this->pathCreateChecks($share->getPath());
+ $this->pathCreateChecks($share->getNode());
// On creation of a share the owner is always the owner of the path
- $share->setShareOwner($share->getPath()->getOwner());
+ $share->setShareOwner($share->getNode()->getOwner());
// Cannot share with the owner
if ($share->getSharedWith() === $share->getShareOwner()) {
}
// Generate the target
- $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getPath()->getName();
+ $target = $this->config->getSystemValue('share_folder', '/') .'/'. $share->getNode()->getName();
$target = \OC\Files\Filesystem::normalizePath($target);
$share->setTarget($target);
$run = true;
$error = '';
$preHookData = [
- 'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder',
- 'itemSource' => $share->getPath()->getId(),
+ 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
+ 'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(),
'uidOwner' => $share->getSharedBy()->getUID(),
'permissions' => $share->getPermissions(),
- 'fileSource' => $share->getPath()->getId(),
+ 'fileSource' => $share->getNode()->getId(),
'expiration' => $share->getExpirationDate(),
'token' => $share->getToken(),
'itemTarget' => $share->getTarget(),
// Post share hook
$postHookData = [
- 'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder',
- 'itemSource' => $share->getPath()->getId(),
+ 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
+ 'itemSource' => $share->getNode()->getId(),
'shareType' => $share->getShareType(),
'uidOwner' => $share->getSharedBy()->getUID(),
'permissions' => $share->getPermissions(),
- 'fileSource' => $share->getPath()->getId(),
+ 'fileSource' => $share->getNode()->getId(),
'expiration' => $share->getExpirationDate(),
'token' => $share->getToken(),
'id' => $share->getId(),
}
}
- $this->pathCreateChecks($share->getPath());
+ $this->pathCreateChecks($share->getNode());
// Now update the share!
$provider = $this->factory->getProviderForType($share->getShareType());
if ($expirationDateUpdated === true) {
\OC_Hook::emit('OCP\Share', 'post_set_expiration_date', [
- 'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder',
- 'itemSource' => $share->getPath()->getId(),
+ 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
+ 'itemSource' => $share->getNode()->getId(),
'date' => $share->getExpirationDate(),
'uidOwner' => $share->getSharedBy()->getUID(),
]);
$hookParams = [
'id' => $share->getId(),
- 'itemType' => $share->getPath() instanceof \OCP\Files\File ? 'file' : 'folder',
- 'itemSource' => $share->getPath()->getId(),
+ 'itemType' => $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder',
+ 'itemSource' => $share->getNode()->getId(),
'shareType' => $shareType,
'shareWith' => $sharedWith,
'itemparent' => $share->getParent(),
'uidOwner' => $share->getSharedBy()->getUID(),
- 'fileSource' => $share->getPath()->getId(),
+ 'fileSource' => $share->getNode()->getId(),
'fileTarget' => $share->getTarget()
];
return $hookParams;
* @param IUser $user
* @return bool
*/
- public function isSharingDisabledForUser(IUser $user) {
+ public function sharingDisabledForUser(IUser $user) {
if ($this->config->getAppValue('core', 'shareapi_exclude_groups', 'no') === 'yes') {
$groupsList = $this->config->getAppValue('core', 'shareapi_exclude_groups_list', '');
$excludedGroups = json_decode($groupsList);
private $path;
/** @var int */
private $shareType;
- /** @var IUser|IGroup|string */
+ /** @var IUser|IGroup */
private $sharedWith;
- /** @var IUser|string */
+ /** @var IUser */
private $sharedBy;
- /** @var IUser|string */
+ /** @var IUser */
private $shareOwner;
/** @var int */
private $permissions;
private $parent;
/** @var string */
private $target;
- /** @var int */
+ /** @var \DateTime */
private $shareTime;
/** @var bool */
private $mailSend;
/**
* @inheritdoc
*/
- public function setPath(Node $path) {
+ public function setNode(Node $path) {
$this->path = $path;
return $this;
}
/**
* @inheritdoc
*/
- public function getPath() {
+ public function getNode() {
return $this->path;
}
/**
* @inheritdoc
*/
- public function setShareTime($shareTime) {
+ public function setShareTime(\DateTime $shareTime) {
$this->shareTime = $shareTime;
return $this;
}
public function checkPassword(IShare $share, $password);
/**
- * Create a new share
+ * Instantiates a new share object. This is to be passed to
+ * createShare.
+ *
* @return IShare
* @since 9.0.0
*/
* @return bool
* @since 9.0.0
*/
- public function isSharingDisabledForUser(IUser $user);
+ public function sharingDisabledForUser(IUser $user);
}
interface IShare {
/**
- * Get the id of the share
+ * Get the internal id of the share.
*
* @return string
* @since 9.0.0
public function getId();
/**
- * Set the id of the share
+ * Set the internal id of the share.
*
* @param string $id
* @return \OCP\Share\IShare The modified share object
public function setId($id);
/**
- * Get the full share id
+ * Get the full share id. This is the <providerid>:<internalid>.
+ * The full id is unique in the system.
*
* @return string
* @since 9.0.0
public function setProviderId($id);
/**
- * Set the path of this share
+ * Set the node of the file/folder that is shared
*
- * @param Node $path
+ * @param File|Folder $path
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
- public function setPath(Node $path);
+ public function setNode(Node $path);
/**
- * Get the path of this share for the current user
+ * Get the node of the file/folder that is shared
*
* @return File|Folder
* @since 9.0.0
*/
- public function getPath();
+ public function getNode();
/**
* Set the shareType
public function getShareType();
/**
- * Set the receiver of this share
+ * Set the receiver of this share.
*
- * @param IUser|IGroup|string
+ * @param IUser|IGroup
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setSharedWith($sharedWith);
/**
- * Get the receiver of this share
+ * Get the receiver of this share.
*
- * @return IUser|IGroup|string
+ * @return IUser|IGroup
* @since 9.0.0
*/
public function getSharedWith();
/**
- * Set the permissions
+ * Set the permissions.
+ * See \OCP\Constants::PERMISSION_*
*
* @param int $permissions
* @return \OCP\Share\IShare The modified object
/**
* Get the share permissions
+ * See \OCP\Constants::PERMISSION_*
*
* @return int
* @since 9.0.0
public function setExpirationDate($expireDate);
/**
- * Get the share expiration date
+ * Get the expiration date
*
* @return \DateTime
* @since 9.0.0
public function getExpirationDate();
/**
- * Set the sharer of the path
+ * Set the sharer of the path.
*
- * @param IUser|string $sharedBy
+ * @param IUser $sharedBy
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
/**
* Get share sharer
*
- * @return IUser|string
+ * @return IUser
* @since 9.0.0
*/
public function getSharedBy();
/**
- * Set the original share owner (who owns the path)
+ * Set the original share owner (who owns the path that is shared)
*
- * @param IUser|string
+ * @param IUser
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
public function setShareOwner($shareOwner);
/**
- * Get the original share owner (who owns the path)
+ * Get the original share owner (who owns the path that is shared)
*
- * @return IUser|string
+ * @return IUser
* @since 9.0.0
*/
public function getShareOwner();
/**
- * Set the password
+ * Set the password for this share.
+ * When the share is passed to the share manager to be created
+ * or updated the password will be hashed.
*
* @param string $password
* @return \OCP\Share\IShare The modified object
public function setPassword($password);
/**
- * Is a password set for this share
+ * Get the password of this share.
+ * If this share is obtained via a shareprovider the password is
+ * hashed.
*
* @return string
* @since 9.0.0
public function getPassword();
/**
- * Set the token
+ * Set the public link token.
*
* @param string $token
* @return \OCP\Share\IShare The modified object
public function setToken($token);
/**
- * Get the token
+ * Get the public link token.
*
* @return string
* @since 9.0.0
public function getToken();
/**
- * Get the parent it
- *
- * @return int
- * @since 9.0.0
- */
- public function getParent();
-
- /**
- * Set the target of this share
+ * Set the target path of this share relative to the recipients user folder.
*
* @param string $target
* @return \OCP\Share\IShare The modified object
public function setTarget($target);
/**
- * Get the target of this share
+ * Get the target path of this share relative to the recipients user folder.
*
* @return string
* @since 9.0.0
/**
* Set the time this share was created
*
- * @param int $shareTime
+ * @param \DateTime $shareTime
* @return \OCP\Share\IShare The modified object
* @since 9.0.0
*/
- public function setShareTime($shareTime);
+ public function setShareTime(\DateTime $shareTime);
/**
* Get the timestamp this share was created
*
- * @return int
+ * @return \DateTime
* @since 9.0.0
*/
public function getShareTime();
/**
- * Set mailSend
+ * Set if the recipient is informed by mail about the share.
*
* @param bool $mailSend
* @return \OCP\Share\IShare The modified object
public function setMailSend($mailSend);
/**
- * Get mailSend
+ * Get if the recipient informed by mail about the share.
*
* @return bool
* @since 9.0.0
public function identifier();
/**
- * Share a path
+ * Create a share
*
* @param \OCP\Share\IShare $share
* @return \OCP\Share\IShare The share object
/**
* Unshare a file from self as recipient.
- * This may require special handling.
+ * This may require special handling. If a user unshares a group
+ * share from their self then the original group share should still exist.
*
* @param \OCP\Share\IShare $share
* @param IUser $recipient
* @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
* @param int $limit The maximum number of shares to be returned, -1 for all shares
* @param int $offset
- * @return Share[]
+ * @return \OCP\Share\I Share[]
* @since 9.0.0
*/
public function getSharesBy(IUser $user, $shareType, $node, $reshares, $limit, $offset);
* Get share by id
*
* @param int $id
- * @return IShare
+ * @return \OCP\Share\IShare
* @throws ShareNotFound
* @since 9.0.0
*/
* Get shares for a given path
*
* @param \OCP\Files\Node $path
- * @return IShare[]
+ * @return \OCP\Share\IShare[]
* @since 9.0.0
*/
public function getSharesByPath(\OCP\Files\Node $path);
* @param int $shareType
* @param int $limit The max number of entries returned, -1 for all
* @param int $offset
- * @param Share
+ * @return \OCP\Share\IShare[]
* @since 9.0.0
*/
public function getSharedWith(IUser $user, $shareType, $limit, $offset);
* Get a share by token
*
* @param string $token
- * @return IShare
+ * @return \OCP\Share\IShare
* @throws ShareNotFound
* @since 9.0.0
*/
$this->assertEquals($sharedWith, $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner());
- $this->assertEquals($ownerPath, $share->getPath());
+ $this->assertEquals($ownerPath, $share->getNode());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate());
$this->assertEquals($sharedWith, $share->getSharedWith());
$this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner());
- $this->assertEquals($ownerPath, $share->getPath());
+ $this->assertEquals($ownerPath, $share->getNode());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals(null, $share->getToken());
$this->assertEquals(null, $share->getExpirationDate());
$this->assertEquals('sharedWith', $share->getPassword());
$this->assertEquals($sharedBy, $share->getSharedBy());
$this->assertEquals($shareOwner, $share->getShareOwner());
- $this->assertEquals($ownerPath, $share->getPath());
+ $this->assertEquals($ownerPath, $share->getNode());
$this->assertEquals(13, $share->getPermissions());
$this->assertEquals('token', $share->getToken());
$this->assertEquals(\DateTime::createFromFormat('Y-m-d H:i:s', '2000-01-02 00:00:00'), $share->getExpirationDate());
$this->assertEquals($user1, $children[0]->getSharedWith());
$this->assertEquals($user2, $children[0]->getSharedBy());
$this->assertEquals($shareOwner, $children[0]->getShareOwner());
- $this->assertEquals($ownerPath, $children[0]->getPath());
+ $this->assertEquals($ownerPath, $children[0]->getNode());
$this->assertEquals(2, $children[0]->getPermissions());
$this->assertEquals(null, $children[0]->getToken());
$this->assertEquals(null, $children[0]->getExpirationDate());
$this->assertEquals($group1, $children[1]->getSharedWith());
$this->assertEquals($user3, $children[1]->getSharedBy());
$this->assertEquals($shareOwner, $children[1]->getShareOwner());
- $this->assertEquals($ownerPath, $children[1]->getPath());
+ $this->assertEquals($ownerPath, $children[1]->getNode());
$this->assertEquals(4, $children[1]->getPermissions());
$this->assertEquals(null, $children[1]->getToken());
$this->assertEquals(null, $children[1]->getExpirationDate());
$share->setSharedWith($sharedWith);
$share->setSharedBy($sharedBy);
$share->setShareOwner($shareOwner);
- $share->setPath($path);
+ $share->setNode($path);
$share->setPermissions(1);
$share->setTarget('/target');
$this->assertSame($shareOwner, $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget());
- $this->assertLessThanOrEqual(time(), $share2->getShareTime());
- $this->assertSame($path, $share2->getPath());
+ $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
+ $this->assertSame($path, $share2->getNode());
}
public function testCreateGroupShare() {
$share->setSharedWith($sharedWith);
$share->setSharedBy($sharedBy);
$share->setShareOwner($shareOwner);
- $share->setPath($path);
+ $share->setNode($path);
$share->setPermissions(1);
$share->setTarget('/target');
$this->assertSame($shareOwner, $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget());
- $this->assertLessThanOrEqual(time(), $share2->getShareTime());
- $this->assertSame($path, $share2->getPath());
+ $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
+ $this->assertSame($path, $share2->getNode());
}
public function testCreateLinkShare() {
$share->setShareType(\OCP\Share::SHARE_TYPE_LINK);
$share->setSharedBy($sharedBy);
$share->setShareOwner($shareOwner);
- $share->setPath($path);
+ $share->setNode($path);
$share->setPermissions(1);
$share->setPassword('password');
$share->setToken('token');
$this->assertSame($shareOwner, $share2->getShareOwner());
$this->assertSame(1, $share2->getPermissions());
$this->assertSame('/target', $share2->getTarget());
- $this->assertLessThanOrEqual(time(), $share2->getShareTime());
- $this->assertSame($path, $share2->getPath());
+ $this->assertLessThanOrEqual(new \DateTime(), $share2->getShareTime());
+ $this->assertSame($path, $share2->getNode());
$this->assertSame('password', $share2->getPassword());
$this->assertSame('token', $share2->getToken());
$this->assertEquals($expireDate, $share2->getExpirationDate());
$share->setSharedWith($users['user3']);
$share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']);
- $share->setPath($file2);
+ $share->setNode($file2);
$share->setPermissions(1);
$share2 = $this->provider->update($share);
$share->setPassword('password');
$share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']);
- $share->setPath($file2);
+ $share->setNode($file2);
$share->setPermissions(1);
$share2 = $this->provider->update($share);
$share->setPassword(null);
$share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']);
- $share->setPath($file2);
+ $share->setNode($file2);
$share->setPermissions(1);
$share2 = $this->provider->update($share);
$share->setSharedWith($groups['group0']);
$share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']);
- $share->setPath($file2);
+ $share->setNode($file2);
$share->setPermissions(1);
$share2 = $this->provider->update($share);
$share->setSharedWith($groups['group0']);
$share->setSharedBy($users['user4']);
$share->setShareOwner($users['user5']);
- $share->setPath($file2);
+ $share->setNode($file2);
$share->setPermissions(1);
$share2 = $this->provider->update($share);
$path = $this->getMock('\OCP\Files\File');
$path->method('getId')->willReturn(1);
- $share = $this->getMock('\OCP\Share\IShare');
- $share->method('getId')->willReturn(42);
- $share->method('getFullId')->willReturn('prov:42');
- $share->method('getShareType')->willReturn($shareType);
- $share->method('getSharedWith')->willReturn($sharedWith);
- $share->method('getSharedBy')->willReturn($sharedBy);
- $share->method('getPath')->willReturn($path);
- $share->method('getTarget')->willReturn('myTarget');
+ $share = $this->manager->newShare();
+ $share->setId(42)
+ ->setProviderId('prov')
+ ->setShareType($shareType)
+ ->setSharedWith($sharedWith)
+ ->setSharedBy($sharedBy)
+ ->setNode($path)
+ ->setTarget('myTarget');
$manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share);
$manager->expects($this->once())->method('deleteChildren')->with($share);
$path = $this->getMock('\OCP\Files\File');
$path->method('getId')->willReturn(1);
- $share1 = $this->getMock('\OCP\Share\IShare');
- $share1->method('getId')->willReturn(42);
- $share1->method('getFullId')->willReturn('prov:42');
- $share1->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_USER);
- $share1->method('getSharedWith')->willReturn($sharedWith1);
- $share1->method('getSharedBy')->willReturn($sharedBy1);
- $share1->method('getPath')->willReturn($path);
- $share1->method('getTarget')->willReturn('myTarget1');
-
- $share2 = $this->getMock('\OCP\Share\IShare');
- $share2->method('getId')->willReturn(43);
- $share2->method('getFullId')->willReturn('prov:43');
- $share2->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_GROUP);
- $share2->method('getSharedWith')->willReturn($sharedWith2);
- $share2->method('getSharedBy')->willReturn($sharedBy2);
- $share2->method('getPath')->willReturn($path);
- $share2->method('getTarget')->willReturn('myTarget2');
- $share2->method('getParent')->willReturn(42);
-
- $share3 = $this->getMock('\OCP\Share\IShare');
- $share3->method('getId')->willReturn(44);
- $share3->method('getFullId')->willReturn('prov:44');
- $share3->method('getShareType')->willReturn(\OCP\Share::SHARE_TYPE_LINK);
- $share3->method('getSharedBy')->willReturn($sharedBy3);
- $share3->method('getPath')->willReturn($path);
- $share3->method('getTarget')->willReturn('myTarget3');
- $share3->method('getParent')->willReturn(43);
+ $share1 = $this->manager->newShare();
+ $share1->setId(42)
+ ->setProviderId('prov')
+ ->setShareType(\OCP\Share::SHARE_TYPE_USER)
+ ->setSharedWith($sharedWith1)
+ ->setSharedBy($sharedBy1)
+ ->setNode($path)
+ ->setTarget('myTarget1');
+
+ $share2 = $this->manager->newShare();
+ $share2->setId(43)
+ ->setProviderId('prov')
+ ->setShareType(\OCP\Share::SHARE_TYPE_GROUP)
+ ->setSharedWith($sharedWith2)
+ ->setSharedBy($sharedBy2)
+ ->setNode($path)
+ ->setTarget('myTarget2')
+ ->setParent(42);
+
+ $share3 = $this->manager->newShare();
+ $share3->setId(44)
+ ->setProviderId('prov')
+ ->setShareType(\OCP\Share::SHARE_TYPE_LINK)
+ ->setSharedBy($sharedBy3)
+ ->setNode($path)
+ ->setTarget('myTarget3')
+ ->setParent(43);
$manager->expects($this->once())->method('getShareById')->with('prov:42')->willReturn($share1);
$share->method('getSharedWith')->willReturn($sharedWith);
$share->method('getSharedBy')->willReturn($sharedBy);
$share->method('getSharedOwner')->willReturn($shareOwner);
- $share->method('getPath')->willReturn($path);
+ $share->method('getNode')->willReturn($path);
$share->method('getPermissions')->willReturn($permissions);
$share->method('getExpirationDate')->willReturn($expireDate);
$share->method('getPassword')->willReturn($password);
$share->setSharedBy($sharedBy)->setSharedWith($sharedWith);
$path = $this->getMock('\OCP\Files\Node');
- $share->setPath($path);
+ $share->setNode($path);
$this->groupManager
->method('getUserGroupIds')
* @expectedExceptionMessage Path already shared with this user
*/
public function testUserCreateChecksIdenticalShareExists() {
- $share = new \OC\Share20\Share();
- $share2 = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
+ $share2 = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node');
- $share->setSharedWith($sharedWith)->setPath($path)
+ $share->setSharedWith($sharedWith)->setNode($path)
->setProviderId('foo')->setId('bar');
- $share2->setSharedWith($sharedWith)->setPath($path)
+ $share2->setSharedWith($sharedWith)->setNode($path)
->setProviderId('foo')->setId('baz');
$this->defaultProvider
* @expectedExceptionMessage Path already shared with this user
*/
public function testUserCreateChecksIdenticalPathSharedViaGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IUser');
$owner = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith($sharedWith)
- ->setPath($path)
+ ->setNode($path)
->setShareOwner($owner)
->setProviderId('foo')
->setId('bar');
$owner = $this->getMock('\OCP\IUser');
$path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith($sharedWith)
- ->setPath($path)
+ ->setNode($path)
->setShareOwner($owner)
->setProviderId('foo')
->setId('bar');
$sharedWith->method('inGroup')->with($sharedBy)->willReturn(true);
$path = $this->getMock('\OCP\Files\Node');
- $share->setPath($path);
+ $share->setNode($path);
$this->defaultProvider->method('getSharesByPath')
->with($path)
* @expectedExceptionMessage Path already shared with this group
*/
public function testGroupCreateChecksPathAlreadySharedWithSameGroup() {
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$sharedWith = $this->getMock('\OCP\IGroup');
$path = $this->getMock('\OCP\Files\Node');
$share->setSharedWith($sharedWith)
- ->setPath($path)
+ ->setNode($path)
->setProviderId('foo')
->setId('bar');
$share->setSharedWith($sharedWith);
$path = $this->getMock('\OCP\Files\Node');
- $share->setPath($path);
+ $share->setNode($path);
$share2 = new \OC\Share20\Share();
$sharedWith2 = $this->getMock('\OCP\IGroup');
->with($user)
->willReturn($groupIds);
- $res = $this->manager->isSharingDisabledForUser($user);
+ $res = $this->manager->sharingDisabledForUser($user);
$this->assertEquals($expected, $res);
}
]));
$manager = $this->createManagerMock()
- ->setMethods(['isSharingDisabledForUser'])
+ ->setMethods(['sharingDisabledForUser'])
->getMock();
- $manager->method('isSharingDisabledForUser')->willReturn($disabledForUser);
+ $manager->method('sharingDisabledForUser')->willReturn($disabledForUser);
$user = $this->getMock('\OCP\IUser');
- $share = new \OC\Share20\Share();
+ $share = $this->manager->newShare();
$share->setSharedBy($user);
$res = $this->invokePrivate($manager, 'canShare', [$share]);
$share = new \OC\Share20\Share();
$share->setShareType(\OCP\Share::SHARE_TYPE_LINK)
- ->setPath($path)
+ ->setNode($path)
->setSharedBy($sharedBy)
->setPermissions(\OCP\Constants::PERMISSION_ALL)
->setExpirationDate($date)
->setShareOwner($user)
->setPassword('password')
->setExpirationDate($tomorrow)
- ->setPath($file);
+ ->setNode($file);
$this->defaultProvider->expects($this->once())
->method('update')