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 support for teams in usergroup column #1326

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 9 additions & 0 deletions lib/Controller/Api1Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -770,6 +770,7 @@ public function indexViewColumns(int $viewId): DataResponse {
* @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 $usergroupSelectTeams Can select teams, if column type is usergroup
* @param bool|null $usergroupShowUserStatus 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
*
Expand Down Expand Up @@ -807,6 +808,7 @@ public function createColumn(
?bool $usergroupMultipleItems = null,
?bool $usergroupSelectUsers = null,
?bool $usergroupSelectGroups = null,
?bool $usergroupSelectTeams = null,
?bool $usergroupShowUserStatus = null,

?array $selectedViewIds = []
Expand Down Expand Up @@ -842,6 +844,7 @@ public function createColumn(
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$usergroupSelectTeams,
$usergroupShowUserStatus,

$selectedViewIds
Expand Down Expand Up @@ -889,6 +892,7 @@ public function createColumn(
* @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 $usergroupSelectTeams Can select teams, if column type is usergroup
* @param bool|null $usergroupShowUserStatus 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 Down Expand Up @@ -922,6 +926,7 @@ public function updateColumn(
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $usergroupSelectTeams,
?bool $usergroupShowUserStatus,

): DataResponse {
Expand Down Expand Up @@ -955,6 +960,7 @@ public function updateColumn(
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$usergroupSelectTeams,
$usergroupShowUserStatus,
);
return new DataResponse($item->jsonSerialize());
Expand Down Expand Up @@ -1488,6 +1494,7 @@ public function createTableShare(int $tableId, string $receiver, string $receive
* @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 $usergroupSelectTeams Can select teams, if column type is usergroup
* @param bool|null $usergroupShowUserStatus 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
*
Expand Down Expand Up @@ -1525,6 +1532,7 @@ public function createTableColumn(
?bool $usergroupMultipleItems = null,
?bool $usergroupSelectUsers = null,
?bool $usergroupSelectGroups = null,
?bool $usergroupSelectTeams = null,
?bool $usergroupShowUserStatus = null,
?array $selectedViewIds = []
): DataResponse {
Expand Down Expand Up @@ -1559,6 +1567,7 @@ public function createTableColumn(
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$usergroupSelectTeams,
$usergroupShowUserStatus,

$selectedViewIds
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/ApiColumnsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
null,
null,
null,
$selectedViewIds

Check failure on line 152 in lib/Controller/ApiColumnsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidArgument

lib/Controller/ApiColumnsController.php:152:4: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<array-key, int>|null provided (see https://psalm.dev/004)

Check failure on line 152 in lib/Controller/ApiColumnsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidArgument

lib/Controller/ApiColumnsController.php:152:4: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<array-key, int>|null provided (see https://psalm.dev/004)
);
return new DataResponse($column->jsonSerialize());
}
Expand Down Expand Up @@ -209,7 +209,7 @@
null,
null,
null,
$selectedViewIds

Check failure on line 212 in lib/Controller/ApiColumnsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidArgument

lib/Controller/ApiColumnsController.php:212:4: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<array-key, int>|null provided (see https://psalm.dev/004)

Check failure on line 212 in lib/Controller/ApiColumnsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidArgument

lib/Controller/ApiColumnsController.php:212:4: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<array-key, int>|null provided (see https://psalm.dev/004)
);
return new DataResponse($column->jsonSerialize());
}
Expand Down Expand Up @@ -268,7 +268,7 @@
null,
null,
null,
$selectedViewIds

Check failure on line 271 in lib/Controller/ApiColumnsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidArgument

lib/Controller/ApiColumnsController.php:271:4: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<array-key, int>|null provided (see https://psalm.dev/004)

Check failure on line 271 in lib/Controller/ApiColumnsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidArgument

lib/Controller/ApiColumnsController.php:271:4: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<array-key, int>|null provided (see https://psalm.dev/004)
);
return new DataResponse($column->jsonSerialize());
}
Expand Down Expand Up @@ -326,7 +326,7 @@
null,
null,
null,
$selectedViewIds

Check failure on line 329 in lib/Controller/ApiColumnsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidArgument

lib/Controller/ApiColumnsController.php:329:4: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<array-key, int>|null provided (see https://psalm.dev/004)

Check failure on line 329 in lib/Controller/ApiColumnsController.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidArgument

lib/Controller/ApiColumnsController.php:329:4: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<array-key, int>|null provided (see https://psalm.dev/004)
);
return new DataResponse($column->jsonSerialize());
}
Expand All @@ -342,6 +342,7 @@
* @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 $usergroupSelectTeams Whether you can select teams
* @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
Expand All @@ -356,7 +357,7 @@
* @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 {
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'): DataResponse {
$tableId = $baseNodeType === 'table' ? $baseNodeId : null;
$viewId = $baseNodeType === 'view' ? $baseNodeId : null;
$column = $this->service->create(
Expand Down Expand Up @@ -384,6 +385,7 @@
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$usergroupSelectTeams,
$showUserStatus,
$selectedViewIds
);
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/ApiTablesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public function createFromScheme(string $title, string $emoji, string $descripti
$column['usergroupMultipleItems'],
$column['usergroupSelectUsers'],
$column['usergroupSelectGroups'],
$column['usergroupSelectTeams'],
$column['showUserStatus'],

[],
Expand Down
6 changes: 6 additions & 0 deletions lib/Controller/ColumnController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ public function create(
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $usergroupSelectTeams,
?bool $showUserStatus,

?array $selectedViewIds
Expand Down Expand Up @@ -135,6 +136,7 @@ public function create(
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$usergroupSelectTeams,
$showUserStatus,

$selectedViewIds) {
Expand Down Expand Up @@ -168,6 +170,7 @@ public function create(
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$usergroupSelectTeams,
$showUserStatus,

$selectedViewIds);
Expand Down Expand Up @@ -206,6 +209,7 @@ public function update(
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $usergroupSelectTeams,
?bool $showUserStatus
): DataResponse {
return $this->handleError(function () use (
Expand Down Expand Up @@ -237,6 +241,7 @@ public function update(
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$usergroupSelectTeams,
$showUserStatus
) {
return $this->service->update(
Expand Down Expand Up @@ -269,6 +274,7 @@ public function update(
$usergroupMultipleItems,
$usergroupSelectUsers,
$usergroupSelectGroups,
$usergroupSelectTeams,
$showUserStatus
);
});
Expand Down
5 changes: 5 additions & 0 deletions lib/Db/Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
* @method setUsergroupSelectUsers(?bool $usergroupSelectUsers)
* @method getUsergroupSelectGroups(): bool
* @method setUsergroupSelectGroups(?bool $usergroupSelectGroups)
* @method getUsergroupSelectTeams(): bool
* @method setUsergroupSelectTeams(?bool $usergroupSelectTeams)
* @method getShowUserStatus(): bool
* @method setShowUserStatus(?bool $showUserStatus)
*/
Expand Down Expand Up @@ -129,6 +131,7 @@ class Column extends Entity implements JsonSerializable {
protected ?bool $usergroupMultipleItems = null;
protected ?bool $usergroupSelectUsers = null;
protected ?bool $usergroupSelectGroups = null;
protected ?bool $usergroupSelectTeams = null;
protected ?bool $showUserStatus = null;

public function __construct() {
Expand All @@ -149,6 +152,7 @@ public function __construct() {
$this->addType('usergroupMultipleItems', 'boolean');
$this->addType('usergroupSelectUsers', 'boolean');
$this->addType('usergroupSelectGroups', 'boolean');
$this->addType('usergroupSelectTeams', 'boolean');
$this->addType('showUserStatus', 'boolean');
}

Expand Down Expand Up @@ -224,6 +228,7 @@ public function jsonSerialize(): array {
'usergroupMultipleItems' => $this->usergroupMultipleItems,
'usergroupSelectUsers' => $this->usergroupSelectUsers,
'usergroupSelectGroups' => $this->usergroupSelectGroups,
'usergroupSelectTeams' => $this->usergroupSelectTeams,
'showUserStatus' => $this->showUserStatus,
];
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Migration/Version000000Date20210921000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
'notnull' => false,
'default' => 0,
]);
$table->addColumn('usergroup_select_teams', Types::BOOLEAN, [
'notnull' => false,
'default' => 0,
]);
$table->addColumn('show_user_status', Types::BOOLEAN, [
'notnull' => false,
'default' => 0,
Expand Down
6 changes: 6 additions & 0 deletions lib/Migration/Version000800Date20240712000000.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@ private function haveUserGroupColumnDefinitionFields(ISchemaWrapper $schema) {
'default' => 0,
]);
}
if (!$table->hasColumn('usergroup_select_teams')) {
$table->addColumn('usergroup_select_teams', Types::BOOLEAN, [
'notnull' => false,
'default' => 0,
]);
}
if (!$table->hasColumn('show_user_status')) {
$table->addColumn('show_user_status', Types::BOOLEAN, [
'notnull' => false,
Expand Down
45 changes: 45 additions & 0 deletions lib/Migration/Version000800Date20240828000000.php
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can I verify that this migration works? I try using a different tables branch initially, then switch to this afterwards. But these changes aren't applied automatically

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

/** @noinspection PhpUnused */

declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Tables\Migration;

use Closure;
use OCP\DB\Exception;
use OCP\DB\ISchemaWrapper;
use OCP\DB\Types;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;

class Version000800Date20240828000000 extends SimpleMigrationStep {
/**
* @param IOutput $output
* @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
* @param array $options
* @return null|ISchemaWrapper
* @throws Exception
*/
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
/** @var ISchemaWrapper $schema */
$schema = $schemaClosure();

if ($schema->hasTable('tables_columns')) {
if ($schema->hasTable('tables_row_cells_usergroup')) {
$table = $schema->getTable('tables_columns');
if (!$table->hasColumn('usergroup_select_teams')) {
$table->addColumn('usergroup_select_teams', Types::BOOLEAN, [
'notnull' => false,
'default' => 0,
]);
}
}
return $schema;
}
return null;
}
}
1 change: 1 addition & 0 deletions lib/ResponseDefinitions.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
* usergroupMultipleItems: bool,
* usergroupSelectUsers: bool,
* usergroupSelectGroups: bool,
* usergroupSelectTeams: bool,
* showUserStatus: bool,
* }
*
Expand Down
6 changes: 6 additions & 0 deletions lib/Service/ColumnService.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@
* @param bool|null $usergroupMultipleItems
* @param bool|null $usergroupSelectUsers
* @param bool|null $usergroupSelectGroups
* @param bool|null $usergroupSelectTeams
* @param bool|null $showUserStatus
* @param array $selectedViewIds
* @return Column
Expand Down Expand Up @@ -200,6 +201,7 @@
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $usergroupSelectTeams,
?bool $showUserStatus,

array $selectedViewIds = []
Expand Down Expand Up @@ -288,6 +290,7 @@
$item->setUsergroupMultipleItems($usergroupMultipleItems);
$item->setUsergroupSelectUsers($usergroupSelectUsers);
$item->setUsergroupSelectGroups($usergroupSelectGroups);
$item->setUsergroupSelectTeams($usergroupSelectTeams);
$item->setShowUserStatus($showUserStatus);

try {
Expand Down Expand Up @@ -343,6 +346,7 @@
* @param bool|null $usergroupMultipleItems
* @param bool|null $usergroupSelectUsers
* @param bool|null $usergroupSelectGroups
* @param bool|null $usergroupSelectTeams
* @param bool|null $showUserStatus
* @return Column
* @throws InternalError
Expand Down Expand Up @@ -377,6 +381,7 @@
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $usergroupSelectTeams,
?bool $showUserStatus,
):Column {
try {
Expand Down Expand Up @@ -431,6 +436,7 @@
$item->setUsergroupMultipleItems($usergroupMultipleItems);
$item->setUsergroupSelectUsers($usergroupSelectUsers);
$item->setUsergroupSelectGroups($usergroupSelectGroups);
$item->setUsergroupSelectTeams($usergroupSelectTeams);
$item->setShowUserStatus($showUserStatus);

$this->updateMetadata($item, $userId);
Expand Down Expand Up @@ -596,7 +602,7 @@
null,
null,
null,
[]

Check failure on line 605 in lib/Service/ColumnService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-master

InvalidArgument

lib/Service/ColumnService.php:605:6: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<never, never> provided (see https://psalm.dev/004)

Check failure on line 605 in lib/Service/ColumnService.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis dev-stable28

InvalidArgument

lib/Service/ColumnService.php:605:6: InvalidArgument: Argument 26 of OCA\Tables\Service\ColumnService::create expects bool|null, but array<never, never> provided (see https://psalm.dev/004)
);
$countCreatedColumns++;
}
Expand Down
1 change: 1 addition & 0 deletions lib/Service/ImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ private function getColumns(Row $firstRow, Row $secondRow): void {
$this->columnsConfig[$index]['usergroupMultipleItems'] ?? null,
$this->columnsConfig[$index]['usergroupSelectUsers'] ?? null,
$this->columnsConfig[$index]['usergroupSelectGroups'] ?? null,
$this->columnsConfig[$index]['usergroupSelectTeams'] ?? null,
$this->columnsConfig[$index]['showUserStatus'] ?? null,
$this->columnsConfig[$index]['selectedViewIds'] ?? []
);
Expand Down
3 changes: 3 additions & 0 deletions lib/Service/TableTemplateService.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,9 @@ private function createColumn(int $tableId, array $parameters): ?Column {
// usergroupSelectGroups
(isset($parameters['usergroupSelectGroups'])) ? $parameters['usergroupSelectGroups'] : null,

// usergroupSelectTeams
(isset($parameters['usergroupSelectTeams'])) ? $parameters['usergroupSelectTeams'] : null,

// showUserStatus
(isset($parameters['showUserStatus'])) ? $parameters['showUserStatus'] : null,

Expand Down
Loading
Loading