From 17608769e0c56ab5652de81e686c265912877a49 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Fri, 27 Sep 2019 20:47:05 +0200 Subject: [PATCH] fix viewer rights Signed-off-by: Maxence Lange --- lib/Controller/SocialPubController.php | 21 +++++++-- lib/Db/StreamDestRequest.php | 44 +++++++++---------- .../Version0002Date20190916000001.php | 2 +- 3 files changed, 39 insertions(+), 28 deletions(-) diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php index 720fa2e2..481bf394 100644 --- a/lib/Controller/SocialPubController.php +++ b/lib/Controller/SocialPubController.php @@ -37,6 +37,7 @@ use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\StreamNotFoundException; use OCA\Social\Exceptions\UrlCloudException; +use OCA\Social\Service\AccountService; use OCA\Social\Service\CacheActorService; use OCA\Social\Service\ConfigService; use OCA\Social\Service\StreamService; @@ -69,6 +70,9 @@ class SocialPubController extends Controller { /** @var NavigationController */ private $navigationController; + /** @var AccountService */ + private $accountService; + /** @var CacheActorService */ private $cacheActorService; @@ -87,18 +91,21 @@ class SocialPubController extends Controller { * @param IL10N $l10n * @param NavigationController $navigationController * @param CacheActorService $cacheActorService + * @param AccountService $accountService * @param StreamService $streamService * @param ConfigService $configService */ public function __construct( $userId, IRequest $request, IL10N $l10n, NavigationController $navigationController, - CacheActorService $cacheActorService, StreamService $streamService, ConfigService $configService + CacheActorService $cacheActorService, AccountService $accountService, StreamService $streamService, + ConfigService $configService ) { parent::__construct(Application::APP_NAME, $request); $this->userId = $userId; $this->l10n = $l10n; $this->navigationController = $navigationController; + $this->accountService = $accountService; $this->cacheActorService = $cacheActorService; $this->streamService = $streamService; $this->configService = $configService; @@ -210,8 +217,16 @@ class SocialPubController extends Controller { */ public function displayPost(string $username, string $token): TemplateResponse { $postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token; - // TODO: remove this, as viewer rights are already implemented in LocalController - $stream = $this->streamService->getStreamById($postId, false); + + if (isset($this->userId)) { + try { + $viewer = $this->accountService->getActorFromUserId($this->userId, true); + $this->streamService->setViewer($viewer); + } catch (Exception $e) { + } + } + + $stream = $this->streamService->getStreamById($postId, true); $data = [ 'id' => $postId, 'item' => $stream, diff --git a/lib/Db/StreamDestRequest.php b/lib/Db/StreamDestRequest.php index 9b68c171..5f0c8822 100644 --- a/lib/Db/StreamDestRequest.php +++ b/lib/Db/StreamDestRequest.php @@ -65,33 +65,29 @@ class StreamDestRequest extends StreamDestRequestBuilder { * @param Stream $stream */ public function generateStreamDest(Stream $stream) { - $recipients = [ - 'to' => $stream->getToAll(), - 'cc' => $stream->getCcArray(), - 'bcc' => $stream->getBccArray(), - 'attributed_to' => [$stream->getAttributedTo()] - ]; + $recipients = array_merge( + $stream->getToAll(), $stream->getCcArray(), $stream->getBccArray(), + [$stream->getAttributedTo()] + ); $streamId = $this->prim($stream->getId()); - foreach (array_keys($recipients) as $dest) { - $type = $dest; - foreach ($recipients[$dest] as $actorId) { - if ($actorId === '') { - continue; - } - - $qb = $this->getStreamDestInsertSql(); - - $qb->setValue('stream_id', $qb->createNamedParameter($streamId)); - $qb->setValue('actor_id', $qb->createNamedParameter($this->prim($actorId))); - $qb->setValue('type', $qb->createNamedParameter($type)); - try { - $qb->execute(); - } catch (UniqueConstraintViolationException $e) { - \OC::$server->getLogger() - ->log(3, 'Social - Duplicate recipient on Stream ' . json_encode($stream)); - } + foreach ($recipients as $actorId) { + if ($actorId === '') { + continue; } + + $qb = $this->getStreamDestInsertSql(); + + $qb->setValue('stream_id', $qb->createNamedParameter($streamId)); + $qb->setValue('actor_id', $qb->createNamedParameter($this->prim($actorId))); + $qb->setValue('type', $qb->createNamedParameter('recipient')); + try { + $qb->execute(); + } catch (UniqueConstraintViolationException $e) { + \OC::$server->getLogger() + ->log(3, 'Social - Duplicate recipient on Stream ' . json_encode($stream)); + } + } } diff --git a/lib/Migration/Version0002Date20190916000001.php b/lib/Migration/Version0002Date20190916000001.php index 73a710dc..8935abe5 100644 --- a/lib/Migration/Version0002Date20190916000001.php +++ b/lib/Migration/Version0002Date20190916000001.php @@ -374,7 +374,7 @@ class Version0002Date20190916000001 extends SimpleMigrationStep { $insert->setValue('stream_id', $insert->createNamedParameter($streamId)); $insert->setValue('actor_id', $insert->createNamedParameter(hash('sha512', $actorId))); - $insert->setValue('type', $insert->createNamedParameter($type)); + $insert->setValue('type', $insert->createNamedParameter('recipient')); try { $insert->execute();