Skip to content

Commit

Permalink
[FEATURE] Respect permissions in default actions
Browse files Browse the repository at this point in the history
  • Loading branch information
einpraegsam committed Mar 1, 2024
1 parent d8bf863 commit 163112e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
56 changes: 24 additions & 32 deletions Classes/Controller/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ public function resetFilterAction(string $redirectAction): ResponseInterface

public function editAction(Newsletter $newsletter): ResponseInterface
{
if ($newsletter->canBeRead() === false) {
throw new AuthenticationFailedException('You are not allowed to see this record', 1709329205);
}

$this->view->assignMultiple([
'newsletter' => $newsletter,
'configurations' => $this->configurationRepository->findAllAuthorized(),
Expand All @@ -104,6 +108,10 @@ public function initializeUpdateAction(): void

public function updateAction(Newsletter $newsletter): ResponseInterface
{
if ($newsletter->canBeRead() === false) {
throw new AuthenticationFailedException('You are not allowed to see this record', 1709329247);
}

$this->setBodytextInNewsletter($newsletter, $newsletter->getLanguage());
if (ConfigurationUtility::isMultiLanguageModeActivated()) {
$newsletter->setSubject(
Expand Down Expand Up @@ -140,6 +148,10 @@ public function initializeCreateAction(): void

public function createAction(Newsletter $newsletter): ResponseInterface
{
if ($newsletter->canBeRead() === false) {
throw new AuthenticationFailedException('You are not allowed to see this record', 1709329276);
}

$languages = $this->pageRepository->getLanguagesFromOrigin($newsletter->getOrigin());
foreach ($languages as $language) {
$newsletterLanguage = clone $newsletter;
Expand Down Expand Up @@ -170,20 +182,32 @@ public function createAction(Newsletter $newsletter): ResponseInterface

public function disableAction(Newsletter $newsletter): ResponseInterface
{
if ($newsletter->canBeRead() === false) {
throw new AuthenticationFailedException('You are not allowed to see this record', 1709329304);
}

$newsletter->disable();
$this->newsletterRepository->update($newsletter);
return $this->redirect('list');
}

public function enableAction(Newsletter $newsletter): ResponseInterface
{
if ($newsletter->canBeRead() === false) {
throw new AuthenticationFailedException('You are not allowed to see this record', 1709329338);
}

$newsletter->enable();
$this->newsletterRepository->update($newsletter);
return $this->redirect('list');
}

public function deleteAction(Newsletter $newsletter): ResponseInterface
{
if ($newsletter->canBeRead() === false) {
throw new AuthenticationFailedException('You are not allowed to see this record', 1709329345);
}

$this->newsletterRepository->removeNewsletterAndQueues($newsletter);
$this->addFlashMessage(LocalizationUtility::translate('module.newsletter.delete.message'));
return $this->redirect('list');
Expand Down Expand Up @@ -229,19 +253,6 @@ public function wizardUserPreviewAjax(ServerRequestInterface $request): Response
return $response;
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws AuthenticationFailedException
* @throws ExceptionDbalDriver
* @throws ApiConnectionException
* @throws InvalidUrlException
* @throws MisconfigurationException
* @throws JsonException
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
* @throws InvalidConfigurationTypeException
*/
public function testMailAjax(ServerRequestInterface $request): ResponseInterface
{
if (BackendUserUtility::isBackendUserAuthenticated() === false) {
Expand Down Expand Up @@ -277,16 +288,6 @@ public function testMailAjax(ServerRequestInterface $request): ResponseInterface
return $response;
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
* @throws AuthenticationFailedException
* @throws ExceptionDbalDriver
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
* @throws InvalidConfigurationTypeException
* @throws MisconfigurationException
*/
public function previewSourcesAjax(ServerRequestInterface $request): ResponseInterface
{
if (BackendUserUtility::isBackendUserAuthenticated() === false) {
Expand All @@ -299,10 +300,6 @@ public function previewSourcesAjax(ServerRequestInterface $request): ResponseInt
return $response;
}

/**
* @param ServerRequestInterface $request
* @return ResponseInterface
*/
public function receiverDetailAjax(ServerRequestInterface $request): ResponseInterface
{
$userRepository = GeneralUtility::makeInstance(UserRepository::class);
Expand All @@ -323,11 +320,6 @@ public function receiverDetailAjax(ServerRequestInterface $request): ResponseInt
return $response;
}

/**
* @return void
* @throws ExtensionConfigurationExtensionNotConfiguredException
* @throws ExtensionConfigurationPathDoesNotExistException
*/
protected function addDocumentHeaderForNewsletterController(): void
{
$menuConfiguration = [
Expand Down
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Newsletter.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public function getUnsubscribeRate(): float
*
* @return bool
*/
private function canBeRead(): bool
public function canBeRead(): bool
{
if (BackendUserUtility::isAdministrator()) {
return true;
Expand Down

0 comments on commit 163112e

Please sign in to comment.