Skip to content

Commit

Permalink
dev, pre-final part
Browse files Browse the repository at this point in the history
  • Loading branch information
bigcat88 committed Dec 2, 2023
1 parent 9afb99d commit b80683e
Show file tree
Hide file tree
Showing 23 changed files with 601 additions and 72 deletions.
12 changes: 11 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
['name' => 'Config#setAdminConfig', 'url' => '/admin-config', 'verb' => 'PUT'],

// Menu Entries
['name' => 'TopMenu#ExAppIcon', 'url' => '/embedded/{appId}/{name}/icon', 'verb' => 'GET' , 'root' => '/embedded'],
['name' => 'TopMenu#viewExAppPage',
'url' => '/embedded/{appId}/{name}/{other}', 'verb' => 'GET' , 'root' => '/embedded',
'requirements' => array('other' => '.*'), 'defaults' => array('other' => '')],
Expand Down Expand Up @@ -88,5 +87,16 @@
['name' => 'OCSUi#registerExAppMenuEntry', 'url' => '/api/v1/ui/top-menu', 'verb' => 'POST'],
['name' => 'OCSUi#unregisterExAppMenuEntry', 'url' => '/api/v1/ui/top-menu', 'verb' => 'DELETE'],
['name' => 'OCSUi#getExAppMenuEntry', 'url' => '/api/v1/ui/top-menu', 'verb' => 'GET'],

//Common UI
['name' => 'OCSUi#setExAppInitialState', 'url' => '/api/v1/ui/initial-state', 'verb' => 'POST'],
['name' => 'OCSUi#deleteExAppInitialState', 'url' => '/api/v1/ui/initial-state', 'verb' => 'DELETE'],
['name' => 'OCSUi#getExAppInitialState', 'url' => '/api/v1/ui/initial-state', 'verb' => 'GET'],
['name' => 'OCSUi#setExAppScript', 'url' => '/api/v1/ui/script', 'verb' => 'POST'],
['name' => 'OCSUi#deleteExAppScript', 'url' => '/api/v1/ui/script', 'verb' => 'DELETE'],
['name' => 'OCSUi#getExAppScript', 'url' => '/api/v1/ui/script', 'verb' => 'GET'],
['name' => 'OCSUi#setExAppStyle', 'url' => '/api/v1/ui/style', 'verb' => 'POST'],
['name' => 'OCSUi#deleteExAppStyle', 'url' => '/api/v1/ui/style', 'verb' => 'DELETE'],
['name' => 'OCSUi#getExAppStyle', 'url' => '/api/v1/ui/style', 'verb' => 'GET'],
],
];
Empty file removed js/proxy_js/10.js
Empty file.
Empty file removed js/proxy_js/11.js
Empty file.
Empty file removed js/proxy_js/12.js
Empty file.
Empty file removed js/proxy_js/13.js
Empty file.
Empty file removed js/proxy_js/14.js
Empty file.
Empty file removed js/proxy_js/15.js
Empty file.
Empty file removed js/proxy_js/16.js
Empty file.
Empty file removed js/proxy_js/17.js
Empty file.
Empty file removed js/proxy_js/18.js
Empty file.
Empty file removed js/proxy_js/19.js
Empty file.
Empty file removed js/proxy_js/20.js
Empty file.
167 changes: 163 additions & 4 deletions lib/Controller/OCSUiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

use OCA\AppAPI\AppInfo\Application;
use OCA\AppAPI\Attribute\AppAPIAuth;
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;
Expand All @@ -24,10 +27,13 @@ class OCSUiController extends OCSController {
protected $request;

public function __construct(
IRequest $request,
private ?string $userId,
private ExFilesActionsMenuService $exFilesActionsMenuService,
private TopMenuService $menuEntryService,
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,
) {
parent::__construct(Application::APP_ID, $request);

Expand Down Expand Up @@ -145,6 +151,159 @@ public function getExAppMenuEntry(string $name): DataResponse {
return new DataResponse($result, Http::STATUS_OK);
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSBadRequestException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function setExAppInitialState(string $type, string $name, string $key, array $value): DataResponse {
$result = $this->initialStateService->setExAppInitialState(
$this->request->getHeader('EX-APP-ID'), $type, $name, $key, $value);
if (!$result) {
throw new OCSBadRequestException("InitialState could not be set");
}
return new DataResponse();
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSNotFoundException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function deleteExAppInitialState(string $type, string $name, string $key): DataResponse {
$result = $this->initialStateService->deleteExAppInitialState(
$this->request->getHeader('EX-APP-ID'), $type, $name, $key);
if (!$result) {
throw new OCSNotFoundException('No such InitialState');
}
return new DataResponse();
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSNotFoundException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function getExAppInitialState(string $type, string $name, string $key): DataResponse {
$result = $this->initialStateService->getExAppInitialState(
$this->request->getHeader('EX-APP-ID'), $type, $name, $key);
if (!$result) {
throw new OCSNotFoundException('No such InitialState');
}
return new DataResponse($result, Http::STATUS_OK);
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSBadRequestException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function setExAppScript(string $type, string $name, string $path, string $afterAppId): DataResponse {
$result = $this->scriptsService->setExAppScript(
$this->request->getHeader('EX-APP-ID'), $type, $name, $path, $afterAppId);
if (!$result) {
throw new OCSBadRequestException("Script could not be set");
}
return new DataResponse();
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSNotFoundException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function deleteExAppScript(string $type, string $name, string $path): DataResponse {
$result = $this->scriptsService->deleteExAppScript(
$this->request->getHeader('EX-APP-ID'), $type, $name, $path);
if (!$result) {
throw new OCSNotFoundException('No such Script');
}
return new DataResponse();
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSNotFoundException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function getExAppScript(string $type, string $name, string $path): DataResponse {
$result = $this->scriptsService->getExAppScript(
$this->request->getHeader('EX-APP-ID'), $type, $name, $path);
if (!$result) {
throw new OCSNotFoundException('No such Script');
}
return new DataResponse($result, Http::STATUS_OK);
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSBadRequestException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function setExAppStyle(string $type, string $name, string $path): DataResponse {
$result = $this->stylesService->setExAppStyle(
$this->request->getHeader('EX-APP-ID'), $type, $name, $path);
if (!$result) {
throw new OCSBadRequestException("Style could not be set");
}
return new DataResponse();
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSNotFoundException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function deleteExAppStyle(string $type, string $name, string $path): DataResponse {
$result = $this->stylesService->deleteExAppStyle(
$this->request->getHeader('EX-APP-ID'), $type, $name, $path);
if (!$result) {
throw new OCSNotFoundException('No such Style');
}
return new DataResponse();
}

/**
* @NoCSRFRequired
* @NoAdminRequired
* @throws OCSNotFoundException
*/
#[NoAdminRequired]
#[NoCSRFRequired]
#[AppAPIAuth]
public function getExAppStyle(string $type, string $name, string $path): DataResponse {
$result = $this->stylesService->getExAppStyle(
$this->request->getHeader('EX-APP-ID'), $type, $name, $path);
if (!$result) {
throw new OCSNotFoundException('No such Style');
}
return new DataResponse($result, Http::STATUS_OK);
}

/**
* @NoCSRFRequired
* @NoAdminRequired
Expand Down
71 changes: 71 additions & 0 deletions lib/Db/UI/InitialStateMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace OCA\AppAPI\Db\UI;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -35,4 +37,73 @@ public function findByAppIdTypeName(string $appId, string $type, string $name):
)->executeQuery();
return $result->fetchAll();
}

/**
* @param string $appId
* @param string $type
* @param string $name
* @param string $key
*
* @return InitialState
* @throws Exception
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function findByAppIdTypeNameKey(string $appId, string $type, string $name, string $key): InitialState {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('name', $qb->createNamedParameter($name, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('key', $qb->createNamedParameter($key, IQueryBuilder::PARAM_STR))
);
return $this->findEntity($qb);
}

/**
* @throws Exception
*/
public function removeAllByAppId(string $appId): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR))
);
return $qb->executeStatement();
}

/**
* @throws Exception
*/
public function removeAllByTypeName(string $appId, string $type, string $name): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('name', $qb->createNamedParameter($name, IQueryBuilder::PARAM_STR))
);
return $qb->executeStatement();
}

public function removeByKey(string $appId, string $type, string $name, string $key): bool {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('name', $qb->createNamedParameter($name, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('key', $qb->createNamedParameter($key, IQueryBuilder::PARAM_STR))
);
try {
$result = $qb->executeStatement();
if ($result) {
return true;
}
} catch (Exception) {
}
return false;
}
}
71 changes: 71 additions & 0 deletions lib/Db/UI/ScriptMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace OCA\AppAPI\Db\UI;

use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\Exception;
use OCP\DB\QueryBuilder\IQueryBuilder;
Expand Down Expand Up @@ -35,4 +37,73 @@ public function findByAppIdTypeName(string $appId, string $type, string $name):
)->executeQuery();
return $result->fetchAll();
}

/**
* @param string $appId
* @param string $type
* @param string $name
* @param string $path
*
* @return Script
* @throws Exception
* @throws DoesNotExistException
* @throws MultipleObjectsReturnedException
*/
public function findByAppIdTypeNamePath(string $appId, string $type, string $name, string $path): Script {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('name', $qb->createNamedParameter($name, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('path', $qb->createNamedParameter($path, IQueryBuilder::PARAM_STR))
);
return $this->findEntity($qb);
}

/**
* @throws Exception
*/
public function removeByAppId(string $appId): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR))
);
return $qb->executeStatement();
}

/**
* @throws Exception
*/
public function removeByTypeName(string $appId, string $type, string $name): int {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('name', $qb->createNamedParameter($name, IQueryBuilder::PARAM_STR))
);
return $qb->executeStatement();
}

public function removeByNameTypePath(string $appId, string $type, string $name, string $path): bool {
$qb = $this->db->getQueryBuilder();
$qb->delete($this->tableName)
->where(
$qb->expr()->eq('appid', $qb->createNamedParameter($appId, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('type', $qb->createNamedParameter($type, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('name', $qb->createNamedParameter($name, IQueryBuilder::PARAM_STR)),
$qb->expr()->eq('path', $qb->createNamedParameter($path, IQueryBuilder::PARAM_STR))
);
try {
$result = $qb->executeStatement();
if ($result) {
return true;
}
} catch (Exception) {
}
return false;
}
}
Loading

0 comments on commit b80683e

Please sign in to comment.