Skip to content

Commit 2c1f898

Browse files
[FEATURE] add "Profile update not authorized" error message
if the user attempt to delete the profile picture of a different user Resolves: in2code-de/femanager/issues#667
1 parent 2150ee4 commit 2c1f898

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

Classes/Controller/UserController.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psr\Http\Message\ResponseInterface;
1616
use TYPO3\CMS\Core\Error\Http\UnauthorizedException;
1717
use TYPO3\CMS\Core\Http\RedirectResponse;
18+
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
1819
use TYPO3\CMS\Core\Utility\GeneralUtility;
1920
use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
2021

@@ -53,14 +54,20 @@ public function showAction(?User $user = null): ResponseInterface
5354
*/
5455
public function imageDeleteAction(User $user): ResponseInterface
5556
{
56-
if (UserUtility::getCurrentUser()->getUid() !== $user->getUid()) {
57-
throw new UnauthorizedException('You are not allowed to delete this image', 1516373759972);
57+
$currentUser = UserUtility::getCurrentUser();
58+
if ($currentUser && $currentUser->getUid() === $user->getUid()) {
59+
$user->setImage(GeneralUtility::makeInstance(ObjectStorage::class));
60+
$this->userRepository->update($user);
61+
$this->logUtility->log(Log::STATUS_PROFILEUPDATEIMAGEDELETE, $user);
62+
$this->addFlashMessage(LocalizationUtility::translateByState(Log::STATUS_PROFILEUPDATEIMAGEDELETE));
63+
} else {
64+
$this->logUtility->log(Log::STATUS_PROFILEUPDATENOTAUTHORIZED, $user);
65+
$this->addFlashMessage(
66+
LocalizationUtility::translateByState(Log::STATUS_PROFILEUPDATENOTAUTHORIZED),
67+
'',
68+
ContextualFeedbackSeverity::ERROR);
5869
}
5970

60-
$user->setImage(GeneralUtility::makeInstance(ObjectStorage::class));
61-
$this->userRepository->update($user);
62-
$this->logUtility->log(Log::STATUS_PROFILEUPDATEIMAGEDELETE, $user);
63-
$this->addFlashMessage(LocalizationUtility::translateByState(Log::STATUS_PROFILEUPDATEIMAGEDELETE));
6471
return $this->redirectToUri(FrontendUtility::getUriToCurrentPage());
6572
}
6673

Classes/Domain/Model/Log.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class Log extends AbstractEntity
3737

3838
final public const STATUS_PROFILEUPDATEATTEMPTEDSPOOF = 207;
3939

40+
final public const STATUS_PROFILEUPDATENOTAUTHORIZED = 208;
41+
4042
final public const STATUS_PROFILEDELETE = 301;
4143

4244
final public const STATUS_INVITATIONPROFILECREATED = 401;

Resources/Private/Language/locallang.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@
165165
<trans-unit id="tx_femanager_domain_model_log.state.207">
166166
<source>Attempted to spoof profile</source>
167167
</trans-unit>
168+
<trans-unit id="tx_femanager_domain_model_log.state.208">
169+
<source>Profile update not authorized</source>
170+
</trans-unit>
168171
<trans-unit id="tx_femanager_domain_model_log.state.300">
169172
<source>Delete</source>
170173
</trans-unit>

Resources/Private/Language/locallang_db.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@
177177
<trans-unit id="tx_femanager_domain_model_log.state.207">
178178
<source>Attempted to spoof profile</source>
179179
</trans-unit>
180+
<trans-unit id="tx_femanager_domain_model_log.state.208">
181+
<source>Profile update not authorized</source>
182+
</trans-unit>
180183
<trans-unit id="tx_femanager_domain_model_log.state.300">
181184
<source>Delete</source>
182185
</trans-unit>

0 commit comments

Comments
 (0)