Skip to content

Commit

Permalink
Fix adding of all space members with status
Browse files Browse the repository at this point in the history
  • Loading branch information
yurabakhtin committed Jan 19, 2024
1 parent 9a43a5c commit 7fe4bb5
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 45 deletions.
3 changes: 2 additions & 1 deletion controllers/EntryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use humhub\modules\calendar\models\CalendarEntryParticipant;
use humhub\modules\calendar\models\forms\CalendarEntryForm;
use humhub\modules\calendar\models\forms\CalendarEntryParticipationForm;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\calendar\notifications\Invited;
use humhub\modules\calendar\widgets\ParticipantItem;
use humhub\modules\content\components\ContentContainerController;
Expand Down Expand Up @@ -129,7 +130,7 @@ protected function renderModal(CalendarEntry $entry, $cal)
*/
protected function renderModalParticipation(CalendarEntry $entry, ?string $activeTab = null, bool $isNewRecord = false): string
{
if ($activeTab === 'list' && $entry->participation_mode == CalendarEntry::PARTICIPATION_MODE_NONE) {
if ($activeTab === 'list' && $entry->participation_mode == CalendarEntryParticipation::PARTICIPATION_MODE_NONE) {
$activeTab = null;
}

Expand Down
3 changes: 2 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Unreleased
------------------------
Fix #437: Hide the profile calendar if the module is not available for users
Fix #439: Attach ICS files to "forced invites"
Fix #441: Send event update notifcation to invitees
Fix #441: Send event update notification to invitees
Fix #434: Fix adding of all space members with status

1.5.7 (January 12, 2024)
------------------------
Expand Down
30 changes: 7 additions & 23 deletions models/CalendarEntry.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,6 @@ class CalendarEntry extends ContentActiveRecord implements Searchable, Recurrent
*/
public $moduleId = 'calendar';

/**
* Participation Modes
*/
const PARTICIPATION_MODE_NONE = 0;
const PARTICIPATION_MODE_INVITE = 1;
const PARTICIPATION_MODE_ALL = 2;

/**
* @var array all given participation modes as array
*/
public static $participationModes = [
self::PARTICIPATION_MODE_NONE,
self::PARTICIPATION_MODE_INVITE,
self::PARTICIPATION_MODE_ALL
];

/**
* Filters
*/
Expand Down Expand Up @@ -250,7 +234,7 @@ public function rules()
[['end_datetime'], 'date', 'format' => $dateFormat],
[['all_day', 'allow_decline', 'allow_maybe', 'max_participants'], 'integer'],
[['title'], 'string', 'max' => 200],
[['participation_mode'], 'in', 'range' => self::$participationModes],
[['participation_mode'], 'in', 'range' => CalendarEntryParticipation::$participationModes],
[['end_datetime'], 'validateEndTime'],
[['recurrence_id'], 'validateRecurrenceId'],
[['description', 'participant_info'], 'safe'],
Expand Down Expand Up @@ -512,20 +496,20 @@ public function getReminderUserQuery()
{
if ($this->content->container instanceof Space) {
switch ($this->participation_mode) {
case static::PARTICIPATION_MODE_NONE:
case CalendarEntryParticipation::PARTICIPATION_MODE_NONE:
return Membership::getSpaceMembersQuery($this->content->container);
case static::PARTICIPATION_MODE_ALL:
case static::PARTICIPATION_MODE_INVITE:
case CalendarEntryParticipation::PARTICIPATION_MODE_ALL:
case CalendarEntryParticipation::PARTICIPATION_MODE_INVITE:
return $this->participation->findParticipants([
CalendarEntryParticipant::PARTICIPATION_STATE_ACCEPTED,
CalendarEntryParticipant::PARTICIPATION_STATE_MAYBE]);
}
} elseif ($this->content->container instanceof User) {
switch ($this->participation_mode) {
case static::PARTICIPATION_MODE_NONE:
case CalendarEntryParticipation::PARTICIPATION_MODE_NONE:
return User::find()->where(['id' => $this->content->container->id]);
case static::PARTICIPATION_MODE_INVITE:
case static::PARTICIPATION_MODE_ALL:
case CalendarEntryParticipation::PARTICIPATION_MODE_INVITE:
case CalendarEntryParticipation::PARTICIPATION_MODE_ALL:
return $this->participation->findParticipants([
CalendarEntryParticipant::PARTICIPATION_STATE_ACCEPTED,
CalendarEntryParticipant::PARTICIPATION_STATE_MAYBE])
Expand Down
7 changes: 4 additions & 3 deletions models/forms/CalendarEntryParticipationForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
namespace humhub\modules\calendar\models\forms;

use humhub\modules\calendar\models\CalendarEntryParticipant;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\calendar\notifications\Invited;
use humhub\modules\calendar\widgets\ParticipantItem;
use humhub\modules\user\models\User;
Expand Down Expand Up @@ -142,9 +143,9 @@ public function save()
public static function getModeItems(): array
{
return [
CalendarEntry::PARTICIPATION_MODE_NONE => Yii::t('CalendarModule.views_entry_edit', 'No participants'),
CalendarEntry::PARTICIPATION_MODE_INVITE => Yii::t('CalendarModule.views_entry_edit', 'Only by Invite'),
CalendarEntry::PARTICIPATION_MODE_ALL => Yii::t('CalendarModule.views_entry_edit', 'Everybody can participate')
CalendarEntryParticipation::PARTICIPATION_MODE_NONE => Yii::t('CalendarModule.views_entry_edit', 'No participants'),
CalendarEntryParticipation::PARTICIPATION_MODE_INVITE => Yii::t('CalendarModule.views_entry_edit', 'Only by Invite'),
CalendarEntryParticipation::PARTICIPATION_MODE_ALL => Yii::t('CalendarModule.views_entry_edit', 'Everybody can participate')
];
}

Expand Down
4 changes: 3 additions & 1 deletion models/participation/CalendarEntryParticipation.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class CalendarEntryParticipation extends Model implements CalendarEventParticipa
* Participation Modes
*/
const PARTICIPATION_MODE_NONE = 0;
const PARTICIPATION_MODE_INVITE = 1;
const PARTICIPATION_MODE_ALL = 2;

/**
* @var array all given participation modes as array
*/
public static $participationModes = [
self::PARTICIPATION_MODE_NONE,
self::PARTICIPATION_MODE_INVITE,
self::PARTICIPATION_MODE_ALL
];

Expand Down Expand Up @@ -210,7 +212,7 @@ public function deleteAll()
*/
public function addAllUsers($status = null)
{
if ($this->entry->participation_mode == static::PARTICIPATION_MODE_ALL && $this->canAddAll()) {
if ($this->entry->participation_mode != static::PARTICIPATION_MODE_NONE && $this->canAddAll()) {
Yii::$app->queue->push(new ForceParticipation([
'entry_id' => $this->entry->id,
'originator_id' => Yii::$app->user->getId(),
Expand Down
6 changes: 3 additions & 3 deletions models/participation/ParticipationSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function init()

private function initSettings()
{
$this->participation_mode = (int) $this->getSetting(self::SETTING_PARTICIPATION_MODE, CalendarEntry::PARTICIPATION_MODE_ALL);
$this->participation_mode = (int) $this->getSetting(self::SETTING_PARTICIPATION_MODE, CalendarEntryParticipation::PARTICIPATION_MODE_ALL);
$this->allow_decline = (int) $this->getSetting(self::SETTING_ALLOW_DECLINE, 1);
$this->allow_maybe = (int) $this->getSetting(self::SETTING_ALLOW_MAYBE, 1);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ public function rules()
{
return [
[['allow_decline', 'allow_maybe'], 'integer'],
[['participation_mode'], 'in', 'range' => CalendarEntry::$participationModes],
[['participation_mode'], 'in', 'range' => CalendarEntryParticipation::$participationModes],
];
}

Expand All @@ -102,7 +102,7 @@ public function attributeLabels()
*/
public function isParticipationAllowed()
{
return $this->participation_mode != CalendarEntry::PARTICIPATION_MODE_NONE;
return $this->participation_mode != CalendarEntryParticipation::PARTICIPATION_MODE_NONE;
}

public function save()
Expand Down
22 changes: 10 additions & 12 deletions tests/codeception/unit/reminder/ReminderProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@

namespace humhub\modules\calendar\tests\codeception\unit\reminder;

use calendar\CalendarUnitTest;
use DateInterval;
use DateTime;
use humhub\modules\calendar\interfaces\CalendarService;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\calendar\models\reminder\CalendarReminder;
use humhub\modules\calendar\models\reminder\CalendarReminderSent;
use humhub\modules\calendar\models\reminder\ReminderService;
use humhub\modules\calendar\models\CalendarEntry;
use humhub\modules\calendar\models\CalendarEntryParticipant;
use humhub\modules\calendar\notifications\Remind;
use humhub\modules\content\models\Content;
use humhub\modules\space\models\Membership;
use humhub\modules\space\models\Space;
use humhub\modules\user\models\User;
use Yii;
use calendar\CalendarUnitTest;
use DateInterval;
use DateTime;
use humhub\modules\calendar\Events;
use humhub\modules\calendar\models\reminder\CalendarReminder;
use humhub\modules\calendar\models\reminder\CalendarReminderSent;

class ReminderProcessTest extends CalendarUnitTest
{
Expand Down Expand Up @@ -442,7 +440,7 @@ public function testSentReminderToNonSpaceMemberParticipant()
$reminder = CalendarReminder::initGlobalDefault(CalendarReminder::UNIT_DAY, 1 );
$this->assertTrue($reminder->save());
$entry = $this->createEntry((new DateTime)->modify('+23 hours'), null, 'Test', Space::findOne(['id' => 3]));
$entry->participation_mode = CalendarEntry::PARTICIPATION_MODE_ALL;
$entry->participation_mode = CalendarEntryParticipation::PARTICIPATION_MODE_ALL;
$entry->saveEvent();

$entry->setParticipationStatus(User::findOne(['id' => 1]));
Expand Down Expand Up @@ -491,7 +489,7 @@ public function testSingleGlobalReminderOnSpaceParticipationAll()
$this->assertTrue($reminder->save());

$entry = $this->createEntry((new DateTime)->modify('+23 hours'), null, 'Test', Space::findOne(['id' => 3]));
$entry->participation_mode = CalendarEntry::PARTICIPATION_MODE_ALL;
$entry->participation_mode = CalendarEntryParticipation::PARTICIPATION_MODE_ALL;
$entry->saveEvent();

$entry->setParticipationStatus(User::findOne(['id' => 1]));
Expand Down Expand Up @@ -530,7 +528,7 @@ public function testSingleGlobalReminderOnSpaceParticipationAllDeclined()
$reminder = CalendarReminder::initGlobalDefault(CalendarReminder::UNIT_DAY, 1 );
$this->assertTrue($reminder->save());
$entry = $this->createEntry((new DateTime)->modify('+23 hours'), null, 'Test', Space::findOne(['id' => 3]));
$entry->participation_mode = CalendarEntry::PARTICIPATION_MODE_ALL;
$entry->participation_mode = CalendarEntryParticipation::PARTICIPATION_MODE_ALL;
$entry->saveEvent();

$entry->setParticipationStatus(User::findOne(['id' => 1]));
Expand Down Expand Up @@ -567,7 +565,7 @@ public function testSingleGlobalReminderOnSpaceParticipationNone()
$reminder = CalendarReminder::initGlobalDefault(CalendarReminder::UNIT_DAY, 1 );
$this->assertTrue($reminder->save());
$entry = $this->createEntry((new DateTime)->modify('+23 hours'), null, 'Test', Space::findOne(['id' => 3]));
$entry->participation_mode = CalendarEntry::PARTICIPATION_MODE_NONE;
$entry->participation_mode = CalendarEntryParticipation::PARTICIPATION_MODE_NONE;
$entry->saveEvent();

(new ReminderService())->sendAllReminder();
Expand Down Expand Up @@ -660,4 +658,4 @@ public function testSimpleEntryLevelUserReminder()
(new ReminderService())->sendAllReminder();
$this->assertTrue(CalendarReminderSent::check($reminder, $entry));
}
}
}
3 changes: 2 additions & 1 deletion widgets/ParticipantItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use humhub\components\Widget;
use humhub\modules\calendar\models\CalendarEntry;
use humhub\modules\calendar\models\CalendarEntryParticipant;
use humhub\modules\calendar\models\participation\CalendarEntryParticipation;
use humhub\modules\user\models\User;
use Yii;

Expand Down Expand Up @@ -50,7 +51,7 @@ public function run()
*/
public static function getStatuses(?CalendarEntry $entry = null, $exclude = null): array
{
if ($entry && $entry->participation_mode == CalendarEntry::PARTICIPATION_MODE_INVITE) {
if ($entry && $entry->participation_mode == CalendarEntryParticipation::PARTICIPATION_MODE_INVITE) {
$statuses = [];
} else {
$statuses = [
Expand Down

0 comments on commit 7fe4bb5

Please sign in to comment.