Skip to content

Commit

Permalink
Hide the settings button when module is not available for a container
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Jul 16, 2024
1 parent 6de8f0b commit 14d7741
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 19 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.6.3 (Unreleased)
---------------------
- Fix #477: Hide the settings button when module is not available for a container

1.6.2 (July 16, 2024)
---------------------
- Enh #495: Fix column `exdate` to delete more than 16 recurrence event entries
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": "Calendar",
"description": "Create one-time or recurring events, invite and manage attendees, and keep track of all your events with the Calendar module.",
"keywords": ["calendar"],
"version": "1.6.2",
"version": "1.6.3",
"humhub": {
"minVersion": "1.16.1"
},
Expand Down
56 changes: 38 additions & 18 deletions widgets/ConfigureButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@

namespace humhub\modules\calendar\widgets;

use humhub\modules\calendar\helpers\Url;
use humhub\modules\user\models\User;
use humhub\widgets\ModalButton;
use Yii;
use humhub\components\Widget;
use humhub\modules\calendar\helpers\Url;
use humhub\modules\content\components\ContentContainerActiveRecord;
use humhub\modules\content\components\ContentContainerModuleManager;
use humhub\modules\content\helpers\ContentContainerHelper;
use humhub\modules\content\models\ContentContainerModuleState;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use humhub\widgets\Button;
use humhub\widgets\ModalButton;
use Yii;

class ConfigureButton extends Widget
{
Expand All @@ -28,20 +30,43 @@ public function init()
{
$this->container = ContentContainerHelper::getCurrent();

if(!$this->container) {
if (!$this->container) {
$this->container = Yii::$app->user->getIdentity();
}

parent::init(); // TODO: Change the autogenerated stub
parent::init();
}

public function run()
/**
* @inheritdoc
*/
public function beforeRun()
{
if(Yii::$app->user->isGuest) {
return '';
if (!parent::beforeRun()) {
return false;
}

if (Yii::$app->user->isGuest) {
return false;
}

if($this->container instanceof User && !Yii::$app->user->getIdentity()->moduleManager->isEnabled('calendar')) {
if ($this->container instanceof User) {
return ContentContainerModuleManager::getDefaultState(User::class, 'calendar') !== ContentContainerModuleState::STATE_NOT_AVAILABLE;
}

if ($this->container instanceof Space) {
return ContentContainerModuleManager::getDefaultState(Space::class, 'calendar') !== ContentContainerModuleState::STATE_NOT_AVAILABLE;
}

return true;
}

/**
* @inheritdoc
*/
public function run()
{
if ($this->container instanceof User && !Yii::$app->user->getIdentity()->moduleManager->isEnabled('calendar')) {
return ModalButton::defaultType()->load(Url::toEnableModuleOnProfileConfig())->icon('fa-cog')->visible($this->canConfigure());
}

Expand All @@ -52,22 +77,17 @@ private function getConfigUrl()
{
$menu = new ContainerConfigMenu();
$first = $menu->getFirstVisibleItem();
if(!$first) {
return '';
}

return $first['url'];
return $first ? $first['url'] : '';
}

public function canConfigure()
public function canConfigure(): bool
{
if($this->container instanceof Space) {
if ($this->container instanceof Space) {
$menu = new ContainerConfigMenu();
return !empty($menu->getFirstVisibleItem());
} else {
return $this->container->isCurrentUser();
}
}


}

0 comments on commit 14d7741

Please sign in to comment.