Merge pull request #2245 from nextcloud/enh/etag-api
This commit is contained in:
@@ -24,6 +24,7 @@
|
||||
namespace OCA\Deck\Activity;
|
||||
|
||||
use OCA\Deck\Db\CardMapper;
|
||||
use OCA\Deck\Db\ChangeHelper;
|
||||
use OCA\Deck\Notification\NotificationHelper;
|
||||
use OCP\Comments\CommentsEvent;
|
||||
use OCP\Comments\IComment;
|
||||
@@ -40,10 +41,14 @@ class CommentEventHandler implements ICommentsEventHandler {
|
||||
/** @var CardMapper */
|
||||
private $cardMapper;
|
||||
|
||||
public function __construct(ActivityManager $activityManager, NotificationHelper $notificationHelper, CardMapper $cardMapper) {
|
||||
/** @var ChangeHelper */
|
||||
private $changeHelper;
|
||||
|
||||
public function __construct(ActivityManager $activityManager, NotificationHelper $notificationHelper, CardMapper $cardMapper, ChangeHelper $changeHelper) {
|
||||
$this->notificationHelper = $notificationHelper;
|
||||
$this->activityManager = $activityManager;
|
||||
$this->cardMapper = $cardMapper;
|
||||
$this->changeHelper = $changeHelper;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -54,6 +59,8 @@ class CommentEventHandler implements ICommentsEventHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->changeHelper->cardChanged($event->getComment()->getObjectId());
|
||||
|
||||
$eventType = $event->getEvent();
|
||||
if ($eventType === CommentsEvent::EVENT_ADD
|
||||
) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
|
||||
namespace OCA\Deck\Controller;
|
||||
|
||||
use OCA\Deck\Db\Board;
|
||||
use OCA\Deck\StatusException;
|
||||
use OCP\AppFramework\ApiController;
|
||||
use OCP\AppFramework\Http;
|
||||
@@ -72,7 +73,11 @@ class BoardApiController extends ApiController {
|
||||
}
|
||||
$boards = $this->boardService->findAll($date->getTimestamp(), $details);
|
||||
}
|
||||
return new DataResponse($boards, HTTP::STATUS_OK);
|
||||
$response = new DataResponse($boards, HTTP::STATUS_OK);
|
||||
$response->setETag(md5(json_encode(array_map(function (Board $board) {
|
||||
return $board->getId() . '-' . $board->getETag();
|
||||
}, $boards))));
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -85,7 +90,9 @@ class BoardApiController extends ApiController {
|
||||
*/
|
||||
public function get() {
|
||||
$board = $this->boardService->find($this->request->getParam('boardId'));
|
||||
return new DataResponse($board, HTTP::STATUS_OK);
|
||||
$response = new DataResponse($board, HTTP::STATUS_OK);
|
||||
$response->setETag($board->getEtag());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,7 +64,9 @@ class CardApiController extends ApiController {
|
||||
*/
|
||||
public function get() {
|
||||
$card = $this->cardService->find($this->request->getParam('cardId'));
|
||||
return new DataResponse($card, HTTP::STATUS_OK);
|
||||
$response = new DataResponse($card, HTTP::STATUS_OK);
|
||||
$response->setETag($card->getEtag());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -83,7 +83,9 @@ class StackApiController extends ApiController {
|
||||
*/
|
||||
public function get() {
|
||||
$stack = $this->stackService->find($this->request->getParam('stackId'));
|
||||
return new DataResponse($stack, HTTP::STATUS_OK);
|
||||
$response = new DataResponse($stack, HTTP::STATUS_OK);
|
||||
$response->setETag($stack->getETag());
|
||||
return $response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -81,4 +81,8 @@ class Board extends RelationalEntity {
|
||||
$this->acl[] = $a;
|
||||
}
|
||||
}
|
||||
|
||||
public function getETag() {
|
||||
return md5((string)$this->getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,4 +155,8 @@ class Card extends RelationalEntity {
|
||||
public function getCalendarPrefix(): string {
|
||||
return 'card';
|
||||
}
|
||||
|
||||
public function getETag() {
|
||||
return md5((string)$this->getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,4 +36,8 @@ class Label extends RelationalEntity {
|
||||
$this->addType('cardId', 'integer');
|
||||
$this->addType('lastModified', 'integer');
|
||||
}
|
||||
|
||||
public function getETag() {
|
||||
return md5((string)$this->getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ class RelationalEntity extends Entity implements \JsonSerializable {
|
||||
$json[$property] = $value;
|
||||
}
|
||||
}
|
||||
if ($reflection->hasMethod('getETag')) {
|
||||
$json['ETag'] = $this->getETag();
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,4 +65,8 @@ class Stack extends RelationalEntity {
|
||||
public function getCalendarPrefix(): string {
|
||||
return 'stack';
|
||||
}
|
||||
|
||||
public function getETag() {
|
||||
return md5((string)$this->getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ class AssignmentService {
|
||||
$assignment->setParticipant($userId);
|
||||
$assignment->setType($type);
|
||||
$assignment = $this->assignedUsersMapper->insert($assignment);
|
||||
$this->changeHelper->cardChanged($cardId, false);
|
||||
$this->changeHelper->cardChanged($cardId);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_ASSIGN, ['assigneduser' => $userId]);
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
@@ -185,7 +185,7 @@ class AssignmentService {
|
||||
$assignment = $this->assignedUsersMapper->delete($assignment);
|
||||
$card = $this->cardMapper->find($cardId);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_CARD_USER_UNASSIGN, ['assigneduser' => $userId]);
|
||||
$this->changeHelper->cardChanged($cardId, false);
|
||||
$this->changeHelper->cardChanged($cardId);
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
'\OCA\Deck\Card::onUpdate', new FTSEvent(null, ['id' => $cardId, 'card' => $card])
|
||||
|
||||
@@ -320,6 +320,7 @@ class AttachmentService {
|
||||
if ($service->allowUndo()) {
|
||||
$service->markAsDeleted($attachment);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $attachment, ActivityManager::SUBJECT_ATTACHMENT_DELETE);
|
||||
$this->changeHelper->cardChanged($attachment->getCardId());
|
||||
return $this->attachmentMapper->update($attachment);
|
||||
}
|
||||
$service->delete($attachment);
|
||||
|
||||
@@ -538,7 +538,7 @@ class CardService {
|
||||
}
|
||||
$label = $this->labelMapper->find($labelId);
|
||||
$this->cardMapper->assignLabel($cardId, $labelId);
|
||||
$this->changeHelper->cardChanged($cardId, false);
|
||||
$this->changeHelper->cardChanged($cardId);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]);
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
@@ -574,7 +574,7 @@ class CardService {
|
||||
}
|
||||
$label = $this->labelMapper->find($labelId);
|
||||
$this->cardMapper->removeLabel($cardId, $labelId);
|
||||
$this->changeHelper->cardChanged($cardId, false);
|
||||
$this->changeHelper->cardChanged($cardId);
|
||||
$this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]);
|
||||
|
||||
$this->eventDispatcher->dispatch(
|
||||
|
||||
Reference in New Issue
Block a user