Skip to content

Commit

Permalink
fixup! fix: add new db migration for usergroup column
Browse files Browse the repository at this point in the history
  • Loading branch information
blizzz committed Jul 24, 2024
1 parent aeae166 commit 1dd2e77
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 13 deletions.
6 changes: 3 additions & 3 deletions lib/Db/RowCellUsergroupMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ public function __construct(IDBConnection $db) {
* @inheritDoc
*/
public function parseValueIncoming(Column $column, $value): array {
return json_decode(json_encode($value), true);
return json_decode($value, true);
}

/**
* @inheritDoc
*/
public function parseValueOutgoing(Column $column, $value, ?int $value_type = null): array {
return ['id' => $value, 'type' => $value_type];
public function parseValueOutgoing(Column $column, $value, ?int $value_type = null): string {
return json_encode(['id' => $value, 'type' => $value_type]);
}
}
4 changes: 2 additions & 2 deletions lib/Service/ColumnTypes/UsergroupBusiness.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function parseValue($value, ?Column $column = null): string {
}

/**
* @param mixed $value array{id: string, type: int}
* @param string $value json encoded array{id: string, type: int}
* @param Column|null $column
* @return bool
*/
Expand All @@ -39,7 +39,7 @@ public function canBeParsed($value, ?Column $column = null): bool {
return true;
}

foreach ($value as $v) {
foreach (json_decode($value, true) as $v) {
if((array_key_exists('id', $v) && !is_string($v['id'])) && (array_key_exists('type', $v) && !is_int($v['type']))) {
return false;
}
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/features/APIv2.feature
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Feature: APIv2
| title | ug column renamed |
| mandatory | 0 |
| description | New description |
| usergroupDefault | [{"id": "admin", "type": 0}] |
| usergroupDefault | [{"id":"admin","type":0}] |
Then table has at least following columns
| ug column renamed |

Expand Down Expand Up @@ -571,20 +571,20 @@ Feature: APIv2

@api1 @rows
Scenario: Create and modify usergroup row via v1
Given table "Usergroup row check" with emoji "👨🏻‍💻" exists for user "participant1" as "base1"
Given table "Usergroup row check" with emoji "👋" exists for user "participant1-v2" as "base1" via v2
Then column "one" exists with following properties
| title | usergroup |
| type | usergroup |
| mandatory | 0 |
| description | New description |
| usergroupMultipleItems | true |
| usergroupSelectUsers | true |
| usergroupSelectGroups | true |
Then row exists with following values
| one | [{"id": "admin", "type": 0}] |
| one | [{"id":"admin","type":0}] |
Then set following values for last created row
| one | [{"id": "admin", "type": 1}] |
| one | [{"id":"admin","type":1}] |
Then user deletes last created row
Then user "participant1" deletes table with keyword "Usergroup row check"
Then user "participant1-v2" deletes table with keyword "Usergroup row check"

@api2 @rows
Scenario: Create rows via v2 and check them
Expand Down
24 changes: 22 additions & 2 deletions tests/integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1268,7 +1268,17 @@ public function createRow(?TableNode $properties = null): void {
$rowToVerify = $this->getDataFromResponse($this->response);
Assert::assertEquals(200, $this->response->getStatusCode());
foreach ($rowToVerify['data'] as $cell) {
Assert::assertEquals($props[$cell['columnId']], $cell['value']);
// I am afraid this is usergroupcolumn specific, but not generic
if (is_array($cell['value'])) {
$retrieved = json_encode(array_reduce($cell['value'], function (array $carry, string $item): array {
$carry[] = json_decode($item, true);
return $carry;
}, []));
} else {
$retrieved = $cell['value'];
}

Assert::assertEquals($props[$cell['columnId']], $retrieved);
}
}

Expand Down Expand Up @@ -1444,7 +1454,17 @@ public function updateRow(?TableNode $properties = null): void {
$rowToVerify = $this->getDataFromResponse($this->response);
Assert::assertEquals(200, $this->response->getStatusCode());
foreach ($rowToVerify['data'] as $cell) {
Assert::assertEquals($props[$cell['columnId']], $cell['value']);
// I am afraid this is usergroupcolumn specific, but not generic
if (is_array($cell['value'])) {
$retrieved = json_encode(array_reduce($cell['value'], function (array $carry, string $item): array {
$carry[] = json_decode($item, true);
return $carry;
}, []));
} else {
$retrieved = $cell['value'];
}

Assert::assertEquals($props[$cell['columnId']], $retrieved);
}
}

Expand Down

0 comments on commit 1dd2e77

Please sign in to comment.