Skip to content

Commit 4809dde

Browse files
committed
feat: add default_action field to files-actions-menu registration
fixes #748 Signed-off-by: Jaap van der Plas <jvdplas@gmail.com>
1 parent cfa6da1 commit 4809dde

12 files changed

Lines changed: 150 additions & 26 deletions

js/app_api-adminSettings.js.license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,5 +147,5 @@ This file is generated from multiple sources. Included packages:
147147
- version: 5.102.1
148148
- license: MIT
149149
- app_api
150-
- version: 34.0.0-dev.1
150+
- version: 35.0.0-dev.0
151151
- license: ( AGPL-3.0-or-later)

js/app_api-adminSettings.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/app_api-filesplugin.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/app_api-filesplugin.js.license

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ This file is generated from multiple sources. Included packages:
8282
- version: 5.102.1
8383
- license: MIT
8484
- app_api
85-
- version: 34.0.0-dev.1
85+
- version: 35.0.0-dev.0
8686
- license: ( AGPL-3.0-or-later)

js/app_api-filesplugin.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/Controller/OCSUiController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,20 @@ public function registerFileActionMenu(string $name, string $displayName, string
6161
}
6262

6363
/**
64+
* @param string $defaultAction One of '', 'default', or 'hidden'
6465
* @throws OCSBadRequestException
6566
*/
6667
#[AppAPIAuth]
6768
#[PublicPage]
6869
#[NoCSRFRequired]
6970
public function registerFileActionMenuV2(string $name, string $displayName, string $actionHandler,
7071
string $icon = '', string $mime = 'file', int $permissions = 31,
71-
int $order = 0): DataResponse {
72+
int $order = 0, string $defaultAction = ''): DataResponse {
73+
if (!in_array($defaultAction, ['', 'default', 'hidden'], true)) {
74+
throw new OCSBadRequestException("Invalid defaultAction '$defaultAction' — must be '', 'default', or 'hidden'");
75+
}
7276
$result = $this->filesActionsMenuService->registerFileActionMenu(
73-
$this->request->getHeader('EX-APP-ID'), $name, $displayName, $actionHandler, $icon, $mime, $permissions, $order, '2.0');
77+
$this->request->getHeader('EX-APP-ID'), $name, $displayName, $actionHandler, $icon, $mime, $permissions, $order, '2.0', $defaultAction ?: null);
7478
if (!$result) {
7579
throw new OCSBadRequestException('File Action Menu entry could not be registered');
7680
}

lib/Db/UI/FilesActionsMenu.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
* @method string getIcon()
2727
* @method string getActionHandler()
2828
* @method string getVersion()
29+
* @method string|null getDefaultAction()
2930
* @method void setAppid(string $appid)
3031
* @method void setName(string $name)
3132
* @method void setDisplayName(string $displayName)
@@ -35,6 +36,7 @@
3536
* @method void setIcon(string $icon)
3637
* @method void setActionHandler(string $actionHandler)
3738
* @method void setVersion(string $version)
39+
* @method void setDefaultAction(string|null $defaultAction)
3840
*/
3941
class FilesActionsMenu extends Entity implements JsonSerializable {
4042
protected $appid;
@@ -46,6 +48,7 @@ class FilesActionsMenu extends Entity implements JsonSerializable {
4648
protected $icon;
4749
protected $actionHandler;
4850
protected $version;
51+
protected $defaultAction;
4952

5053
/**
5154
* @param array $params
@@ -60,6 +63,7 @@ public function __construct(array $params = []) {
6063
$this->addType('icon', 'string');
6164
$this->addType('actionHandler', 'string');
6265
$this->addType('version', 'string');
66+
$this->addType('defaultAction', 'string');
6367

6468
if (isset($params['id'])) {
6569
$this->setId($params['id']);
@@ -91,6 +95,9 @@ public function __construct(array $params = []) {
9195
if (isset($params['version'])) {
9296
$this->setVersion($params['version']);
9397
}
98+
if (array_key_exists('default_action', $params)) {
99+
$this->setDefaultAction($params['default_action']);
100+
}
94101
}
95102

96103
public function jsonSerialize(): array {
@@ -105,6 +112,7 @@ public function jsonSerialize(): array {
105112
'icon' => $this->getIcon(),
106113
'action_handler' => $this->getActionHandler(),
107114
'version' => $this->getVersion(),
115+
'default_action' => $this->getDefaultAction(),
108116
];
109117
}
110118
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\AppAPI\Migration;
11+
12+
use Closure;
13+
use OCP\DB\ISchemaWrapper;
14+
use OCP\DB\Types;
15+
use OCP\Migration\Attributes\AddColumn;
16+
use OCP\Migration\Attributes\ColumnType;
17+
use OCP\Migration\IOutput;
18+
use OCP\Migration\SimpleMigrationStep;
19+
20+
#[AddColumn('ex_ui_files_actions', 'default_action', ColumnType::STRING, 'DefaultType for ExApp file actions')]
21+
class Version035000Date20260518120000 extends SimpleMigrationStep {
22+
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
23+
/** @var ISchemaWrapper $schema */
24+
$schema = $schemaClosure();
25+
26+
if ($schema->hasTable('ex_ui_files_actions')) {
27+
$table = $schema->getTable('ex_ui_files_actions');
28+
29+
if (!$table->hasColumn('default_action')) {
30+
$table->addColumn('default_action', Types::STRING, [
31+
'notnull' => false,
32+
'length' => 16,
33+
'default' => null,
34+
]);
35+
}
36+
}
37+
38+
return $schema;
39+
}
40+
}

lib/Service/UI/FilesActionsMenuService.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,38 @@ public function __construct(
4444
* @param int $permissions
4545
* @param int $order
4646
* @param string $version
47+
* @param string|null $defaultAction
4748
* @return FilesActionsMenu|null
4849
*/
4950
public function registerFileActionMenu(string $appId, string $name, string $displayName, string $actionHandler,
50-
string $icon, string $mime, int $permissions, int $order, string $version): ?FilesActionsMenu {
51+
string $icon, string $mime, int $permissions, int $order, string $version,
52+
?string $defaultAction = null): ?FilesActionsMenu {
5153
try {
52-
$fileActionMenu = $this->mapper->findByAppidName($appId, $name);
54+
$existing = $this->mapper->findByAppidName($appId, $name);
5355
} catch (DoesNotExistException|MultipleObjectsReturnedException|Exception) {
54-
$fileActionMenu = null;
56+
$existing = null;
5557
}
5658
try {
57-
$newFileActionMenu = new FilesActionsMenu([
58-
'appid' => $appId,
59-
'name' => $name,
60-
'display_name' => $displayName,
61-
'action_handler' => ltrim($actionHandler, '/'),
62-
'icon' => ltrim($icon, '/'),
63-
'mime' => $mime,
64-
'permissions' => $permissions,
65-
'order' => $order,
66-
'version' => $version,
67-
]);
68-
if ($fileActionMenu !== null) {
69-
$newFileActionMenu->setId($fileActionMenu->getId());
70-
}
71-
$fileActionMenu = $this->mapper->insertOrUpdate($newFileActionMenu);
59+
$entity = $existing ?? new FilesActionsMenu();
60+
$entity->setAppid($appId);
61+
$entity->setName($name);
62+
$entity->setDisplayName($displayName);
63+
$entity->setActionHandler(ltrim($actionHandler, '/'));
64+
$entity->setIcon(ltrim($icon, '/'));
65+
$entity->setMime($mime);
66+
$entity->setPermissions((string)$permissions);
67+
$entity->setOrder($order);
68+
$entity->setVersion($version);
69+
$entity->setDefaultAction($defaultAction);
70+
$result = $existing === null ? $this->mapper->insert($entity) : $this->mapper->update($entity);
7271
$this->resetCacheEnabled();
72+
return $result;
7373
} catch (Exception $e) {
7474
$this->logger->error(
7575
sprintf('Failed to register ExApp %s FileActionMenu %s. Error: %s', $appId, $name, $e->getMessage()), ['exception' => $e]
7676
);
7777
return null;
7878
}
79-
return $fileActionMenu;
8079
}
8180

8281
public function unregisterFileActionMenu(string $appId, string $name): ?FilesActionsMenu {

src/filesplugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,8 @@ export function registerFileAction33(fileAction, iconProvider) {
151151
execBatch: async ({ nodes }) => execBatch(nodes),
152152
}
153153

154+
action.default = fileAction.default_action
155+
154156
registerFileAction(action)
155157
}
156158

0 commit comments

Comments
 (0)