Skip to content

Commit

Permalink
Allow blocking file extensions of text-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
kulmann committed Jun 23, 2022
1 parent e80a417 commit 7705420
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Option to block file extensions from text-editor app

We've added support to block certain file extensions from the text-editor app with additional config. See https://owncloud.dev/clients/web/deployments/oc10-app/#additional-configuration-for-certain-core-apps

https://github.com/owncloud/web/issues/6661
https://github.com/owncloud/web/pull/7174
22 changes: 20 additions & 2 deletions docs/deployments/oc10-app.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,31 @@ In case the backend has additional preview providers configured there is no mech
"mimeTypes": ["image/tiff", "image/webp"]
}
}
],
]
```

If you already have an `"external_apps"` section, just add the preview app to the list. Please adjust the `"mimeTypes"` list according to your additional preview providers. See https://github.com/owncloud/files_mediaviewer#supporting-more-media-types for advise on how to add preview providers to the backend.

### Text-Editor app
The `text-editor` app provides a list of file extensions that the app is associated with, both for opening files and for creating new files. If any of those file extensions should not be handled by the text editor you can set up the following config to block file extensions from the text-editor.
1. Remove the `"text-editor"` string from the `"apps"` section in your `config.json` file
2. Add the following config to your `config.json` file:
```json
"external_apps": [
{
"id": "text-editor",
"path": "web-app-text-editor",
"config": {
"blockedFileExtensions": ["yaml", "md"]
}
}
]
```

If you already have an `"external_apps"` section, just add the preview app to the list. Please adjust the `"mimeTypes"` list according to your additional preview providers. See https://github.com/owncloud/files_mediaviewer#supporting-more-media-types for advise on how to add preview providers to the backend.

{{< hint info >}}
The reason why the `preview` app needs to be ported from the `apps` section to the `external_apps` section is that only the `external_apps` support additional configuration. There are plans to change the configuration of apps to give you a coherent admin experience in that regard.
The reason why the app needs to be ported from the `apps` section to the `external_apps` section is that only the `external_apps` support additional configuration. There are plans to change the configuration of apps to give you a coherent admin experience in that regard.
{{< /hint >}}

## Accessing ownCloud Web
Expand Down
78 changes: 54 additions & 24 deletions packages/web-app-text-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ function $gettext(msg) {
return msg
}

const appId = 'text-editor'

const routes = [
{
path: '/:filePath*',
Expand All @@ -19,41 +21,69 @@ const routes = [
}
]

const fileExtensionConfig = {
canBeDefault: true
const fileExtensions = () => {
const extensions = [
{
extension: 'txt',
label: $gettext('Plain text file')
},
{
extension: 'md',
label: $gettext('Markdown file')
},
{
extension: 'js',
label: $gettext('JavaScript file')
},
{
extension: 'json',
label: $gettext('JSON file')
},
{
extension: 'xml',
label: $gettext('XML file')
},
{
extension: 'py',
label: $gettext('Python file')
},
{
extension: 'php',
label: $gettext('PHP file')
},
{
extension: 'yaml',
label: $gettext('YAML file')
}
]
let blackList =
window.Vue.$store.getters.extensionConfigByAppId(appId).blockedFileExtensions || []
if (typeof blackList === 'string') {
blackList = [blackList]
}
return extensions.reduce((acc, extensionItem) => {
if (!blackList.includes(extensionItem.extension)) {
acc.push(extensionItem)
}
return acc
}, [])
}

const appInfo = {
name: $gettext('Text Editor'),
id: 'text-editor',
id: appId,
icon: 'file-text',
isFileEditor: true,
extensions: [
{
extension: 'txt',
extensions: fileExtensions().map((extensionItem) => {
return {
extension: extensionItem.extension,
newFileMenu: {
menuTitle($gettext) {
return $gettext('Plain text file')
return $gettext(extensionItem.label)
}
},
...fileExtensionConfig
},
{
extension: 'md',
newFileMenu: {
menuTitle($gettext) {
return $gettext('Markdown file')
}
},
...fileExtensionConfig
canBeDefault: true
}
]
}

for (const ext of ['js', 'json', 'xml', 'py', 'php', 'yaml']) {
appInfo.extensions.push({
extension: ext,
...fileExtensionConfig
})
}

Expand Down

0 comments on commit 7705420

Please sign in to comment.