Skip to content

Commit fef09bc

Browse files
committed
Added option to disable EditLocally menu option (code review fixes)
Signed-off-by: Konstantin Myakshin <molodchick@gmail.com>
1 parent efd7543 commit fef09bc

File tree

5 files changed

+12
-4
lines changed

5 files changed

+12
-4
lines changed

apps/files/lib/Controller/ViewController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ public function index($dir = '', $view = '', $fileid = null, $fileNotFound = fal
278278

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

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

287287
$response = new TemplateResponse(

apps/files/src/actions/editLocallyAction.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ import { encodePath } from '@nextcloud/paths'
2323
import { generateOcsUrl } from '@nextcloud/router'
2424
import { getCurrentUser } from '@nextcloud/auth'
2525
import { FileAction, Permission, type Node } from '@nextcloud/files'
26+
import { loadState } from '@nextcloud/initial-state'
2627
import { showError } from '@nextcloud/dialogs'
2728
import { translate as t } from '@nextcloud/l10n'
2829
import axios from '@nextcloud/axios'
2930

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

33+
let disableEditLocally = loadState('files', 'disable_edit_locally', false)
34+
3235
const openLocalClient = async function(path: string) {
3336
const link = generateOcsUrl('apps/files/api/v1') + '/openlocaleditor?format=json'
3437

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

5255
// Only works on single files
5356
enabled(nodes: Node[]) {
54-
if ($('#disableEditLocally').val() === "1") {
57+
if (disableEditLocally) {
5558
return false
5659
}
5760

apps/files/templates/index.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
<!-- config hints for javascript -->
88
<input type="hidden" name="filesApp" id="filesApp" value="1" />
99
<input type="hidden" name="fileNotFound" id="fileNotFound" value="<?php p($_['fileNotFound']); ?>" />
10-
<input type="hidden" name="disableEditLocally" id="disableEditLocally" value="<?php p($_['disableEditLocally']); ?>" />

apps/files/tests/Controller/ViewControllerTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ public function testIndexWithRegularBrowser() {
186186
'index',
187187
[
188188
'fileNotFound' => 0,
189-
'disableEditLocally' => 0,
190189
]
191190
);
192191
$policy = new Http\ContentSecurityPolicy();

config/config.sample.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,4 +2412,11 @@
24122412
* Defaults to ``true``
24132413
*/
24142414
'enable_non-accessible_features' => true,
2415+
2416+
/**
2417+
* Disable "Edit locally" menu item in file viewer
2418+
*
2419+
* Defaults to ``false``
2420+
*/
2421+
'disable_edit_locally' => false,
24152422
];

0 commit comments

Comments
 (0)