Skip to content

Commit 62b92c6

Browse files
ArtificialOwlbackportbot[bot]
authored andcommitted
isLocalInstance()
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 83ffa55 commit 62b92c6

File tree

7 files changed

+35
-13
lines changed

7 files changed

+35
-13
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->getLocalInstance()) {
64+
if ($this->configService->isLocalInstance($instance)) {
6565
$instance = '';
6666
}
6767

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

481481
$instance = $member->getInstance();
482-
if ($instance === $this->configService->getLocalInstance()) {
482+
if ($this->configService->isLocalInstance($instance)) {
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->getLocalInstance()) {
548+
if ($this->configService->isLocalInstance($instance)) {
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->getLocalInstance()) {
569+
if ($this->configService->isLocalInstance($instance)) {
570570
$instance = '';
571571
}
572572

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

627627
$instance = $member->getInstance();
628-
if ($instance === $this->configService->getLocalInstance()) {
628+
if ($this->configService->isLocalInstance($instance)) {
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->getLocalInstance()) {
654+
if ($this->configService->isLocalInstance($instance)) {
655655
$instance = '';
656656
}
657657

lib/GlobalScale/AGlobalScaleEvent.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -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->getLocalInstance()) {
286+
if ($this->configService->isLocalInstance($member->getInstance())) {
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->getLocalInstance()) {
76+
if (!$this->configService->isLocalInstance($event->getSource())) {
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->getLocalInstance()) {
111+
if (!$this->configService->isLocalInstance($event->getSource())) {
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->getLocalInstance()) {
164+
&& $this->configService->isLocalInstance($member->getInstance())) {
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->getLocalInstance()) {
107+
if ($this->configService->isLocalInstance($instance)) {
108108
continue;
109109
}
110110

lib/Service/ConfigService.php

+22
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ public function __construct(
148148
}
149149

150150

151+
/**
152+
* @return string
153+
* @deprecated
154+
*/
151155
public function getLocalAddress() {
152156
return (($this->isLocalNonSSL()) ? 'http://' : '')
153157
. $this->request->getServerHost();
@@ -561,6 +565,24 @@ public function getLocalInstance(): string {
561565
}
562566

563567

568+
/**
569+
* @param string $instance
570+
*
571+
* @return bool
572+
*/
573+
public function isLocalInstance(string $instance): bool {
574+
if ($instance === $this->getLocalInstance()) {
575+
return true;
576+
}
577+
578+
if ($this->getAppValue(self::LOCAL_CLOUD_ID) === 'use-trusted-domain') {
579+
return (in_array($instance, $this->getTrustedDomains()));
580+
}
581+
582+
return false;
583+
}
584+
585+
564586
/**
565587
* @param NC19Request $request
566588
* @param string $routeName

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->getLocalInstance()) {
228+
if ($this->configService->isLocalInstance($new->getInstance())) {
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->getLocalInstance()) {
339+
if ($this->configService->isLocalInstance($instance)) {
340340
$instance = '';
341341
}
342342

0 commit comments

Comments
 (0)