Skip to content

Commit

Permalink
feat: add new column for user and group to backend
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed May 13, 2024
1 parent 3145800 commit 232b63c
Show file tree
Hide file tree
Showing 19 changed files with 1,093 additions and 26 deletions.
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 @@ -710,7 +710,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 @@ -726,6 +726,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, icon: string, isUser: bool, displayName: string})
* @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 @@ -757,6 +762,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 @@ -785,6 +797,13 @@ public function createColumn(
$selectionDefault,

$datetimeDefault,

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

$selectedViewIds
)->jsonSerialize());
} catch (PermissionError $e) {
Expand Down Expand Up @@ -826,6 +845,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 @@ -852,7 +876,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 @@ -878,7 +909,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 @@ -1390,7 +1427,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 @@ -1406,6 +1443,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 @@ -1437,6 +1479,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 @@ -1465,6 +1514,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, isUser: bool, displayName: string}, eg [{"id": "admin", "isUser": true, "displayName": "admin"}, {"id": "user1", "isUser": true, "displayName": "user1"}]
* @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
47 changes: 44 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,14 @@ public function update(
$selectionOptions,
$selectionDefault,

$datetimeDefault
$datetimeDefault,

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

) {
return $this->service->update(
$id,
Expand All @@ -225,7 +259,14 @@ public function update(
$selectionOptions,
$selectionDefault,

$datetimeDefault);
$datetimeDefault,

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

Expand Down
Loading

0 comments on commit 232b63c

Please sign in to comment.