Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 15 additions & 0 deletions Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,4 +449,19 @@ public static function onContentAfterSoftDelete(ContentEvent $event): void
}
}
}

public static function onContentAfterUpdate($event): void
{
if (!CalendarEntry::isRecurrenceContentVisibilitySyncEnabled()
|| !array_key_exists('visibility', $event->changedAttributes)
|| $event->sender->object_model !== CalendarEntry::class) {
return;
}

/* @var CalendarEntry $calendarEntry */
$calendarEntry = $event->sender->getModel();
if ($calendarEntry) {
$calendarEntry->syncRecurrenceContentVisibility();
}
}
}
1 change: 1 addition & 0 deletions config.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
['class' => 'humhub\modules\rest\Module', 'event' => 'restApiAddRules', 'callback' => [Events::class, 'onRestApiAddRules']],
['class' => 'humhub\modules\custom_pages\modules\template\services\ElementTypeService', 'event' => 'init', 'callback' => [Events::class, 'onCustomPagesTemplateElementTypeServiceInit']],
['class' => Content::class, 'event' => Content::EVENT_AFTER_SOFT_DELETE, 'callback' => [Events::class, 'onContentAfterSoftDelete']],
['class' => Content::class, 'event' => Content::EVENT_AFTER_UPDATE, 'callback' => [Events::class, 'onContentAfterUpdate']],
],
'urlManagerRules' => [
'calendar' => 'calendar/global',
Expand Down
4 changes: 4 additions & 0 deletions controllers/EntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ public function actionViewRecurrence($parent_id, $recurrence_id, $cal = null)
throw new NotFoundHttpException();
}

if (!$recurrence->content->canView()) {
throw new ForbiddenHttpException('You have no permission to view the event!');
}

return $this->renderEntry($recurrence, $cal);
}

Expand Down
18 changes: 17 additions & 1 deletion controllers/GlobalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use humhub\modules\calendar\models\fullcalendar\FullCalendar;
use humhub\modules\calendar\models\SnippetModuleSettings;
use humhub\modules\calendar\widgets\FilterType;
use humhub\modules\content\components\ActiveQueryContent;
use humhub\modules\content\components\ContentContainerModuleManager;
use humhub\modules\content\models\ContentContainer;
use humhub\modules\content\models\ContentContainerModuleState;
Expand Down Expand Up @@ -98,7 +99,22 @@ private function getSelectorSettings()
return [];
}

return $this->getUserSettings()->getSerialized('lastSelectors', []);
return $this->getUserSettings()->getSerialized('lastSelectors') ?? $this->getDefaultSelectorSettings();
}

private function getDefaultSelectorSettings(): array
{
$selectors = [];

$selectors[] = ActiveQueryContent::USER_RELATED_SCOPE_OWN_PROFILE;
$selectors[] = ActiveQueryContent::USER_RELATED_SCOPE_SPACES;

if (!Yii::$app->getModule('user')->disableFollow) {
$selectors[] = ActiveQueryContent::USER_RELATED_SCOPE_FOLLOWED_SPACES;
$selectors[] = ActiveQueryContent::USER_RELATED_SCOPE_FOLLOWED_USERS;
}

return $selectors;
}

/**
Expand Down
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
1.8.15 (Unreleased)
-------------------
- Enh: Automated code refactoring for HumHub 1.18.0-beta.6 using Rector
- Fix #689: Fix calendar defaults and recurring visibility

1.8.14 (May 21, 2026)
---------------------
Expand Down
5 changes: 5 additions & 0 deletions integration/BirthdayCalendarQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ protected function filterDashboard()

protected function filterUserRelated()
{
if (empty($this->_userScopes)) {
$this->_query->andWhere('1=2');
return;
}

if (!empty($this->_userScopes) && !(in_array(ActiveQueryContent::USER_RELATED_SCOPE_FOLLOWED_USERS, $this->_userScopes) || in_array(ActiveQueryContent::USER_RELATED_SCOPE_OWN_PROFILE, $this->_userScopes))) {
throw new FilterNotSupportedException('Non supported user related filters');
}
Expand Down
7 changes: 4 additions & 3 deletions interfaces/event/AbstractCalendarQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ public static function findForFilter(?DateTime $start = null, ?DateTime $end = n
}
}

return $expand ? $expandResult : $result;
return $expand ? $query->preFilter($expandResult) : $result;
}

/**
Expand Down Expand Up @@ -950,11 +950,12 @@ protected function setupFilters()
if (Yii::$app->user->isGuest) {
$this->filterGuests($this->_container);
} else {
if ($this->hasFilter(self::FILTER_USERRELATED)) {
$hasUserRelatedFilter = $this->hasFilter(self::FILTER_USERRELATED);
if ($hasUserRelatedFilter) {
$this->_userScopes = $this->_filters[self::FILTER_USERRELATED];
}

if (!empty($this->_userScopes)) {
if ($hasUserRelatedFilter || !empty($this->_userScopes)) {
$this->filterUserRelated();
}

Expand Down
50 changes: 50 additions & 0 deletions models/CalendarEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ class CalendarEntry extends ContentActiveRecord implements
*/
private $_recurrenceRoot = false;

private static bool $recurrenceContentVisibilitySyncEnabled = true;
private static bool $syncingRecurrenceContentVisibility = false;

/**
* @var bool Cached of reminder enabled
*/
Expand Down Expand Up @@ -844,6 +847,7 @@ public function setRecurrenceId($recurrenceId)
public function setRecurrenceRootId($rootId)
{
$this->parent_event_id = $rootId;
$this->_recurrenceRoot = false;
}

public function getRecurring(): bool
Expand Down Expand Up @@ -904,6 +908,52 @@ public function getRecurrenceRoot(): ?self
return $this->_recurrenceRoot;
}

public static function withoutRecurrenceContentVisibilitySync(callable $callback)
{
$enabled = static::$recurrenceContentVisibilitySyncEnabled;
static::$recurrenceContentVisibilitySyncEnabled = false;

try {
return $callback();
} finally {
static::$recurrenceContentVisibilitySyncEnabled = $enabled;
}
}

public static function isRecurrenceContentVisibilitySyncEnabled(): bool
{
return static::$recurrenceContentVisibilitySyncEnabled && !static::$syncingRecurrenceContentVisibility;
}

public function syncRecurrenceContentVisibility(): void
{
if (!RecurrenceHelper::isRecurrent($this) || static::$syncingRecurrenceContentVisibility || empty($this->id)) {
return;
}

$root = empty($this->parent_event_id) ? $this : self::findOne(['id' => $this->parent_event_id]);
if (!$root) {
return;
}

$entryIds = $root->getRecurrenceInstances()->select('calendar_entry.id')->column();
$entryIds[] = $root->id;

static::$syncingRecurrenceContentVisibility = true;
try {
foreach (Content::find()
->where(['object_model' => static::getObjectModel(), 'object_id' => $entryIds])
->andWhere(['<>', 'visibility', $this->content->visibility])
->each() as $content) {
/* @var Content $content */
$content->visibility = $this->content->visibility;
$content->save();
}
} finally {
static::$syncingRecurrenceContentVisibility = false;
}
}

/**
* @param $start
* @param $end
Expand Down
11 changes: 11 additions & 0 deletions models/CalendarEntryQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use DateTime;
use yii\db\Query;
use yii\helpers\ArrayHelper;
use Yii;

/**
* CalendarEntryQuery class can be used for creating filter queries for [[CalendarEntry]] models.
Expand Down Expand Up @@ -127,5 +128,15 @@ private function participantJoin()
}
}

protected function preFilter($result = [])
{
if (!method_exists(Yii::$app, 'getUser')) {
return parent::preFilter($result);
}

return array_values(array_filter(parent::preFilter($result), static function (CalendarEntry $entry) {
return $entry->content->isNewRecord || $entry->content->canView();
}));
}

}
52 changes: 30 additions & 22 deletions models/forms/CalendarEntryForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -472,37 +472,45 @@ public function save()
//$this->translateDateTimes($this->entry->start_datetime, $this->entry->end_datetime, Yii::$app->timeZone, $this->timeZone);

return CalendarEntry::getDb()->transaction(function ($db) {
$result = CalendarEntry::withoutRecurrenceContentVisibilitySync(function () {

if (!$this->entry->saveEvent()) {
return false;
}
if (!$this->entry->saveEvent()) {
return false;
}

// Patch for https://github.com/humhub/humhub/issues/4847 in 1.8.beta1
if ($this->entry->description) {
RichText::postProcess($this->entry->description, $this->entry);
}
// Patch for https://github.com/humhub/humhub/issues/4847 in 1.8.beta1
if ($this->entry->description) {
RichText::postProcess($this->entry->description, $this->entry);
}

$this->entry->setType($this->type_id);
$this->entry->setType($this->type_id);

Topic::attach($this->entry->content, $this->topics);
Topic::attach($this->entry->content, $this->topics);

if ($this->sendUpdateNotification && !$this->entry->isNewRecord && !$this->entry->closed) {
$this->entry->participation->sendUpdateNotification();
}
if ($this->sendUpdateNotification && !$this->entry->isNewRecord && !$this->entry->closed) {
$this->entry->participation->sendUpdateNotification();
}

if (!$this->reminder) {
$this->reminderSettings->reminderType = ReminderSettings::REMINDER_TYPE_NONE;
$this->reminderSettings->reminders = [];
}
$result = $this->reminderSettings->save();
if (!$this->reminder) {
$this->reminderSettings->reminderType = ReminderSettings::REMINDER_TYPE_NONE;
$this->reminderSettings->reminders = [];
}
$result = $this->reminderSettings->save();

if (!$this->recurring) {
$this->recurrenceForm->frequency = RecurrenceFormModel::FREQUENCY_NEVER;
}
$result = $this->recurrenceForm->save($this->original) && $result;
if (!$this->recurring) {
$this->recurrenceForm->frequency = RecurrenceFormModel::FREQUENCY_NEVER;
}
$result = $this->recurrenceForm->save($this->original) && $result;

if ($result) {
$this->sequenceCheck();
}

return $result;
});

if ($result) {
$this->sequenceCheck();
$this->entry->syncRecurrenceContentVisibility();
}

return $result;
Expand Down
7 changes: 4 additions & 3 deletions tests/codeception/acceptance/GlobalCalendarCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ public function testGlobalCalendarCreateEntry(AcceptanceTester $I)
$I->see('My Test Profile Entry', '.fc-title');

// Active space filter
$I->amGoingTo('Select the space calendar filter');
$I->amGoingTo('deselect the space calendar filter');
$I->click('.calendar_my_spaces');
$I->wait(2);
$I->waitForText('Space Event', 10, '#calendar');
$I->dontSee('Space Event', '#calendar');
$I->see('My Test Profile Entry', '#calendar');

$I->wantToTest('the global calendar filters');
$I->amGoingTo('deselect the space calendar filter');
$I->amGoingTo('select the space calendar filter');
$I->click('.calendar_my_spaces');
$I->wait(2);
$I->waitForText('Space Event', 10, '#calendar');
Expand Down
3 changes: 3 additions & 0 deletions widgets/views/calendarFilterBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
<?= Yii::t('CalendarModule.views', 'My profile'); ?>
</label>
</div>
<?php elseif (in_array(ActiveQueryContent::USER_RELATED_SCOPE_OWN_PROFILE, $selectors)): ?>
<input type="checkbox" name="selector" class="selectorCheckbox d-none"
value="<?= ActiveQueryContent::USER_RELATED_SCOPE_OWN_PROFILE; ?>" checked="checked">
<?php endif; ?>
<div class="checkbox">
<label class="calendar_my_spaces">
Expand Down
Loading