Skip to content

Commit

Permalink
Merge pull request 'feature/open-pdf-on-edit-by-default' from feature…
Browse files Browse the repository at this point in the history
…/open-pdf-on-edit-by-default into develop

Reviewed-on: https://git.onlyoffice.com/ONLYOFFICE/onlyoffice-nextcloud/pulls/10
  • Loading branch information
LinneyS committed Oct 16, 2024
2 parents 23b46ae + 51c1586 commit bc8ea7f
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 50 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Change Log

##
## Added
- default empty templates
- Finnish, Hebrew, Norwegian, Slovenian empty file templates

## Changed
- update en-US empty templates
- demo server address changed
- editing pdf by default

## 9.4.0
## Added
Expand Down
5 changes: 2 additions & 3 deletions lib/Controller/EditorApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,13 @@ public function __construct(
* @param string $guestName - nickname not logged user
* @param bool $template - file is template
* @param string $anchor - anchor for file content
* @param bool $forceEdit - open editing
*
* @return JSONResponse
*
* @NoAdminRequired
* @PublicPage
*/
public function config($fileId, $filePath = null, $shareToken = null, $directToken = null, $inframe = false, $inviewer = false, $desktop = false, $guestName = null, $template = false, $anchor = null, $forceEdit = false) {
public function config($fileId, $filePath = null, $shareToken = null, $directToken = null, $inframe = false, $inviewer = false, $desktop = false, $guestName = null, $template = false, $anchor = null) {

if (!empty($directToken)) {
list($directData, $error) = $this->crypt->readHash($directToken);
Expand Down Expand Up @@ -409,7 +408,7 @@ public function config($fileId, $filePath = null, $shareToken = null, $directTok
&& !$isTempLock
&& (empty($shareToken) || ($share->getPermissions() & Constants::PERMISSION_UPDATE) === Constants::PERMISSION_UPDATE)
&& !$restrictedEditing;
$params["document"]["permissions"]["edit"] = $editable && ($forceEdit || !$canFillForms);
$params["document"]["permissions"]["edit"] = $editable;
if (($editable || $restrictedEditing) && ($canEdit || $canFillForms)) {
$ownerId = null;
$owner = $file->getOwner();
Expand Down
11 changes: 4 additions & 7 deletions lib/Controller/EditorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1283,7 +1283,6 @@ public function download($fileId, $toExtension = null, $template = false) {
* @param string $filePath - file path
* @param string $shareToken - access token
* @param bool $inframe - open in frame
* @param bool $forceEdit - open editing
* @param bool $inviewer - open in viewer
* @param bool $template - file is template
* @param string $anchor - anchor for file content
Expand All @@ -1293,7 +1292,7 @@ public function download($fileId, $toExtension = null, $template = false) {
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index($fileId, $filePath = null, $shareToken = null, $inframe = false, $forceEdit = false, $inviewer = false, $template = false, $anchor = null) {
public function index($fileId, $filePath = null, $shareToken = null, $inframe = false, $inviewer = false, $template = false, $anchor = null) {
$this->logger->debug("Open: $fileId $filePath ", ["app" => $this->appName]);

$isLoggedIn = $this->userSession->isLoggedIn();
Expand Down Expand Up @@ -1332,8 +1331,7 @@ public function index($fileId, $filePath = null, $shareToken = null, $inframe =
"isTemplate" => $template,
"inframe" => false,
"inviewer" => $inviewer === true,
"anchor" => $anchor,
"forceEdit" => $forceEdit
"anchor" => $anchor
];

$response = null;
Expand Down Expand Up @@ -1374,16 +1372,15 @@ public function index($fileId, $filePath = null, $shareToken = null, $inframe =
* @param integer $fileId - file identifier
* @param string $shareToken - access token
* @param bool $inframe - open in frame
* @param bool $forceEdit - open editing
*
* @return TemplateResponse
*
* @NoAdminRequired
* @NoCSRFRequired
* @PublicPage
*/
public function publicPage($fileId, $shareToken, $inframe = false, $forceEdit = false) {
return $this->index($fileId, null, $shareToken, $inframe, $forceEdit);
public function publicPage($fileId, $shareToken, $inframe = false) {
return $this->index($fileId, null, $shareToken, $inframe);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions lib/DirectEditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ public function open(IToken $token): Response {
"isTemplate" => false,
"inframe" => false,
"inviewer" => false,
"anchor" => null,
"forceEdit" => false
"anchor" => null
];

$response = new TemplateResponse($this->appName, "editor", $params, "base");
Expand Down
21 changes: 0 additions & 21 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
OCA.Onlyoffice.inviewer = !!$('#iframeEditor').data('inviewer')
OCA.Onlyoffice.filePath = $('#iframeEditor').data('path')
OCA.Onlyoffice.anchor = $('#iframeEditor').attr('data-anchor')
OCA.Onlyoffice.forceEdit = $('#iframeEditor').attr('data-forceEdit')
const guestName = localStorage.getItem('nick')
OCA.Onlyoffice.currentWindow = window
OCA.Onlyoffice.currentUser = OC.getCurrentUser()

Check warning on line 58 in src/editor.js

View workflow job for this annotation

GitHub Actions / Lint

The property or function OC.getCurrentUser was deprecated in Nextcloud 19.0.0
Expand Down Expand Up @@ -105,9 +104,6 @@
if (OCA.Onlyoffice.anchor) {
params.push('anchor=' + encodeURIComponent(OCA.Onlyoffice.anchor))
}
if (OCA.Onlyoffice.forceEdit) {
params.push('forceEdit=true')
}

if (OCA.Onlyoffice.inframe || directToken) {
params.push('inframe=true')
Expand Down Expand Up @@ -217,12 +213,6 @@
config.events.onRequestSharingSettings = OCA.Onlyoffice.onRequestSharingSettings
}

if (!config.document.permissions.edit
&& config.document.permissions.fillForms
&& config.canEdit) {
config.events.onRequestEditRights = OCA.Onlyoffice.onRequestEditRights
}

OCA.Onlyoffice.docEditor = new DocsAPI.DocEditor('iframeEditor', config)

if (OCA.Onlyoffice.directEditor) {
Expand All @@ -249,17 +239,6 @@
})
}

OCA.Onlyoffice.onRequestEditRights = function() {
if (OCA.Onlyoffice.inframe) {
window.parent.postMessage({
method: 'onRequestEditRights',
},
'*')
return
}
location.href += '&forceEdit=true'
}

OCA.Onlyoffice.onRequestHistory = function(version) {
$.get(OC.generateUrl('apps/' + OCA.Onlyoffice.AppName + '/ajax/history?fileId={fileId}',

Check warning on line 243 in src/editor.js

View workflow job for this annotation

GitHub Actions / Lint

The property or function OC.generateUrl was deprecated in Nextcloud 19.0.0
{
Expand Down
6 changes: 0 additions & 6 deletions src/listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@
}
}

OCA.Onlyoffice.onRequestEditRights = function() {
$(OCA.Onlyoffice.frameSelector).attr('src', $(OCA.Onlyoffice.frameSelector).attr('src') + '&forceEdit=true')
}

window.addEventListener('message', function(event) {
if (!$(OCA.Onlyoffice.frameSelector).length
|| $(OCA.Onlyoffice.frameSelector)[0].contentWindow !== event.source
Expand Down Expand Up @@ -176,8 +172,6 @@
case 'onShowMessage':
OCA.Onlyoffice.onShowMessage(event.data.param)
break
case 'onRequestEditRights':
OCA.Onlyoffice.onRequestEditRights()
}
}, false)

Expand Down
10 changes: 2 additions & 8 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ import NewPdfSvg from '!!raw-loader!../img/new-pdf.svg';

if (open) {
const fileName = response.name
const extension = OCA.Onlyoffice.getFileExtension(fileName)
const forceEdit = OCA.Onlyoffice.setting.formats[extension].fillForms
OCA.Onlyoffice.OpenEditor(response.id, dir, fileName, winEditor, forceEdit)
OCA.Onlyoffice.OpenEditor(response.id, dir, fileName, winEditor)

OCA.Onlyoffice.context = {
fileName: response.name,
Expand All @@ -139,7 +137,7 @@ import NewPdfSvg from '!!raw-loader!../img/new-pdf.svg';
)
}

OCA.Onlyoffice.OpenEditor = function(fileId, fileDir, fileName, winEditor, forceEdit) {
OCA.Onlyoffice.OpenEditor = function(fileId, fileDir, fileName, winEditor) {
let filePath = ''
if (fileName) {
filePath = fileDir.replace(/\/$/, '') + '/' + fileName
Expand All @@ -158,10 +156,6 @@ import NewPdfSvg from '!!raw-loader!../img/new-pdf.svg';
})
}

if (forceEdit) {
url += '&forceEdit=true'
}

if (winEditor && winEditor.location) {
winEditor.location.href = url
} else if (!OCA.Onlyoffice.setting.sameTab || OCA.Onlyoffice.mobile || OCA.Onlyoffice.Desktop) {
Expand Down
3 changes: 1 addition & 2 deletions templates/editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class="onlyoffice-inviewer"
data-template="<?php p($_["isTemplate"]) ?>"
data-anchor="<?php p($_["anchor"]) ?>"
data-inframe="<?php p($_["inframe"]) ?>"
data-inviewer="<?php p($_["inviewer"]) ?>"
data-forceedit="<?php p($_["forceEdit"]) ?>"></div>
data-inviewer="<?php p($_["inviewer"]) ?>"></div>

<?php if (!empty($_["documentServerUrl"])) { ?>
<script nonce="<?php p(\OC::$server->get(\OC\Security\CSP\ContentSecurityPolicyNonceManager::class)->getNonce()) ?>"
Expand Down

0 comments on commit bc8ea7f

Please sign in to comment.