]> source.dussan.org Git - nextcloud-server.git/commitdiff
allow to add labels to shares
authorBjoern Schiessle <bjoern@schiessle.org>
Tue, 16 Oct 2018 08:31:38 +0000 (10:31 +0200)
committerDaniel Calviño Sánchez <danxuliu@gmail.com>
Thu, 1 Nov 2018 01:15:07 +0000 (02:15 +0100)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/files_sharing/lib/Controller/ShareAPIController.php
core/Migrations/Version15000Date20181029084625.php [new file with mode: 0644]
lib/composer/composer/autoload_classmap.php
lib/composer/composer/autoload_static.php
lib/private/Share20/DefaultShareProvider.php
lib/private/Share20/Share.php
lib/public/Share/IShare.php
version.php

index 5137b102b5a15ca848700040af5313a3207865b3..9fb78533a43a4fcb17c89a00198732402a0b850b 100644 (file)
@@ -160,6 +160,7 @@ class ShareAPIController extends OCSController {
                        'token' => null,
                        'uid_file_owner' => $share->getShareOwner(),
                        'note' => $share->getNote(),
+                       'label' => $share->getLabel(),
                        'displayname_file_owner' => $shareOwner !== null ? $shareOwner->getDisplayName() : $share->getShareOwner(),
                ];
 
@@ -354,15 +355,17 @@ class ShareAPIController extends OCSController {
         * @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(
@@ -373,7 +376,8 @@ class ShareAPIController extends OCSController {
                string $publicUpload = 'false',
                string $password = '',
                string $sendPasswordByTalk = null,
-               string $expireDate = ''
+               string $expireDate = '',
+               string $label = ''
        ): DataResponse {
                $share = $this->shareManager->newShare();
 
@@ -473,6 +477,10 @@ class ShareAPIController extends OCSController {
                                $share->setPassword($password);
                        }
 
+                       if (!empty($label)) {
+                               $share->setLabel($label);
+                       }
+
                        //Expire date
                        if ($expireDate !== '') {
                                try {
diff --git a/core/Migrations/Version15000Date20181029084625.php b/core/Migrations/Version15000Date20181029084625.php
new file mode 100644 (file)
index 0000000..f3e12dd
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv@protonmail.com)
+ *
+ * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OC\Core\Migrations;
+
+use Closure;
+use OCP\DB\ISchemaWrapper;
+use OCP\Migration\SimpleMigrationStep;
+use OCP\Migration\IOutput;
+
+class Version15000Date20181029084625 extends SimpleMigrationStep {
+
+       /**
+        * @param IOutput $output
+        * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
+        * @param array $options
+        * @return null|ISchemaWrapper
+        */
+       public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
+               /** @var ISchemaWrapper $schema */
+               $schema = $schemaClosure();
+
+               $table = $schema->getTable('share');
+               $table->addColumn('label', 'string', [
+                       'notnull' => false,
+                       'length' => 255,
+               ]);
+
+               return $schema;
+       }
+
+}
index c94837ed15c6cb8b66de886f9e6cae4c9f80f469..afac26420eb872540395ba6d8b1bb17af548fe4d 100644 (file)
@@ -670,6 +670,7 @@ return array(
     'OC\\Core\\Migrations\\Version14000Date20180712153140' => $baseDir . '/core/Migrations/Version14000Date20180712153140.php',
     'OC\\Core\\Migrations\\Version15000Date20180926101451' => $baseDir . '/core/Migrations/Version15000Date20180926101451.php',
     'OC\\Core\\Migrations\\Version15000Date20181015062942' => $baseDir . '/core/Migrations/Version15000Date20181015062942.php',
+    'OC\\Core\\Migrations\\Version15000Date20181029084625' => $baseDir . '/core/Migrations/Version15000Date20181029084625.php',
     'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php',
     'OC\\DB\\AdapterMySQL' => $baseDir . '/lib/private/DB/AdapterMySQL.php',
     'OC\\DB\\AdapterOCI8' => $baseDir . '/lib/private/DB/AdapterOCI8.php',
index 80aabae238982c3d2b33d6fba9dab67069e8c994..db20d9a1c9a6bd71e58a5f56aa2558534578cf7c 100644 (file)
@@ -700,6 +700,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
         'OC\\Core\\Migrations\\Version14000Date20180712153140' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180712153140.php',
         'OC\\Core\\Migrations\\Version15000Date20180926101451' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180926101451.php',
         'OC\\Core\\Migrations\\Version15000Date20181015062942' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20181015062942.php',
+        'OC\\Core\\Migrations\\Version15000Date20181029084625' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20181029084625.php',
         'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php',
         'OC\\DB\\AdapterMySQL' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterMySQL.php',
         'OC\\DB\\AdapterOCI8' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterOCI8.php',
index 3dcca0facbcc6f6ca37e27efb8ad45396ff355a3..dc0ecea880771bd36f740048d74ca33cb2517618 100644 (file)
@@ -146,6 +146,8 @@ class DefaultShareProvider implements IShareProvider {
                        //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 @@ class DefaultShareProvider implements IShareProvider {
         *
         * @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) {
 
@@ -919,7 +924,8 @@ class DefaultShareProvider implements IShareProvider {
                        ->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']);
index e218360f87b5364a4bf412f0f527a6fb67703cdd..f9b548c1adf9857fca7bca7ba0141ebddd1871df 100644 (file)
@@ -76,6 +76,8 @@ class Share implements \OCP\Share\IShare {
        private $shareTime;
        /** @var bool */
        private $mailSend;
+       /** @var string */
+       private $label = '';
 
        /** @var IRootFolder */
        private $rootFolder;
@@ -334,6 +336,21 @@ class Share implements \OCP\Share\IShare {
                return '';
        }
 
+       /**
+        * @inheritdoc
+        */
+       public function setLabel($label) {
+               $this->label = $label;
+               return $this;
+       }
+
+       /**
+        * @inheritdoc
+        */
+       public function getLabel() {
+               return $this->label;
+       }
+
        /**
         * @inheritdoc
         */
index dcd5fdecbea575fcc9013260794c434899ffdd7c..7bcecbdc872db37a549fc24f6573e946f5f304b3 100644 (file)
@@ -257,6 +257,23 @@ interface IShare {
         */
        public function getExpirationDate();
 
+       /**
+        * set a label for a share, some shares, e.g. public links can have a label
+        *
+        * @param string $label
+        * @return \OCP\Share\IShare The modified object
+        * @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.
         *
index 93a8b5fd53e63c95068e76fc8a63201cbb48ea00..235e18bf61d8ad8bd60b6af2567d1497ab91907a 100644 (file)
@@ -29,7 +29,7 @@
 // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
 // when updating major/minor version number.
 
-$OC_Version = array(15, 0, 0, 2);
+$OC_Version = array(15, 0, 0, 3);
 
 // The human readable string
 $OC_VersionString = '15.0.0 alpha';