2021-10-14 04:19:40 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @copyright 2021 Christopher Ng <chrng8@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* @author Christopher Ng <chrng8@gmail.com>
|
|
|
|
|
*
|
|
|
|
|
* @license GNU AGPL version 3 or any later version
|
|
|
|
|
*
|
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace OC\Core\Controller;
|
|
|
|
|
|
2021-11-04 21:42:44 -04:00
|
|
|
use OC\Profile\ProfileManager;
|
2022-09-12 16:58:53 -04:00
|
|
|
use OCP\Profile\BeforeTemplateRenderedEvent;
|
2021-10-14 04:19:40 -04:00
|
|
|
use OCP\AppFramework\Controller;
|
|
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
|
|
|
|
use OCP\IRequest;
|
2021-11-05 05:44:51 -04:00
|
|
|
use OCP\IUser;
|
2021-10-14 04:19:40 -04:00
|
|
|
use OCP\IUserManager;
|
|
|
|
|
use OCP\IUserSession;
|
2021-11-04 21:42:44 -04:00
|
|
|
use OCP\Share\IManager as IShareManager;
|
2021-10-14 04:19:40 -04:00
|
|
|
use OCP\UserStatus\IManager as IUserStatusManager;
|
2022-09-12 16:58:53 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2021-10-14 04:19:40 -04:00
|
|
|
|
|
|
|
|
class ProfilePageController extends Controller {
|
2023-06-04 16:16:27 -04:00
|
|
|
public function __construct(string $appName,
|
|
|
|
|
IRequest $request,
|
|
|
|
|
private IInitialState $initialStateService,
|
|
|
|
|
private ProfileManager $profileManager,
|
|
|
|
|
private IShareManager $shareManager,
|
|
|
|
|
private IUserManager $userManager,
|
|
|
|
|
private IUserSession $userSession,
|
|
|
|
|
private IUserStatusManager $userStatusManager,
|
|
|
|
|
private IEventDispatcher $eventDispatcher) {
|
2021-10-14 04:19:40 -04:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @PublicPage
|
|
|
|
|
* @NoCSRFRequired
|
|
|
|
|
* @NoAdminRequired
|
|
|
|
|
* @NoSubAdminRequired
|
|
|
|
|
*/
|
|
|
|
|
public function index(string $targetUserId): TemplateResponse {
|
2021-11-04 21:42:44 -04:00
|
|
|
$profileNotFoundTemplate = new TemplateResponse(
|
|
|
|
|
'core',
|
|
|
|
|
'404-profile',
|
|
|
|
|
[],
|
|
|
|
|
TemplateResponse::RENDER_AS_GUEST,
|
|
|
|
|
);
|
|
|
|
|
|
2021-11-05 05:44:51 -04:00
|
|
|
$targetUser = $this->userManager->get($targetUserId);
|
2022-08-22 15:26:56 -04:00
|
|
|
if (!($targetUser instanceof IUser) || !$targetUser->isEnabled()) {
|
2021-11-04 21:42:44 -04:00
|
|
|
return $profileNotFoundTemplate;
|
2021-10-14 04:19:40 -04:00
|
|
|
}
|
|
|
|
|
$visitingUser = $this->userSession->getUser();
|
|
|
|
|
|
2022-03-10 21:11:28 -05:00
|
|
|
if (!$this->profileManager->isProfileEnabled($targetUser)) {
|
2021-11-04 21:42:44 -04:00
|
|
|
return $profileNotFoundTemplate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run user enumeration checks only if viewing another user's profile
|
|
|
|
|
if ($targetUser !== $visitingUser) {
|
2021-11-05 05:44:51 -04:00
|
|
|
if (!$this->shareManager->currentUserCanEnumerateTargetUser($visitingUser, $targetUser)) {
|
2021-11-04 21:42:44 -04:00
|
|
|
return $profileNotFoundTemplate;
|
|
|
|
|
}
|
2021-10-14 04:19:40 -04:00
|
|
|
}
|
|
|
|
|
|
2021-11-23 17:58:44 -05:00
|
|
|
if ($visitingUser !== null) {
|
|
|
|
|
$userStatuses = $this->userStatusManager->getUserStatuses([$targetUserId]);
|
|
|
|
|
$status = $userStatuses[$targetUserId] ?? null;
|
|
|
|
|
if ($status !== null) {
|
|
|
|
|
$this->initialStateService->provideInitialState('status', [
|
|
|
|
|
'icon' => $status->getIcon(),
|
|
|
|
|
'message' => $status->getMessage(),
|
|
|
|
|
]);
|
|
|
|
|
}
|
2021-10-14 04:19:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->initialStateService->provideInitialState(
|
|
|
|
|
'profileParameters',
|
|
|
|
|
$this->profileManager->getProfileParams($targetUser, $visitingUser),
|
|
|
|
|
);
|
|
|
|
|
|
2022-09-12 16:58:53 -04:00
|
|
|
$this->eventDispatcher->dispatchTyped(new BeforeTemplateRenderedEvent($targetUserId));
|
|
|
|
|
|
2021-12-01 18:08:08 -05:00
|
|
|
\OCP\Util::addScript('core', 'profile');
|
2021-10-14 04:19:40 -04:00
|
|
|
|
|
|
|
|
return new TemplateResponse(
|
|
|
|
|
'core',
|
|
|
|
|
'profile',
|
|
|
|
|
[],
|
|
|
|
|
$this->userSession->isLoggedIn() ? TemplateResponse::RENDER_AS_USER : TemplateResponse::RENDER_AS_PUBLIC,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|