Updated SelectionPlan entity

Added allow_new_presentations field
to prevent user to add new presentations on a particular selection plan

Change-Id: I900e28df8e329277fbf8da64612c4e1722b688ad
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2020-10-21 10:03:55 -03:00
parent 3b0dc89867
commit bed3d61680
10 changed files with 113 additions and 12 deletions

View File

@ -27,6 +27,7 @@ final class SummitSelectionPlanValidationRulesFactory
return [
'name' => 'sometimes|string|max:255',
'is_enabled' => 'sometimes|boolean',
'allow_new_presentations' => 'sometimes|boolean',
'max_submission_allowed_per_user' => 'sometimes|integer|min:1',
'submission_begin_date' => 'nullable|date_format:U',
'submission_end_date' => 'nullable|required_with:submission_begin_date|date_format:U|after_or_equal:submission_begin_date',
@ -39,6 +40,7 @@ final class SummitSelectionPlanValidationRulesFactory
return [
'name' => 'required|string|max:255',
'is_enabled' => 'required|boolean',
'allow_new_presentations' => 'required|boolean',
'max_submission_allowed_per_user' => 'sometimes|integer|min:1',
'submission_begin_date' => 'nullable|date_format:U',
'submission_end_date' => 'nullable|required_with:submission_begin_date|date_format:U|after_or_equal:submission_begin_date',

View File

@ -32,6 +32,7 @@ final class SelectionPlanSerializer extends SilverStripeSerializer
'SelectionBeginDate' => 'selection_begin_date:datetime_epoch',
'SelectionEndDate' => 'selection_end_date:datetime_epoch',
'SummitId' => 'summit_id:json_int',
'AllowNewPresentations' => 'allow_new_presentations:json_boolean',
];
/**

View File

@ -140,10 +140,10 @@ class SummitEventSerializer extends SilverStripeSerializer
$values['current_attendance'] = $attendance;
}
//if($event->hasAccess($this->resource_server_context->getCurrentUser())){
if($event->hasAccess($this->resource_server_context->getCurrentUser())){
$values['streaming_url'] = $event->getStreamingUrl();
$values['etherpad_link'] = $event->getEtherpadLink();
//}
}
if (!empty($expand)) {
foreach (explode(',', $expand) as $relation) {

View File

@ -1222,6 +1222,7 @@ class SummitEvent extends SilverstripeBaseModel
* @return bool
*/
public function hasAccess(?Member $member):bool{
if($this->summit->isPubliclyOpen()) return true;
if(is_null($member)) return false;
if($member->isAdmin()) return true;
if($member->hasPaidTicketOnSummit($this->summit)) return true;

View File

@ -44,6 +44,9 @@ final class SummitSelectionPlanFactory
if(isset($data['is_enabled']))
$selection_plan->setIsEnabled(boolval($data['is_enabled']));
if(isset($data['allow_new_presentations']))
$selection_plan->setAllowNewPresentations(boolval($data['allow_new_presentations']));
if(isset($data['max_submission_allowed_per_user']) ){
$selection_plan->setMaxSubmissionAllowedPerUser(intval($data['max_submission_allowed_per_user']));
}

View File

@ -61,6 +61,12 @@ class SelectionPlan extends SilverstripeBaseModel
*/
private $is_enabled;
/**
* @ORM\Column(name="AllowNewPresentations", type="boolean")
* @var bool
*/
private $allow_new_presentations;
/**
* @ORM\Column(name="SubmissionBeginDate", type="datetime")
* @var \DateTime
@ -274,6 +280,7 @@ class SelectionPlan extends SilverstripeBaseModel
{
parent::__construct();
$this->is_enabled = false;
$this->allow_new_presentations = true;
$this->category_groups = new ArrayCollection;
$this->presentations = new ArrayCollection;
$this->max_submission_allowed_per_user = Summit::DefaultMaxSubmissionAllowedPerUser;
@ -395,4 +402,21 @@ class SelectionPlan extends SilverstripeBaseModel
{
return $this->getStageStatus('Selection') === Summit::STAGE_OPEN;
}
/**
* @return bool
*/
public function isAllowNewPresentations(): bool
{
return $this->allow_new_presentations;
}
/**
* @param bool $allow_new_presentations
*/
public function setAllowNewPresentations(bool $allow_new_presentations): void
{
$this->allow_new_presentations = $allow_new_presentations;
}
}

View File

@ -558,7 +558,7 @@ class Summit extends SilverstripeBaseModel
private $category_groups;
/**
* @ORM\OneToMany(targetEntity="models\summit\SummitTicketType", mappedBy="summit", cascade={"persist","remove"}, orphanRemoval=true)
* @ORM\OneToMany(targetEntity="models\summit\SummitTicketType", mappedBy="summit", cascade={"persist","remove"}, orphanRemoval=true, fetch="EXTRA_LAZY")
* var SummitTicketType[]
*/
private $ticket_types;
@ -5032,4 +5032,7 @@ SQL;
$metric->setSummit($this);
}
public function isPubliclyOpen():bool{
return $this->ticket_types->count() == 0;
}
}

View File

@ -248,6 +248,16 @@ final class PresentationService
return $this->tx_service->transaction(function () use ($summit, $member, $data) {
$current_selection_plan = $summit->getCurrentSelectionPlanByStatus(SelectionPlan::STATUS_SUBMISSION);
if (is_null($current_selection_plan))
throw new ValidationException(trans(
'validation_errors.PresentationService.submitPresentation.NotValidSelectionPlan'
));
if(!$current_selection_plan->isAllowNewPresentations()){
throw new ValidationException(sprintf("Selection Plan %s does not allow new submissions", $current_selection_plan->getId()));
}
$current_speaker = $this->speaker_repository->getByMember($member);
if (is_null($current_speaker))
@ -255,11 +265,6 @@ final class PresentationService
'validation_errors.PresentationService.submitPresentation.NotValidSpeaker'
));
if (is_null($current_selection_plan))
throw new ValidationException(trans(
'validation_errors.PresentationService.submitPresentation.NotValidSelectionPlan'
));
if(!$current_selection_plan->IsEnabled()){
throw new ValidationException(sprintf("Submission Period is Closed."));
}

View File

@ -1,10 +1,23 @@
<?php
namespace Database\Migrations\Model;
<?php namespace Database\Migrations\Model;
/**
* Copyright 2019 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;
/**
* Class Version20201018045210
* @package Database\Migrations\Model
*/
class Version20201018045210 extends AbstractMigration
{
/**

View File

@ -0,0 +1,49 @@
<?php namespace Database\Migrations\Model;
/**
* Copyright 2019 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Doctrine\Migrations\AbstractMigration;
use Doctrine\DBAL\Schema\Schema as Schema;
use LaravelDoctrine\Migrations\Schema\Builder;
use LaravelDoctrine\Migrations\Schema\Table;
/**
* Class Version20201021125624
* @package Database\Migrations\Model
*/
class Version20201021125624 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$builder = new Builder($schema);
if($schema->hasTable("SelectionPlan") && !$builder->hasColumn("SelectionPlan","AllowNewPresentations") ) {
$builder->table('SelectionPlan', function (Table $table) {
$table->boolean('AllowNewPresentations')->setNotnull(true)->setDefault(true);
});
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
$builder = new Builder($schema);
if($schema->hasTable("SelectionPlan") && $builder->hasColumn("SelectionPlan","AllowNewPresentations") ) {
$builder->table('SelectionPlan', function (Table $table) {
$table->dropColumn('AllowNewPresentations');
});
}
}
}