Skip to content

Commit e0e1e92

Browse files
committed
Rewrite DB with Doctrine
Signed-off-by: Carl Schwan <[email protected]>
1 parent 7b26303 commit e0e1e92

19 files changed

+1183
-564
lines changed

appinfo/routes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@
6767
['name' => 'OStatus#getLink', 'url' => '/api/v1/ostatus/link/{local}/{account}', 'verb' => 'GET'],
6868

6969
// OAuth
70-
['name' => 'OAuth#nodeinfo', 'url' => '/.well-known/nodeinfo', 'verb' => 'GET'],
71-
['name' => 'OAuth#nodeinfo2', 'url' => '/.well-known/nodeinfo/2.0', 'verb' => 'GET'],
70+
['name' => 'OAuth#index', 'url' => '/.well-known/nodeinfo', 'verb' => 'GET'],
71+
['name' => 'OAuth#show', 'url' => '/.well-known/nodeinfo/2.{version}{extension}', 'verb' => 'GET'],
7272
['name' => 'OAuth#apps', 'url' => '/api/v1/apps', 'verb' => 'POST'],
7373
['name' => 'OAuth#authorize', 'url' => '/oauth/authorize', 'verb' => 'GET'],
7474
['name' => 'OAuth#token', 'url' => '/oauth/token', 'verb' => 'POST'],

lib/Controller/ApiController.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
use OCA\Social\Model\Client\SocialClient;
4444
use OCA\Social\Service\AccountService;
4545
use OCA\Social\Service\CacheActorService;
46-
use OCA\Social\Service\ClientService;
46+
use OCA\Social\Service\ApplicationService;
4747
use OCA\Social\Service\ConfigService;
4848
use OCA\Social\Service\FollowService;
4949
use OCA\Social\Service\InstanceService;
@@ -65,7 +65,7 @@ class ApiController extends Controller {
6565

6666
private IUserSession $userSession;
6767
private InstanceService $instanceService;
68-
private ClientService $clientService;
68+
private ApplicationService $clientService;
6969
private AccountService $accountService;
7070
private CacheActorService $cacheActorService;
7171
private FollowService $followService;
@@ -77,10 +77,10 @@ class ApiController extends Controller {
7777
private ?Person $viewer = null;
7878

7979
public function __construct(
80-
IRequest $request, IUserSession $userSession, InstanceService $instanceService,
81-
ClientService $clientService, AccountService $accountService, CacheActorService $cacheActorService,
82-
FollowService $followService, StreamService $streamService, ConfigService $configService,
83-
MiscService $miscService
80+
IRequest $request, IUserSession $userSession, InstanceService $instanceService,
81+
ApplicationService $clientService, AccountService $accountService, CacheActorService $cacheActorService,
82+
FollowService $followService, StreamService $streamService, ConfigService $configService,
83+
MiscService $miscService
8484
) {
8585
parent::__construct(Application::APP_NAME, $request);
8686

lib/Controller/NavigationController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
use OCP\AppFramework\Http\FileDisplayResponse;
5050
use OCP\AppFramework\Http\Response;
5151
use OCP\AppFramework\Http\TemplateResponse;
52+
use OCP\DB\ORM\IEntityManager;
5253
use OCP\IConfig;
5354
use OCP\IInitialStateService;
5455
use OCP\IL10N;
@@ -88,7 +89,8 @@ public function __construct(
8889
DocumentService $documentService,
8990
ConfigService $configService,
9091
CheckService $checkService,
91-
MiscService $miscService
92+
MiscService $miscService,
93+
IEntityManager $manager
9294
) {
9395
parent::__construct(Application::APP_NAME, $request);
9496

lib/Controller/OAuthController.php

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@
3030

3131
namespace OCA\Social\Controller;
3232

33+
use OCA\Social\Entity\Account;
34+
use OCA\Social\Entity\Instance;
35+
use OCA\Social\Repository\InstanceRepository;
3336
use OCA\Social\Tools\Traits\TNCDataResponse;
3437
use Exception;
35-
use OCA\Social\AppInfo\Application;
38+
use OCA\Social\Entity\Application;
3639
use OCA\Social\Exceptions\ClientException;
3740
use OCA\Social\Exceptions\ClientNotFoundException;
38-
use OCA\Social\Exceptions\InstanceDoesNotExistException;
39-
use OCA\Social\Model\Client\SocialClient;
4041
use OCA\Social\Service\AccountService;
4142
use OCA\Social\Service\CacheActorService;
42-
use OCA\Social\Service\ClientService;
43+
use OCA\Social\Service\ApplicationService;
4344
use OCA\Social\Service\ConfigService;
4445
use OCA\Social\Service\InstanceService;
4546
use OCA\Social\Service\MiscService;
4647
use OCP\AppFramework\Controller;
4748
use OCP\AppFramework\Http;
4849
use OCP\AppFramework\Http\DataResponse;
49-
use OCP\AppFramework\Http\Response;
50+
use OCP\DB\ORM\IEntityManager;
5051
use OCP\IRequest;
5152
use OCP\IURLGenerator;
5253
use OCP\IUserSession;
@@ -59,17 +60,24 @@ class OAuthController extends Controller {
5960
private InstanceService $instanceService;
6061
private AccountService $accountService;
6162
private CacheActorService $cacheActorService;
62-
private ClientService $clientService;
63+
private ApplicationService $clientService;
6364
private ConfigService $configService;
6465
private MiscService $miscService;
66+
private IEntityManager $entityManager;
6567

6668
public function __construct(
67-
IRequest $request, IUserSession $userSession, IURLGenerator $urlGenerator,
68-
InstanceService $instanceService, AccountService $accountService,
69-
CacheActorService $cacheActorService, ClientService $clientService, ConfigService $configService,
70-
MiscService $miscService
69+
IRequest $request,
70+
IUserSession $userSession,
71+
IURLGenerator $urlGenerator,
72+
InstanceService $instanceService,
73+
AccountService $accountService,
74+
CacheActorService $cacheActorService,
75+
ApplicationService $clientService,
76+
ConfigService $configService,
77+
MiscService $miscService,
78+
IEntityManager $entityManager
7179
) {
72-
parent::__construct(Application::APP_NAME, $request);
80+
parent::__construct('social', $request);
7381

7482
$this->userSession = $userSession;
7583
$this->urlGenerator = $urlGenerator;
@@ -79,21 +87,19 @@ public function __construct(
7987
$this->clientService = $clientService;
8088
$this->configService = $configService;
8189
$this->miscService = $miscService;
82-
83-
$body = file_get_contents('php://input');
84-
$this->miscService->log('[OAuthController] input: ' . $body, 0);
90+
$this->entityManager = $entityManager;
8591
}
8692

8793

8894
/**
8995
* @NoCSRFRequired
9096
* @PublicPage
9197
*/
92-
public function nodeinfo(): DataResponse {
98+
public function index(): DataResponse {
9399
$nodeInfo = [
94100
'links' => [
95101
'rel' => 'http://nodeinfo.diaspora.software/ns/schema/2.0',
96-
'href' => $this->urlGenerator->linkToRouteAbsolute('social.OAuth.nodeinfo2')
102+
'href' => $this->urlGenerator->linkToRouteAbsolute('social.OAuth.show')
97103
]
98104
];
99105

@@ -105,32 +111,24 @@ public function nodeinfo(): DataResponse {
105111
* @NoCSRFRequired
106112
* @PublicPage
107113
*/
108-
public function nodeinfo2(): Response {
109-
try {
110-
$local = $this->instanceService->getLocal();
111-
$name = $local->getTitle();
112-
113-
$version = $local->getVersion();
114-
$usage = $local->getUsage();
115-
$openReg = $local->isRegistrations();
116-
} catch (InstanceDoesNotExistException $e) {
117-
$name = 'Nextcloud Social';
118-
$version = $this->configService->getAppValue('installed_version');
119-
$usage = [];
120-
$openReg = false;
121-
}
114+
public function show(): DataResponse {
115+
$query = $this->entityManager->createQuery('SELECT COUNT(a) FROM \OCA\Social\Entity\Account a');
116+
$query->setCacheable(true);
117+
$countUser = $query->getSingleScalarResult();
122118

123119
$nodeInfo = [
124120
"version" => "2.0",
125121
"software" => [
126-
"name" => $name,
127-
"version" => $version
122+
"name" => 'Nextcloud Social',
123+
"version" => $this->configService->getAppValue('installed_version'),
128124
],
129125
"protocols" => [
130126
"activitypub"
131127
],
132-
"usage" => $usage,
133-
"openRegistrations" => $openReg
128+
"usage" => [
129+
"total" => (int)$countUser,
130+
],
131+
"openRegistrations" => false,
134132
];
135133

136134
return new DataResponse($nodeInfo, Http::STATUS_OK);
@@ -151,10 +149,10 @@ public function apps(
151149
$redirect_uris = [$redirect_uris];
152150
}
153151

154-
$client = new SocialClient();
152+
$client = new Application();
155153
$client->setAppWebsite($website);
156154
$client->setAppRedirectUris($redirect_uris);
157-
$client->setAppScopes($client->getScopesFromString($scopes));
155+
$client->setAppScopes(Application::getScopesFromString($scopes));
158156
$client->setAppName($client_name);
159157

160158
$this->clientService->createApp($client);
@@ -181,6 +179,11 @@ public function authorize(
181179
): DataResponse {
182180
try {
183181
$user = $this->userSession->getUser();
182+
$accountRepository = $this->entityManager->getRepository(Account::class);
183+
$accountRepository->findBy([
184+
''
185+
]);
186+
184187
$account = $this->accountService->getActorFromUserId($user->getUID());
185188

186189
if ($response_type !== 'code') {

lib/Db/ClientRequest.php

Lines changed: 0 additions & 164 deletions
This file was deleted.

0 commit comments

Comments
 (0)