Skip to content

Commit

Permalink
feat: add support for teams in usergroup column
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 Aug 29, 2024
1 parent ae2f333 commit cec679d
Show file tree
Hide file tree
Showing 18 changed files with 168 additions and 48 deletions.
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 @@ -342,6 +342,7 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
* @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 @@ public function createDatetimeColumn(int $baseNodeId, string $title, ?string $da
* @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 @@ public function createUsergroupColumn(int $baseNodeId, string $title, ?string $u
$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
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 @@ public function find(int $id, ?string $userId = null): Column {
* @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 @@ public function create(
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $usergroupSelectTeams,
?bool $showUserStatus,

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

try {
Expand Down Expand Up @@ -343,6 +346,7 @@ public function create(
* @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 @@ public function update(
?bool $usergroupMultipleItems,
?bool $usergroupSelectUsers,
?bool $usergroupSelectGroups,
?bool $usergroupSelectTeams,
?bool $showUserStatus,
):Column {
try {
Expand Down Expand Up @@ -431,6 +436,7 @@ public function update(
$item->setUsergroupMultipleItems($usergroupMultipleItems);
$item->setUsergroupSelectUsers($usergroupSelectUsers);
$item->setUsergroupSelectGroups($usergroupSelectGroups);
$item->setUsergroupSelectTeams($usergroupSelectTeams);
$item->setShowUserStatus($showUserStatus);

$this->updateMetadata($item, $userId);
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
3 changes: 3 additions & 0 deletions src/modules/modals/CreateColumn.vue
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export default {
usergroupMultipleItems: false,
usergroupSelectUsers: true,
usergroupSelectGroups: false,
usergroupSelectTeams: false,
showUserStatus: false,
},
textAppAvailable: !!window.OCA?.Text?.createEditor,
Expand Down Expand Up @@ -335,6 +336,7 @@ export default {
data.usergroupMultipleItems = this.column.usergroupMultipleItems
data.usergroupSelectUsers = this.column.usergroupSelectUsers
data.usergroupSelectGroups = this.column.usergroupSelectGroups
data.usergroupSelectTeams = this.column.usergroupSelectTeams
data.showUserStatus = this.column.showUserStatus
} else if (this.column.type === 'number') {
data.numberDefault = this.column.numberDefault
Expand Down Expand Up @@ -388,6 +390,7 @@ export default {
usergroupMultipleItems: false,
usergroupSelectUsers: true,
usergroupSelectGroups: false,
usergroupSelectTeams: false,
showUserStatus: false,
}
if (mainForm) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export default class UsergroupColumn extends AbstractUsergroupColumn {
this.usergroupMultipleItems = data.usergroupMultipleItems
this.usergroupSelectUsers = data.usergroupSelectUsers
this.usergroupSelectGroups = data.usergroupSelectGroups
this.usergroupSelectTeams = data.usergroupSelectTeams
}

getValueString(valueObject) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<!-- eslint-disable-next-line vue/no-v-html -->
<div v-if="value">
<div v-for="item in value" :key="item.id" class="inline usergroup-entry">
<NcUserBubble :user="item.id" :avatar-image="item.type === 1 ? 'icon-group' : undefined" :is-no-user="item.type !== 0" :display-name="item.displayName ?? item.id" :show-user-status="isUser(item) && column.showUserStatus" :size="column.showUserStatus ? 34 : 20" :primary="isCurrentUser(item)" />
<NcUserBubble :user="item.id" :avatar-image="item.type === 1 ? 'icon-group' : ''" :is-no-user="item.type !== 0" :display-name="item.displayName ?? item.id" :show-user-status="isUser(item) && column.showUserStatus" :size="column.showUserStatus ? 34 : 20" :primary="isCurrentUser(item)" />
</div>
</div>
</template>
Expand Down
Loading

0 comments on commit cec679d

Please sign in to comment.