Skip to content
Permalink
Browse files Browse the repository at this point in the history
check permissions before rollback
  • Loading branch information
schiessle committed Jun 30, 2016
1 parent 95f6dd9 commit 1208953
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions apps/files_versions/lib/storage.php
Expand Up @@ -78,7 +78,7 @@ class Storage {
//until the end one version per week
6 => array('intervalEndsAfter' => -1, 'step' => 604800),
);

/** @var \OCA\Files_Versions\AppInfo\Application */
private static $application;

Expand Down Expand Up @@ -325,6 +325,13 @@ public static function rollback($file, $revision) {
$files_view = new View('/'. User::getUser().'/files');
$versionCreated = false;

$fileInfo = $files_view->getFileInfo($file);

// check if user has the permissions to revert a version
if (!$fileInfo->isUpdateable()) {
return false;
}

//first create a new version
$version = 'files_versions'.$filename.'.v'.$users_view->filemtime('files'.$filename);
if (!$users_view->file_exists($version)) {
Expand All @@ -338,10 +345,9 @@ public static function rollback($file, $revision) {
// This has to happen manually here since the file is manually copied below
$oldVersion = $users_view->getFileInfo($fileToRestore)->getEncryptedVersion();
$oldFileInfo = $users_view->getFileInfo($fileToRestore);
$newFileInfo = $files_view->getFileInfo($filename);
$cache = $newFileInfo->getStorage()->getCache();
$cache = $fileInfo->getStorage()->getCache();
$cache->update(
$newFileInfo->getId(), [
$fileInfo->getId(), [
'encrypted' => $oldVersion,
'encryptedVersion' => $oldVersion,
'size' => $oldFileInfo->getSize()
Expand Down Expand Up @@ -681,7 +687,7 @@ private static function scheduleExpire($uid, $fileName) {
public static function expire($filename) {
$config = \OC::$server->getConfig();
$expiration = self::getExpiration();

if($config->getSystemValue('files_versions', Storage::DEFAULTENABLED)=='true' && $expiration->isEnabled()) {

if (!Filesystem::file_exists($filename)) {
Expand Down

0 comments on commit 1208953

Please sign in to comment.