Skip to content

Commit 83ffa55

Browse files
ArtificialOwlbackportbot[bot]
authored andcommitted
merging getLocalInstance+getLocalCloudId
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 574ca3f commit 83ffa55

9 files changed

+45
-56
lines changed

lib/Db/MembersRequest.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class MembersRequest extends MembersRequestBuilder {
6161
public function forceGetMember($circleUniqueId, $userId, $type, string $instance = '') {
6262
$qb = $this->getMembersSelectSql();
6363

64-
if ($instance === $this->configService->getLocalCloudId()) {
64+
if ($instance === $this->configService->getLocalInstance()) {
6565
$instance = '';
6666
}
6767

@@ -479,7 +479,7 @@ public function createMember(Member $member) {
479479
}
480480

481481
$instance = $member->getInstance();
482-
if ($instance === $this->configService->getLocalCloudId()) {
482+
if ($instance === $this->configService->getLocalInstance()) {
483483
$instance = '';
484484
}
485485

@@ -545,7 +545,7 @@ public function getGroupsFromCircle($circleUniqueId, Member $viewer) {
545545
*/
546546
public function updateMemberLevel(Member $member) {
547547
$instance = $member->getInstance();
548-
if ($instance === $this->configService->getLocalCloudId()) {
548+
if ($instance === $this->configService->getLocalInstance()) {
549549
$instance = '';
550550
}
551551

@@ -566,7 +566,7 @@ public function updateMemberLevel(Member $member) {
566566
*/
567567
public function updateMemberInfo(Member $member) {
568568
$instance = $member->getInstance();
569-
if ($instance === $this->configService->getLocalCloudId()) {
569+
if ($instance === $this->configService->getLocalInstance()) {
570570
$instance = '';
571571
}
572572

@@ -625,7 +625,7 @@ public function removeAllMembershipsFromUser(Member $member) {
625625
}
626626

627627
$instance = $member->getInstance();
628-
if ($instance === $this->configService->getLocalCloudId()) {
628+
if ($instance === $this->configService->getLocalInstance()) {
629629
$instance = '';
630630
}
631631

@@ -651,7 +651,7 @@ public function removeAllMembershipsFromUser(Member $member) {
651651
*/
652652
public function removeMember(Member $member) {
653653
$instance = $member->getInstance();
654-
if ($instance === $this->configService->getLocalCloudId()) {
654+
if ($instance === $this->configService->getLocalInstance()) {
655655
$instance = '';
656656
}
657657

lib/GlobalScale/AGlobalScaleEvent.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -243,11 +243,11 @@ private function checkViewer(GSEvent $event, bool $mustBeChecked) {
243243
*/
244244
protected function compareMembers(Member $member1, Member $member2) {
245245
if ($member1->getInstance() === '') {
246-
$member1->setInstance($this->configService->getLocalCloudId());
246+
$member1->setInstance($this->configService->getLocalInstance());
247247
}
248248

249249
if ($member2->getInstance() === '') {
250-
$member2->setInstance($this->configService->getLocalCloudId());
250+
$member2->setInstance($this->configService->getLocalInstance());
251251
}
252252

253253
if ($member1->getCircleId() !== $member2->getCircleId()
@@ -283,7 +283,7 @@ protected function compareCircles(Circle $circle1, Circle $circle2): bool {
283283

284284

285285
protected function cleanMember(Member $member) {
286-
if ($member->getInstance() === $this->configService->getLocalCloudId()) {
286+
if ($member->getInstance() === $this->configService->getLocalInstance()) {
287287
$member->setInstance('');
288288
}
289289
}

lib/GlobalScale/FileShare.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class FileShare extends AGlobalScaleEvent {
7373
*/
7474
public function verify(GSEvent $event, bool $localCheck = false, bool $mustBeChecked = false): void {
7575
// if event/file is local, we generate a federate share for the same circle on other instances
76-
if ($event->getSource() !== $this->configService->getLocalCloudId()) {
76+
if ($event->getSource() !== $this->configService->getLocalInstance()) {
7777
return;
7878
}
7979

@@ -108,7 +108,7 @@ public function manage(GSEvent $event): void {
108108
$circle = $event->getCircle();
109109

110110
// if event is not local, we create a federated file to the right instance of Nextcloud, using the right token
111-
if ($event->getSource() !== $this->configService->getLocalCloudId()) {
111+
if ($event->getSource() !== $this->configService->getLocalInstance()) {
112112
try {
113113
$share = $this->getShareFromData($event->getData());
114114
} catch (Exception $e) {

lib/GlobalScale/MemberAdd.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function manage(GSEvent $event): void {
161161
];
162162

163163
if ($member->getType() === Member::TYPE_CONTACT
164-
&& $member->getInstance() === $this->configService->getLocalCloudId()) {
164+
&& $member->getInstance() === $this->configService->getLocalInstance()) {
165165
$result['contact'] = $this->miscService->getInfosFromContact($member);
166166
}
167167

lib/Search/GlobalScaleUsers.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public function search($search) {
104104
$result = [];
105105
foreach ($users as $user) {
106106
list(, $instance) = explode('@', $this->get('federationId', $user), 2);
107-
if ($instance === $this->configService->getLocalCloudId()) {
107+
if ($instance === $this->configService->getLocalInstance()) {
108108
continue;
109109
}
110110

lib/Service/ConfigService.php

+22-17
Original file line numberDiff line numberDiff line change
@@ -530,33 +530,34 @@ public function getGSStatus(string $type = '') {
530530
* @return array
531531
*/
532532
public function getTrustedDomains(): array {
533-
$domains = [];
534-
foreach ($this->config->getSystemValue('trusted_domains', []) as $v) {
535-
$domains[] = $v;
536-
}
537-
538-
return $domains;
533+
return array_values($this->config->getSystemValue('trusted_domains', []));
539534
}
540535

541536

542537
/**
538+
* - returns host+port, does not specify any protocol
539+
* - can be forced using LOCAL_CLOUD_ID
540+
* - use 'overwrite.cli.url'
541+
* - can use the first entry from trusted_domains is LOCAL_CLOUD_ID = 'use-trusted-domain'
542+
* - used mainly to assign instance and source to a request
543+
*
543544
* @return string
544545
*/
545-
public function getLocalCloudId(): string {
546+
public function getLocalInstance(): string {
546547
$localCloudId = $this->getAppValue(self::LOCAL_CLOUD_ID);
547548
if ($localCloudId === '') {
549+
$cliUrl = $this->config->getSystemValue('overwrite.cli.url', '');
550+
$local = parse_url($cliUrl);
551+
if (array_key_exists('port', $local)) {
552+
return $local['host'] . ':' . $local['port'];
553+
} else {
554+
return $local['host'];
555+
}
556+
} else if ($localCloudId === 'use-trusted-domain') {
548557
return $this->getTrustedDomains()[0];
558+
} else {
559+
return $localCloudId;
549560
}
550-
551-
return $localCloudId;
552-
}
553-
554-
555-
/**
556-
* @return mixed
557-
*/
558-
public function getInstanceId() {
559-
return $this->config->getSystemValue('instanceid');
560561
}
561562

562563

@@ -576,6 +577,10 @@ public function configureRequest(NC19Request $request, string $routeName = '', a
576577
}
577578

578579
/**
580+
* - Create route using overwrite.cli.url.
581+
* - can be forced using FORCE_NC_BASE or TEST_BC_BASE (temporary)
582+
* - perfect for loopback request.
583+
*
579584
* @param NC19Request $request
580585
* @param string $routeName
581586
* @param array $args

lib/Service/GSUpstreamService.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public function __construct(
132132
* @throws Exception
133133
*/
134134
public function newEvent(GSEvent $event): string {
135-
$event->setSource($this->configService->getLocalCloudId());
135+
$event->setSource($this->configService->getLocalInstance());
136136

137137
try {
138138
$gs = $this->globalScaleService->getGlobalScaleEvent($event);
@@ -357,7 +357,7 @@ public function synchronize(array $sync) {
357357
*/
358358
public function synchronizeCircles(array $circles): void {
359359
$event = new GSEvent(GSEvent::GLOBAL_SYNC, true);
360-
$event->setSource($this->configService->getLocalCloudId());
360+
$event->setSource($this->configService->getLocalInstance());
361361
$event->setData(new SimpleDataStore($circles));
362362

363363
foreach ($this->globalScaleService->getInstances() as $instance) {
@@ -411,7 +411,7 @@ private function checkCircle(Circle $circle): void {
411411
*/
412412
public function confirmCircleStatus(Circle $circle): bool {
413413
$event = new GSEvent(GSEvent::CIRCLE_STATUS, true);
414-
$event->setSource($this->configService->getLocalCloudId());
414+
$event->setSource($this->configService->getLocalInstance());
415415
$event->setCircle($circle);
416416

417417
$this->signEvent($event);

lib/Service/GlobalScaleService.php

+5-21
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,11 @@ public function getInstances(bool $all = false): array {
237237
return [];
238238
}
239239
} catch (GSStatusException $e) {
240-
return $this->getLocalInstance($all);
240+
if (!$all) {
241+
return [];
242+
}
243+
244+
return [$this->configService->getLocalInstance()];
241245
}
242246

243247
if ($all) {
@@ -248,26 +252,6 @@ public function getInstances(bool $all = false): array {
248252
}
249253

250254

251-
/**
252-
* @param bool $all
253-
*
254-
* @return array
255-
*/
256-
private function getLocalInstance(bool $all): array {
257-
if (!$all) {
258-
return [];
259-
}
260-
261-
$absolute = $this->urlGenerator->linkToRouteAbsolute('circles.Navigation.navigate');
262-
$local = parse_url($absolute);
263-
264-
if (array_key_exists('port', $local)) {
265-
return [$local['host'] . ':' . $local['port']];
266-
} else {
267-
return [$local['host']];
268-
}
269-
}
270-
271255

272256
/**
273257
* @param GSEvent $event

lib/Service/MembersService.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private function addSingleMember(Circle $circle, $ident, $type, $instance = '',
225225
$new->setStatus(Member::STATUS_MEMBER);
226226
}
227227

228-
if ($new->getInstance() === $this->configService->getLocalCloudId()) {
228+
if ($new->getInstance() === $this->configService->getLocalInstance()) {
229229
$new->setInstance('');
230230
}
231231

@@ -336,7 +336,7 @@ private function addContact(Member $member) {
336336
* @throws NoUserException
337337
*/
338338
public function verifyIdentBasedOnItsType(&$ident, $type, string $instance = '') {
339-
if ($instance === $this->configService->getLocalCloudId()) {
339+
if ($instance === $this->configService->getLocalInstance()) {
340340
$instance = '';
341341
}
342342

0 commit comments

Comments
 (0)