Skip to content

Commit

Permalink
Deny access for files from template of hidden content
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Nov 21, 2023
1 parent 5ffda0d commit 93c3054
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 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.10.0 (Unreleased)
-------------------------
- Enh #308: Deny access for files from template of hidden content

1.9.5 (November 16, 2023)
-------------------------
- Enh #303: Fix visibility of the method `Controller::getAccessRules()`
Expand Down
4 changes: 2 additions & 2 deletions module.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"name": "Custom Pages",
"description": "Create custom pages and widgets and share them with your users. Take advantage of a wide range of editing options, including HTML and Markdown.",
"keywords": ["pages", "custom", "iframe", "markdown", "link", "navigation", "spaces"],
"version": "1.9.5",
"version": "1.10.0",
"homepage": "https://github.com/humhub/custom-pages",
"humhub": {
"minVersion": "1.14"
"minVersion": "1.16"
}
}
49 changes: 47 additions & 2 deletions modules/template/models/TemplateContentActiveRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@

namespace humhub\modules\custom_pages\modules\template\models;

use Yii;
use humhub\components\ActiveRecord;
use humhub\interfaces\ViewableInterface;
use humhub\modules\content\components\ContentActiveRecord;
use humhub\modules\custom_pages\models\CustomContentContainer;
use Yii;
use yii\db\ActiveQuery;

/**
* This is the base class for all TemplateContent types.
*
* @property-read OwnerContent $ownerContent
*/
abstract class TemplateContentActiveRecord extends ActiveRecord
abstract class TemplateContentActiveRecord extends ActiveRecord implements ViewableInterface
{

const SCENARIO_CREATE = 'create';
Expand Down Expand Up @@ -325,4 +331,43 @@ public function isEmpty(): bool
return false;
}

public function getOwnerContent(): ActiveQuery
{
return $this->hasOne(OwnerContent::class, ['content_id' => 'id'])
->andWhere([OwnerContent::tableName() . '.content_type' => get_class($this)]);
}

public function getCustomContentContainer(): ?CustomContentContainer
{
$ownerContent = $this->ownerContent;
if (!$ownerContent instanceof OwnerContent) {
return null;
}

$ownerModel = $ownerContent->getOwner();
if (!$ownerModel instanceof TemplateInstance) {
return null;
}

return $ownerModel->getObject();
}

/**
* @inheritdoc
*/
public function canView($user = null): bool
{
$customContentContainer = $this->getCustomContentContainer();

if ($customContentContainer instanceof ContentActiveRecord) {
return $customContentContainer->content->canView($user);
}

if ($customContentContainer instanceof ViewableInterface) {
return $customContentContainer->canView($user);
}

return false;
}

}
10 changes: 10 additions & 0 deletions modules/template/models/TemplateInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use humhub\components\ActiveRecord;
use humhub\modules\content\models\Content;
use humhub\modules\custom_pages\models\CustomContentContainer;
use yii\db\ActiveQuery;

/**
Expand Down Expand Up @@ -98,6 +99,15 @@ public function getTemplate()
return $this->hasOne(Template::class, ['id' => 'template_id']);
}

public function getObject(): ?CustomContentContainer
{
if (empty($this->object_model) || empty($this->object_id)) {
return null;
}

return call_user_func($this->object_model . '::findOne', ['id' => $this->object_id]);
}

public function getTemplateId()
{
return $this->template_id;
Expand Down

0 comments on commit 93c3054

Please sign in to comment.