summaryrefslogtreecommitdiffstats
path: root/apps/files_sharing
diff options
context:
space:
mode:
authorBjoern Schiessle <bjoern@schiessle.org>2017-03-28 15:11:07 +0200
committerBjoern Schiessle <bjoern@schiessle.org>2017-04-03 10:20:49 +0200
commit0d5147bd492e11dcb1ed264bcc27d21dc026c6f1 (patch)
tree987445dafba0171b933727e6b4060ba7ad4845e6 /apps/files_sharing
parentd0eefd17d3c47de8d13d41e57a2a6966af94428f (diff)
downloadnextcloud-server-0d5147bd492e11dcb1ed264bcc27d21dc026c6f1.tar.gz
nextcloud-server-0d5147bd492e11dcb1ed264bcc27d21dc026c6f1.zip
add new password column to the share table in order to set passwords for share by mails
Signed-off-by: Bjoern Schiessle <bjoern@schiessle.org>
Diffstat (limited to 'apps/files_sharing')
-rw-r--r--apps/files_sharing/appinfo/info.xml2
-rw-r--r--apps/files_sharing/appinfo/update.php5
-rw-r--r--apps/files_sharing/lib/Controller/ShareAPIController.php1
-rw-r--r--apps/files_sharing/lib/Migration.php18
-rw-r--r--apps/files_sharing/tests/MigrationTest.php80
5 files changed, 95 insertions, 11 deletions
diff --git a/apps/files_sharing/appinfo/info.xml b/apps/files_sharing/appinfo/info.xml
index e2a08d951ac..29a137fed0b 100644
--- a/apps/files_sharing/appinfo/info.xml
+++ b/apps/files_sharing/appinfo/info.xml
@@ -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>
diff --git a/apps/files_sharing/appinfo/update.php b/apps/files_sharing/appinfo/update.php
index ed0d7732b37..917cb7b6639 100644
--- a/apps/files_sharing/appinfo/update.php
+++ b/apps/files_sharing/appinfo/update.php
@@ -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();
+}
diff --git a/apps/files_sharing/lib/Controller/ShareAPIController.php b/apps/files_sharing/lib/Controller/ShareAPIController.php
index 78eef6c26bb..80ba7534da0 100644
--- a/apps/files_sharing/lib/Controller/ShareAPIController.php
+++ b/apps/files_sharing/lib/Controller/ShareAPIController.php
@@ -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) {
diff --git a/apps/files_sharing/lib/Migration.php b/apps/files_sharing/lib/Migration.php
index 605a11fd22c..49e275cbe6e 100644
--- a/apps/files_sharing/lib/Migration.php
+++ b/apps/files_sharing/lib/Migration.php
@@ -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
*
diff --git a/apps/files_sharing/tests/MigrationTest.php b/apps/files_sharing/tests/MigrationTest.php
index 572f64da743..a357e814f25 100644
--- a/apps/files_sharing/tests/MigrationTest.php
+++ b/apps/files_sharing/tests/MigrationTest.php
@@ -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']);
+ }
+ }
+ }
}