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 OC\AppFramework\Http;
use OCA\Social\AppInfo\Application;
use OCA\Social\Exceptions\AccountDoesNotExistException;
use OCA\Social\Exceptions\ItemUnknownException;
use OCA\Social\Exceptions\RealTokenException;
use OCA\Social\Exceptions\SignatureIsGoneException;
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\FediverseService;
@ -82,6 +84,9 @@ class ActivityPubController extends Controller {
/** @var ImportService */
private $importService;
/** @var AccountService */
private $accountService;
/** @var FollowService */
private $followService;
@ -105,17 +110,18 @@ class ActivityPubController extends Controller {
* @param SignatureService $signatureService
* @param StreamQueueService $streamQueueService
* @param ImportService $importService
* @param AccountService $accountService
* @param FollowService $followService
* @param StreamService $streamService
* @param ConfigService $configService
* @param MiscService $miscService
*/
public function __construct(
IRequest $request, SocialPubController $socialPubController,
FediverseService $fediverseService, CacheActorService $cacheActorService,
SignatureService $signatureService, StreamQueueService $streamQueueService,
ImportService $importService, FollowService $followService, StreamService $streamService,
ConfigService $configService, MiscService $miscService
IRequest $request, SocialPubController $socialPubController, FediverseService $fediverseService,
CacheActorService $cacheActorService, SignatureService $signatureService,
StreamQueueService $streamQueueService, ImportService $importService, AccountService $accountService,
FollowService $followService, StreamService $streamService, ConfigService $configService,
MiscService $miscService
) {
parent::__construct(Application::APP_NAME, $request);
@ -125,6 +131,7 @@ class ActivityPubController extends Controller {
$this->signatureService = $signatureService;
$this->streamQueueService = $streamQueueService;
$this->importService = $importService;
$this->accountService = $accountService;
$this->followService = $followService;
$this->streamService = $streamService;
$this->configService = $configService;
@ -351,8 +358,8 @@ class ActivityPubController extends Controller {
*
* @return Response
* @throws SocialAppConfigException
* @throws StreamNotFoundException
* @throws UrlCloudException
* @throws StreamNotFoundException
*/
public function displayPost(string $username, string $token): Response {
try {
@ -364,9 +371,18 @@ class ActivityPubController extends Controller {
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;
$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);

Wyświetl plik

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

Wyświetl plik

@ -381,9 +381,12 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
/**
* @param string $aliasDest
* @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()) {
$this->selectDestFollowing($aliasDest);
@ -403,10 +406,14 @@ class SocialLimitsQueryBuilder extends SocialCrossQueryBuilder {
);
$orX->add($following);
if ($public) {
if ($allowPublic) {
$orX->add($this->exprLimitToDest(ACore::CONTEXT_PUBLIC, 'recipient', '', $aliasDest));
}
if ($allowDirect) {
$orX->add($this->exprLimitToDest($actor->getId(), 'dm', '', $aliasDest));
}
$this->andWhere($orX);
}

Wyświetl plik

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

Wyświetl plik

@ -37,6 +37,7 @@ use OCA\Social\Db\ActorsRequest;
use OCA\Social\Db\FollowsRequest;
use OCA\Social\Db\StreamRequest;
use OCA\Social\Exceptions\AccountAlreadyExistsException;
use OCA\Social\Exceptions\AccountDoesNotExistException;
use OCA\Social\Exceptions\ActorDoesNotExistException;
use OCA\Social\Exceptions\ItemAlreadyExistsException;
use OCA\Social\Exceptions\ItemUnknownException;
@ -45,6 +46,7 @@ use OCA\Social\Exceptions\UrlCloudException;
use OCA\Social\Model\ActivityPub\Actor\Person;
use OCP\Accounts\IAccountManager;
use OCP\IUserManager;
use OCP\IUserSession;
/**
@ -64,6 +66,9 @@ class AccountService {
/** @var IUserManager */
private $userManager;
/** @var IUserSession */
private $userSession;
/** @var IAccountManager */
private $accountManager;
@ -96,6 +101,7 @@ class AccountService {
* ActorService constructor.
*
* @param IUserManager $userManager
* @param IUserSession $userSession
* @param IAccountManager $accountManager
* @param ActorsRequest $actorsRequest
* @param FollowsRequest $followsRequest
@ -107,12 +113,14 @@ class AccountService {
* @param MiscService $miscService
*/
public function __construct(
IUserManager $userManager, IAccountManager $accountManager, ActorsRequest $actorsRequest,
IUserManager $userManager, IUserSession $userSession, IAccountManager $accountManager,
ActorsRequest $actorsRequest,
FollowsRequest $followsRequest, StreamRequest $streamRequest, ActorService $actorService,
DocumentService $documentService, SignatureService $signatureService,
ConfigService $configService, MiscService $miscService
) {
$this->userManager = $userManager;
$this->userSession = $userSession;
$this->accountManager = $accountManager;
$this->actorsRequest = $actorsRequest;
$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 bool $create