]> source.dussan.org Git - nextcloud-server.git/commitdiff
add new password column to the share table in order to set passwords for share by...
authorBjoern Schiessle <bjoern@schiessle.org>
Tue, 28 Mar 2017 13:11:07 +0000 (15:11 +0200)
committerBjoern Schiessle <bjoern@schiessle.org>
Mon, 3 Apr 2017 08:20:49 +0000 (10:20 +0200)
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
apps/files_sharing/appinfo/info.xml
apps/files_sharing/appinfo/update.php
apps/files_sharing/lib/Controller/ShareAPIController.php
apps/files_sharing/lib/Migration.php
apps/files_sharing/tests/MigrationTest.php
core/js/shareitemmodel.js
db_structure.xml
lib/private/Share20/DefaultShareProvider.php
version.php

index e2a08d951acfca4fd22d1398c696f387db2cdeab..29a137fed0b755465661183640cc0f396a0caac0 100644 (file)
@@ -10,7 +10,7 @@ Turning the feature off removes shared files and folders on the server for all s
        <licence>AGPL</licence>
        <author>Michael Gapczynski, Bjoern Schiessle</author>
        <default_enable/>
-       <version>1.2.0</version>
+       <version>1.4.0</version>
        <types>
                <filesystem/>
        </types>
index ed0d7732b377545c0bb598bc70b5f88c36b9570f..917cb7b6639f9755b075d0c1b39cc87192c0e3e5 100644 (file)
@@ -34,3 +34,8 @@ if (version_compare($installedVersion, '0.9.1', '<')) {
 if (version_compare($installedVersion, '1.1.1', '<')) {
        $m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig());
 }
+
+if (version_compare($installedVersion, '1.4.0', '<')) {
+       $m = new Migration(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig());
+       $m->addPasswordColumn();
+}
index 78eef6c26bb65ac040b12c4437d7515dd7d0c049..80ba7534da0575fe17f7eb8f34aa2ee5f36e4844 100644 (file)
@@ -190,6 +190,7 @@ class ShareAPIController extends OCSController {
                        $result['token'] = $share->getToken();
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) {
                        $result['share_with'] = $share->getSharedWith();
+                       $result['password'] = $share->getPassword();
                        $result['share_with_displayname'] = $this->getDisplayNameFromAddressBook($share->getSharedWith(), 'EMAIL');
                        $result['token'] = $share->getToken();
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_CIRCLE) {
index 605a11fd22c19ac62b1270889004a63047f089d5..49e275cbe6e70cef5f914c1f95147484e4043e80 100644 (file)
@@ -123,6 +123,24 @@ class Migration {
                $this->config->deleteAppValue('core', 'shareapi_allow_public_notification');
        }
 
+       public function addPasswordColumn() {
+               $query = $this->connection->getQueryBuilder();
+               $query
+                       ->update('share')
+                       ->set('password', 'share_with')
+                       ->where($query->expr()->eq('share_type', $query->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
+                       ->andWhere($query->expr()->isNotNull('share_with'));
+               $query->execute();
+
+               $clearQuery = $this->connection->getQueryBuilder();
+               $clearQuery
+                       ->update('share')->set('share_with', $clearQuery->createNamedParameter(null))
+                       ->where($clearQuery->expr()->eq('share_type', $clearQuery->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)));
+
+               $clearQuery->execute();
+
+       }
+
        /**
         * find the owner of a re-shared file/folder
         *
index 572f64da7436955694fcbfbb89e968f3627700f4..a357e814f25a2281de68ba4993d48ee99d6933b8 100644 (file)
@@ -28,6 +28,7 @@ namespace OCA\Files_Sharing\Tests;
 
 
 use OCA\Files_Sharing\Migration;
+use OCP\Share;
 
 /**
  * Class MigrationTest
@@ -87,7 +88,7 @@ class MigrationTest extends TestCase {
                                )
                        );
                // shared contact, shouldn't be modified
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_CONTACT)
+               $query->setParameter('share_type', Share::SHARE_TYPE_CONTACT)
                        ->setParameter('share_with', 'user1')
                        ->setParameter('uid_owner', 'owner1')
                        ->setParameter('uid_initiator', '')
@@ -103,7 +104,7 @@ class MigrationTest extends TestCase {
                        $query->execute()
                );
                // shared calendar, shouldn't be modified
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_USER)
+               $query->setParameter('share_type', Share::SHARE_TYPE_USER)
                        ->setParameter('share_with', 'user1')
                        ->setParameter('uid_owner', 'owner1')
                        ->setParameter('uid_initiator', '')
@@ -119,7 +120,7 @@ class MigrationTest extends TestCase {
                        $query->execute()
                );
                // single user share, shouldn't be modified
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_USER)
+               $query->setParameter('share_type', Share::SHARE_TYPE_USER)
                        ->setParameter('share_with', 'user1')
                        ->setParameter('uid_owner', 'owner1')
                        ->setParameter('uid_initiator', '')
@@ -135,7 +136,7 @@ class MigrationTest extends TestCase {
                        $query->execute()
                );
                // single group share, shouldn't be modified
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_GROUP)
+               $query->setParameter('share_type', Share::SHARE_TYPE_GROUP)
                        ->setParameter('share_with', 'group1')
                        ->setParameter('uid_owner', 'owner1')
                        ->setParameter('uid_initiator', '')
@@ -168,7 +169,7 @@ class MigrationTest extends TestCase {
                        $query->execute()
                );
                // first user share, shouldn't be modified
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_USER)
+               $query->setParameter('share_type', Share::SHARE_TYPE_USER)
                        ->setParameter('share_with', 'user1')
                        ->setParameter('uid_owner', 'owner2')
                        ->setParameter('uid_initiator', '')
@@ -185,7 +186,7 @@ class MigrationTest extends TestCase {
                );
                $parent = $query->getLastInsertId();
                // first re-share, should be attached to the first user share after migration
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_USER)
+               $query->setParameter('share_type', Share::SHARE_TYPE_USER)
                        ->setParameter('share_with', 'user2')
                        ->setParameter('uid_owner', 'user1')
                        ->setParameter('uid_initiator', '')
@@ -202,7 +203,7 @@ class MigrationTest extends TestCase {
                );
                $parent = $query->getLastInsertId();
                // second re-share, should be attached to the first user share after migration
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_USER)
+               $query->setParameter('share_type', Share::SHARE_TYPE_USER)
                        ->setParameter('share_with', 'user3')
                        ->setParameter('uid_owner', 'user2')
                        ->setParameter('uid_initiator', '')
@@ -219,7 +220,7 @@ class MigrationTest extends TestCase {
                );
                $parent = $query->getLastInsertId();
                // third re-share, should be attached to the first user share after migration
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_REMOTE)
+               $query->setParameter('share_type', Share::SHARE_TYPE_REMOTE)
                        ->setParameter('share_with', 'user@server.com')
                        ->setParameter('uid_owner', 'user3')
                        ->setParameter('uid_initiator', '')
@@ -236,7 +237,7 @@ class MigrationTest extends TestCase {
                );
 
                // Link reshare should keep its parent
-               $query->setParameter('share_type', \OCP\Share::SHARE_TYPE_LINK)
+               $query->setParameter('share_type', Share::SHARE_TYPE_LINK)
                        ->setParameter('share_with', null)
                        ->setParameter('uid_owner', 'user3')
                        ->setParameter('uid_initiator', '')
@@ -317,7 +318,7 @@ class MigrationTest extends TestCase {
                                                'stime' => $query->createParameter('stime'),
                                        ]
                                )
-                               ->setParameter('share_type', \OCP\Share::SHARE_TYPE_USER)
+                               ->setParameter('share_type', Share::SHARE_TYPE_USER)
                                ->setParameter('share_with', 'user'.($i+1))
                                ->setParameter('uid_owner', 'user'.($i))
                                ->setParameter('uid_initiator', null)
@@ -377,4 +378,63 @@ class MigrationTest extends TestCase {
                        $this->config->getAppValue('core', 'shareapi_setting1', null)
                );
        }
+
+       public function testAddPasswordColumn() {
+
+               $shareTypes = [Share::SHARE_TYPE_USER, Share::SHARE_TYPE_GROUP, Share::SHARE_TYPE_REMOTE, Share::SHARE_TYPE_EMAIL, Share::SHARE_TYPE_LINK];
+
+               foreach ($shareTypes as $shareType) {
+
+                       for ($i = 0; $i < 5; $i++) {
+                               $query = $this->connection->getQueryBuilder();
+                               $query->insert($this->table)
+                                       ->values(
+                                               [
+                                                       'share_type' => $query->createParameter('share_type'),
+                                                       'share_with' => $query->createParameter('share_with'),
+                                                       'uid_owner' => $query->createParameter('uid_owner'),
+                                                       'uid_initiator' => $query->createParameter('uid_initiator'),
+                                                       'parent' => $query->createParameter('parent'),
+                                                       'item_type' => $query->createParameter('item_type'),
+                                                       'item_source' => $query->createParameter('item_source'),
+                                                       'item_target' => $query->createParameter('item_target'),
+                                                       'file_source' => $query->createParameter('file_source'),
+                                                       'file_target' => $query->createParameter('file_target'),
+                                                       'permissions' => $query->createParameter('permissions'),
+                                                       'stime' => $query->createParameter('stime'),
+                                               ]
+                                       )
+                                       ->setParameter('share_type', $shareType)
+                                       ->setParameter('share_with', 'shareWith')
+                                       ->setParameter('uid_owner', 'user' . ($i))
+                                       ->setParameter('uid_initiator', null)
+                                       ->setParameter('parent', 0)
+                                       ->setParameter('item_type', 'file')
+                                       ->setParameter('item_source', '2')
+                                       ->setParameter('item_target', '/2')
+                                       ->setParameter('file_source', 2)
+                                       ->setParameter('file_target', '/foobar')
+                                       ->setParameter('permissions', 31)
+                                       ->setParameter('stime', time());
+
+                               $this->assertSame(1, $query->execute());
+                       }
+               }
+
+               $this->migration->addPasswordColumn();
+
+               $query = $this->connection->getQueryBuilder();
+               $query->select('*')->from('share');
+               $allShares = $query->execute()->fetchAll();
+
+               foreach ($allShares as $share) {
+                       if ((int)$share['share_type'] === Share::SHARE_TYPE_LINK) {
+                               $this->assertSame(null, $share['share_with']);
+                               $this->assertSame('shareWith', $share['password']);
+                       } else {
+                               $this->assertSame('shareWith', $share['share_with']);
+                               $this->assertSame(null, $share['password']);
+                       }
+               }
+       }
 }
index ae4c07e3f4e52c37ca2900cdee95032b6f8a2574..87d0556b996a013e0511e73cce31e35072891063 100644 (file)
                                                        isLinkShare: true,
                                                        id: share.id,
                                                        token: share.token,
-                                                       password: share.share_with,
+                                                       password: share.password,
                                                        link: link,
                                                        permissions: share.permissions,
                                                        // currently expiration is only effective for link shares.
index 545628a9233a78fafa8c279b16c392e6bc5602b6..ca832b6281900b2becf3e1c78f4dcab45ab48d10 100644 (file)
                                <notnull>false</notnull>
                                <length>255</length>
                        </field>
+                       <field>
+                               <name>password</name>
+                               <type>text</type>
+                               <default></default>
+                               <notnull>false</notnull>
+                               <length>255</length>
+                       </field>
 
                        <!-- Foreign Key users::uid -->
             <!-- This is the owner of the share
index e4ae26be13d1fbafc72e8801ef4d6e3d52ad9db6..cf7666f99e7c5a61a0f66f65527b8d5264420d08 100644 (file)
@@ -240,7 +240,7 @@ class DefaultShareProvider implements IShareProvider {
                        $qb = $this->dbConn->getQueryBuilder();
                        $qb->update('share')
                                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
-                               ->set('share_with', $qb->createNamedParameter($share->getPassword()))
+                               ->set('password', $qb->createNamedParameter($share->getPassword()))
                                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
                                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
                                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
@@ -646,7 +646,7 @@ class DefaultShareProvider implements IShareProvider {
                // exclude shares leading to trashbin on home storages
                $pathSections = explode('/', $data['path'], 2);
                // FIXME: would not detect rare md5'd home storage case properly
-               if ($pathSections[0] !== 'files' 
+               if ($pathSections[0] !== 'files'
                        && in_array(explode(':', $data['storage_string_id'], 2)[0], array('home', 'object'))) {
                        return false;
                }
@@ -838,7 +838,7 @@ class DefaultShareProvider implements IShareProvider {
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
                        $share->setSharedWith($data['share_with']);
                } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
-                       $share->setPassword($data['share_with']);
+                       $share->setPassword($data['password']);
                        $share->setToken($data['token']);
                }
 
index a556a9f72995de9b32a8eb7cb34b5f6befd1d138..0d1d327cb7f848637bbb0f3702a6d5eee9aaeaad 100644 (file)
@@ -26,7 +26,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(12, 0, 0, 13);
+$OC_Version = array(12, 0, 0, 14);
 
 // The human readable string
 $OC_VersionString = '12.0 alpha';