Skip to content
Open
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
6 changes: 6 additions & 0 deletions app/Models/Foundation/Summit/Events/SummitEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
26 changes: 26 additions & 0 deletions tests/SummitEventModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Loading