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

feat: add backend for new user/group column #1090

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
['name' => 'ApiColumns#createTextColumn', 'url' => '/api/2/columns/text', 'verb' => 'POST'],
['name' => 'ApiColumns#createSelectionColumn', 'url' => '/api/2/columns/selection', 'verb' => 'POST'],
['name' => 'ApiColumns#createDatetimeColumn', 'url' => '/api/2/columns/datetime', 'verb' => 'POST'],
['name' => 'ApiColumns#createUsergroupColumn', 'url' => '/api/2/columns/usergroup', 'verb' => 'POST'],

['name' => 'ApiFavorite#create', 'url' => '/api/2/favorites/{nodeType}/{nodeId}', 'verb' => 'POST', 'requirements' => ['nodeType' => '(\d+)', 'nodeId' => '(\d+)']],
['name' => 'ApiFavorite#destroy', 'url' => '/api/2/favorites/{nodeType}/{nodeId}', 'verb' => 'DELETE', 'requirements' => ['nodeType' => '(\d+)', 'nodeId' => '(\d+)']],
Expand Down
1 change: 1 addition & 0 deletions lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function getCapabilities(): array {
'datetime',
'datetime-date',
'datetime-time',
'usergroup',
]
],
];
Expand Down
64 changes: 60 additions & 4 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ public function indexViewColumns(int $viewId): DataResponse {
* @param int|null $tableId Table ID
* @param int|null $viewId View ID
* @param string $title Title
* @param 'text'|'number'|'datetime'|'select' $type Column main type
* @param 'text'|'number'|'datetime'|'select'|'usergroup' $type Column main type
* @param string|null $subtype Column sub type
* @param bool $mandatory Is the column mandatory
* @param string|null $description Description
Expand All @@ -728,6 +728,11 @@ public function indexViewColumns(int $viewId): DataResponse {
* @param string|null $selectionOptions Options for a selection (json array{id: int, label: string})
* @param string|null $selectionDefault Default option IDs for a selection (json int[])
* @param string|null $datetimeDefault Default value, if column is datetime
* @param string|null $usergroupDefault Default value, if column is usergroup (json array{id: string, type: int})
* @param bool|null $usergroupMultipleItems Can select multiple users or/and groups, if column is usergroup
* @param bool|null $usergroupSelectUsers Can select users, if column type is usergroup
* @param bool|null $usergroupSelectGroups Can select groups, if column type is usergroup
* @param bool|null $showUserStatus Whether to show the user's status, if column type is usergroup
* @param int[]|null $selectedViewIds View IDs where this column should be added to be presented
*
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
Expand Down Expand Up @@ -759,6 +764,13 @@ public function createColumn(
?string $selectionDefault = '',

?string $datetimeDefault = '',

?string $usergroupDefault = '',
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $showUserStatus,

?array $selectedViewIds = []
): DataResponse {
try {
Expand Down Expand Up @@ -787,6 +799,13 @@ public function createColumn(
$selectionDefault,

$datetimeDefault,

$usergroupDefault,
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$showUserStatus,

$selectedViewIds
)->jsonSerialize());
} catch (PermissionError $e) {
Expand Down Expand Up @@ -828,6 +847,11 @@ public function createColumn(
* @param string|null $selectionOptions Options for a selection (json array{id: int, label: string})
* @param string|null $selectionDefault Default option IDs for a selection (json int[])
* @param string|null $datetimeDefault Default value, if column is datetime
* @param string|null $usergroupDefault Default value, if column is usergroup
* @param bool|null $usergroupMultipleItems Can select multiple users or/and groups, if column is usergroup
* @param bool|null $usergroupSelectUsers Can select users, if column type is usergroup
* @param bool|null $usergroupSelectGroups Can select groups, if column type is usergroup
* @param bool|null $showUserStatus Whether to show the user's status, if column type is usergroup
*
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
*
Expand All @@ -854,7 +878,14 @@ public function updateColumn(
?string $selectionOptions,
?string $selectionDefault,

?string $datetimeDefault
?string $datetimeDefault,

?string $usergroupDefault,
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $showUserStatus,

): DataResponse {
try {
$item = $this->columnService->update(
Expand All @@ -880,7 +911,13 @@ public function updateColumn(

$selectionOptions,
$selectionDefault,
$datetimeDefault
$datetimeDefault,

$usergroupDefault,
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$showUserStatus,
);
return new DataResponse($item->jsonSerialize());
} catch (InternalError $e) {
Expand Down Expand Up @@ -1393,7 +1430,7 @@ public function createTableShare(int $tableId, string $receiver, string $receive
*
* @param int $tableId Table ID
* @param string $title Title
* @param 'text'|'number'|'datetime'|'select' $type Column main type
* @param 'text'|'number'|'datetime'|'select'|'usergroup' $type Column main type
* @param string|null $subtype Column sub type
* @param bool $mandatory Is the column mandatory
* @param string|null $description Description
Expand All @@ -1409,6 +1446,11 @@ public function createTableShare(int $tableId, string $receiver, string $receive
* @param string|null $selectionOptions Options for a selection (json array{id: int, label: string})
* @param string|null $selectionDefault Default option IDs for a selection (json int[])
* @param string|null $datetimeDefault Default value, if column is datetime
* @param string|null $usergroupDefault Default value, if column is usergroup
* @param bool|null $usergroupMultipleItems Can select multiple users or/and groups, if column is usergroup
* @param bool|null $usergroupSelectUsers Can select users, if column type is usergroup
* @param bool|null $usergroupSelectGroups Can select groups, if column type is usergroup
* @param bool|null $showUserStatus Whether to show the user's status, if column type is usergroup
* @param int[]|null $selectedViewIds View IDs where this column should be added to be presented
*
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
Expand Down Expand Up @@ -1440,6 +1482,13 @@ public function createTableColumn(
?string $selectionDefault = '',

?string $datetimeDefault = '',

?string $usergroupDefault = '',
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $showUserStatus,

?array $selectedViewIds = []
): DataResponse {
try {
Expand Down Expand Up @@ -1468,6 +1517,13 @@ public function createTableColumn(
$selectionDefault,

$datetimeDefault,

$usergroupDefault,
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$showUserStatus,

$selectedViewIds
);
return new DataResponse($item->jsonSerialize());
Expand Down
79 changes: 79 additions & 0 deletions lib/Controller/ApiColumnsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public function createNumberColumn(int $baseNodeId, string $title, ?float $numbe
null,
null,
null,
null,
null,
null,
null,
null,
$selectedViewIds
);
return new DataResponse($column->jsonSerialize());
Expand Down Expand Up @@ -195,6 +200,11 @@ public function createTextColumn(int $baseNodeId, string $title, ?string $textDe
null,
null,
null,
null,
null,
null,
null,
null,
$selectedViewIds
);
return new DataResponse($column->jsonSerialize());
Expand Down Expand Up @@ -249,6 +259,11 @@ public function createSelectionColumn(int $baseNodeId, string $title, string $se
$selectionOptions,
$selectionDefault,
null,
null,
null,
null,
null,
null,
$selectedViewIds
);
return new DataResponse($column->jsonSerialize());
Expand Down Expand Up @@ -302,6 +317,70 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
null,
null,
$datetimeDefault,
null,
null,
null,
null,
null,
$selectedViewIds
);
return new DataResponse($column->jsonSerialize());
}

/**
* [api v2] Create new usergroup column
*
* @NoAdminRequired
*
* @param int $baseNodeId Context of the column creation
* @param string $title Title
* @param string|null $usergroupDefault Json array{id: string, type: int}, eg [{"id": "admin", "type": 0}, {"id": "user1", "type": 0}]
* @param boolean $usergroupMultipleItems Whether you can select multiple users or/and groups
* @param boolean $usergroupSelectUsers Whether you can select users
* @param boolean $usergroupSelectGroups Whether you can select groups
* @param boolean $showUserStatus Whether to show the user's status
* @param string|null $description Description
* @param int[]|null $selectedViewIds View IDs where this columns should be added
* @param boolean $mandatory Is mandatory
* @param 'table'|'view' $baseNodeType Context type of the column creation
* @return DataResponse<Http::STATUS_OK, TablesColumn, array{}>|DataResponse<Http::STATUS_FORBIDDEN|Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*
* 200: Column created
* 403: No permission
* 404: Not found
* @throws InternalError
* @throws NotFoundError
* @throws PermissionError
*/
public function createUsergroupColumn(int $baseNodeId, string $title, ?string $usergroupDefault, bool $usergroupMultipleItems = null, bool $usergroupSelectUsers = null, bool $usergroupSelectGroups = null, bool $showUserStatus = null, string $description = null, ?array $selectedViewIds = [], bool $mandatory = false, string $baseNodeType = 'table'): DataResponse {
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
$column = $this->service->create(
$this->userId,
$tableId,
$viewId,
'usergroup',
null,
$title,
$mandatory,
$description,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
$usergroupDefault,
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$showUserStatus,
$selectedViewIds
);
return new DataResponse($column->jsonSerialize());
Expand Down
46 changes: 43 additions & 3 deletions lib/Controller/ColumnController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ public function create(
?string $selectionDefault,

?string $datetimeDefault,

?string $usergroupDefault,
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $showUserStatus,

?array $selectedViewIds
): DataResponse {
return $this->handleError(function () use (
Expand All @@ -118,6 +125,13 @@ public function create(
$selectionDefault,

$datetimeDefault,

$usergroupDefault,
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$showUserStatus,

$selectedViewIds) {
return $this->service->create(
$this->userId,
Expand All @@ -144,6 +158,13 @@ public function create(
$selectionDefault,

$datetimeDefault,

$usergroupDefault,
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$showUserStatus,

$selectedViewIds);
});
}
Expand Down Expand Up @@ -174,7 +195,13 @@ public function update(
?string $selectionOptions,
?string $selectionDefault,

?string $datetimeDefault
?string $datetimeDefault,

?string $usergroupDefault,
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $showUserStatus
): DataResponse {
return $this->handleError(function () use (
$id,
Expand All @@ -199,7 +226,13 @@ public function update(
$selectionOptions,
$selectionDefault,

$datetimeDefault
$datetimeDefault,

$usergroupDefault,
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$showUserStatus
) {
return $this->service->update(
$id,
Expand All @@ -225,7 +258,14 @@ public function update(
$selectionOptions,
$selectionDefault,

$datetimeDefault);
$datetimeDefault,

$usergroupDefault,
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$showUserStatus
);
});
}

Expand Down
Loading
Loading