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>
pull/4136/head
Bjoern Schiessle 8 years ago
parent d0eefd17d3
commit 0d5147bd49
No known key found for this signature in database
GPG Key ID: 2378A753E2BF04F6
  1. 2
      apps/files_sharing/appinfo/info.xml
  2. 5
      apps/files_sharing/appinfo/update.php
  3. 1
      apps/files_sharing/lib/Controller/ShareAPIController.php
  4. 18
      apps/files_sharing/lib/Migration.php
  5. 80
      apps/files_sharing/tests/MigrationTest.php
  6. 2
      core/js/shareitemmodel.js
  7. 7
      db_structure.xml
  8. 4
      lib/private/Share20/DefaultShareProvider.php
  9. 2
      version.php

@ -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>

@ -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();
}

@ -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) {

@ -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
*

@ -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']);
}
}
}
}

@ -757,7 +757,7 @@
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.

@ -791,6 +791,13 @@
<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

@ -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()))
@ -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']);
}

@ -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';

Loading…
Cancel
Save