summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaxence Lange <maxence@artificial-owl.com>2019-09-29 13:37:20 +0200
committerGitHub <noreply@github.com>2019-09-29 13:37:20 +0200
commit453d03f0383e4685b27429c4934c84403286b5a7 (patch)
tree097270f68a248af02db087a2853a34c5b02629d3
parentb01f5b44dad72119661f844d1497cd02cd1758a4 (diff)
parent17608769e0c56ab5652de81e686c265912877a49 (diff)
Merge pull request #761 from nextcloud/bugfix/noid/viewer-rights-on-singlepost
fix viewer rights
-rw-r--r--lib/Controller/SocialPubController.php21
-rw-r--r--lib/Db/StreamDestRequest.php44
-rw-r--r--lib/Migration/Version0002Date20190916000001.php2
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 c7f3338d..07ea1b6a 100644
--- a/lib/Migration/Version0002Date20190916000001.php
+++ b/lib/Migration/Version0002Date20190916000001.php
@@ -376,7 +376,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();