diff --git a/app/Models/Foundation/Summit/Events/SummitEvent.php b/app/Models/Foundation/Summit/Events/SummitEvent.php index 64ca573f2..1e4ad7979 100644 --- a/app/Models/Foundation/Summit/Events/SummitEvent.php +++ b/app/Models/Foundation/Summit/Events/SummitEvent.php @@ -1770,6 +1770,12 @@ public function setDuration(int $duration_in_seconds, bool $skipDatesSetting = f if (!$this->type->isAllowsPublishingDates()) { throw new ValidationException("Type does not allows Publishing Period."); } + // Once an event is published, only summit admins may change its duration. + // The published path silently shifts end_date via _setDuration when start_date + // is set, which would move a live schedule slot for any non-admin caller. + if ($this->isPublished() && !is_null($member) && !$member->isSummitAllowed($this->getSummit())) { + throw new ValidationException("Cannot modify duration of a published event."); + } $this->_setDuration($this->getSummit(), $duration_in_seconds, $skipDatesSetting, $member); } diff --git a/tests/SummitEventModelTest.php b/tests/SummitEventModelTest.php index a337efdbe..5ca6817f1 100644 --- a/tests/SummitEventModelTest.php +++ b/tests/SummitEventModelTest.php @@ -11,11 +11,13 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ +use models\main\Member; use models\summit\SummitEvent; use models\summit\Presentation; use LaravelDoctrine\ORM\Facades\EntityManager; use Doctrine\Persistence\ObjectRepository; use Illuminate\Support\Facades\DB; +use models\exceptions\ValidationException; use DateTimeZone; use DateTime; use DateInterval; @@ -77,4 +79,28 @@ public function testChangingEndDateShouldRecalculateDuration(){ $new_duration = $presentation->getDuration(); $this->assertTrue($old_duration < $new_duration); } + + public function testNonAdminMemberCannotChangeDurationOnPublishedEvent(){ + $presentation = self::$presentations[0]; + $this->assertTrue($presentation->isPublished()); + + $member = Mockery::mock(Member::class)->makePartial(); + $member->shouldReceive('isSummitAllowed')->andReturn(false); + + $this->expectException(ValidationException::class); + $presentation->setDuration(864000, false, $member); + } + + public function testAdminMemberCanChangeDurationOnPublishedEvent(){ + $presentation = self::$presentations[0]; + $this->assertTrue($presentation->isPublished()); + + $member = Mockery::mock(Member::class)->makePartial(); + $member->shouldReceive('isSummitAllowed')->andReturn(true); + + $old_end_date = $presentation->getEndDate(); + $presentation->setDuration(864000, false, $member); + $new_end_date = $presentation->getEndDate(); + $this->assertTrue($old_end_date < $new_end_date); + } } \ No newline at end of file