diff --git a/appinfo/info.xml b/appinfo/info.xml
index d2fc97014..224441102 100644
--- a/appinfo/info.xml
+++ b/appinfo/info.xml
@@ -22,7 +22,7 @@ In your Nextcloud instance, simply navigate to **»Apps«**, find the
**»Circles«** and **»Collectives«** apps and enable them.
]]>
- 0.11.22
+ 0.12.22-beta1
agpl
CollectiveCloud Team
Collectives
diff --git a/lib/Controller/CollectiveController.php b/lib/Controller/CollectiveController.php
index 4720f58c0..0ee9ef124 100644
--- a/lib/Controller/CollectiveController.php
+++ b/lib/Controller/CollectiveController.php
@@ -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,
diff --git a/lib/Db/Collective.php b/lib/Db/Collective.php
index 94aea29bc..5d4c219e8 100644
--- a/lib/Db/Collective.php
+++ b/lib/Db/Collective.php
@@ -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)
*/
@@ -24,6 +26,9 @@ class Collective extends Entity implements JsonSerializable {
/** @var string */
protected $emoji;
+ /** @var string */
+ protected $conversationToken;
+
/** @var int|null */
protected $trashTimestamp;
@@ -53,6 +58,7 @@ public function jsonSerialize() {
'id' => $this->id,
'emoji' => $this->emoji,
'circleId' => $this->circleUniqueId,
+ 'conversationToken' => $this->conversationToken,
'trashTimestamp' => $this->trashTimestamp
];
}
diff --git a/lib/Migration/Version001000Date20210809000000.php b/lib/Migration/Version001000Date20210809000000.php
new file mode 100644
index 000000000..9af2999f8
--- /dev/null
+++ b/lib/Migration/Version001000Date20210809000000.php
@@ -0,0 +1,34 @@
+getTable('collectives');
+ if (!$table->hasColumn('conversation_token')) {
+ $table->addColumn('conversation_token', Types::STRING, [
+ 'notnull' => false,
+ 'length' => 8,
+ ]);
+ }
+ return $schema;
+ }
+}
diff --git a/lib/Model/CollectiveInfo.php b/lib/Model/CollectiveInfo.php
index 70fff4992..383f9c6d0 100644
--- a/lib/Model/CollectiveInfo.php
+++ b/lib/Model/CollectiveInfo.php
@@ -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;
@@ -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,
diff --git a/lib/Service/CollectiveService.php b/lib/Service/CollectiveService.php
index 69d78c7d4..56e537fad 100644
--- a/lib/Service/CollectiveService.php
+++ b/lib/Service/CollectiveService.php
@@ -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);
}
@@ -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);
diff --git a/tests/Integration/features/bootstrap/FeatureContext.php b/tests/Integration/features/bootstrap/FeatureContext.php
index 0e9997b1e..e7f511c07 100644
--- a/tests/Integration/features/bootstrap/FeatureContext.php
+++ b/tests/Integration/features/bootstrap/FeatureContext.php
@@ -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
*
@@ -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');
@@ -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);
+ }
}
/**
@@ -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
diff --git a/tests/Integration/features/collective.feature b/tests/Integration/features/collective.feature
index dc9c8da50..d59f51961 100644
--- a/tests/Integration/features/collective.feature
+++ b/tests/Integration/features/collective.feature
@@ -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"
diff --git a/tests/Unit/Service/CollectiveServiceTest.php b/tests/Unit/Service/CollectiveServiceTest.php
index 8eb24522b..769db7dd1 100644
--- a/tests/Unit/Service/CollectiveServiceTest.php
+++ b/tests/Unit/Service/CollectiveServiceTest.php
@@ -148,6 +148,7 @@ public function testCreate(): void {
'id' => 123,
'emoji' => null,
'circleId' => null,
+ 'conversationToken' => null,
'trashTimestamp' => null,
'name' => 'free',
'level' => Member::LEVEL_OWNER