Merge pull request #12666 from MrPetovan/bug/12661-public-calendar-export

Enable calendar export for public_calendar = true
This commit is contained in:
Philipp 2023-01-14 19:20:20 +01:00 committed by GitHub
commit 0c14e51112
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View file

@ -23,11 +23,14 @@ namespace Friendica\Module\Calendar;
use Friendica\App; use Friendica\App;
use Friendica\BaseModule; use Friendica\BaseModule;
use Friendica\Content\Feature;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Session\Capability\IHandleUserSessions; use Friendica\Core\Session\Capability\IHandleUserSessions;
use Friendica\Model\Event; use Friendica\Model\Event;
use Friendica\Model\Profile;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Module\Response; use Friendica\Module\Response;
use Friendica\Module\Security\Login;
use Friendica\Navigation\SystemMessages; use Friendica\Navigation\SystemMessages;
use Friendica\Network\HTTPException; use Friendica\Network\HTTPException;
use Friendica\Util\Profiler; use Friendica\Util\Profiler;
@ -47,25 +50,39 @@ class Export extends BaseModule
protected $session; protected $session;
/** @var SystemMessages */ /** @var SystemMessages */
protected $sysMessages; protected $sysMessages;
/** @var App */
protected $app;
public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, array $server, array $parameters = []) public function __construct(App $app, L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IHandleUserSessions $session, SystemMessages $sysMessages, array $server, array $parameters = [])
{ {
parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters);
$this->session = $session; $this->session = $session;
$this->sysMessages = $sysMessages; $this->sysMessages = $sysMessages;
$this->app = $app;
} }
protected function rawContent(array $request = []) protected function rawContent(array $request = [])
{ {
if (!$this->session->getLocalUserId()) { $nickname = $this->parameters['nickname'] ?? null;
throw new HTTPException\UnauthorizedException($this->t('Permission denied.')); if (!$nickname) {
throw new HTTPException\BadRequestException();
} }
$owner = User::getByNickname($this->parameters['nickname'], ['uid']); $owner = Profile::load($this->app, $nickname, false);
if (empty($owner)) { if (!$owner || $owner['account_expired'] || $owner['account_removed']) {
throw new HTTPException\NotFoundException($this->t('User not found.')); throw new HTTPException\NotFoundException($this->t('User not found.'));
} }
if (!$this->session->isAuthenticated() && $owner['hidewall']) {
$this->baseUrl->redirect('profile/' . $nickname . '/restricted');
}
if (!$this->session->isAuthenticated() && !Feature::isEnabled($owner['uid'], 'public_calendar')) {
$this->sysMessages->addNotice($this->t('Permission denied.'));
$this->baseUrl->redirect('profile/' . $nickname);
}
$ownerUid = $owner['uid']; $ownerUid = $owner['uid'];
$format = $this->parameters['format'] ?: static::DEFAULT_EXPORT; $format = $this->parameters['format'] ?: static::DEFAULT_EXPORT;

View file

@ -64,7 +64,7 @@ class Show extends BaseModule
protected function content(array $request = []): string protected function content(array $request = []): string
{ {
$nickname = $this->parameters['nickname'] ?? $this->app->getLoggedInUserNickname(); $nickname = $this->parameters['nickname'] ?? $this->session->getLocalUserNickname();
if (!$nickname) { if (!$nickname) {
throw new HTTPException\UnauthorizedException(); throw new HTTPException\UnauthorizedException();
} }