Skip to content

Commit

Permalink
allow to add labels to shares
Browse files Browse the repository at this point in the history
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
  • Loading branch information
schiessle committed Oct 18, 2018
1 parent 83444b3 commit 818ca4d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 6 deletions.
18 changes: 13 additions & 5 deletions apps/files_sharing/lib/Controller/ShareAPIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
];

Expand Down Expand Up @@ -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(
Expand All @@ -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();

Expand Down Expand Up @@ -472,6 +476,10 @@ public function createShare(
$share->setPassword($password);
}

if (!empty($label)) {
$share->setLabel($label);
}

//Expire date
if ($expireDate !== '') {
try {
Expand Down
4 changes: 4 additions & 0 deletions core/Migrations/Version13000Date20170718121200.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
8 changes: 7 additions & 1 deletion lib/private/Share20/DefaultShareProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));

Expand Down Expand Up @@ -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) {

Expand Down Expand Up @@ -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']);
Expand Down
16 changes: 16 additions & 0 deletions lib/private/Share20/Share.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ class Share implements \OCP\Share\IShare {
private $shareTime;
/** @var bool */
private $mailSend;
/** @var string */
private $label = '';

/** @var IRootFolder */
private $rootFolder;
Expand Down Expand Up @@ -330,6 +332,20 @@ public function getNote() {
return '';
}

/**
* @inheritdoc
*/
public function setLabel($label) {
$this->label = $label;
}

/**
* @inheritdoc
*/
public function getLabel() {
return $this->label;
}

/**
* @inheritdoc
*/
Expand Down
16 changes: 16 additions & 0 deletions lib/public/Share/IShare.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit 818ca4d

Please sign in to comment.