Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI: FileActions rework #141

Merged
merged 17 commits into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@
['name' => 'TalkBot#registerExAppTalkBot', 'url' => '/api/v1/talk_bot', 'verb' => 'POST'],
['name' => 'TalkBot#unregisterExAppTalkBot', 'url' => '/api/v1/talk_bot', 'verb' => 'DELETE'],

// --- UI ---
// File Actions Menu
['name' => 'OCSUi#registerFileActionMenu', 'url' => '/api/v1/files/actions/menu', 'verb' => 'POST'],
['name' => 'OCSUi#unregisterFileActionMenu', 'url' => '/api/v1/files/actions/menu', 'verb' => 'DELETE'],
['name' => 'OCSUi#getFileActionMenu', 'url' => '/api/v1/files/actions/menu', 'verb' => 'GET'],
['name' => 'OCSUi#registerFileActionMenu', 'url' => '/api/v1/ui/files-actions-menu', 'verb' => 'POST'],
['name' => 'OCSUi#unregisterFileActionMenu', 'url' => '/api/v1/ui/files-actions-menu', 'verb' => 'DELETE'],
['name' => 'OCSUi#getFileActionMenu', 'url' => '/api/v1/ui/files-actions-menu', 'verb' => 'GET'],
['name' => 'OCSUi#handleFileAction', 'url' => '/api/v1/files/action', 'verb' => 'POST'],
['name' => 'OCSUi#loadFileActionIcon', 'url' => '/api/v1/files/action/icon', 'verb' => 'GET'],

Expand Down
4 changes: 1 addition & 3 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
use OCA\AppAPI\Notifications\ExAppNotifier;
use OCA\AppAPI\Profiler\AppAPIDataCollector;
use OCA\AppAPI\PublicCapabilities;

use OCA\AppAPI\Service\TopMenuService;
use OCA\AppAPI\Service\UI\TopMenuService;
use OCA\DAV\Events\SabrePluginAuthInitEvent;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\App;
Expand All @@ -32,7 +31,6 @@
use OCP\IUserSession;
use OCP\Profiler\IProfiler;
use OCP\SabrePluginEvent;

use OCP\User\Events\UserDeletedEvent;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
Expand Down
73 changes: 40 additions & 33 deletions lib/Controller/OCSUiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Attribute\AppAPIAuth;
use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\ExAppInitialStateService;
use OCA\AppAPI\Service\ExAppScriptsService;
use OCA\AppAPI\Service\ExAppStylesService;
use OCA\AppAPI\Service\ExFilesActionsMenuService;

use OCA\AppAPI\Service\TopMenuService;
use OCA\AppAPI\Service\UI\FilesActionsMenuService;
use OCA\AppAPI\Service\UI\InitialStateService;
use OCA\AppAPI\Service\UI\ScriptsService;
use OCA\AppAPI\Service\UI\StylesService;
use OCA\AppAPI\Service\UI\TopMenuService;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
Expand All @@ -31,16 +30,16 @@ class OCSUiController extends OCSController {
protected $request;

public function __construct(
IRequest $request,
private readonly ?string $userId,
private readonly ExFilesActionsMenuService $exFilesActionsMenuService,
private readonly TopMenuService $menuEntryService,
private readonly ExAppInitialStateService $initialStateService,
private readonly ExAppScriptsService $scriptsService,
private readonly ExAppStylesService $stylesService,
private readonly AppAPIService $appAPIService,
private readonly IConfig $config,
private readonly LoggerInterface $logger,
IRequest $request,
private readonly ?string $userId,
private readonly FilesActionsMenuService $filesActionsMenuService,
private readonly TopMenuService $menuEntryService,
private readonly InitialStateService $initialStateService,
private readonly ScriptsService $scriptsService,
private readonly StylesService $stylesService,
private readonly AppAPIService $appAPIService,
private readonly IConfig $config,
private readonly LoggerInterface $logger,
) {
parent::__construct(Application::APP_ID, $request);

Expand All @@ -51,37 +50,45 @@ public function __construct(
* @PublicPage
* @NoCSRFRequired
*
* @param array $fileActionMenuParams [name, display_name, mime, permissions, order, icon, icon_class, action_handler]
*
* @param string $name
* @param string $displayName
* @param string $actionHandler
* @param string $icon
* @param string $mime
* @param int $permissions
* @param int $order
* @return DataResponse
* @throws OCSBadRequestException
*/
#[AppAPIAuth]
#[PublicPage]
#[NoCSRFRequired]
public function registerFileActionMenu(array $fileActionMenuParams): DataResponse {
$registeredFileActionMenu = $this->exFilesActionsMenuService->registerFileActionMenu(
$this->request->getHeader('EX-APP-ID'), $fileActionMenuParams);
return new DataResponse([
'success' => $registeredFileActionMenu !== null,
'registeredFileActionMenu' => $registeredFileActionMenu,
], Http::STATUS_OK);
public function registerFileActionMenu(string $name, string $displayName, string $actionHandler,
string $icon = "", string $mime = "file", int $permissions = 31,
int $order = 0): DataResponse {
$result = $this->filesActionsMenuService->registerFileActionMenu(
$this->request->getHeader('EX-APP-ID'), $name, $displayName, $actionHandler, $icon, $mime, $permissions, $order);
if (!$result) {
throw new OCSBadRequestException("File Action Menu entry could not be registered");
}
return new DataResponse();
}

/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $fileActionMenuName
* @param string $name
*
* @throws OCSNotFoundException
* @return DataResponse
*/
#[AppAPIAuth]
#[PublicPage]
#[NoCSRFRequired]
public function unregisterFileActionMenu(string $fileActionMenuName): DataResponse {
$unregisteredFileActionMenu = $this->exFilesActionsMenuService->unregisterFileActionMenu(
$this->request->getHeader('EX-APP-ID'), $fileActionMenuName);
public function unregisterFileActionMenu(string $name): DataResponse {
$unregisteredFileActionMenu = $this->filesActionsMenuService->unregisterFileActionMenu(
$this->request->getHeader('EX-APP-ID'), $name);
if ($unregisteredFileActionMenu === null) {
throw new OCSNotFoundException('FileActionMenu not found');
}
Expand All @@ -97,7 +104,7 @@ public function unregisterFileActionMenu(string $fileActionMenuName): DataRespon
#[PublicPage]
#[NoCSRFRequired]
public function getFileActionMenu(string $name): DataResponse {
$result = $this->exFilesActionsMenuService->getExAppFileAction(
$result = $this->filesActionsMenuService->getExAppFileAction(
$this->request->getHeader('EX-APP-ID'), $name);
if (!$result) {
throw new OCSNotFoundException('FileActionMenu not found');
Expand Down Expand Up @@ -326,7 +333,7 @@ public function getExAppStyle(string $type, string $name, string $path): DataRes
#[NoCSRFRequired]
public function handleFileAction(string $appId, string $actionName, array $actionFile, string $actionHandler): DataResponse {
$result = false;
$exFileAction = $this->exFilesActionsMenuService->getExAppFileAction($appId, $actionName);
$exFileAction = $this->filesActionsMenuService->getExAppFileAction($appId, $actionName);
if ($exFileAction !== null) {
$handler = $exFileAction->getActionHandler(); // route on ex app
$params = [
Expand Down Expand Up @@ -380,14 +387,14 @@ public function handleFileAction(string $appId, string $actionName, array $actio
#[NoAdminRequired]
#[NoCSRFRequired]
public function loadFileActionIcon(string $appId, string $exFileActionName): DataDisplayResponse {
$icon = $this->exFilesActionsMenuService->loadFileActionIcon($appId, $exFileActionName);
$icon = $this->filesActionsMenuService->loadFileActionIcon($appId, $exFileActionName);
if ($icon !== null && isset($icon['body'], $icon['headers'])) {
$response = new DataDisplayResponse(
$icon['body'],
Http::STATUS_OK,
['Content-Type' => $icon['headers']['Content-Type'][0] ?? 'image/svg+xml']
);
$response->cacheFor(ExFilesActionsMenuService::ICON_CACHE_TTL, false, true);
$response->cacheFor(FilesActionsMenuService::ICON_CACHE_TTL, false, true);
return $response;
}
return new DataDisplayResponse('', 400);
Expand Down
26 changes: 13 additions & 13 deletions lib/Controller/TopMenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Service\AppAPIService;
use OCA\AppAPI\Service\ExAppInitialStateService;
use OCA\AppAPI\Service\ExAppScriptsService;
use OCA\AppAPI\Service\ExAppStylesService;
use OCA\AppAPI\Service\ExAppUsersService;
use OCA\AppAPI\Service\TopMenuService;
use OCA\AppAPI\Service\UI\InitialStateService;
use OCA\AppAPI\Service\UI\ScriptsService;
use OCA\AppAPI\Service\UI\StylesService;
use OCA\AppAPI\Service\UI\TopMenuService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
Expand All @@ -26,15 +26,15 @@ class TopMenuController extends Controller {
public array $jsProxyMap = [];

public function __construct(
IRequest $request,
private IInitialState $initialState,
private TopMenuService $menuEntryService,
private ExAppInitialStateService $initialStateService,
private ExAppScriptsService $scriptsService,
private ExAppStylesService $stylesService,
private ExAppUsersService $exAppUsersService,
private AppAPIService $service,
private ?string $userId,
IRequest $request,
private IInitialState $initialState,
private TopMenuService $menuEntryService,
private InitialStateService $initialStateService,
private ScriptsService $scriptsService,
private StylesService $stylesService,
private ExAppUsersService $exAppUsersService,
private AppAPIService $service,
private ?string $userId,
) {
parent::__construct(Application::APP_ID, $request);
}
Expand Down
14 changes: 3 additions & 11 deletions lib/Db/UI/FilesActionsMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,16 @@
* @method string getDisplayName()
* @method string getMime()
* @method string getPermissions()
* @method string getOrder()
* @method int getOrder()
* @method string getIcon()
* @method string getIconClass()
* @method string getActionHandler()
* @method void setAppid(string $appid)
* @method void setName(string $name)
* @method void setDisplayName(string $displayName)
* @method void setMime(string $mime)
* @method void setPermissions(string $permissions)
* @method void setOrder(string $order)
* @method void setOrder(int $order)
* @method void setIcon(string $icon)
* @method void setIconClass(string $iconClass)
* @method void setActionHandler(string $actionHandler)
*/
class FilesActionsMenu extends Entity implements JsonSerializable {
Expand All @@ -39,7 +37,6 @@ class FilesActionsMenu extends Entity implements JsonSerializable {
protected $permissions;
protected $order;
protected $icon;
protected $iconClass;
protected $actionHandler;

/**
Expand All @@ -51,9 +48,8 @@ public function __construct(array $params = []) {
$this->addType('displayName', 'string');
$this->addType('mime', 'string');
$this->addType('permissions', 'string');
$this->addType('order', 'string');
$this->addType('order', 'int');
$this->addType('icon', 'string');
$this->addType('iconClass', 'string');
$this->addType('actionHandler', 'string');

if (isset($params['id'])) {
Expand All @@ -80,9 +76,6 @@ public function __construct(array $params = []) {
if (isset($params['icon'])) {
$this->setIcon($params['icon']);
}
if (isset($params['icon_class'])) {
$this->setIconClass($params['icon_class']);
}
if (isset($params['action_handler'])) {
$this->setActionHandler($params['action_handler']);
}
Expand All @@ -98,7 +91,6 @@ public function jsonSerialize(): array {
'permissions' => $this->getPermissions(),
'order' => $this->getOrder(),
'icon' => $this->getIcon(),
'icon_class' => $this->getIconClass(),
'action_handler' => $this->getActionHandler(),
];
}
Expand Down
5 changes: 2 additions & 3 deletions lib/Listener/LoadFilesPluginListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
namespace OCA\AppAPI\Listener;

use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Service\ExFilesActionsMenuService;

use OCA\AppAPI\Service\UI\FilesActionsMenuService;
use OCA\Files\Event\LoadAdditionalScriptsEvent;
use OCP\AppFramework\Services\IInitialState;
use OCP\EventDispatcher\Event;
Expand All @@ -20,7 +19,7 @@ class LoadFilesPluginListener implements IEventListener {

public function __construct(
private IInitialState $initialState,
private ExFilesActionsMenuService $service
private FilesActionsMenuService $service
) {
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Migration/Version1003Date202311061844.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
$table->addUniqueIndex(['appid', 'type', 'name', 'path'], 'ui_style__idx');
}

$table = $schema->getTable('ex_files_actions_menu');
$table->dropColumn('icon_class');
bigcat88 marked this conversation as resolved.
Show resolved Hide resolved

return $schema;
}
}
52 changes: 28 additions & 24 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@
use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Db\ExApp;
use OCA\AppAPI\Db\ExAppMapper;

use OCA\AppAPI\Fetcher\ExAppArchiveFetcher;
use OCA\AppAPI\Fetcher\ExAppFetcher;
use OCA\AppAPI\Notifications\ExNotificationsManager;
use OCA\AppAPI\Service\UI\FilesActionsMenuService;
use OCA\AppAPI\Service\UI\InitialStateService;
use OCA\AppAPI\Service\UI\ScriptsService;
use OCA\AppAPI\Service\UI\StylesService;
use OCA\AppAPI\Service\UI\TopMenuService;
use OCP\App\IAppManager;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
Expand Down Expand Up @@ -43,29 +47,29 @@ class AppAPIService {
public function __construct(
private readonly LoggerInterface $logger,
private readonly ILogFactory $logFactory,
ICacheFactory $cacheFactory,
private readonly IThrottler $throttler,
private readonly IConfig $config,
IClientService $clientService,
private readonly ExAppMapper $exAppMapper,
private readonly IAppManager $appManager,
private readonly ExAppUsersService $exAppUsersService,
private readonly ExAppApiScopeService $exAppApiScopeService,
private readonly ExAppScopesService $exAppScopesService,
private readonly TopMenuService $topMenuService,
private readonly ExAppInitialStateService $initialStateService,
private readonly ExAppScriptsService $scriptsService,
private readonly ExAppStylesService $stylesService,
private readonly ExFilesActionsMenuService $filesActionsMenuService,
private readonly ISecureRandom $random,
private readonly IUserSession $userSession,
private readonly ISession $session,
private readonly IUserManager $userManager,
private readonly ExAppConfigService $exAppConfigService,
private readonly ExNotificationsManager $exNotificationsManager,
private readonly TalkBotsService $talkBotsService,
private readonly ExAppFetcher $exAppFetcher,
private readonly ExAppArchiveFetcher $exAppArchiveFetcher,
ICacheFactory $cacheFactory,
private readonly IThrottler $throttler,
private readonly IConfig $config,
IClientService $clientService,
private readonly ExAppMapper $exAppMapper,
private readonly IAppManager $appManager,
private readonly ExAppUsersService $exAppUsersService,
private readonly ExAppApiScopeService $exAppApiScopeService,
private readonly ExAppScopesService $exAppScopesService,
private readonly TopMenuService $topMenuService,
private readonly InitialStateService $initialStateService,
private readonly ScriptsService $scriptsService,
private readonly StylesService $stylesService,
private readonly FilesActionsMenuService $filesActionsMenuService,
private readonly ISecureRandom $random,
private readonly IUserSession $userSession,
private readonly ISession $session,
private readonly IUserManager $userManager,
private readonly ExAppConfigService $exAppConfigService,
private readonly ExNotificationsManager $exNotificationsManager,
private readonly TalkBotsService $talkBotsService,
private readonly ExAppFetcher $exAppFetcher,
private readonly ExAppArchiveFetcher $exAppArchiveFetcher,
) {
$this->cache = $cacheFactory->createDistributed(Application::APP_ID . '/service');
$this->client = $clientService->newClient();
Expand Down
2 changes: 1 addition & 1 deletion lib/Service/ExAppApiScopeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function registerInitScopes(): bool {

$initApiScopes = [
// AppAPI scopes
['api_route' => $aeApiV1Prefix . '/files/actions/menu', 'scope_group' => 1, 'name' => 'BASIC', 'user_check' => 0],
['api_route' => $aeApiV1Prefix . '/ui/files-actions-menu', 'scope_group' => 1, 'name' => 'BASIC', 'user_check' => 0],
['api_route' => $aeApiV1Prefix . '/ui/top-menu', 'scope_group' => 1, 'name' => 'BASIC', 'user_check' => 0],
['api_route' => $aeApiV1Prefix . '/ui/initial-state', 'scope_group' => 1, 'name' => 'BASIC', 'user_check' => 0],
['api_route' => $aeApiV1Prefix . '/ui/script', 'scope_group' => 1, 'name' => 'BASIC', 'user_check' => 0],
Expand Down
Loading