Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions apps/dav/lib/Meta/MetaFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
use OCA\DAV\Files\IProvidesAdditionalHeaders;
use OCA\DAV\Files\IFileNode;
use OCP\Files\IProvidesVersionAuthor;
use OCP\Files\IProvidesVersionIsCurrent;
use OCP\Files\IProvidesVersionString;
use OCP\Files\Node;
use Sabre\DAV\File;

Expand Down Expand Up @@ -150,4 +152,24 @@ public function getVersionAuthorName() : string {
}
return '';
}

/**
* @return string
*/
public function getVersionString() : string {
if ($this->file instanceof IProvidesVersionString) {
return $this->file->getVersionString();
}
return '';
}

/**
* @return bool
*/
public function getVersionIsCurrent() : bool {
if ($this->file instanceof IProvidesVersionIsCurrent) {
return $this->file->getVersionIsCurrent();
}
return false;
}
}
9 changes: 9 additions & 0 deletions apps/dav/lib/Meta/MetaPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ class MetaPlugin extends ServerPlugin {

public const VERSION_EDITED_BY_PROPERTYNAME = '{http://owncloud.org/ns}meta-version-edited-by';
public const VERSION_EDITED_BY_PROPERTYNAME_NAME = '{http://owncloud.org/ns}meta-version-edited-by-name';
public const VERSION_STRING_PROPERTYNAME = '{http://owncloud.org/ns}meta-version-string';
public const VERSION_IS_CURRENT_PROPERTYNAME = '{http://owncloud.org/ns}meta-version-is-current';

/**
* Reference to main server object
*
Expand Down Expand Up @@ -106,6 +109,12 @@ public function handleGetProperties(PropFind $propFind, INode $node) {
$propFind->handle(self::VERSION_EDITED_BY_PROPERTYNAME_NAME, function () use ($node) {
return $node->getVersionAuthorName();
});
$propFind->handle(self::VERSION_STRING_PROPERTYNAME, function () use ($node) {
return $node->getVersionString();
});
$propFind->handle(self::VERSION_IS_CURRENT_PROPERTYNAME, function () use ($node) {
return $node->getVersionIsCurrent();
});
}
}
}
36 changes: 36 additions & 0 deletions apps/files_versions/appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @author Jannik Stehle <jstehle@owncloud.com>
*
* @copyright Copyright (c) 2022, ownCloud GmbH
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/

$application = new \OCA\Files_Versions\AppInfo\Application();

$application->registerRoutes(
// @phan-suppress-next-line PhanUndeclaredThis
$this,
[
'routes' => [
[
'name' => 'Version#publishVersion',
'url' => '/publish-version',
'verb' => 'POST'
]
]
]
);
23 changes: 21 additions & 2 deletions apps/files_versions/css/versions.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
.versionsTabView li {
width: 100%;
cursor: default;
height: 56px;
height: 60px;
float: left;
border-bottom: 1px solid rgba(100,100,100,.1);
}
Expand Down Expand Up @@ -34,9 +34,13 @@

.versionsTabView .preview-container {
display: inline-block;
vertical-align: top;
vertical-align: top;
text-align: center;
}

.versionsTabView .preview-container {
padding: 5px;
}
.versionsTabView img {
cursor: pointer;
padding-right: 4px;
Expand All @@ -47,10 +51,13 @@
background-size: 32px;
width: 32px;
height: 32px;
display: block;
margin: 0 auto;
}

.versionsTabView .version-container {
display: inline-block;
margin-top: 5px;
}

.versionsTabView .versiondate {
Expand All @@ -71,3 +78,15 @@
float: right;
margin-right: -10px;
}

.versionsTabView .publishVersion {
cursor: pointer;
float: right;
margin-right: -10px;
}
.versionsTabView .current-version .version-headline {
font-weight: bold;
}
.versionsTabView .current-version {
background: #f8f8f8;
}
14 changes: 10 additions & 4 deletions apps/files_versions/js/versioncollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
_.extend(OC.Files.Client, {
PROPERTY_FILEID: '{' + OC.Files.Client.NS_OWNCLOUD + '}id',
PROPERTY_VERSION_EDITED_BY: '{' + OC.Files.Client.NS_OWNCLOUD + '}meta-version-edited-by',
PROPERTY_VERSION_EDITED_BY_NAME: '{' + OC.Files.Client.NS_OWNCLOUD + '}meta-version-edited-by-name',
PROPERTY_VERSION_EDITED_BY_NAME: '{' + OC.Files.Client.NS_OWNCLOUD + '}meta-version-edited-by-name',
PROPERTY_VERSION_STRING: '{' + OC.Files.Client.NS_OWNCLOUD + '}meta-version-string',
PROPERTY_VERSION_IS_CURRENT: '{' + OC.Files.Client.NS_OWNCLOUD + '}meta-version-is-current',
});

/**
Expand All @@ -26,7 +28,9 @@

davProperties: {
'meta-version-edited-by': OC.Files.Client.PROPERTY_VERSION_EDITED_BY,
'meta-version-edited-by-name': OC.Files.Client.PROPERTY_VERSION_EDITED_BY_NAME,
'meta-version-edited-by-name': OC.Files.Client.PROPERTY_VERSION_EDITED_BY_NAME,
'meta-version-string': OC.Files.Client.PROPERTY_VERSION_STRING,
'meta-version-is-current': OC.Files.Client.PROPERTY_VERSION_IS_CURRENT,
'id': OC.Files.Client.PROPERTY_FILEID,
'getlastmodified': OC.Files.Client.PROPERTY_GETLASTMODIFIED,
'getcontentlength': OC.Files.Client.PROPERTY_GETCONTENTLENGTH,
Expand Down Expand Up @@ -68,8 +72,10 @@
size: version.getcontentlength,
mimetype: version.getcontenttype,
editedBy: version['meta-version-edited-by'],
editedByName: version['meta-version-edited-by-name'],
fileId: fileId
editedByName: version['meta-version-edited-by-name'],
fileId: fileId,
versionString: version['meta-version-string'],
isCurrent: version['meta-version-is-current'] === '1',
};
});
}
Expand Down
18 changes: 18 additions & 0 deletions apps/files_versions/js/versionmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@
});
},

/**
* Publish a new version
*/
publish: function(options) {
var model = this;
$.post(OC.generateUrl('/apps/files_versions/publish-version'), { path: this.getFullPath() })
.done(function() {
if (options.success) {
options.success.call(options.context, model, {}, options);
}
})
.fail(function () {
if (options.error) {
options.error.call(options.context, model, {}, options);
}
});
},

getFullPath: function() {
return this.get('fullPath');
},
Expand Down
62 changes: 55 additions & 7 deletions apps/files_versions/js/versionstabview.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
}

var TEMPLATE_ITEM =
'<li data-revision="{{versionId}}">' +
'<li data-revision="{{versionId}}" class="{{#isCurrent}}current-version{{/isCurrent}}">' +
'<div>' +
'<div class="preview-container">' +
'<img class="preview" src="{{previewUrl}}"/>' +
'<img class="preview" src="{{previewUrl}}"/><span>{{versionString}}</span>' +
'</div>' +
'<div class="version-container">' +
'<div>' +
'<div class="version-headline">' +
'<a href="{{downloadUrl}}" class="downloadVersion"><img src="{{downloadIconUrl}}" />' +
'<span class="versiondate has-tooltip" title="{{formattedTimestamp}}">{{relativeTimestamp}}</span>' +
'<span class="versiondate has-tooltip" title="{{formattedTimestamp}}">{{relativeTimestamp}} {{#isCurrent}}· current{{/isCurrent}}</span>' +
'</a>' +
'</div>' +
'{{#hasDetails}}' +
Expand All @@ -43,6 +43,9 @@
'</div>' +
'{{/hasDetails}}' +
'</div>' +
'{{#canPublish}}' +
'<a href="#" class="publishVersion" title="{{publishLabel}}"><img src="{{publishIconUrl}}" /></a>' +
'{{/canPublish}}' +
'{{#canRevert}}' +
'<a href="#" class="revertVersion" title="{{revertLabel}}"><img src="{{revertIconUrl}}" /></a>' +
'{{/canRevert}}' +
Expand All @@ -68,7 +71,8 @@
$versionsContainer: null,

events: {
'click .revertVersion': '_onClickRevertVersion'
'click .revertVersion': '_onClickRevertVersion',
'click .publishVersion': '_onClickPublishVersion'
},

initialize: function() {
Expand Down Expand Up @@ -150,6 +154,44 @@
fileInfoModel.trigger('busy', fileInfoModel, true);
},

_onClickPublishVersion: function(ev) {
var self = this;
var $target = $(ev.target);
var fileInfoModel = this.collection.getFileInfo();
var revision;
if (!$target.is('li')) {
$target = $target.closest('li');
}

ev.preventDefault();
revision = $target.attr('data-revision');

var versionModel = this.collection.get(revision);
versionModel.publish({
success: function() {
// reset and re-fetch the updated collection
self.$versionsContainer.empty();
self.collection.setFileInfo(fileInfoModel);
self.collection.reset([], {silent: true});
self.collection.fetch();

self.$el.find('.versions').removeClass('hidden');
self._toggleLoading(false);
fileInfoModel.trigger('busy', fileInfoModel, false);
},
error: function() {
self.$el.find('.versions').removeClass('hidden');
self._toggleLoading(false);
fileInfoModel.trigger('busy', fileInfoModel, false);
OC.Notification.show(t('files_versions', 'Failed to publish version'),{type: 'error'});
}
});

// spinner
this._toggleLoading(true);
fileInfoModel.trigger('busy', fileInfoModel, true);
},

_toggleLoading: function(state) {
this._loading = state;
this.$el.find('.loading').toggleClass('hidden', !state);
Expand Down Expand Up @@ -201,6 +243,7 @@
_formatItem: function(version) {
var timestamp = version.get('timestamp') * 1000;
var size = version.has('size') ? version.get('size') : 0;
var isMajorVersion = version.get('versionString').indexOf('.0', version.get('versionString').length - '.0'.length) !== -1;

return _.extend({
versionId: version.get('id'),
Expand All @@ -212,11 +255,16 @@
downloadUrl: version.getDownloadUrl(),
downloadIconUrl: OC.imagePath('core', 'actions/download'),
revertIconUrl: OC.imagePath('core', 'actions/history'),
publishIconUrl: OC.imagePath('core', 'actions/checkmark'),
previewUrl: getPreviewUrl(version),
revertLabel: t('files_versions', 'Restore'),
canRevert: (this.collection.getFileInfo().get('permissions') & OC.PERMISSION_UPDATE) !== 0,
publishLabel: t('files_versions', 'Publish version'),
canRevert: (this.collection.getFileInfo().get('permissions') & OC.PERMISSION_UPDATE) !== 0 && version.get('isCurrent') === false,
canPublish: version.get('isCurrent') === true && !isMajorVersion,
editedBy: version.has('editedBy'),
editedByName: version.has('editedByName')
editedByName: version.has('editedByName'),
versionString: version.has('versionString'),
isCurrent: version.has('isCurrent')
}, version.attributes);
},

Expand Down
12 changes: 12 additions & 0 deletions apps/files_versions/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,30 @@
namespace OCA\Files_Versions\AppInfo;

use OC\AllConfig;
use OCA\Files_Versions\Controller\VersionController;
use OCA\Files_Versions\Expiration;
use OCA\Files_Versions\FileHelper;
use OCA\Files_Versions\MetaStorage;
use OCA\Files_Versions\Storage;
use OCP\AppFramework\App;
use OCP\IContainer;

class Application extends App {
public function __construct(array $urlParams = []) {
parent::__construct('files_versions', $urlParams);

$container = $this->getContainer();

/**
* Controllers
*/
$container->registerService('VersionController', function ($c) {
return new VersionController(
$c->query('AppName'),
$c->query('Request')
);
});

/*
* Register capabilities
*/
Expand Down
3 changes: 2 additions & 1 deletion apps/files_versions/lib/Command/CleanUp.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace OCA\Files_Versions\Command;

use OCA\Files_Versions\Storage;
use OCP\Files\IRootFolder;
use OCP\IUserBackend;
use OCP\IUserManager;
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function deleteVersions($user) {
\OC_Util::tearDownFS();
\OC_Util::setupFS($user);
if ($this->rootFolder->nodeExists('/' . $user . '/files_versions')) {
$this->rootFolder->get('/' . $user . '/files_versions')->delete();
Storage::cleanUp($user);
}
}
}
Loading