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

Merged
merged 20 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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
4 changes: 3 additions & 1 deletion lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public function getCapabilities(): array {
'version' => $this->appManager->getAppVersion('tables'),
'apiVersions' => [
'1.0',
'2.0'
'2.0',
'2.1',
],
'features' => [
'favorite',
Expand All @@ -81,6 +82,7 @@ public function getCapabilities(): array {
'datetime',
'datetime-date',
'datetime-time',
'usergroup',
juliusknorr marked this conversation as resolved.
Show resolved Hide resolved
]
],
];
Expand Down
2 changes: 1 addition & 1 deletion lib/Controller/AOCSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function handlePermissionError(PermissionError $e): DataResponse {
* @return DataResponse<Http::STATUS_NOT_FOUND, array{message: string}, array{}>
*/
protected function handleNotFoundError(NotFoundError $e): DataResponse {
$this->logger->warning('A not found error occurred: ['. $e->getCode() . ']' . $e->getMessage());
$this->logger->info('A not found error occurred: ['. $e->getCode() . ']' . $e->getMessage());
return new DataResponse(['message' => $this->n->t('A not found error occurred. More details can be found in the logs. Please reach out to your administration.')], Http::STATUS_NOT_FOUND);
}

Expand Down
109 changes: 82 additions & 27 deletions lib/Controller/Api1Controller.php

Large diffs are not rendered by default.

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
7 changes: 7 additions & 0 deletions lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ public function createFromScheme(string $title, string $emoji, string $descripti
$column['selectionDefault'],

$column['datetimeDefault'],

$column['usergroupDefault'],
$column['usergroupMultipleItems'],
$column['usergroupSelectUsers'],
$column['usergroupSelectGroups'],
$column['showUserStatus'],

[],
);
};
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
45 changes: 45 additions & 0 deletions lib/Db/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@
* @method setSelectionDefault(?string $selectionDefault)
* @method getDatetimeDefault(): string
* @method setDatetimeDefault(?string $datetimeDefault)
* @method getUsergroupDefault(): string
* @method setUsergroupDefault(?string $usergroupDefaultArray)
* @method getUsergroupMultipleItems(): bool
* @method setUsergroupMultipleItems(?bool $usergroupMultipleItems)
* @method getUsergroupSelectUsers(): bool
* @method setUsergroupSelectUsers(?bool $usergroupSelectUsers)
* @method getUsergroupSelectGroups(): bool
* @method setUsergroupSelectGroups(?bool $usergroupSelectGroups)
* @method getShowUserStatus(): bool
* @method setShowUserStatus(?bool $showUserStatus)
*/
class Column extends Entity implements JsonSerializable {
// Meta column types
Expand All @@ -73,6 +83,7 @@ class Column extends Entity implements JsonSerializable {
public const TYPE_TEXT = 'text';
public const TYPE_NUMBER = 'number';
public const TYPE_DATETIME = 'datetime';
public const TYPE_USERGROUP = 'usergroup';

protected ?string $title = null;
protected ?int $tableId = null;
Expand Down Expand Up @@ -108,6 +119,13 @@ class Column extends Entity implements JsonSerializable {
// type datetime
protected ?string $datetimeDefault = null;

// type usergroup
protected ?string $usergroupDefault = null;
protected ?bool $usergroupMultipleItems = null;
protected ?bool $usergroupSelectUsers = null;
protected ?bool $usergroupSelectGroups = null;
protected ?bool $showUserStatus = null;

public function __construct() {
$this->addType('id', 'integer');
$this->addType('tableId', 'integer');
Expand All @@ -121,6 +139,26 @@ public function __construct() {

// type text
$this->addType('textMaxLength', 'integer');

// // type usergroup
$this->addType('usergroupMultipleItems', 'boolean');
$this->addType('usergroupSelectUsers', 'boolean');
$this->addType('usergroupSelectGroups', 'boolean');
$this->addType('showUserStatus', 'boolean');
}

public function getUsergroupDefaultArray():array {
$default = $this->getUsergroupDefault();
if ($default !== "" && $default !== null) {
return \json_decode($default, true) ?? [];
} else {
return [];
}
}

public function setUsergroupDefaultArray(array $array):void {
$json = \json_encode($array);
$this->setUsergroup($json);
}

public function getSelectionOptionsArray():array {
Expand Down Expand Up @@ -175,6 +213,13 @@ public function jsonSerialize(): array {

// type datetime
'datetimeDefault' => $this->datetimeDefault,

// type usergroup
'usergroupDefault' => $this->getUsergroupDefaultArray(),
'usergroupMultipleItems' => $this->usergroupMultipleItems,
'usergroupSelectUsers' => $this->usergroupSelectUsers,
'usergroupSelectGroups' => $this->usergroupSelectGroups,
'showUserStatus' => $this->showUserStatus,
];
}
}
12 changes: 12 additions & 0 deletions lib/Db/ColumnTypes/UsergroupColumnQB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace OCA\Tables\Db\ColumnTypes;

use OCP\DB\QueryBuilder\IQueryBuilder;

class UsergroupColumnQB extends SuperColumnQB implements IColumnTypeQB {
public function passSearchValue(IQueryBuilder $qb, string $unformattedSearchValue, string $operator, string $searchValuePlaceHolder): void {
// TODO how to handle searching for multiple users/groups?
enjeck marked this conversation as resolved.
Show resolved Hide resolved
$qb->setParameter($searchValuePlaceHolder, $unformattedSearchValue, IQueryBuilder::PARAM_STR);
}
}
Loading
Loading