Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add secure view using using IShare attributes #245

Merged
merged 13 commits into from
May 15, 2019
101 changes: 101 additions & 0 deletions appinfo/Migrations/Version20190310162809.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?php
/**
* @author Piotr Mrowczynski piotr@owncloud.com
*
* @copyright Copyright (c) 2019, 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/>
*
*/

namespace OCA\richdocuments\Migrations;

use Doctrine\DBAL\Schema\Schema;
use OCP\Migration\ISchemaMigration;

/**
* Auto-generated migration step: Please modify to your needs!
*/
class Version20190310162809 implements ISchemaMigration {
public function changeSchema(Schema $schema, array $options) {
$prefix = $options['tablePrefix'];

// clean old legacy table if exists (only temporary tokens)
if ($schema->hasTable("{$prefix}richdocuments_wopi")) {
$schema->dropTable("{$prefix}richdocuments_wopi");
PVince81 marked this conversation as resolved.
Show resolved Hide resolved
}

// create richdocuments wopi tokens table, which will be used for
// wopi session tokens for the users
$table = $schema->createTable("${prefix}richdocuments_wopi");

// Document owner UserId - a textual user identifier
$table->addColumn('owner_uid', 'text', [
'length' => 64,
]);

// Document editor's UserId, can be different from uid if shared
$table->addColumn('editor_uid', 'text', [
'length' => 64,
]);

// The unique ID of the file authorized
$table->addColumn('fileid', 'integer', [
'length' => 10,
'notnull' => true,
]);

// Authorized version, if any, of given fileid
$table->addColumn('version', 'integer', [
'length' => 4,
'default' => 0,
'notnull' => true,
]);

// Relative to storage e.g. /welcome.odt
$table->addColumn('path', 'text', [
'length' => 512,
'notnull' => true,
]);

// Attributes of file authorized
$table->addColumn('attributes', 'integer', [
'length' => 4,
'default' => 0,
'notnull' => true,
]);

// Host from which token generation request originated
$table->addColumn('server_host', 'text', [
'default' => 'localhost',
'notnull' => true,
]);

// File access token
$table->addColumn('token', 'string', [
'length' => 32,
'default' => '',
'notnull' => true,
]);

// Expiration time of the token
$table->addColumn('expiry', 'integer', [
'length' => 4,
'unsigned' => true,
'notnull' => true,
]);

$table->addUniqueIndex(['token'], 'richdocuments_wopi_token_idx');
PVince81 marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 2 additions & 0 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@
$app->registerScripts();

\OCP\App::registerAdmin('richdocuments', 'admin');

\OCP\Util::connectHook('\OCP\Config', 'js', '\OCA\Files\App', 'extendJsConfig');
93 changes: 0 additions & 93 deletions appinfo/database.xml

This file was deleted.

1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@
<screenshot>https://owncloud.com/wp-content/uploads/2016/07/code_v2_calc-1-1024x576.png</screenshot>
<screenshot>https://owncloud.com/wp-content/uploads/2016/07/code_v2_impress-1-1024x576.png</screenshot>
<ocsid>174727</ocsid>
<use-migrations>true</use-migrations>
</info>
10 changes: 5 additions & 5 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
['name' => 'document#create', 'url' => 'ajax/documents/create', 'verb' => 'POST'],
['name' => 'document#listAll', 'url' => 'ajax/documents/list', 'verb' => 'GET'],
["name" => 'document#publicIndex', "url" => "public", "verb" => "GET"],
['name' => 'document#extAppWopiGetData', 'url' => 'wopi/extapp/data/{documentId}', 'verb' => 'POST'],
//documents - for WOPI access
['name' => 'document#extAppWopiGetData', 'url' => 'wopi/extapp/data/{fileId}', 'verb' => 'POST'],
['name' => 'document#wopiCheckFileInfo', 'url' => 'wopi/files/{fileId}', 'verb' => 'GET'],
['name' => 'document#wopiGetFile', 'url' => 'wopi/files/{fileId}/contents', 'verb' => 'GET'],
['name' => 'document#wopiPutFile', 'url' => 'wopi/files/{fileId}/contents', 'verb' => 'POST'],
['name' => 'document#wopiPutRelativeFile', 'url' => 'wopi/files/{fileId}', 'verb' => 'POST'],
['name' => 'document#wopiCheckFileInfo', 'url' => 'wopi/files/{documentId}', 'verb' => 'GET'],
['name' => 'document#wopiGetFile', 'url' => 'wopi/files/{documentId}/contents', 'verb' => 'GET'],
['name' => 'document#wopiPutFile', 'url' => 'wopi/files/{documentId}/contents', 'verb' => 'POST'],
['name' => 'document#wopiPutRelativeFile', 'url' => 'wopi/files/{documentId}', 'verb' => 'POST'],
//settings
['name' => 'settings#setSettings', 'url' => 'ajax/admin.php', 'verb' => 'POST'],
['name' => 'settings#getSettings', 'url' => 'ajax/settings.php', 'verb' => 'GET'],
Expand Down
54 changes: 54 additions & 0 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,36 @@ var documentsSettings = {
);
},

saveWatermarkText: function(value) {
$.post(
OC.filePath('richdocuments', 'ajax', 'admin.php'),
{ 'watermark_text': value }
);

OC.Notification.showTemporary(t('richdocuments', 'Saved watermark'), {timeout: 2});
mrow4a marked this conversation as resolved.
Show resolved Hide resolved
},

saveSecureViewOption: function(value) {
$.post(
OC.filePath('richdocuments', 'ajax', 'admin.php'),
{ 'secure_view_option': value }
);
},

saveCanPrintDefaultOption: function(value) {
$.post(
OC.filePath('richdocuments', 'ajax', 'admin.php'),
{ 'secure_view_can_print_default': value }
);
},

saveHasWatermarkDefaultOption: function(value) {
$.post(
OC.filePath('richdocuments', 'ajax', 'admin.php'),
{ 'secure_view_has_watermark_default': value }
);
},

afterSaveExternalApps: function(response) {
OC.msg.finishedAction('#enable-external-apps-section-msg', response);
},
Expand Down Expand Up @@ -297,6 +327,30 @@ var documentsSettings = {
var page = $(this).parent();
documentsSettings.saveMenuOption(this.checked);
});

$(document).on('change', '#enable_secure_view_option_cb-richdocuments', function() {
var page = $(this).parent();
page.find('#enable-watermark-section').toggleClass('hidden', !this.checked);
page.find('#enable-share-attributes-defaults').toggleClass('hidden', !this.checked);

documentsSettings.saveSecureViewOption(this.checked);
if (this.checked) {
var val = $('#secure-view-watermark').val();
documentsSettings.saveWatermarkText(val);
}
});

$(document).on('change', '#secure_view_has_watermark_default_option_cb-richdocuments', function() {
documentsSettings.saveHasWatermarkDefaultOption(this.checked);
});

$(document).on('change', '#secure_view_can_print_default_option_cb-richdocuments', function() {
documentsSettings.saveCanPrintDefaultOption(this.checked);
});

$(document).on('change', '#secure-view-watermark', function() {
documentsSettings.saveWatermarkText(this.value);
});
}
};

Expand Down
Loading