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

Draft: create and open a talk room for the current collective #442

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ In your Nextcloud instance, simply navigate to **»Apps«**, find the
**»Circles«** and **»Collectives«** apps and enable them.

]]></description>
<version>0.11.22</version>
<version>0.12.22-beta1</version>
<licence>agpl</licence>
<author>CollectiveCloud Team</author>
<namespace>Collectives</namespace>
Expand Down
8 changes: 5 additions & 3 deletions lib/Controller/CollectiveController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,17 @@ public function create(string $name, string $emoji = null): DataResponse {
*
* @param int $id
* @param string|null $emoji
* @param string|null $conversationToken
*
* @return DataResponse
*/
public function update(int $id, string $emoji = null): DataResponse {
return $this->prepareResponse(function () use ($id, $emoji) {
public function update(int $id, string $emoji = null, string $conversationToken = null): DataResponse {
return $this->prepareResponse(function () use ($id, $emoji, $conversationToken) {
$collective = $this->service->updateCollective(
$this->getUserId(),
$id,
$emoji
$emoji,
$conversationToken
);
return [
"data" => $collective,
Expand Down
6 changes: 6 additions & 0 deletions lib/Db/Collective.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* @method void setEmoji(string $value)
* @method string getCircleUniqueId()
* @method void setCircleUniqueId(string $value)
* @method string getConversationToken()
* @method void setConversationToken(string $value)
* @method int|null getTrashTimestamp()
* @method void setTrashTimestamp(?int $value)
*/
Expand All @@ -24,6 +26,9 @@ class Collective extends Entity implements JsonSerializable {
/** @var string */
protected $emoji;

/** @var string */
protected $conversationToken;

/** @var int|null */
protected $trashTimestamp;

Expand Down Expand Up @@ -53,6 +58,7 @@ public function jsonSerialize() {
'id' => $this->id,
'emoji' => $this->emoji,
'circleId' => $this->circleUniqueId,
'conversationToken' => $this->conversationToken,
'trashTimestamp' => $this->trashTimestamp
];
}
Expand Down
34 changes: 34 additions & 0 deletions lib/Migration/Version001000Date20210809000000.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace OCA\Collectives\Migration;

use Closure;
use Doctrine\DBAL\Types\Types;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\SimpleMigrationStep;
use OCP\Migration\IOutput;

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

$table = $schema->getTable('collectives');
if (!$table->hasColumn('conversation_token')) {
$table->addColumn('conversation_token', Types::STRING, [
'notnull' => false,
'length' => 8,
]);
}
return $schema;
}
}
2 changes: 2 additions & 0 deletions lib/Model/CollectiveInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class CollectiveInfo extends Collective {
public function __construct(Collective $collective, string $name, int $level = Member::LEVEL_MEMBER) {
$this->id = $collective->getId();
$this->circleUniqueId = $collective->getCircleId();
$this->conversationToken = $collective->getConversationToken();
$this->emoji = $collective->getEmoji();
$this->trashTimestamp = $collective->getTrashTimestamp();
$this->name = $name;
Expand All @@ -32,6 +33,7 @@ public function jsonSerialize() {
return [
'id' => $this->id,
'circleId' => $this->circleUniqueId,
'conversationToken' => $this->conversationToken,
'emoji' => $this->emoji,
'trashTimestamp' => $this->trashTimestamp,
'name' => $this->name,
Expand Down
7 changes: 6 additions & 1 deletion lib/Service/CollectiveService.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,13 +166,14 @@ public function createCollective(string $userId, string $userLang, string $safeN
* @param string $userId
* @param int $id
* @param string|null $emoji
* @param string|null $conversationToken
*
* @return CollectiveInfo
* @throws NotFoundException
* @throws NotPermittedException
* @throws MissingDependencyException
*/
public function updateCollective(string $userId, int $id, string $emoji = null): CollectiveInfo {
public function updateCollective(string $userId, int $id, string $emoji = null, string $conversationToken = null): CollectiveInfo {
if (null === $collective = $this->collectiveMapper->findById($id, $userId)) {
throw new NotFoundException('Collective not found: ' . $id);
}
Expand All @@ -186,6 +187,10 @@ public function updateCollective(string $userId, int $id, string $emoji = null):
$collective->setEmoji($emoji);
}

if ($conversationToken) {
$collective->setConversationToken($conversationToken);
}

return new CollectiveInfo($this->collectiveMapper->update($collective),
$name,
true);
Expand Down
43 changes: 42 additions & 1 deletion tests/Integration/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,24 @@ public function userCreatesCollective(string $user, string $collective, ?string
}
}

/**
* @When user :user sets :key to :value for collective :collective
*
* @param string $user
* @param string $key
* @param string $value
* @param string $collective
*
* @throws GuzzleException
*/
public function userUpdatesCollective(string $user, string $key, string $value, string $collective): void {
$this->setCurrentUser($user);
$collectiveId = $this->collectiveIdByName($collective);
$formData = new TableNode([[$key, $value]]);
$this->sendRequest('PUT', '/apps/collectives/_collectives/' . $collectiveId , $formData);
$this->assertStatusCode(200);
}

/**
* @When user :user creates page :page with parentPath :parentPath in :collective
*
Expand All @@ -96,14 +114,17 @@ public function userCreatesPage(string $user, string $page, string $parentPath,
/**
* @Then user :user sees collective :collective
* @Then user :user sees collective :collective in :trash
* @Then user :user sees collective :collective with :key set to :value
*
* @param string $user
* @param string $collective
* @param string|null $trash
* @param string|null $key
* @param string|null $value
*
* @throws GuzzleException
*/
public function userSeesCollective(string $user, string $collective, ?string $trash = null): void {
public function userSeesCollective(string $user, string $collective, ?string $trash = null, ?string $key = null, ?string $value = null): void {
$this->setCurrentUser($user);
if ($trash) {
$this->sendRequest('GET', '/apps/collectives/_collectives/trash');
Expand All @@ -112,6 +133,9 @@ public function userSeesCollective(string $user, string $collective, ?string $tr
}
$this->assertStatusCode(200);
$this->assertCollectiveByName($collective);
if ($key && $value) {
$this->assertCollectiveProperty($collective, $key, $value);
}
}

/**
Expand Down Expand Up @@ -689,6 +713,23 @@ private function assertCollectiveByName(string $name, ?bool $revert = false): vo
}
}

/**
* @param string $name
* @param string $key
* @param string $value
*/
private function assertCollectiveProperty(string $name, string $key, string $value): void {
$jsonBody = $this->getJson();
foreach ($jsonBody['data'] as $collective) {
if ($collective['name'] === $name) {
Assert::assertEquals($collective[$key], $value,
'Expected ' . $key . ' to be ' . $value . ' in ' .
json_encode($collective, JSON_PRETTY_PRINT)
);
}
}
}

/**
* @param Response $response
* @param string $path
Expand Down
8 changes: 8 additions & 0 deletions tests/Integration/features/collective.feature
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ Feature: collective
And user "alice" sees pagePath "Readme.md" in "mycollective"
And user "john" doesn't see collective "mycollective"

Scenario: Update a collectives emoji
When user "jane" sets "emoji" to "🌊" for collective "mycollective"
Then user "alice" sees collective "mycollective" with "emoji" set to "🌊"

Scenario: Update a collectives conversation token
When user "jane" sets "conversationToken" to "12345678" for collective "mycollective"
Then user "alice" sees collective "mycollective" with "conversationToken" set to "12345678"

Scenario: Fail to trash a collective as simple member
And user "alice" fails to trash collective "mycollective"

Expand Down
1 change: 1 addition & 0 deletions tests/Unit/Service/CollectiveServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public function testCreate(): void {
'id' => 123,
'emoji' => null,
'circleId' => null,
'conversationToken' => null,
'trashTimestamp' => null,
'name' => 'free',
'level' => Member::LEVEL_OWNER
Expand Down