Merge pull request #69 from Ashod/versions
Correct editor attribution in file change history
This commit is contained in:
commit
2c078c9aef
2
Makefile
2
Makefile
@ -1,4 +1,4 @@
|
|||||||
VERSION=0.15.3
|
VERSION=0.16.0
|
||||||
|
|
||||||
.PHONY: dist
|
.PHONY: dist
|
||||||
dist: owncloud-collabora-online.spec info.xml
|
dist: owncloud-collabora-online.spec info.xml
|
||||||
|
@ -287,10 +287,16 @@
|
|||||||
<comments>Unique per token</comments>
|
<comments>Unique per token</comments>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>uid</name>
|
<name>owner_uid</name>
|
||||||
<type>text</type>
|
<type>text</type>
|
||||||
<length>64</length>
|
<length>64</length>
|
||||||
<comments>UserId - a textual user identifier (unique?)</comments>
|
<comments>Document owner UserId - a textual user identifier (unique?)</comments>
|
||||||
|
</field>
|
||||||
|
<field>
|
||||||
|
<name>editor_uid</name>
|
||||||
|
<type>text</type>
|
||||||
|
<length>64</length>
|
||||||
|
<comments>Document editor's UserId, can be different from uid if shared</comments>
|
||||||
</field>
|
</field>
|
||||||
<field>
|
<field>
|
||||||
<name>fileid</name>
|
<name>fileid</name>
|
||||||
|
@ -50,7 +50,6 @@ class DocumentController extends Controller {
|
|||||||
private $settings;
|
private $settings;
|
||||||
private $cache;
|
private $cache;
|
||||||
private $logger;
|
private $logger;
|
||||||
|
|
||||||
const ODT_TEMPLATE_PATH = '/assets/odttemplate.odt';
|
const ODT_TEMPLATE_PATH = '/assets/odttemplate.odt';
|
||||||
|
|
||||||
public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $uid, ICacheFactory $cache, ILogger $logger){
|
public function __construct($appName, IRequest $request, IConfig $settings, IL10N $l10n, $uid, ICacheFactory $cache, ILogger $logger){
|
||||||
@ -379,7 +378,7 @@ class DocumentController extends Controller {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$view = new \OC\Files\View('/' . $res['user'] . '/files');
|
$view = new \OC\Files\View('/' . $res['owner'] . '/files');
|
||||||
$info = $view->getFileInfo($res['path']);
|
$info = $view->getFileInfo($res['path']);
|
||||||
|
|
||||||
\OC::$server->getLogger()->debug('File info: {info}.', [ 'app' => $this->appName, 'info' => $info ]);
|
\OC::$server->getLogger()->debug('File info: {info}.', [ 'app' => $this->appName, 'info' => $info ]);
|
||||||
@ -412,7 +411,7 @@ class DocumentController extends Controller {
|
|||||||
|
|
||||||
//TODO: Support X-WOPIMaxExpectedSize header.
|
//TODO: Support X-WOPIMaxExpectedSize header.
|
||||||
$res = $row->getPathForToken($fileId, $token);
|
$res = $row->getPathForToken($fileId, $token);
|
||||||
return new DownloadResponse($this->request, $res['user'], '/files' . $res['path']);
|
return new DownloadResponse($this->request, $res['owner'], '/files' . $res['path']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -431,16 +430,31 @@ class DocumentController extends Controller {
|
|||||||
$row->loadBy('token', $token);
|
$row->loadBy('token', $token);
|
||||||
|
|
||||||
$res = $row->getPathForToken($fileId, $token);
|
$res = $row->getPathForToken($fileId, $token);
|
||||||
$root = '/' . $res['user'] . '/files';
|
|
||||||
|
// Log-in as the user to regiser the change under her name.
|
||||||
|
$editorid = $res['editor'];
|
||||||
|
$users = \OC::$server->getUserManager()->search($editorid, 1, 0);
|
||||||
|
if (count($users) > 0)
|
||||||
|
{
|
||||||
|
$user = array_shift($users);
|
||||||
|
if (strcasecmp($user->getUID(),$editorid) === 0)
|
||||||
|
{
|
||||||
|
\OC::$server->getUserSession()->setUser($user);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the filesystem view for the owner (where the file actually is).
|
||||||
|
$userid = $res['owner'];
|
||||||
|
$root = '/' . $userid . '/files';
|
||||||
$view = new \OC\Files\View($root);
|
$view = new \OC\Files\View($root);
|
||||||
|
|
||||||
// Read the contents of the file from the POST body and store.
|
// Read the contents of the file from the POST body and store.
|
||||||
$content = fopen('php://input', 'r');
|
$content = fopen('php://input', 'r');
|
||||||
\OC::$server->getLogger()->debug('Putting {size} bytes.', [ 'app' => $this->appName, 'size' => strlen($content) ]);
|
\OC::$server->getLogger()->debug('Storing file {fileId} by {editor} owned by {owner}.', [ 'app' => $this->appName, 'fileId' => $fileId, 'editor' => $editorid, 'owner' => $userid ]);
|
||||||
|
|
||||||
// Setup the FS which is needed to emit hooks (versioning).
|
// Setup the FS which is needed to emit hooks (versioning).
|
||||||
\OC_Util::tearDownFS();
|
\OC_Util::tearDownFS();
|
||||||
\OC_Util::setupFS($res['user'], $root);
|
\OC_Util::setupFS($userid, $root);
|
||||||
|
|
||||||
$view->file_put_contents($res['path'], $content);
|
$view->file_put_contents($res['path'], $content);
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ class Wopi extends \OCA\Richdocuments\Db{
|
|||||||
|
|
||||||
protected $tableName = '`*PREFIX*richdocuments_wopi`';
|
protected $tableName = '`*PREFIX*richdocuments_wopi`';
|
||||||
|
|
||||||
protected $insertStatement = 'INSERT INTO `*PREFIX*richdocuments_wopi` (`uid`, `fileid`, `path`, `token`, `expiry`)
|
protected $insertStatement = 'INSERT INTO `*PREFIX*richdocuments_wopi` (`owner_uid`, `editor_uid`, `fileid`, `path`, `token`, `expiry`)
|
||||||
VALUES (?, ?, ?, ?, ?)';
|
VALUES (?, ?, ?, ?, ?, ?)';
|
||||||
|
|
||||||
protected $loadStatement = 'SELECT * FROM `*PREFIX*richdocuments_wopi` WHERE `token`= ?';
|
protected $loadStatement = 'SELECT * FROM `*PREFIX*richdocuments_wopi` WHERE `token`= ?';
|
||||||
|
|
||||||
@ -51,25 +51,28 @@ class Wopi extends \OCA\Richdocuments\Db{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Figure out the real owner, if not us.
|
// Figure out the real owner, if not us.
|
||||||
$user = $view->getOwner($path);
|
$owner = $view->getOwner($path);
|
||||||
|
|
||||||
// Create a view into the owner's FS.
|
// Create a view into the owner's FS.
|
||||||
$view = new \OC\Files\View('/' . $user . '/files');
|
$view = new \OC\Files\View('/' . $owner . '/files');
|
||||||
// Find the real path.
|
// Find the real path.
|
||||||
$path = $view->getPath($fileId);
|
$path = $view->getPath($fileId);
|
||||||
if (!$view->is_file($path)) {
|
if (!$view->is_file($path)) {
|
||||||
throw new \Exception('Invalid fileId.');
|
throw new \Exception('Invalid fileId.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$editor = \OC::$server->getUserSession()->getUser()->getUID();
|
||||||
|
|
||||||
$token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32,
|
$token = \OC::$server->getSecureRandom()->getMediumStrengthGenerator()->generate(32,
|
||||||
\OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_UPPER .
|
\OCP\Security\ISecureRandom::CHAR_LOWER . \OCP\Security\ISecureRandom::CHAR_UPPER .
|
||||||
\OCP\Security\ISecureRandom::CHAR_DIGITS);
|
\OCP\Security\ISecureRandom::CHAR_DIGITS);
|
||||||
|
|
||||||
\OC::$server->getLogger()->debug('Issuing token for {user} file {fileId}, path {path}: {token}',
|
\OC::$server->getLogger()->debug('Issuing token for {editor} file {fileId} owned by {owner}, path {path}: {token}',
|
||||||
[ 'user' => $user, 'fileId' => $fileId, 'path' => $path, 'token' => $token ]);
|
[ 'owner' => $owner, 'editor' => $editor, 'fileId' => $fileId, 'path' => $path, 'token' => $token ]);
|
||||||
|
|
||||||
$wopi = new \OCA\Richdocuments\Db\Wopi([
|
$wopi = new \OCA\Richdocuments\Db\Wopi([
|
||||||
$user,
|
$owner,
|
||||||
|
$editor,
|
||||||
$fileId,
|
$fileId,
|
||||||
$path,
|
$path,
|
||||||
$token,
|
$token,
|
||||||
@ -113,14 +116,15 @@ class Wopi extends \OCA\Richdocuments\Db{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$user = $row['uid'];
|
$owner = $row['owner_uid'];
|
||||||
$view = new \OC\Files\View('/' . $user . '/files');
|
$view = new \OC\Files\View('/' . $owner . '/files');
|
||||||
$path = $row['path'];
|
$path = $row['path'];
|
||||||
|
|
||||||
if (!$view->is_file($path)) {
|
if (!$view->is_file($path)) {
|
||||||
throw new \Exception('Invalid file path.');
|
throw new \Exception('Invalid file path.');
|
||||||
}
|
}
|
||||||
|
|
||||||
return array('user' => $user, 'path' => $path);
|
$editor = $row['editor_uid'];
|
||||||
|
return array('owner' => $owner, 'editor' => $editor, 'path' => $path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user