Skip to content

Commit

Permalink
add switch to enable features and adjust to reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
mrow4a committed Apr 17, 2019
1 parent af3f878 commit 589dbd2
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 71 deletions.
13 changes: 7 additions & 6 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,17 @@ var documentsSettings = {
);
},

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

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

Expand Down Expand Up @@ -341,9 +341,10 @@ var documentsSettings = {
}
});

$(document).on('change', '#secure_view_can_download_default_option_cb-richdocuments', function() {
documentsSettings.saveCanDownloadDefaultOption(this.checked);
$(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);
});
Expand Down
119 changes: 90 additions & 29 deletions js/viewer/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,100 @@ OC.Plugins.register('OC.Share.ShareItemModel', {
var mimetype = model.getFileInfo().getMimeType();
var folderMimeType = 'httpd/unix-directory';
if ((odfViewer.isSupportedMimeType(mimetype) || mimetype === folderMimeType) &&
OC.appConfig.richdocuments && OC.appConfig.richdocuments.defaultShareAttributes) {
/** @type OC.Share.Types.RegisteredShareAttribute **/
var secureViewCanDownload = {
"scope": "permissions",
"key": "download",
"default": JSON.parse(OC.appConfig.richdocuments.defaultShareAttributes.secureViewCanDownload),
"label": t('richdocuments', 'can view without watermark'),
"description": t('richdocuments', 'With this permission being' +
' set, share receiver will be allowed to download file ' +
' directly. Disabling this option will restrict receiver ' +
' to viewing the document(s) in secure mode with watermark included'),
"shareType" : [OC.Share.SHARE_TYPE_GROUP, OC.Share.SHARE_TYPE_USER],
"incompatiblePermissions": [OC.PERMISSION_UPDATE],
"incompatibleAttributes": []
OC.appConfig.richdocuments &&
OC.appConfig.richdocuments.secureViewAllowed &&
OC.appConfig.richdocuments.defaultShareAttributes) {
// Check if can download has been already added by other app,
// as this is core permission
if (model.getRegisteredShareAttribute("permissions", "download") === null) {
/**
* With this permission being set, share receiver will be allowed
* to download file directly. Disabling this option will restrict
* receiver to viewing the document(s)
*
* @type OC.Share.Types.RegisteredShareAttribute
*/
var canDownload = {
scope: "permissions",
key: "download",
default: JSON.parse(OC.appConfig.richdocuments.defaultShareAttributes.secureViewCanDownload),
label: t('richdocuments', 'can download'),
shareType : [
OC.Share.SHARE_TYPE_GROUP,
OC.Share.SHARE_TYPE_USER
],
incompatiblePermissions: [
OC.PERMISSION_UPDATE,
OC.PERMISSION_CREATE,
OC.PERMISSION_DELETE,
OC.PERMISSION_SHARE
],
requiredPermissions: [],
incompatibleAttributes: []
};
model.registerShareAttribute(canDownload);
}


/**
* This option will secure the viewed document with watermark on
* each tale of the document
*
* @type OC.Share.Types.RegisteredShareAttribute
*/
var secureViewHasWatermark = {
scope: "richdocuments",
key: "watermark",
default: JSON.parse(OC.appConfig.richdocuments.defaultShareAttributes.secureViewHasWatermark),
label: t('richdocuments', 'secure view with watermarks'),
shareType : [
OC.Share.SHARE_TYPE_GROUP,
OC.Share.SHARE_TYPE_USER
],
incompatiblePermissions: [
OC.PERMISSION_UPDATE,
OC.PERMISSION_CREATE,
OC.PERMISSION_DELETE,
OC.PERMISSION_SHARE
],
requiredPermissions: [],
incompatibleAttributes: [
{
scope: "permissions",
key: "download",
enabled: true
}
]
};
model.registerShareAttribute(secureViewCanDownload);
model.registerShareAttribute(secureViewHasWatermark);

/** @type OC.Share.Types.RegisteredShareAttribute **/
/**
* With this permission being set, share receiver
* will be able to print document(s)
*
* @type OC.Share.Types.RegisteredShareAttribute
*/
var secureViewCanPrint = {
"scope": "richdocuments",
"key": "print",
"default": JSON.parse(OC.appConfig.richdocuments.defaultShareAttributes.secureViewCanPrint),
"label": t('richdocuments', 'can print/export (will include watermark)'),
"description": t('richdocuments', 'With this permission being' +
' set, share receiver will be able to print document(s) ' +
' with watermark included'),
"shareType" : [OC.Share.SHARE_TYPE_GROUP, OC.Share.SHARE_TYPE_USER],
"incompatiblePermissions": [OC.PERMISSION_UPDATE],
"incompatibleAttributes": [
scope: "richdocuments",
key: "print",
default: JSON.parse(OC.appConfig.richdocuments.defaultShareAttributes.secureViewCanPrint),
label: t('richdocuments', 'allow print/export'),
shareType : [
OC.Share.SHARE_TYPE_GROUP,
OC.Share.SHARE_TYPE_USER
],
incompatiblePermissions: [
OC.PERMISSION_UPDATE,
OC.PERMISSION_CREATE,
OC.PERMISSION_DELETE,
OC.PERMISSION_SHARE
],
requiredPermissions: [],
incompatibleAttributes: [
{
"scope": "permissions",
"key": "download",
"enabled": true
scope: "permissions",
key: "download",
enabled: true
}
]
};
Expand Down
19 changes: 17 additions & 2 deletions lib/AppConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ class AppConfig {
private $appName = 'richdocuments';
private $defaults = [
'wopi_url' => 'https://localhost:9980',
'secure_view_can_download_default' => 'false',
'secure_view_can_print_default' => 'false'
'secure_view_option' => 'false',
'secure_view_can_print_default' => 'true',
'secure_view_has_watermark_default' => 'true'
];

private $config;
Expand Down Expand Up @@ -74,4 +75,18 @@ public function getUserValue($userId, $key) {
public function setUserValue($userId, $key, $value) {
return $this->config->setAppValue($userId, $this->appName, $key, $value);
}

/**
* Check if app can have enterprise features enabled
*
* @return bool
*/
public function enterpriseFeaturesEnabled() {
if ($this->config->getAppValue('enterprise_key', 'license-key', null) === null &&
$this->config->getSystemValue('license-key', null) === null) {
return false;
}

return true;
}
}
41 changes: 25 additions & 16 deletions lib/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,18 +638,21 @@ private function getWopiInfoForAuthUser($fileId, $version, $currentUser) {

// Check download attribute
$canDownload = $share->getAttributes()->getAttribute('permissions', 'download');
if ($canDownload !== null && !$canDownload) {
// cant download, use user id as id for unique session fork (no shared editing)
$sessionid = $currentUser;

// Disabling print with watermark only makes sense when cannot dowload
$canPrint = $share->getAttributes()->getAttribute('richdocuments', 'secure-view-can-print');
if ($canPrint === null || $canPrint === true) {
// can print is not set or true
$attributes = $attributes | WOPI::ATTR_CAN_PRINT;
}
} else {
$attributes = $attributes | WOPI::ATTR_CAN_DOWNLOAD | WOPI::ATTR_CAN_PRINT;
if ($canDownload === null || $canDownload === true) {
// can print is not set or true
$attributes = $attributes | WOPI::ATTR_CAN_DOWNLOAD;
}

$canPrint = $share->getAttributes()->getAttribute('richdocuments', 'print');
if ($canPrint === null || $canPrint === true) {
// can print is not set or true
$attributes = $attributes | WOPI::ATTR_CAN_PRINT;
}

$hasWatermark = $share->getAttributes()->getAttribute('richdocuments', 'watermark');
if ($hasWatermark === true) {
// can print is not set or true
$attributes = $attributes | WOPI::ATTR_HAS_WATERMARK;
}
} else {
$attributes = $attributes | WOPI::ATTR_CAN_DOWNLOAD | WOPI::ATTR_CAN_PRINT;
Expand Down Expand Up @@ -856,17 +859,23 @@ public function wopiCheckFileInfo($documentId) {
if ($secureMode) {
$canDownload = $res['attributes'] & WOPI::ATTR_CAN_DOWNLOAD;
if (!$canDownload) {
$result = \array_merge($result, [
'DisableExport' => true,
'HideExportOption' => true,
'HideSaveOption' => true, // dont show the §save to OC§ option as user cannot download file
'DisableCopy' => true, // disallow copying in document
]);
}

$hasWatermark = $res['attributes'] & WOPI::ATTR_HAS_WATERMARK;
if ($hasWatermark) {
$watermark = \str_replace(
'{viewer-email}',
$editor->getEMailAddress() === null ? $editor->getDisplayName() : $editor->getEMailAddress(),
\OC::$server->getConfig()->getAppValue('richdocuments', 'watermark_text', '')
);
$result = \array_merge($result, [
'WatermarkText' => $watermark,
'DisableExport' => true, // FIXME: new permission?
'HideExportOption' => true, // FIXME: new permission?
'HideSaveOption' => true, // dont show the §save to OC§ option as user cannot download file
'DisableCopy' => true, // disallow copying in document
]);
}

Expand Down
17 changes: 9 additions & 8 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,17 @@ public function adminIndex() {
'external_apps' => $this->appConfig->getAppValue('external_apps'),
'canonical_webroot' => $this->appConfig->getAppValue('canonical_webroot'),
'menu_option' => $this->appConfig->getAppValue('menu_option'),
'secure_view_allowed' => $this->appConfig->enterpriseFeaturesEnabled() ? 'true' : 'false',
'secure_view_option' => $this->appConfig->getAppValue('secure_view_option'),
'secure_view_can_download_default' => $this->appConfig->getAppValue('secure_view_can_download_default'),
'secure_view_has_watermark_default' => $this->appConfig->getAppValue('secure_view_has_watermark_default'),
'secure_view_can_print_default' => $this->appConfig->getAppValue('secure_view_can_print_default'),
'watermark_text' => $this->appConfig->getAppValue('watermark_text')
],
'blank'
);
}

public function setSettings($wopi_url, $edit_groups, $doc_format, $test_wopi_url, $test_server_groups, $external_apps, $canonical_webroot, $menu_option, $secure_view_option, $watermark_text, $secure_view_can_download_default, $secure_view_can_print_default) {
public function setSettings($wopi_url, $edit_groups, $doc_format, $test_wopi_url, $test_server_groups, $external_apps, $canonical_webroot, $menu_option, $secure_view_option, $secure_view_can_print_default, $secure_view_has_watermark_default, $watermark_text) {
$message = $this->l10n->t('Saved');

if ($wopi_url !== null) {
Expand Down Expand Up @@ -119,16 +120,16 @@ public function setSettings($wopi_url, $edit_groups, $doc_format, $test_wopi_url
$this->appConfig->setAppValue('secure_view_option', $secure_view_option);
}

if ($watermark_text !== null) {
$this->appConfig->setAppValue('watermark_text', $watermark_text);
if ($secure_view_can_print_default !== null) {
$this->appConfig->setAppValue('secure_view_can_print_default', $secure_view_can_print_default);
}

if ($secure_view_can_download_default !== null) {
$this->appConfig->setAppValue('secure_view_can_download_default', $secure_view_can_download_default);
if ($secure_view_has_watermark_default !== null) {
$this->appConfig->setAppValue('secure_view_has_watermark_default', $secure_view_has_watermark_default);
}

if ($secure_view_can_print_default !== null) {
$this->appConfig->setAppValue('secure_view_can_print_default', $secure_view_can_print_default);
if ($watermark_text !== null) {
$this->appConfig->setAppValue('watermark_text', $watermark_text);
}

$richMemCache = \OC::$server->getMemCacheFactory()->create('richdocuments');
Expand Down
3 changes: 2 additions & 1 deletion lib/Db/Wopi.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ class Wopi extends \OCA\Richdocuments\Db {
const ATTR_CAN_VIEW = 0;
const ATTR_CAN_DOWNLOAD = 1;
const ATTR_CAN_PRINT = 2;
const ATTR_CAN_UPDATE = 4;
const ATTR_HAS_WATERMARK = 4;
const ATTR_CAN_UPDATE = 8;

const appName = 'richdocuments';

Expand Down
10 changes: 7 additions & 3 deletions lib/HookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ public static function addViewerScripts() {
}

public static function addConfigScripts($array) {
$appConfig = new AppConfig(\OC::$server->getConfig());
$config = \OC::$server->getConfig();
$richdocumentsConfig = new AppConfig($config);
$array['array']['oc_appconfig']['richdocuments'] = [
'defaultShareAttributes' => [
'secureViewCanDownload' => $appConfig->getAppValue('secure_view_can_dowload_default'),
'secureViewCanPrint' => $appConfig->getAppValue('secure_view_can_print_default'),
// is secure view is enabled for read-only shares, user cannot download by default
'secureViewCanDownload' => $richdocumentsConfig->getAppValue('secure_view_option') ? false : true,
'secureViewHasWatermark' => $richdocumentsConfig->getAppValue('secure_view_has_watermark_default'),
'secureViewCanPrint' => $richdocumentsConfig->getAppValue('secure_view_can_print_default'),
],
'secureViewAllowed' => $richdocumentsConfig->enterpriseFeaturesEnabled()
];
}
}
25 changes: 19 additions & 6 deletions templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,30 @@
<label for="enable_menu_option_cb-richdocuments"><?php p($l->t('Use Menu option')) ?></label>

<br/>
<input type="checkbox" id="enable_secure_view_option_cb-richdocuments" <?php p($_['secure_view_option'] === 'true' ? 'checked' : '') ?> />
<label for="enable_secure_view_option_cb-richdocuments"><?php p($l->t('Enable Secure View for read-only shares')) ?></label>
<br/>
<input type="checkbox" id="enable_secure_view_option_cb-richdocuments" <?php if ($_['secure_view_option'] === 'true') {
p('checked />');
} elseif ($_['secure_view_allowed'] !== 'true') {
p('disabled />');
} else {
p(' />');
}?>
<label for="enable_secure_view_option_cb-richdocuments"><?php p($l->t('Enable Secure View for read-only shares')) ?>
</label>
<?php if ($_['secure_view_allowed'] !== 'true') {
print_unescaped('<br/><em>');
p($l->t('This option is disabled, as requires enterprise version'));
print_unescaped('</em>');
}?>
<div id="enable-share-attributes-defaults" style="padding-left: 28px;" class="indent <?php if ($_['secure_view_option'] !== 'true') {
p('hidden');
} ?>" >
<p style="max-width: 50em;"><em><?php p($l->t('Set default share permissions for all users')) ?></em></p>
<input type="checkbox" id="secure_view_can_download_default_option_cb-richdocuments" <?php p($_['secure_view_can_download_default'] === 'true' ? 'checked' : '') ?> />
<label for="secure_view_can_download_default_option_cb-richdocuments"><?php p($l->t('can view with watermark (disabling allows only viewing with watermark)')) ?></label>
<br/>
<input type="checkbox" id="secure_view_can_print_default_option_cb-richdocuments" <?php p($_['secure_view_can_print_default'] === 'true' ? 'checked' : '') ?> />
<label for="secure_view_can_print_default_option_cb-richdocuments"><?php p($l->t('can print/export (with watermark included)')) ?></label>
<label for="secure_view_can_print_default_option_cb-richdocuments"><?php p($l->t('can print/export')) ?></label>
<br/>
<input type="checkbox" id="secure_view_has_watermark_default_option_cb-richdocuments" <?php p($_['secure_view_has_watermark_default'] === 'true' ? 'checked' : '') ?> />
<label for="secure_view_has_watermark_default_option_cb-richdocuments"><?php p($l->t('secure view with watermark')) ?></label>
</div>
<br/>
<div id="enable-watermark-section" style="padding-left: 28px;" class="indent <?php if ($_['secure_view_option'] !== 'true') {
Expand Down

0 comments on commit 589dbd2

Please sign in to comment.