Skip to content

Commit

Permalink
Merge pull request #242 from humhub/fix/241-access-pages-only-admin
Browse files Browse the repository at this point in the history
Fix access to view HTML pages
  • Loading branch information
luke- authored Sep 9, 2022
2 parents 8268e6e + e96419a commit 0c9e884
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 10 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
Changelog
=========

1.8.4 (September 9, 2022)
-------------------------
- Fix #241: Fix access to view HTML pages

1.8.3 (September 7, 2022)
-------------------------
- Fix #238: Allow HTML Pages and Snippets only for global admins
Expand Down
8 changes: 6 additions & 2 deletions models/CustomContentContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,14 +283,18 @@ private function getRulesByTarget()
return $result;
}

public function canEdit(): bool
public function canEdit($type = null): bool
{
if (!($this->content->container instanceof Space && $this->content->container->isAdmin()) &&
!Yii::$app->user->can(ManagePages::class)) {
return false;
}

return $this->getTargetModel()->isAllowedContentType($this->type);
if (HtmlType::isType($type ?? $this->type) && !Yii::$app->user->isAdmin()) {
return false;
}

return true;
}

public function canView() {
Expand Down
5 changes: 0 additions & 5 deletions models/Target.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\custom_pages\helpers\Url;
use humhub\modules\custom_pages\Module;
use Yii;
use yii\base\Model;

/**
Expand Down Expand Up @@ -105,10 +104,6 @@ public function isAllowedContentType($type)
$type = $type->getId();
}

if (HtmlType::isType($type) && !Yii::$app->user->isAdmin()) {
return false;
}

return empty($this->contentTypes) || in_array($type, $this->contentTypes);
}

Expand Down
14 changes: 12 additions & 2 deletions models/forms/AddPageForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace humhub\modules\custom_pages\models\forms;

use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\custom_pages\helpers\Url;
use humhub\modules\custom_pages\models\ContainerPage;
use humhub\modules\custom_pages\models\ContainerSnippet;
Expand All @@ -25,6 +26,7 @@
/**
* AddPageForm selects a page type
*
* @property-read CustomContentContainer $pageInstance
* @author luke
*/
class AddPageForm extends Model
Expand Down Expand Up @@ -107,7 +109,11 @@ public function isAllowedType($type)
}
}

return in_array($type ,$this->getPageInstance()->getContentTypes()) && $this->target->isAllowedContentType($type);
if (!$this->pageInstance->canEdit($type)) {
return false;
}

return in_array($type, $this->pageInstance->getContentTypes()) && $this->target->isAllowedContentType($type);
}

/**
Expand Down Expand Up @@ -151,7 +157,11 @@ public function showTemplateType()
public function getPageInstance()
{
if($this->_instance == null) {
$this->_instance = Yii::createObject($this->class);
$params = [];
if ($this->target->container instanceof ContentContainerActiveRecord) {
$params[] = $this->target->container;
}
$this->_instance = Yii::createObject($this->class, $params);
}
return $this->_instance;
}
Expand Down
2 changes: 1 addition & 1 deletion module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Custom Pages",
"description": "Allows admins to create custom pages (html or markdown) or external links to various navigations (e.g. top navigation, account menu).",
"keywords": ["pages", "custom", "iframe", "markdown", "link", "navigation", "spaces"],
"version": "1.8.3",
"version": "1.8.4",
"homepage": "https://github.com/humhub/custom-pages",
"humhub": {
"minVersion": "1.12"
Expand Down

0 comments on commit 0c9e884

Please sign in to comment.