Fix comments if activity stream is disabled (#1110)

Fix comments if activity stream is disabled
This commit is contained in:
Julius Härtl
2019-06-30 13:44:55 +02:00
committed by GitHub
9 changed files with 93 additions and 17 deletions

View File

@@ -17,7 +17,7 @@
- 🚀 Get your project organized - 🚀 Get your project organized
</description> </description>
<version>0.6.2</version> <version>0.6.2-1</version>
<licence>agpl</licence> <licence>agpl</licence>
<author>Julius Härtl</author> <author>Julius Härtl</author>
<namespace>Deck</namespace> <namespace>Deck</namespace>
@@ -36,7 +36,7 @@
<database min-version="9.4">pgsql</database> <database min-version="9.4">pgsql</database>
<database>sqlite</database> <database>sqlite</database>
<database min-version="5.5">mysql</database> <database min-version="5.5">mysql</database>
<nextcloud min-version="15" max-version="16" /> <nextcloud min-version="15" max-version="17" />
</dependencies> </dependencies>
<background-jobs> <background-jobs>
<job>OCA\Deck\Cron\DeleteCron</job> <job>OCA\Deck\Cron\DeleteCron</job>
@@ -54,6 +54,7 @@
<activity> <activity>
<settings> <settings>
<setting>OCA\Deck\Activity\Setting</setting> <setting>OCA\Deck\Activity\Setting</setting>
<setting>OCA\Deck\Activity\SettingComment</setting>
<setting>OCA\Deck\Activity\DescriptionSetting</setting> <setting>OCA\Deck\Activity\DescriptionSetting</setting>
</settings> </settings>
<filters> <filters>

View File

@@ -94,7 +94,7 @@ class ActivityService {
static getUrl(type, id, since) { static getUrl(type, id, since) {
if (type === DECK_ACTIVITY_TYPE_CARD) { if (type === DECK_ACTIVITY_TYPE_CARD) {
return OC.linkToOCS('apps/activity/api/v2/activity', 2) + 'filter?format=json&object_type=deck_card&object_id=' + id + '&limit=' + this.RESULT_PER_PAGE + '&since=' + since; return OC.linkToOCS('apps/activity/api/v2/activity', 2) + 'deck?format=json&object_type=deck_card&object_id=' + id + '&limit=' + this.RESULT_PER_PAGE + '&since=' + since;
} }
if (type === DECK_ACTIVITY_TYPE_BOARD) { if (type === DECK_ACTIVITY_TYPE_BOARD) {
return OC.linkToOCS('apps/activity/api/v2/activity', 2) + 'deck?format=json&limit=' + this.RESULT_PER_PAGE + '&since=' + since; return OC.linkToOCS('apps/activity/api/v2/activity', 2) + 'deck?format=json&limit=' + this.RESULT_PER_PAGE + '&since=' + since;

View File

@@ -47,6 +47,7 @@ use OCP\IUser;
class ActivityManager { class ActivityManager {
const DECK_NOAUTHOR_COMMENT_SYSTEM_ENFORCED = 'DECK_NOAUTHOR_COMMENT_SYSTEM_ENFORCED';
private $manager; private $manager;
private $userId; private $userId;
private $permissionService; private $permissionService;
@@ -142,7 +143,7 @@ class ActivityManager {
$subject = $ownActivity ? $this->l10n->t('You have restored the board {board}') : $this->l10n->t('{user} has restored the board {board}'); $subject = $ownActivity ? $this->l10n->t('You have restored the board {board}') : $this->l10n->t('{user} has restored the board {board}');
break; break;
case self::SUBJECT_BOARD_SHARE: case self::SUBJECT_BOARD_SHARE:
$subject = $ownActivity ? $this->l10n->t('You have shared the board {board} with {acl}') : $this->l10n->t('{user} has shared the board {board} with {sharee}'); $subject = $ownActivity ? $this->l10n->t('You have shared the board {board} with {acl}') : $this->l10n->t('{user} has shared the board {board} with {acl}');
break; break;
case self::SUBJECT_BOARD_UNSHARE: case self::SUBJECT_BOARD_UNSHARE:
$subject = $ownActivity ? $this->l10n->t('You have removed {acl} from the board {board}') : $this->l10n->t('{user} has removed {acl} from the board {board}'); $subject = $ownActivity ? $this->l10n->t('You have removed {acl} from the board {board}') : $this->l10n->t('{user} has removed {acl} from the board {board}');
@@ -280,7 +281,7 @@ class ActivityManager {
} }
} else { } else {
try { try {
$events = [$this->createEvent($objectType, $entity, $subject, $author)]; $events = [$this->createEvent($objectType, $entity, $subject)];
} catch (\Exception $e) { } catch (\Exception $e) {
// Ignore exception for undefined activities on update events // Ignore exception for undefined activities on update events
} }
@@ -327,6 +328,7 @@ class ActivityManager {
// case self::SUBJECT_BOARD_UPDATE_COLOR // case self::SUBJECT_BOARD_UPDATE_COLOR
break; break;
case self::SUBJECT_CARD_COMMENT_CREATE: case self::SUBJECT_CARD_COMMENT_CREATE:
$eventType = 'deck_comment';
$subjectParams = $this->findDetailsForCard($entity->getId()); $subjectParams = $this->findDetailsForCard($entity->getId());
if (array_key_exists('comment', $additionalParams)) { if (array_key_exists('comment', $additionalParams)) {
/** @var IComment $entity */ /** @var IComment $entity */
@@ -335,7 +337,6 @@ class ActivityManager {
unset($additionalParams['comment']); unset($additionalParams['comment']);
} }
break; break;
case self::SUBJECT_STACK_CREATE: case self::SUBJECT_STACK_CREATE:
case self::SUBJECT_STACK_UPDATE: case self::SUBJECT_STACK_UPDATE:
case self::SUBJECT_STACK_UPDATE_TITLE: case self::SUBJECT_STACK_UPDATE_TITLE:
@@ -356,7 +357,7 @@ class ActivityManager {
case self::SUBJECT_LABEL_UNASSING: case self::SUBJECT_LABEL_UNASSING:
case self::SUBJECT_CARD_USER_ASSIGN: case self::SUBJECT_CARD_USER_ASSIGN:
case self::SUBJECT_CARD_USER_UNASSIGN: case self::SUBJECT_CARD_USER_UNASSIGN:
$subjectParams = $this->findDetailsForCard($entity->getId()); $subjectParams = $this->findDetailsForCard($entity->getId(), $subject);
$object = $entity; $object = $entity;
break; break;
case self::SUBJECT_ATTACHMENT_CREATE: case self::SUBJECT_ATTACHMENT_CREATE:
@@ -402,6 +403,12 @@ class ActivityManager {
$event->setMessage($message); $event->setMessage($message);
} }
// FIXME: We currently require activities for comments even if they are disabled though settings
// Get rid of this once the frontend fetches comments/activity individually
if ($eventType === 'deck_comment') {
$event->setAuthor(self::DECK_NOAUTHOR_COMMENT_SYSTEM_ENFORCED);
}
return $event; return $event;
} }
@@ -486,10 +493,17 @@ class ActivityManager {
]; ];
} }
private function findDetailsForCard($cardId) { private function findDetailsForCard($cardId, $subject = null) {
$card = $this->cardMapper->find($cardId); $card = $this->cardMapper->find($cardId);
$stack = $this->stackMapper->find($card->getStackId()); $stack = $this->stackMapper->find($card->getStackId());
$board = $this->boardMapper->find($stack->getBoardId()); $board = $this->boardMapper->find($stack->getBoardId());
if ($subject !== self::SUBJECT_CARD_UPDATE_DESCRIPTION) {
$card = [
'id' => $card->getId(),
'title' => $card->getTitle(),
'archived' => $card->getArchived()
];
}
return [ return [
'card' => $card, 'card' => $card,
'stack' => $stack, 'stack' => $stack,

View File

@@ -90,7 +90,7 @@ class DeckProvider implements IProvider {
$author = $event->getAuthor(); $author = $event->getAuthor();
// get author if // get author if
if ($author === '' && array_key_exists('author', $subjectParams)) { if (($author === '' || $author === ActivityManager::DECK_NOAUTHOR_COMMENT_SYSTEM_ENFORCED) && array_key_exists('author', $subjectParams)) {
$author = $subjectParams['author']; $author = $subjectParams['author'];
unset($subjectParams['author']); unset($subjectParams['author']);
} }

View File

@@ -79,7 +79,7 @@ class Filter implements \OCP\Activity\IFilter {
* @since 11.0.0 * @since 11.0.0
*/ */
public function filterTypes(array $types) { public function filterTypes(array $types) {
return $types; return array_merge($types, ['deck_comment']);
} }
/** /**

View File

@@ -0,0 +1,53 @@
<?php
/**
* @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Activity;
class SettingComment extends Setting {
/**
* @return string Lowercase a-z and underscore only identifier
* @since 11.0.0
*/
public function getIdentifier() {
return 'deck_comment';
}
/**
* @return string A translated string
* @since 11.0.0
*/
public function getName() {
return $this->l->t('A <strong>comment</strong> was created on a card');
}
/**
* @return bool True when the option can be changed for the stream
* @since 11.0.0
*/
public function canChangeStream() {
return false;
}
}

View File

@@ -295,7 +295,11 @@ class ActivityManagerTest extends TestCase {
$this->assertEquals([ $this->assertEquals([
'stack' => $stack, 'stack' => $stack,
'board' => $board, 'board' => $board,
'card' => $card 'card' => [
'id' => $card->getId(),
'title' => $card->getTitle(),
'archived' => $card->getArchived()
]
], $this->invokePrivate($this->activityManager, 'findDetailsForCard', [555])); ], $this->invokePrivate($this->activityManager, 'findDetailsForCard', [555]));
} }
@@ -329,7 +333,11 @@ class ActivityManagerTest extends TestCase {
$this->assertEquals([ $this->assertEquals([
'stack' => $stack, 'stack' => $stack,
'board' => $board, 'board' => $board,
'card' => $card, 'card' => [
'id' => $card->getId(),
'title' => $card->getTitle(),
'archived' => $card->getArchived()
],
'attachment' => $attachment 'attachment' => $attachment
], $this->invokePrivate($this->activityManager, 'findDetailsForAttachment', [777])); ], $this->invokePrivate($this->activityManager, 'findDetailsForAttachment', [777]));
} }

View File

@@ -71,7 +71,7 @@ class FilterTest extends TestCase {
public function testFilterTypes() { public function testFilterTypes() {
$data = ['deck_board', 'deck_card']; $data = ['deck_board', 'deck_card'];
$this->assertEquals($data, $this->filter->filterTypes($data)); $this->assertEquals(array_merge($data, ['deck_comment']), $this->filter->filterTypes($data));
} }
public function testAllowedApps() { public function testAllowedApps() {