Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion lib/Command/AddTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OCA\Tables\Command;

use InvalidArgumentException;
use OCA\Tables\Errors\InternalError;
use OCA\Tables\Errors\PermissionError;
use OCA\Tables\Service\TableService;
Expand Down Expand Up @@ -78,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
unset($arr['rowsCount']);
unset($arr['ownerDisplayName']);
$output->writeln(json_encode($arr, JSON_PRETTY_PRINT));
} catch (InternalError|PermissionError|Exception $e) {
} catch (InternalError|PermissionError|Exception|InvalidArgumentException $e) {
$output->writeln('Error occurred: ' . $e->getMessage());
$this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]);
return 1;
Expand Down
3 changes: 2 additions & 1 deletion lib/Command/RenameTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OCA\Tables\Command;

use InvalidArgumentException;
use OCA\Tables\Errors\InternalError;
use OCA\Tables\Service\TableService;
use Psr\Log\LoggerInterface;
Expand Down Expand Up @@ -84,7 +85,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
unset($arr['rowsCount']);
unset($arr['ownerDisplayName']);
$output->writeln(json_encode($arr, JSON_PRETTY_PRINT));
} catch (InternalError $e) {
} catch (InternalError|InvalidArgumentException $e) {
$output->writeln('Error occurred: ' . $e->getMessage());
$this->logger->warning('Following error occurred during executing occ command "' . self::class . '"', ['exception' => $e]);
return 1;
Expand Down
14 changes: 12 additions & 2 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ public function index(): DataResponse {
* @param string|null $emoji Emoji for the table
* @param string $template Template to use if wanted
*
* @return DataResponse<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
* @return DataResponse<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
*
* 200: Tables returned
* 400: Invalid request data
*/
#[NoAdminRequired]
#[NoCSRFRequired]
Expand All @@ -142,6 +143,10 @@ public function index(): DataResponse {
public function createTable(string $title, ?string $emoji, string $template = 'custom'): DataResponse {
try {
return new DataResponse($this->tableService->create($title, $template, $emoji)->jsonSerialize());
} catch (InvalidArgumentException $e) {
$this->logger->warning('An invalid request occurred: ' . $e->getMessage(), ['exception' => $e]);
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_BAD_REQUEST);
} catch (InternalError|Exception $e) {
$this->logger->error('An internal error or exception occurred: ' . $e->getMessage(), ['exception' => $e]);
$message = ['message' => $e->getMessage()];
Expand Down Expand Up @@ -232,9 +237,10 @@ public function getTable(int $tableId): DataResponse {
* @param string|null $title New table title
* @param string|null $emoji New table emoji
* @param bool $archived Whether the table is archived
* @return DataResponse<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
* @return DataResponse<Http::STATUS_OK, TablesTable, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: Tables returned
* 400: Invalid request data
* 403: No permissions
* 404: Not found
*/
Expand All @@ -246,6 +252,10 @@ public function getTable(int $tableId): DataResponse {
public function updateTable(int $tableId, ?string $title = null, ?string $emoji = null, ?bool $archived = false): DataResponse {
try {
return new DataResponse($this->tableService->update($tableId, $title, $emoji, null, $archived, $this->userId)->jsonSerialize());
} catch (InvalidArgumentException $e) {
$this->logger->warning('An invalid request occurred: ' . $e->getMessage(), ['exception' => $e]);
$message = ['message' => $e->getMessage()];
return new DataResponse($message, Http::STATUS_BAD_REQUEST);
} catch (PermissionError $e) {
$this->logger->warning('A permission error occurred: ' . $e->getMessage(), ['exception' => $e]);
$message = ['message' => $e->getMessage()];
Expand Down
211 changes: 118 additions & 93 deletions lib/Controller/ApiColumnsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,12 @@ public function show(int $id): DataResponse {
*
*
* @return DataResponse<Http::STATUS_OK, TablesColumn,
* array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{message: string}, array{}>
*
*
* 200: Column created
* 400: Invalid request data
* 403: No permission
* 404: Not found
* @throws InternalError
Expand All @@ -147,26 +148,30 @@ public function show(int $id): DataResponse {
public function createNumberColumn(int $baseNodeId, string $title, ?float $numberDefault, ?int $numberDecimals, ?string $numberPrefix, ?string $numberSuffix, ?float $numberMin, ?float $numberMax, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::NUMBER->value,
subtype: $subtype,
mandatory: $mandatory,
description: $description,
numberDefault: $numberDefault,
numberMin: $numberMin,
numberMax: $numberMax,
numberDecimals: $numberDecimals,
numberPrefix: $numberPrefix,
numberSuffix: $numberSuffix,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
try {
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::NUMBER->value,
subtype: $subtype,
mandatory: $mandatory,
description: $description,
numberDefault: $numberDefault,
numberMin: $numberMin,
numberMax: $numberMax,
numberDecimals: $numberDecimals,
numberPrefix: $numberPrefix,
numberSuffix: $numberSuffix,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
} catch (BadRequestError $e) {
return $this->handleBadRequestError($e);
}
return new DataResponse($column->jsonSerialize());
}

Expand All @@ -193,11 +198,12 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe
* @param array<string, mixed> $customSettings Custom settings for the
* column
* @return DataResponse<Http::STATUS_OK, TablesColumn,
* array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{message: string}, array{}>
*
*
* 200: Column created
* 400: Invalid request data
* 403: No permission
* 404: Not found
* @throws InternalError
Expand All @@ -210,24 +216,28 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe
public function createTextColumn(int $baseNodeId, string $title, ?string $textDefault, ?string $textAllowedPattern, ?int $textMaxLength, ?bool $textUnique = false, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::TEXT->value,
subtype: $subtype,
mandatory: $mandatory,
description: $description,
textDefault: $textDefault,
textAllowedPattern: $textAllowedPattern,
textMaxLength: $textMaxLength,
textUnique: $textUnique,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
try {
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::TEXT->value,
subtype: $subtype,
mandatory: $mandatory,
description: $description,
textDefault: $textDefault,
textAllowedPattern: $textAllowedPattern,
textMaxLength: $textMaxLength,
textUnique: $textUnique,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
} catch (BadRequestError $e) {
return $this->handleBadRequestError($e);
}
return new DataResponse($column->jsonSerialize());
}

Expand Down Expand Up @@ -256,11 +266,12 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe
*
*
* @return DataResponse<Http::STATUS_OK, TablesColumn,
* array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{message: string}, array{}>
*
*
* 200: Column created
* 400: Invalid request data
* 403: No permission
* 404: Not found
* @throws InternalError
Expand All @@ -273,22 +284,26 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe
public function createSelectionColumn(int $baseNodeId, string $title, string $selectionOptions, ?string $selectionDefault, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::SELECTION->value,
subtype: $subtype,
mandatory: $mandatory,
description: $description,
selectionOptions: $selectionOptions,
selectionDefault: $selectionDefault,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
try {
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::SELECTION->value,
subtype: $subtype,
mandatory: $mandatory,
description: $description,
selectionOptions: $selectionOptions,
selectionDefault: $selectionDefault,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
} catch (BadRequestError $e) {
return $this->handleBadRequestError($e);
}
return new DataResponse($column->jsonSerialize());
}

Expand All @@ -314,11 +329,12 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se
*
*
* @return DataResponse<Http::STATUS_OK, TablesColumn,
* array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{message: string}, array{}>
*
*
* 200: Column created
* 400: Invalid request data
* 403: No permission
* 404: Not found
* @throws InternalError
Expand All @@ -331,21 +347,25 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se
public function createDatetimeColumn(int $baseNodeId, string $title, ?string $datetimeDefault, ?string $subtype = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::DATETIME->value,
subtype: $subtype,
mandatory: $mandatory,
description: $description,
datetimeDefault: $datetimeDefault,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
try {
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::DATETIME->value,
subtype: $subtype,
mandatory: $mandatory,
description: $description,
datetimeDefault: $datetimeDefault,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
} catch (BadRequestError $e) {
return $this->handleBadRequestError($e);
}
return new DataResponse($column->jsonSerialize());
}

Expand Down Expand Up @@ -374,11 +394,12 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
*
*
* @return DataResponse<Http::STATUS_OK, TablesColumn,
* array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND,
* array{message: string}, array{}>
*
*
* 200: Column created
* 400: Invalid request data
* 403: No permission
* 404: Not found
* @throws InternalError
Expand All @@ -391,25 +412,29 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
public function createUsergroupColumn(int $baseNodeId, string $title, ?string $usergroupDefault, ?bool $usergroupMultipleItems = null, ?bool $usergroupSelectUsers = null, ?bool $usergroupSelectGroups = null, ?bool $usergroupSelectTeams = null, ?bool $showUserStatus = null, ?string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table', array $customSettings = []): DataResponse {
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::PEOPLE->value,
mandatory: $mandatory,
description: $description,
usergroupDefault: $usergroupDefault,
usergroupMultipleItems: $usergroupMultipleItems,
usergroupSelectUsers: $usergroupSelectUsers,
usergroupSelectGroups: $usergroupSelectGroups,
usergroupSelectTeams: $usergroupSelectTeams,
showUserStatus: $showUserStatus,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
try {
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
new ColumnDto(
title: $title,
type: ColumnType::PEOPLE->value,
mandatory: $mandatory,
description: $description,
usergroupDefault: $usergroupDefault,
usergroupMultipleItems: $usergroupMultipleItems,
usergroupSelectUsers: $usergroupSelectUsers,
usergroupSelectGroups: $usergroupSelectGroups,
usergroupSelectTeams: $usergroupSelectTeams,
showUserStatus: $showUserStatus,
customSettings: json_encode($customSettings),
),
$selectedViewIds
);
} catch (BadRequestError $e) {
return $this->handleBadRequestError($e);
}
return new DataResponse($column->jsonSerialize());
}
}
Loading
Loading