fix: update attachments count when sharing

Signed-off-by: Luka Trovic <luka@nextcloud.com>
This commit is contained in:
Luka Trovic
2022-04-27 09:40:27 +02:00
committed by backportbot-nextcloud[bot]
parent 461ed6b81f
commit bfcd5357e3
3 changed files with 26 additions and 7 deletions

View File

@@ -137,16 +137,17 @@ class AttachmentService {
/** /**
* @param $cardId * @param $cardId
* @param bool $update | Force the update of the cached values
* @return int|mixed * @return int|mixed
* @throws BadRequestException * @throws BadRequestException
*/ */
public function count($cardId) { public function count($cardId, $update = false) {
if (is_numeric($cardId) === false) { if (is_numeric($cardId) === false) {
throw new BadRequestException('card id must be a number'); throw new BadRequestException('card id must be a number');
} }
$count = $this->cache->get('card-' . $cardId); $count = $this->cache->get('card-' . $cardId);
if (!$count) { if ($update OR !$count) {
$count = count($this->attachmentMapper->findAll($cardId)); $count = count($this->attachmentMapper->findAll($cardId));
foreach (array_keys($this->services) as $attachmentType) { foreach (array_keys($this->services) as $attachmentType) {

View File

@@ -34,6 +34,7 @@ use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\User; use OCA\Deck\Db\User;
use OCA\Deck\NoPermissionException; use OCA\Deck\NoPermissionException;
use OCA\Deck\Service\PermissionService; use OCA\Deck\Service\PermissionService;
use OCA\Deck\Service\AttachmentService;
use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException; use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\AppFramework\Utility\ITimeFactory; use OCP\AppFramework\Utility\ITimeFactory;
@@ -75,16 +76,29 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
private $cardMapper; private $cardMapper;
/** @var PermissionService */ /** @var PermissionService */
private $permissionService; private $permissionService;
/** @var AttachmentService */
private $attachmentService;
/** @var ITimeFactory */ /** @var ITimeFactory */
private $timeFactory; private $timeFactory;
private $l; private $l;
public function __construct(IDBConnection $connection, IManager $shareManager, ISecureRandom $secureRandom, BoardMapper $boardMapper, CardMapper $cardMapper, PermissionService $permissionService, IL10N $l) { public function __construct(
IDBConnection $connection,
IManager $shareManager,
ISecureRandom $secureRandom,
BoardMapper $boardMapper,
CardMapper $cardMapper,
AttachmentService $attachmentService,
PermissionService $permissionService,
IL10N $l
) {
$this->dbConnection = $connection; $this->dbConnection = $connection;
$this->shareManager = $shareManager; $this->shareManager = $shareManager;
$this->boardMapper = $boardMapper; $this->boardMapper = $boardMapper;
$this->cardMapper = $cardMapper; $this->cardMapper = $cardMapper;
$this->attachmentService = $attachmentService;
$this->permissionService = $permissionService; $this->permissionService = $permissionService;
$this->l = $l; $this->l = $l;
$this->timeFactory = \OC::$server->get(ITimeFactory::class); $this->timeFactory = \OC::$server->get(ITimeFactory::class);
} }
@@ -152,6 +166,8 @@ class DeckShareProvider implements \OCP\Share\IShareProvider {
); );
$data = $this->getRawShare($shareId); $data = $this->getRawShare($shareId);
$this->attachmentService->count($cardId, true);
return $this->createShareObject($data); return $this->createShareObject($data);
} }

View File

@@ -109,7 +109,7 @@ import relativeDate from '../../mixins/relativeDate'
import { formatFileSize } from '@nextcloud/files' import { formatFileSize } from '@nextcloud/files'
import { getCurrentUser } from '@nextcloud/auth' import { getCurrentUser } from '@nextcloud/auth'
import { generateUrl, generateOcsUrl, generateRemoteUrl } from '@nextcloud/router' import { generateUrl, generateOcsUrl, generateRemoteUrl } from '@nextcloud/router'
import { mapState } from 'vuex' import { mapState, mapActions } from 'vuex'
import { loadState } from '@nextcloud/initial-state' import { loadState } from '@nextcloud/initial-state'
import attachmentUpload from '../../mixins/attachmentUpload' import attachmentUpload from '../../mixins/attachmentUpload'
import { getFilePickerBuilder } from '@nextcloud/dialogs' import { getFilePickerBuilder } from '@nextcloud/dialogs'
@@ -205,11 +205,14 @@ export default {
cardId: { cardId: {
immediate: true, immediate: true,
handler() { handler() {
this.$store.dispatch('fetchAttachments', this.cardId) this.fetchAttachments(this.cardId)
}, },
}, },
}, },
methods: { methods: {
...mapActions([
"fetchAttachments",
]),
handleUploadFile(event) { handleUploadFile(event) {
const files = event.target.files ?? [] const files = event.target.files ?? []
for (const file of files) { for (const file of files) {
@@ -233,8 +236,7 @@ export default {
shareType: 12, shareType: 12,
shareWith: '' + this.cardId, shareWith: '' + this.cardId,
}).then(() => { }).then(() => {
this.$store.dispatch('fetchAttachments', this.cardId) this.fetchAttachments(this.cardId)
this.$store.commit('cardIncreaseAttachmentCount', this.cardId)
}) })
}) })
}, },