Skip to content

Commit

Permalink
Fixed #15408
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkelly committed Jul 25, 2024
1 parent e663091 commit 4a0149f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 23 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fixed a bug where element index result counts weren’t getting updated when the element list was refreshed but pagination was preserved. ([#15367](https://github.com/craftcms/cms/issues/15367))
- Fixed a PHP error that occurred when making a field layout component conditional on a Time or CKEditor field. ([craftcms/ckeditor#267](https://github.com/craftcms/ckeditor/issues/267))
- Fixed an error that occurred when editing a user via a slideout, if the current user didn’t have permission to edit the primary site. ([#15408](https://github.com/craftcms/cms/issues/15408))

## 4.10.6 - 2024-07-16

Expand Down
49 changes: 26 additions & 23 deletions src/controllers/ElementsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1863,25 +1863,9 @@ private function _element(
$elementId = $elementId ?? $this->_elementId;
$elementUid = $elementUid ?? $this->_elementUid;

$sitesService = Craft::$app->getSites();
$elementsService = Craft::$app->getElements();
$user = static::currentUser();

if ($this->_siteId) {
$site = $sitesService->getSiteById($this->_siteId, true);
if (!$site) {
throw new BadRequestHttpException("Invalid side ID: $this->_siteId");
}
if (Craft::$app->getIsMultiSite() && !$user->can("editSite:$site->uid")) {
throw new ForbiddenHttpException('User not authorized to edit content for this site.');
}
} else {
$site = Cp::requestedSite();
if (!$site) {
throw new ForbiddenHttpException('User not authorized to edit content in any sites.');
}
}

if ($this->_elementType) {
$elementType = $this->_elementType;
} elseif ($elementId || $elementUid) {
Expand All @@ -1901,12 +1885,31 @@ private function _element(
/** @phpstan-var class-string<ElementInterface>|ElementInterface $elementType */
$this->_validateElementType($elementType);

if ($strictSite) {
$siteId = $site->id;
$preferSites = null;
if ($elementType::isLocalized()) {
if ($this->_siteId) {
$site = Craft::$app->getSites()->getSiteById($this->_siteId, true);
if (!$site) {
throw new BadRequestHttpException("Invalid side ID: $this->_siteId");
}
if (Craft::$app->getIsMultiSite() && !$user->can("editSite:$site->uid")) {
throw new ForbiddenHttpException('User not authorized to edit content for this site.');
}
} else {
$site = Cp::requestedSite();
if (!$site) {
throw new ForbiddenHttpException('User not authorized to edit content in any sites.');
}
}

if ($strictSite) {
$siteId = $site->id;
$preferSites = null;
} else {
$siteId = Craft::$app->getSites()->getEditableSiteIds();
$preferSites = [$site->id];
}
} else {
$siteId = $sitesService->getEditableSiteIds();
$preferSites = [$site->id];
$siteId = $preferSites = null;
}

// Loading an existing element?
Expand Down Expand Up @@ -1942,7 +1945,7 @@ private function _element(
throw new ForbiddenHttpException('User not authorized to edit this element.');
}

if (!$strictSite && $element->siteId !== $site->id) {
if (!$strictSite && isset($site) && $element->siteId !== $site->id) {
return $this->redirect($element->getCpEditUrl());
}

Expand All @@ -1955,7 +1958,7 @@ private function _elementById(
bool $checkForProvisionalDraft,
string $elementType,
User $user,
int|array $siteId,
int|array|null $siteId,
?array $preferSites,
): ?ElementInterface {
/** @var string|ElementInterface $elementType */
Expand Down

0 comments on commit 4a0149f

Please sign in to comment.