diff options
author | Maxence Lange <maxence@artificial-owl.com> | 2019-09-13 20:56:40 -0100 |
---|---|---|
committer | Maxence Lange <maxence@artificial-owl.com> | 2019-09-25 14:07:24 +0200 |
commit | ea34bc6e70de68fbf3af3a5b620af4619f6a26a1 (patch) | |
tree | f45e5d40be8df4eee7b83cc267b863c4aa5ae86f /lib | |
parent | de841d182691fc52771217f46d60609db91a0061 (diff) |
cleaning
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/ActivityPubController.php | 12 | ||||
-rw-r--r-- | lib/Controller/LocalController.php | 9 | ||||
-rw-r--r-- | lib/Controller/NavigationController.php | 2 | ||||
-rw-r--r-- | lib/Controller/SocialPubController.php | 8 | ||||
-rw-r--r-- | lib/Db/ActorsRequest.php | 14 | ||||
-rw-r--r-- | lib/Db/CacheActorsRequest.php | 16 | ||||
-rw-r--r-- | lib/Db/CoreRequestBuilder.php | 26 | ||||
-rw-r--r-- | lib/Db/SocialQueryBuilder.php (renamed from lib/IQueryRow.php) | 27 | ||||
-rw-r--r-- | lib/Db/StreamRequest.php | 3 | ||||
-rw-r--r-- | lib/Db/StreamRequestBuilder.php | 4 | ||||
-rw-r--r-- | lib/Model/ActivityPub/Stream.php | 10 | ||||
-rw-r--r-- | lib/Service/FediverseService.php | 4 | ||||
-rw-r--r-- | lib/Service/SignatureService.php | 2 | ||||
-rw-r--r-- | lib/Service/StreamService.php | 1 |
14 files changed, 75 insertions, 63 deletions
diff --git a/lib/Controller/ActivityPubController.php b/lib/Controller/ActivityPubController.php index d7aac730..5dd30fd7 100644 --- a/lib/Controller/ActivityPubController.php +++ b/lib/Controller/ActivityPubController.php @@ -38,6 +38,8 @@ use OC\AppFramework\Http; use OCA\Social\AppInfo\Application; use OCA\Social\Exceptions\ItemUnknownException; use OCA\Social\Exceptions\SignatureIsGoneException; +use OCA\Social\Exceptions\SocialAppConfigException; +use OCA\Social\Exceptions\StreamNotFoundException; use OCA\Social\Exceptions\UrlCloudException; use OCA\Social\Service\CacheActorService; use OCA\Social\Service\FediverseService; @@ -131,6 +133,7 @@ class ActivityPubController extends Controller { * * @return Response * @throws UrlCloudException + * @throws SocialAppConfigException */ public function actor(string $username): Response { if (!$this->checkSourceActivityStreams()) { @@ -162,6 +165,7 @@ class ActivityPubController extends Controller { * * @return Response * @throws UrlCloudException + * @throws SocialAppConfigException */ public function actorAlias(string $username): Response { return $this->actor($username); @@ -281,6 +285,7 @@ class ActivityPubController extends Controller { * * @return Response * @throws UrlCloudException + * @throws SocialAppConfigException */ public function followers(string $username): Response { @@ -311,6 +316,7 @@ class ActivityPubController extends Controller { * * @return Response * @throws UrlCloudException + * @throws SocialAppConfigException */ public function following(string $username): Response { if (!$this->checkSourceActivityStreams()) { @@ -328,11 +334,13 @@ class ActivityPubController extends Controller { * @PublicPage * * @param string $username - * @param $postId + * @param string $postId * * @return Response + * @throws SocialAppConfigException + * @throws StreamNotFoundException */ - public function displayPost($username, $postId) { + public function displayPost(string $username, string $postId) { if (!$this->checkSourceActivityStreams()) { return $this->socialPubController->displayPost($username, $postId); } diff --git a/lib/Controller/LocalController.php b/lib/Controller/LocalController.php index d642d59b..e61dcd08 100644 --- a/lib/Controller/LocalController.php +++ b/lib/Controller/LocalController.php @@ -27,6 +27,7 @@ declare(strict_types=1); * */ + namespace OCA\Social\Controller; @@ -130,10 +131,10 @@ class LocalController extends Controller { * @param MiscService $miscService */ public function __construct( - IRequest $request, $userId, AccountService $accountService, - CacheActorService $cacheActorService, HashtagService $hashtagService, - FollowService $followService, - PostService $postService, StreamService $streamService, SearchService $searchService, + IRequest $request, $userId, AccountService $accountService, CacheActorService $cacheActorService, + HashtagService $hashtagService, + FollowService $followService, PostService $postService, StreamService $streamService, + SearchService $searchService, BoostService $boostService, LikeService $likeService, DocumentService $documentService, MiscService $miscService ) { diff --git a/lib/Controller/NavigationController.php b/lib/Controller/NavigationController.php index 0160a72b..66ef0cc9 100644 --- a/lib/Controller/NavigationController.php +++ b/lib/Controller/NavigationController.php @@ -261,6 +261,7 @@ class NavigationController extends Controller { * * @return TemplateResponse * @throws UrlCloudException + * @throws SocialAppConfigException */ public function timeline(string $path = ''): TemplateResponse { return $this->navigate(); @@ -276,6 +277,7 @@ class NavigationController extends Controller { * * @return TemplateResponse * @throws UrlCloudException + * @throws SocialAppConfigException */ public function account(string $path = ''): TemplateResponse { return $this->navigate(); diff --git a/lib/Controller/SocialPubController.php b/lib/Controller/SocialPubController.php index ad35412f..851ec86b 100644 --- a/lib/Controller/SocialPubController.php +++ b/lib/Controller/SocialPubController.php @@ -48,6 +48,12 @@ use OCP\AppFramework\Http\TemplateResponse; use OCP\IL10N; use OCP\IRequest; + +/** + * Class SocialPubController + * + * @package OCA\Social\Controller + */ class SocialPubController extends Controller { @@ -193,7 +199,7 @@ class SocialPubController extends Controller { * Display the navigation page of the Social app. * * @NoCSRFRequired - * @NoAdminRequired + * @PublicPage * * @param string $username * @param string $token diff --git a/lib/Db/ActorsRequest.php b/lib/Db/ActorsRequest.php index 7417be12..631fe0e4 100644 --- a/lib/Db/ActorsRequest.php +++ b/lib/Db/ActorsRequest.php @@ -44,20 +44,6 @@ class ActorsRequest extends ActorsRequestBuilder { /** - * ActorsRequest constructor. - * - * @param IDBConnection $connection - * @param ConfigService $configService - * @param MiscService $miscService - */ - public function __construct( - IDBConnection $connection, ConfigService $configService, MiscService $miscService - ) { - parent::__construct($connection, $configService, $miscService); - } - - - /** * create a new Person in the database. * * @param Person $actor diff --git a/lib/Db/CacheActorsRequest.php b/lib/Db/CacheActorsRequest.php index f74dcb40..eec7a545 100644 --- a/lib/Db/CacheActorsRequest.php +++ b/lib/Db/CacheActorsRequest.php @@ -35,29 +35,13 @@ use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Exception; use OCA\Social\Exceptions\CacheActorDoesNotExistException; use OCA\Social\Model\ActivityPub\Actor\Person; -use OCA\Social\Service\ConfigService; -use OCA\Social\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IDBConnection; class CacheActorsRequest extends CacheActorsRequestBuilder { const CACHE_TTL = 60 * 24; // 1d - /** - * CacheActorsRequest constructor. - * - * @param IDBConnection $connection - * @param ConfigService $configService - * @param MiscService $miscService - */ - public function __construct( - IDBConnection $connection, ConfigService $configService, MiscService $miscService - ) { - parent::__construct($connection, $configService, $miscService); - } - /** * insert cache about an Actor in database. diff --git a/lib/Db/CoreRequestBuilder.php b/lib/Db/CoreRequestBuilder.php index 4e9f1888..697df5fd 100644 --- a/lib/Db/CoreRequestBuilder.php +++ b/lib/Db/CoreRequestBuilder.php @@ -31,16 +31,17 @@ declare(strict_types=1); namespace OCA\Social\Db; +use daita\MySmallPhpTools\IQueryRow; use DateInterval; use DateTime; use Doctrine\DBAL\Query\QueryBuilder; use Exception; use OC\DB\SchemaWrapper; +use OC\SystemConfig; use OCA\Social\AP; use OCA\Social\Exceptions\DateTimeException; use OCA\Social\Exceptions\InvalidResourceException; use OCA\Social\Exceptions\RowNotFoundException; -use OCA\Social\IQueryRow; use OCA\Social\Model\ActivityPub\Actor\Person; use OCA\Social\Model\ActivityPub\Object\Document; use OCA\Social\Model\ActivityPub\Object\Follow; @@ -50,6 +51,7 @@ use OCA\Social\Service\ConfigService; use OCA\Social\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IDBConnection; +use OCP\ILogger; /** @@ -123,6 +125,20 @@ class CoreRequestBuilder { } +// /** +// * @return SocialQueryBuilder +// */ +// public function getQueryBuilder(): SocialQueryBuilder { +// $qb = new SocialQueryBuilder( +// $this->dbConnection, +// $this->config, +// $this->logger +// ); +// +// return $qb; +// } + + /** * @param Person $viewer */ @@ -515,7 +531,7 @@ class CoreRequestBuilder { $dTime->setTimestamp($since); $this->limitToDBFieldDateTime($qb, 'published_time', $dTime); } - } catch (\Exception $e) { + } catch (Exception $e) { throw new DateTimeException(); } @@ -1190,7 +1206,7 @@ class CoreRequestBuilder { * @return IQueryRow * @throws RowNotFoundException */ - public function getRowFromRequest(IQueryBuilder $qb, callable $method): IQueryRow { + public function getRow(IQueryBuilder $qb, callable $method): IQueryRow { $cursor = $qb->execute(); $data = $cursor->fetch(); $cursor->closeCursor(); @@ -1206,9 +1222,9 @@ class CoreRequestBuilder { * @param IQueryBuilder $qb * @param callable $method * - * @return array + * @return IQueryRow[] */ - public function getRowsFromRequest(IQueryBuilder $qb, callable $method): array { + public function getRows(IQueryBuilder $qb, callable $method): array { $rows = []; $cursor = $qb->execute(); while ($data = $cursor->fetch()) { diff --git a/lib/IQueryRow.php b/lib/Db/SocialQueryBuilder.php index 1157cc02..9a9f82b5 100644 --- a/lib/IQueryRow.php +++ b/lib/Db/SocialQueryBuilder.php @@ -28,30 +28,31 @@ declare(strict_types=1); */ -namespace OCA\Social; +namespace OCA\Social\Db; -use OCA\Social\Exceptions\ItemAlreadyExistsException; -use OCA\Social\Exceptions\ItemNotFoundException; -use OCA\Social\Model\ActivityPub\ACore; +use daita\MySmallPhpTools\Db\ExtendedQueryBuilder; /** - * Interface IQueryRow + * Class SocialQueryBuilder * - * TODO: MOVE THIS TO MyPhpTools - * - * @package OCA\Social\Service + * @package OCA\Push\Db */ -interface IQueryRow { - +class SocialQueryBuilder extends ExtendedQueryBuilder { /** - * import data to feed the model. + * Limit the request to the Type * - * @param array $data + * @param string $type + * + * @return SocialQueryBuilder */ - public function import(array $data); + public function limitToType(string $type): self { + $this->limitToDBField('type', $type, false); + + return $this; + } } diff --git a/lib/Db/StreamRequest.php b/lib/Db/StreamRequest.php index 1d120ebe..e9680055 100644 --- a/lib/Db/StreamRequest.php +++ b/lib/Db/StreamRequest.php @@ -47,10 +47,7 @@ use OCA\Social\Model\ActivityPub\Object\Document; use OCA\Social\Model\ActivityPub\Object\Like; use OCA\Social\Model\ActivityPub\Object\Note; use OCA\Social\Model\ActivityPub\Stream; -use OCA\Social\Service\ConfigService; -use OCA\Social\Service\MiscService; use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IDBConnection; /** diff --git a/lib/Db/StreamRequestBuilder.php b/lib/Db/StreamRequestBuilder.php index 7096fc7d..7e5d6803 100644 --- a/lib/Db/StreamRequestBuilder.php +++ b/lib/Db/StreamRequestBuilder.php @@ -458,7 +458,7 @@ class StreamRequestBuilder extends CoreRequestBuilder { protected function getStreamFromRequest(IQueryBuilder $qb): Stream { /** @var Stream $result */ try { - $result = $this->getRowFromRequest($qb, [$this, 'parseStreamSelectSql']); + $result = $this->getRow($qb, [$this, 'parseStreamSelectSql']); } catch (RowNotFoundException $e) { throw new StreamNotFoundException($e->getMessage()); } @@ -474,7 +474,7 @@ class StreamRequestBuilder extends CoreRequestBuilder { */ public function getStreamsFromRequest(IQueryBuilder $qb): array { /** @var Stream[] $result */ - $result = $this->getRowsFromRequest($qb, [$this, 'parseStreamSelectSql']); + $result = $this->getRows($qb, [$this, 'parseStreamSelectSql']); return $result; } diff --git a/lib/Model/ActivityPub/Stream.php b/lib/Model/ActivityPub/Stream.php index 816437e5..cd3c7c12 100644 --- a/lib/Model/ActivityPub/Stream.php +++ b/lib/Model/ActivityPub/Stream.php @@ -30,16 +30,21 @@ declare(strict_types=1); namespace OCA\Social\Model\ActivityPub; +use daita\MySmallPhpTools\IQueryRow; use daita\MySmallPhpTools\Model\Cache; use daita\MySmallPhpTools\Model\CacheItem; use DateTime; use Exception; use JsonSerializable; -use OCA\Social\IQueryRow; use OCA\Social\Model\StreamAction; use OCA\Social\Traits\TDetails; +/** + * Class Stream + * + * @package OCA\Social\Model\ActivityPub + */ class Stream extends ACore implements IQueryRow, JsonSerializable { @@ -397,8 +402,7 @@ class Stream extends ACore implements IQueryRow, JsonSerializable { [ 'content' => $this->getContent(), 'attributedTo' => ($this->getAttributedTo() !== '') ? $this->getUrlSocial() - . $this->getAttributedTo( - ) : '', + . $this->getAttributedTo() : '', 'inReplyTo' => $this->getInReplyTo(), 'sensitive' => $this->isSensitive(), 'conversation' => $this->getConversation() diff --git a/lib/Service/FediverseService.php b/lib/Service/FediverseService.php index 4b91bf0b..d903977e 100644 --- a/lib/Service/FediverseService.php +++ b/lib/Service/FediverseService.php @@ -72,6 +72,10 @@ class FediverseService { * @throws SocialAppConfigException */ public function authorized(string $address): bool { + if ($address === '') { + throw new UnauthorizedFediverseException('Empty Origin'); + } + if ($this->getAccessType() === $this->configService->accessTypeList['BLACKLIST'] && !$this->isListed($address)) { diff --git a/lib/Service/SignatureService.php b/lib/Service/SignatureService.php index dd035e09..0b13e200 100644 --- a/lib/Service/SignatureService.php +++ b/lib/Service/SignatureService.php @@ -262,6 +262,8 @@ class SignatureService { throw new SignatureIsGoneException(); } catch (SignatureException $e) { } + + return ''; } diff --git a/lib/Service/StreamService.php b/lib/Service/StreamService.php index fd1e5f17..016244ac 100644 --- a/lib/Service/StreamService.php +++ b/lib/Service/StreamService.php @@ -383,6 +383,7 @@ class StreamService { * * @return Stream * @throws StreamNotFoundException + * @throws SocialAppConfigException */ public function getStreamById(string $id, bool $asViewer = false): Stream { return $this->streamRequest->getStreamById($id, $asViewer); |