Skip to content

Commit ef33033

Browse files
🐛 Change the check way to check if the user have right to change some property
1 parent 0f01434 commit ef33033

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

src/Controller/Backend/ContentEditController.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,21 +178,16 @@ public function save(?Content $originalContent = null, ?ContentValidatorInterfac
178178

179179
// check for status changes
180180
if ($originalContent !== null) {
181-
// deny if we detect the status field being changed
182-
if ($originalStatus !== $content->getStatus() ) {
183-
$this->denyAccessUnlessGranted(ContentVoter::CONTENT_CHANGE_STATUS, $content);
181+
// revert the propery change if the current user dont have right
182+
if ($this->isGranted(ContentVoter::CONTENT_CHANGE_STATUS, $content) === false) {
183+
$content->setStatus($originalStatus);
184+
$content->setPublishedAt($originalPublishedAt);
185+
$content->setDepublishedAt($originalDepublishedAt);
184186
}
185187

186-
// deny if we detect the publication dates field being changed
187-
if (($originalPublishedAt !== null && Date::datesDiffer($originalPublishedAt, $content->getPublishedAt())) ||
188-
($originalDepublishedAt !== null && Date::datesDiffer($originalDepublishedAt, $content->getDepublishedAt()))
189-
) {
190-
$this->denyAccessUnlessGranted(ContentVoter::CONTENT_CHANGE_STATUS, $content);
191-
}
192-
193-
// deny if owner changes
194-
if ($originalAuthor !== $content->getAuthor()) {
195-
$this->denyAccessUnlessGranted(ContentVoter::CONTENT_CHANGE_OWNERSHIP, $content);
188+
// revert the owner property if the current user dont have right
189+
if ($this->isGranted(ContentVoter::CONTENT_CHANGE_OWNERSHIP, $content) === false) {
190+
$content->setAuthor($originalAuthor);
196191
}
197192
}
198193

0 commit comments

Comments
 (0)