diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php index 2a5faecffffdf..d4f89492854eb 100644 --- a/apps/files_sharing/lib/Controller/ShareAPIController.php +++ b/apps/files_sharing/lib/Controller/ShareAPIController.php @@ -160,6 +160,7 @@ protected function formatShare(\OCP\Share\IShare $share, Node $recipientNode = n 'token' => null, 'uid_file_owner' => $share->getShareOwner(), 'note' => $share->getNote(), + 'label' => $share->getLabel(), 'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(), ]; @@ -353,15 +354,17 @@ public function deleteShare(string $id): DataResponse { * @param string $shareWith * @param string $publicUpload * @param string $password - * @param bool $sendPasswordByTalk + * @param string $sendPasswordByTalk * @param string $expireDate + * @param string $label * * @return DataResponse - * @throws OCSNotFoundException - * @throws OCSForbiddenException + * @throws NotFoundException * @throws OCSBadRequestException * @throws OCSException - * + * @throws OCSForbiddenException + * @throws OCSNotFoundException + * @throws \OCP\Files\InvalidPathException * @suppress PhanUndeclaredClassMethod */ public function createShare( @@ -372,7 +375,8 @@ public function createShare( string $publicUpload = 'false', string $password = '', string $sendPasswordByTalk = null, - string $expireDate = '' + string $expireDate = '', + string $label = '' ): DataResponse { $share = $this->shareManager->newShare(); @@ -472,6 +476,10 @@ public function createShare( $share->setPassword($password); } + if (!empty($label)) { + $share->setLabel($label); + } + //Expire date if ($expireDate !== '') { try { diff --git a/core/Migrations/Version13000Date20170718121200.php b/core/Migrations/Version13000Date20170718121200.php index 0b2c255738c5b..8a268a052b4fe 100644 --- a/core/Migrations/Version13000Date20170718121200.php +++ b/core/Migrations/Version13000Date20170718121200.php @@ -397,6 +397,10 @@ public function changeSchema(IOutput $output, \Closure $schemaClosure, array $op 'notnull' => false, 'length' => 64, ]); + $table->addColumn('label', 'string', [ + 'notnull' => false, + 'length' => 255, + ]); $table->setPrimaryKey(['id']); $table->addIndex(['item_type', 'share_type'], 'item_share_type_index'); $table->addIndex(['file_source'], 'file_source_index'); diff --git a/lib/private/Share20/DefaultShareProvider.php b/lib/private/Share20/DefaultShareProvider.php index 9c5d78a59589f..ce3e9ae795cd2 100644 --- a/lib/private/Share20/DefaultShareProvider.php +++ b/lib/private/Share20/DefaultShareProvider.php @@ -146,6 +146,8 @@ public function create(\OCP\Share\IShare $share) { //Set the GID of the group we share with $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith())); } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) { + //set label for public link + $qb->setValue('label', $qb->createNamedParameter($share->getLabel())); //Set the token of the share $qb->setValue('token', $qb->createNamedParameter($share->getToken())); @@ -225,6 +227,9 @@ public function create(\OCP\Share\IShare $share) { * * @param \OCP\Share\IShare $share * @return \OCP\Share\IShare The share object + * @throws ShareNotFound + * @throws \OCP\Files\InvalidPathException + * @throws \OCP\Files\NotFoundException */ public function update(\OCP\Share\IShare $share) { @@ -918,7 +923,8 @@ private function createShare($data) { ->setPermissions((int)$data['permissions']) ->setTarget($data['file_target']) ->setNote($data['note']) - ->setMailSend((bool)$data['mail_send']); + ->setMailSend((bool)$data['mail_send']) + ->setLabel($data['label']); $shareTime = new \DateTime(); $shareTime->setTimestamp((int)$data['stime']); diff --git a/lib/private/Share20/Share.php b/lib/private/Share20/Share.php index 71c0453d9e578..b279f9492aa32 100644 --- a/lib/private/Share20/Share.php +++ b/lib/private/Share20/Share.php @@ -75,6 +75,8 @@ class Share implements \OCP\Share\IShare { private $shareTime; /** @var bool */ private $mailSend; + /** @var string */ + private $label = ''; /** @var IRootFolder */ private $rootFolder; @@ -330,6 +332,20 @@ public function getNote() { return ''; } + /** + * @inheritdoc + */ + public function setLabel($label) { + $this->label = $label; + } + + /** + * @inheritdoc + */ + public function getLabel() { + return $this->label; + } + /** * @inheritdoc */ diff --git a/lib/public/Share/IShare.php b/lib/public/Share/IShare.php index 43543fdad4761..88c0e417d70ee 100644 --- a/lib/public/Share/IShare.php +++ b/lib/public/Share/IShare.php @@ -257,6 +257,22 @@ public function setExpirationDate($expireDate); */ public function getExpirationDate(); + /** + * set a label for a share, some shares, e.g. public links can have a label + * + * @param $label + * @since 15.0.0 + */ + public function setLabel($label); + + /** + * get label for the share, some shares, e.g. public links can have a label + * + * @return string + * @since 15.0.0 + */ + public function getLabel(); + /** * Set the sharer of the path. *