Skip to content

Commit 8e8fbf5

Browse files
committed
fix(profile): Check profile config before creating room from guest
Signed-off-by: Joas Schilling <[email protected]>
1 parent b08ccf6 commit 8e8fbf5

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

lib/Controller/PageController.php

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
use OCA\Talk\TalkSession;
3838
use OCA\Talk\TInitialState;
3939
use OCA\Viewer\Event\LoadViewer;
40+
use OCP\Accounts\IAccountManager;
4041
use OCP\App\IAppManager;
4142
use OCP\AppFramework\Controller;
4243
use OCP\AppFramework\Http;
@@ -67,6 +68,7 @@
6768
use OCP\IUserSession;
6869
use OCP\L10N\IFactory;
6970
use OCP\Notification\IManager as INotificationManager;
71+
use OCP\Profile\IProfileManager;
7072
use OCP\Security\Bruteforce\IThrottler;
7173
use OCP\Security\RateLimiting\ILimiter;
7274
use OCP\Security\RateLimiting\IRateLimitExceededException;
@@ -98,6 +100,7 @@ public function __construct(
98100
IConfig $serverConfig,
99101
IGroupManager $groupManager,
100102
protected IUserManager $userManager,
103+
protected IProfileManager $profileManager,
101104
protected ILimiter $limiter,
102105
protected IFactory $l10nFactory,
103106
) {
@@ -150,25 +153,26 @@ public function duplicateSession(): Response {
150153
return $this->index();
151154
}
152155

153-
protected function createPrivateRoom(string $targetUserId): ?Room {
156+
/**
157+
* @throws \InvalidArgumentException
158+
*/
159+
protected function createPrivateRoom(string $targetUserId): Room {
154160
$user = $this->userManager->get($targetUserId);
155161
if (!$user instanceof IUser) {
156-
return null;
162+
throw new \InvalidArgumentException('user');
157163
}
158164

159-
$l = $this->l10nFactory->get('spreed', $this->l10nFactory->getUserLanguage($user));
160-
161-
try {
162-
$room = $this->roomService->createConversation(
163-
Room::TYPE_PUBLIC,
164-
$l->t('Contact request'),
165-
$user,
166-
);
167-
} catch (\InvalidArgumentException) {
168-
return null;
165+
if ($this->profileManager->isProfileFieldVisible('talk', $user, null)) {
166+
throw new \InvalidArgumentException('profile');
169167
}
170168

171-
return $room;
169+
$l = $this->l10nFactory->get('spreed', $this->l10nFactory->getUserLanguage($user));
170+
171+
return $this->roomService->createConversation(
172+
Room::TYPE_PUBLIC,
173+
$l->t('Contact request'),
174+
$user,
175+
);
172176
}
173177

174178
/**
@@ -199,8 +203,9 @@ public function index(string $token = '', string $callUser = '', string $passwor
199203
return new TooManyRequestsResponse();
200204
}
201205

202-
$room = $this->createPrivateRoom($callUser);
203-
if ($room === null) {
206+
try {
207+
$room = $this->createPrivateRoom($callUser);
208+
} catch (\InvalidArgumentException) {
204209
$response = new TemplateResponse('core', '404-profile', [], TemplateResponse::RENDER_AS_GUEST);
205210
$response->throttle(['action' => 'callUser', 'callUser' => $callUser]);
206211
return $response;

0 commit comments

Comments
 (0)