Skip to content

Commit

Permalink
Added option to disable EditLocally menu option (code review fixes)
Browse files Browse the repository at this point in the history
Signed-off-by: Konstantin Myakshin <[email protected]>
  • Loading branch information
Koc committed Dec 7, 2023
1 parent 8352683 commit 8d42af0
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/files/lib/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal

$this->initialState->provideInitialState('templates_path', $this->templateManager->hasTemplateDirectory() ? $this->templateManager->getTemplatePath() : false);
$this->initialState->provideInitialState('templates', $this->templateManager->listCreators());
$this->initialState->provideInitialState('disable_edit_locally', $this->config->getSystemValueBool('disable_edit_locally'));

$params = [
'fileNotFound' => $fileNotFound ? 1 : 0,
'disableEditLocally' => $this->config->getSystemValueBool('disable_edit_locally') ? 1 : 0,
];

$response = new TemplateResponse(
Expand Down
5 changes: 4 additions & 1 deletion apps/files/src/actions/editLocallyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,15 @@ import { encodePath } from '@nextcloud/paths'
import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { FileAction, Permission, type Node } from '@nextcloud/files'
import { loadState } from '@nextcloud/initial-state'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'

import LaptopSvg from '@mdi/svg/svg/laptop.svg?raw'

let disableEditLocally = loadState('files', 'disable_edit_locally', false)

const openLocalClient = async function(path: string) {
const link = generateOcsUrl('apps/files/api/v1') + '/openlocaleditor?format=json'

Expand All @@ -51,7 +54,7 @@ export const action = new FileAction({

// Only works on single files
enabled(nodes: Node[]) {
if ($('#disableEditLocally').val() === "1") {
if (disableEditLocally) {
return false
}

Expand Down
1 change: 0 additions & 1 deletion apps/files/templates/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
<!-- config hints for javascript -->
<input type="hidden" name="filesApp" id="filesApp" value="1" />
<input type="hidden" name="fileNotFound" id="fileNotFound" value="<?php p($_['fileNotFound']); ?>" />
<input type="hidden" name="disableEditLocally" id="disableEditLocally" value="<?php p($_['disableEditLocally']); ?>" />
1 change: 0 additions & 1 deletion apps/files/tests/Controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ public function testIndexWithRegularBrowser() {
'index',
[
'fileNotFound' => 0,
'disableEditLocally' => 0,
]
);
$policy = new Http\ContentSecurityPolicy();
Expand Down
7 changes: 7 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -2405,4 +2405,11 @@
* Defaults to ``false``
*/
'unified_search.enabled' => false,

/**
* Disable "Edit locally" menu item in file viewer
*
* Defaults to ``false``
*/
'disable_edit_locally' => false,
];

0 comments on commit 8d42af0

Please sign in to comment.