Skip to content

Commit

Permalink
Exclude MSOffice mime types association if OnlyOffice app is installed
Browse files Browse the repository at this point in the history
Signed-off-by: Grégory Marigot <[email protected]>
  • Loading branch information
proxyconcept authored and juliusknorr committed Sep 1, 2023
1 parent 9411b3d commit ab55363
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
25 changes: 18 additions & 7 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ class Capabilities implements ICapability {
'application/vnd.visio',
'application/vnd.ms-visio.drawing',
'application/vnd.wordperfect',
'application/msonenote',
'application/msword',
'application/rtf',
'text/rtf',
'text/csv'
];

const MIMETYPES_MSOFFICE = [
'application/msonenote',
'application/msword',
'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
'application/vnd.openxmlformats-officedocument.wordprocessingml.template',
'application/vnd.ms-word.document.macroEnabled.12',
Expand All @@ -66,7 +70,6 @@ class Capabilities implements ICapability {
'application/vnd.ms-powerpoint.presentation.macroEnabled.12',
'application/vnd.ms-powerpoint.template.macroEnabled.12',
'application/vnd.ms-powerpoint.slideshow.macroEnabled.12',
'text/csv'
];

public const MIMETYPES_OPTIONAL = [
Expand Down Expand Up @@ -104,25 +107,33 @@ public function getCapabilities() {

if (!$this->capabilities) {
$collaboraCapabilities = $this->capabilitiesService->getCapabilities();
$filteredMimetypes = self::MIMETYPES;

$defaultMimetypes = self::MIMETYPES;
$optionalMimetypes = self::MIMETYPES_OPTIONAL;

if (!$this->capabilitiesService->hasOtherOOXMLApps()) {
array_push($defaultMimetypes, ...self::MIMETYPES_MSOFFICE);
} else {
array_push($optionalMimetypes, ...self::MIMETYPES_MSOFFICE);
}

// If version is too old, draw is not supported
if (!$this->capabilitiesService->hasDrawSupport()) {
$filteredMimetypes = array_diff($filteredMimetypes, [
$defaultMimetypes = array_diff($defaultMimetypes, [
'application/vnd.oasis.opendocument.graphics',
'application/vnd.oasis.opendocument.graphics-flat-xml',
]);
}

if (!$this->appManager->isEnabledForUser('files_pdfviewer')) {
$filteredMimetypes[] = 'application/pdf';
$defaultMimetypes[] = 'application/pdf';
$optionalMimetypes = array_diff($optionalMimetypes, ['application/pdf']);
}

$this->capabilities = [
'richdocuments' => [
'version' => \OC::$server->getAppManager()->getAppVersion('richdocuments'),
'mimetypes' => array_values($filteredMimetypes),
'mimetypes' => array_values($defaultMimetypes),
'mimetypesNoDefaultOpen' => array_values($optionalMimetypes),
'collabora' => $collaboraCapabilities,
'direct_editing' => isset($collaboraCapabilities['hasMobileSupport']) && $this->config->getAppValue('mobile_editing') ?: false,
Expand Down
8 changes: 8 additions & 0 deletions lib/Service/CapabilitiesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ public function getProductName(): string {
return $this->l10n->t('Nextcloud Office');
}

public function hasOtherOOXMLApps(): bool {
if ($this->appManager->isEnabledForUser('onlyoffice')) {
return true;
}

return false;
}

public function clear(): void {
$this->cache->remove('capabilities');
}
Expand Down

0 comments on commit ab55363

Please sign in to comment.