Skip to content

🐛 Change the check way to check if the user have right to change some property #3534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 5.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/Controller/Backend/ContentEditController.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,21 +178,16 @@ public function save(?Content $originalContent = null, ?ContentValidatorInterfac

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

// deny if we detect the publication dates field being changed
if (($originalPublishedAt !== null && Date::datesDiffer($originalPublishedAt, $content->getPublishedAt())) ||
($originalDepublishedAt !== null && Date::datesDiffer($originalDepublishedAt, $content->getDepublishedAt()))
) {
$this->denyAccessUnlessGranted(ContentVoter::CONTENT_CHANGE_STATUS, $content);
}

// deny if owner changes
if ($originalAuthor !== $content->getAuthor()) {
$this->denyAccessUnlessGranted(ContentVoter::CONTENT_CHANGE_OWNERSHIP, $content);
// revert the owner property if the current user dont have right
if ($this->isGranted(ContentVoter::CONTENT_CHANGE_OWNERSHIP, $content) === false) {
$content->setAuthor($originalAuthor);
}
}

Expand Down