Skip to content

Commit

Permalink
adjust to reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
mrow4a committed Mar 27, 2019
1 parent 4fc5fc1 commit ae72637
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 30 deletions.
8 changes: 4 additions & 4 deletions js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ var documentsSettings = {
);
},

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

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

$(document).on('change', '#secure_view_enabled_default_option_cb-richdocuments', function() {
documentsSettings.saveSecureViewDefaultOption(this.checked);
$(document).on('change', '#secure_view_can_download_default_option_cb-richdocuments', function() {
documentsSettings.saveCanDownloadDefaultOption(this.checked);
});
$(document).on('change', '#secure_view_can_print_default_option_cb-richdocuments', function() {
documentsSettings.saveCanPrintDefaultOption(this.checked);
Expand Down
31 changes: 20 additions & 11 deletions js/viewer/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,37 @@ OC.Plugins.register('OC.Share.ShareItemModel', {
if ((odfViewer.isSupportedMimeType(mimetype) || mimetype === folderMimeType) &&
OC.appConfig.richdocuments && OC.appConfig.richdocuments.defaultShareAttributes) {
/** @type OC.Share.Types.RegisteredShareAttribute **/
var secureViewEnabled = {
"scope": "core",
"name": "secure-view-enabled",
"default": JSON.parse(OC.appConfig.richdocuments.defaultShareAttributes.secureViewEnabled),
"label": t('richdocuments', 'secure viewing only'),
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": []
};
model.registerShareAttribute(secureViewEnabled);
model.registerShareAttribute(secureViewCanDownload);

/** @type OC.Share.Types.RegisteredShareAttribute **/
var secureViewCanPrint = {
"scope": "richdocuments",
"name": "secure-view-can-print",
"key": "print",
"default": JSON.parse(OC.appConfig.richdocuments.defaultShareAttributes.secureViewCanPrint),
"label": t('richdocuments', 'allow printing (will include watermarks)'),
"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": "core",
"name": "secure-view-enabled",
"enabled": false
"scope": "permissions",
"key": "download",
"enabled": true
}
]
};
Expand Down
4 changes: 3 additions & 1 deletion js/viewer/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,5 +214,7 @@ $(document).ready(function() {
}
}

$('#odf_close').live('click', odfViewer.onClose);
if ($( "#odf_close" ).length) {
$('#odf_close').live('click', odfViewer.onClose);
}
});
12 changes: 7 additions & 5 deletions lib/Controller/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -637,12 +637,12 @@ private function getWopiInfoForAuthUser($fileId, $version, $currentUser) {
$share = $storage->getShare();

// Check download attribute
$secureViewEnabled = $share->getAttributes()->getAttribute('core', 'secure-view-enabled');
if ($secureViewEnabled !== null && $secureViewEnabled) {
$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;

// Check print attribute for secure view
// 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
Expand All @@ -651,6 +651,8 @@ private function getWopiInfoForAuthUser($fileId, $version, $currentUser) {
} else {
$attributes = $attributes | WOPI::ATTR_CAN_DOWNLOAD | WOPI::ATTR_CAN_PRINT;
}
} else {
$attributes = $attributes | WOPI::ATTR_CAN_DOWNLOAD | WOPI::ATTR_CAN_PRINT;
}
}

Expand Down Expand Up @@ -746,9 +748,9 @@ private function getWopiInfoForPublicLink($fileId, $version, $path, $permissions
$editorUid = $currentUser;
}

$attributes = WOPI::ATTR_CAN_VIEW;
$attributes = WOPI::ATTR_CAN_VIEW | WOPI::ATTR_CAN_DOWNLOAD | WOPI::ATTR_CAN_PRINT;
if ($updateable) {
$attributes = $attributes | WOPI::ATTR_CAN_UPDATE | WOPI::ATTR_CAN_DOWNLOAD | WOPI::ATTR_CAN_PRINT;
$attributes = $attributes | WOPI::ATTR_CAN_UPDATE;
}

$row = new Db\Wopi();
Expand Down
8 changes: 4 additions & 4 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ public function adminIndex() {
'canonical_webroot' => $this->appConfig->getAppValue('canonical_webroot'),
'menu_option' => $this->appConfig->getAppValue('menu_option'),
'secure_view_option' => $this->appConfig->getAppValue('secure_view_option'),
'secure_view_enabled_default' => $this->appConfig->getAppValue('secure_view_enabled_default'),
'secure_view_can_download_default' => $this->appConfig->getAppValue('secure_view_can_download_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_enabled_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, $watermark_text, $secure_view_can_download_default, $secure_view_can_print_default) {
$message = $this->l10n->t('Saved');

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

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

if ($secure_view_can_print_default !== null) {
Expand Down
2 changes: 1 addition & 1 deletion lib/HookHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public static function addConfigScripts($array) {
$appConfig = new AppConfig(\OC::$server->getConfig());
$array['array']['oc_appconfig']['richdocuments'] = [
'defaultShareAttributes' => [
'secureViewEnabled' => $appConfig->getAppValue('secure_view_enabled_default'),
'secureViewCanDownload' => $appConfig->getAppValue('secure_view_can_dowload_default'),
'secureViewCanPrint' => $appConfig->getAppValue('secure_view_can_print_default'),
],
];
Expand Down
8 changes: 4 additions & 4 deletions templates/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@
<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 attributes for all the users')) ?></em></p>
<input type="checkbox" id="secure_view_enabled_default_option_cb-richdocuments" <?php p($_['secure_view_enabled_default'] === 'true' ? 'checked' : '') ?> />
<label for="secure_view_enabled_default_option_cb-richdocuments"><?php p($l->t('enable secure view by default')) ?></label>
<p style="max-width: 50em;"><em><?php p($l->t('Set default share permissions on documents for all the 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>
<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('enable printing with watermark by default for secure view')) ?></label>
<label for="secure_view_can_print_default_option_cb-richdocuments"><?php p($l->t('can print/export (with watermark included)')) ?></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 ae72637

Please sign in to comment.