Merge remote-tracking branch 'origin/master'

Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
pull/955/head
Maxence Lange 2020-07-30 19:12:28 -01:00
commit 39280310b2
5 zmienionych plików z 72 dodań i 27 usunięć

Wyświetl plik

@ -36,12 +36,14 @@ use daita\MySmallPhpTools\Traits\TStringTools;
use Exception; use Exception;
use OC\AppFramework\Http; use OC\AppFramework\Http;
use OCA\Social\AppInfo\Application; use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountDoesNotExistException;
use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RealTokenException; use OCA\Social\Exceptions\RealTokenException;
use OCA\Social\Exceptions\SignatureIsGoneException; use OCA\Social\Exceptions\SignatureIsGoneException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException; use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Service\AccountService;
use OCA\Social\Service\CacheActorService; use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\ConfigService; use OCA\Social\Service\ConfigService;
use OCA\Social\Service\FediverseService; use OCA\Social\Service\FediverseService;
@ -82,6 +84,9 @@ class ActivityPubController extends Controller {
/** @var ImportService */ /** @var ImportService */
private $importService; private $importService;
/** @var AccountService */
private $accountService;
/** @var FollowService */ /** @var FollowService */
private $followService; private $followService;
@ -105,17 +110,18 @@ class ActivityPubController extends Controller {
* @param SignatureService $signatureService * @param SignatureService $signatureService
* @param StreamQueueService $streamQueueService * @param StreamQueueService $streamQueueService
* @param ImportService $importService * @param ImportService $importService
* @param AccountService $accountService
* @param FollowService $followService * @param FollowService $followService
* @param StreamService $streamService * @param StreamService $streamService
* @param ConfigService $configService * @param ConfigService $configService
* @param MiscService $miscService * @param MiscService $miscService
*/ */
public function __construct( public function __construct(
IRequest $request, SocialPubController $socialPubController, IRequest $request, SocialPubController $socialPubController, FediverseService $fediverseService,
FediverseService $fediverseService, CacheActorService $cacheActorService, CacheActorService $cacheActorService, SignatureService $signatureService,
SignatureService $signatureService, StreamQueueService $streamQueueService, StreamQueueService $streamQueueService, ImportService $importService, AccountService $accountService,
ImportService $importService, FollowService $followService, StreamService $streamService, FollowService $followService, StreamService $streamService, ConfigService $configService,
ConfigService $configService, MiscService $miscService MiscService $miscService
) { ) {
parent::__construct(Application::APP_NAME, $request); parent::__construct(Application::APP_NAME, $request);
@ -125,6 +131,7 @@ class ActivityPubController extends Controller {
$this->signatureService = $signatureService; $this->signatureService = $signatureService;
$this->streamQueueService = $streamQueueService; $this->streamQueueService = $streamQueueService;
$this->importService = $importService; $this->importService = $importService;
$this->accountService = $accountService;
$this->followService = $followService; $this->followService = $followService;
$this->streamService = $streamService; $this->streamService = $streamService;
$this->configService = $configService; $this->configService = $configService;
@ -351,8 +358,8 @@ class ActivityPubController extends Controller {
* *
* @return Response * @return Response
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws StreamNotFoundException
* @throws UrlCloudException * @throws UrlCloudException
* @throws StreamNotFoundException
*/ */
public function displayPost(string $username, string $token): Response { public function displayPost(string $username, string $token): Response {
try { try {
@ -364,9 +371,18 @@ class ActivityPubController extends Controller {
return $this->socialPubController->displayPost($username, $token); return $this->socialPubController->displayPost($username, $token);
} }
// TODO - check viewer rights ! try {
$viewer = $this->accountService->getCurrentViewer();
$this->streamService->setViewer($viewer);
} catch (AccountDoesNotExistException $e) {
}
$postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token; $postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token;
$stream = $this->streamService->getStreamById($postId, false); try {
$stream = $this->streamService->getStreamById($postId, true);
} catch (StreamNotFoundException $e) {
return $this->fail($e, ['stream' => $postId], Http::STATUS_NOT_FOUND);
}
$stream->setCompleteDetails(false); $stream->setCompleteDetails(false);

Wyświetl plik

@ -33,10 +33,12 @@ namespace OCA\Social\Controller;
use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse; use daita\MySmallPhpTools\Traits\Nextcloud\TNCDataResponse;
use Exception; use Exception;
use OCA\Social\AppInfo\Application; use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountDoesNotExistException;
use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Exceptions\CacheActorDoesNotExistException;
use OCA\Social\Exceptions\SocialAppConfigException; use OCA\Social\Exceptions\SocialAppConfigException;
use OCA\Social\Exceptions\StreamNotFoundException; use OCA\Social\Exceptions\StreamNotFoundException;
use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCA\Social\Service\AccountService; use OCA\Social\Service\AccountService;
use OCA\Social\Service\CacheActorService; use OCA\Social\Service\CacheActorService;
use OCA\Social\Service\ConfigService; use OCA\Social\Service\ConfigService;
@ -212,20 +214,18 @@ class SocialPubController extends Controller {
* @param string $token * @param string $token
* *
* @return TemplateResponse * @return TemplateResponse
* @throws StreamNotFoundException
* @throws SocialAppConfigException * @throws SocialAppConfigException
* @throws StreamNotFoundException
*/ */
public function displayPost(string $username, string $token): TemplateResponse { public function displayPost(string $username, string $token): TemplateResponse {
$postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token;
if (isset($this->userId)) {
try { try {
$viewer = $this->accountService->getActorFromUserId($this->userId, true); $viewer = $this->accountService->getCurrentViewer();
$this->streamService->setViewer($viewer); $this->streamService->setViewer($viewer);
} catch (Exception $e) { } catch (AccountDoesNotExistException $e) {
}
} }
$postId = $this->configService->getSocialUrl() . '@' . $username . '/' . $token;
$stream = $this->streamService->getStreamById($postId, true); $stream = $this->streamService->getStreamById($postId, true);
$data = [ $data = [
'id' => $postId, 'id' => $postId,

Wyświetl plik

@ -381,9 +381,12 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
/** /**
* @param string $aliasDest * @param string $aliasDest
* @param string $aliasFollowing * @param string $aliasFollowing
* @param bool $public * @param bool $allowPublic
* @param bool $allowDirect
*/ */
public function limitToViewer(string $aliasDest = 'sd', string $aliasFollowing = 'f', bool $public = false public function limitToViewer(
string $aliasDest = 'sd', string $aliasFollowing = 'f', bool $allowPublic = false,
bool $allowDirect = false
) { ) {
if (!$this->hasViewer()) { if (!$this->hasViewer()) {
$this->selectDestFollowing($aliasDest); $this->selectDestFollowing($aliasDest);
@ -403,10 +406,14 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
); );
$orX->add($following); $orX->add($following);
if ($public) { if ($allowPublic) {
$orX->add($this->exprLimitToDest(ACore::CONTEXT_PUBLIC, 'recipient', '', $aliasDest)); $orX->add($this->exprLimitToDest(ACore::CONTEXT_PUBLIC, 'recipient', '', $aliasDest));
} }
if ($allowDirect) {
$orX->add($this->exprLimitToDest($actor->getId(), 'dm', '', $aliasDest));
}
$this->andWhere($orX); $this->andWhere($orX);
} }

Wyświetl plik

@ -241,13 +241,11 @@ class StreamRequest extends StreamRequestBuilder {
}; };
$qb = $this->getStreamSelectSql(); $qb = $this->getStreamSelectSql();
$expr = $qb->expr();
$qb->limitToIdPrim($qb->prim($id)); $qb->limitToIdPrim($qb->prim($id));
$qb->linkToCacheActors('ca', 's.attributed_to_prim'); $qb->linkToCacheActors('ca', 's.attributed_to_prim');
if ($asViewer) { if ($asViewer) {
$qb->limitToViewer('sd', 'f', true); $qb->limitToViewer('sd', 'f', true, true);
$qb->leftJoinStreamAction('sa'); $qb->leftJoinStreamAction('sa');
} }
@ -256,9 +254,7 @@ class StreamRequest extends StreamRequestBuilder {
} catch (ItemUnknownException $e) { } catch (ItemUnknownException $e) {
throw new StreamNotFoundException('Malformed Stream'); throw new StreamNotFoundException('Malformed Stream');
} catch (StreamNotFoundException $e) { } catch (StreamNotFoundException $e) {
throw new StreamNotFoundException( throw new StreamNotFoundException('Stream not found');
'Stream (ById) not found - ' . $id . ' (asViewer: ' . $asViewer . ')'
);
} }
} }

Wyświetl plik

@ -37,6 +37,7 @@ use OCA\Social\Db\ActorsRequest;
use OCA\Social\Db\FollowsRequest; use OCA\Social\Db\FollowsRequest;
use OCA\Social\Db\StreamRequest; use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\AccountAlreadyExistsException; use OCA\Social\Exceptions\AccountAlreadyExistsException;
use OCA\Social\Exceptions\AccountDoesNotExistException;
use OCA\Social\Exceptions\ActorDoesNotExistException; use OCA\Social\Exceptions\ActorDoesNotExistException;
use OCA\Social\Exceptions\ItemAlreadyExistsException; use OCA\Social\Exceptions\ItemAlreadyExistsException;
use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\ItemUnknownException;
@ -45,6 +46,7 @@ use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Actor\Person;
use OCP\Accounts\IAccountManager; use OCP\Accounts\IAccountManager;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\IUserSession;
/** /**
@ -64,6 +66,9 @@ class AccountService {
/** @var IUserManager */ /** @var IUserManager */
private $userManager; private $userManager;
/** @var IUserSession */
private $userSession;
/** @var IAccountManager */ /** @var IAccountManager */
private $accountManager; private $accountManager;
@ -96,6 +101,7 @@ class AccountService {
* ActorService constructor. * ActorService constructor.
* *
* @param IUserManager $userManager * @param IUserManager $userManager
* @param IUserSession $userSession
* @param IAccountManager $accountManager * @param IAccountManager $accountManager
* @param ActorsRequest $actorsRequest * @param ActorsRequest $actorsRequest
* @param FollowsRequest $followsRequest * @param FollowsRequest $followsRequest
@ -107,12 +113,14 @@ class AccountService {
* @param MiscService $miscService * @param MiscService $miscService
*/ */
public function __construct( public function __construct(
IUserManager $userManager, IAccountManager $accountManager, ActorsRequest $actorsRequest, IUserManager $userManager, IUserSession $userSession, IAccountManager $accountManager,
ActorsRequest $actorsRequest,
FollowsRequest $followsRequest, StreamRequest $streamRequest, ActorService $actorService, FollowsRequest $followsRequest, StreamRequest $streamRequest, ActorService $actorService,
DocumentService $documentService, SignatureService $signatureService, DocumentService $documentService, SignatureService $signatureService,
ConfigService $configService, MiscService $miscService ConfigService $configService, MiscService $miscService
) { ) {
$this->userManager = $userManager; $this->userManager = $userManager;
$this->userSession = $userSession;
$this->accountManager = $accountManager; $this->accountManager = $accountManager;
$this->actorsRequest = $actorsRequest; $this->actorsRequest = $actorsRequest;
$this->followsRequest = $followsRequest; $this->followsRequest = $followsRequest;
@ -152,6 +160,24 @@ class AccountService {
} }
/**
* @return Person
* @throws AccountDoesNotExistException
*/
public function getCurrentViewer(): Person {
$user = $this->userSession->getUser();
if ($user === null) {
throw new AccountDoesNotExistException();
}
try {
return $this->getActorFromUserId($user->getUID());
} catch (Exception $e) {
throw new AccountDoesNotExistException();
}
}
/** /**
* @param string $userId * @param string $userId
* @param bool $create * @param bool $create