From bed3d616805d136055625334acc9a4e09cadbe09 Mon Sep 17 00:00:00 2001 From: smarcet Date: Wed, 21 Oct 2020 10:03:55 -0300 Subject: [PATCH] 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 --- ...mitSelectionPlanValidationRulesFactory.php | 2 + .../Summit/SelectionPlanSerializer.php | 1 + .../Summit/SummitEventSerializer.php | 4 +- .../Foundation/Summit/Events/SummitEvent.php | 1 + .../Factories/SummitSelectionPlanFactory.php | 3 ++ .../Foundation/Summit/SelectionPlan.php | 24 +++++++++ app/Models/Foundation/Summit/Summit.php | 5 +- .../Model/Imp/PresentationService.php | 15 ++++-- .../model/Version20201018045210.php | 21 ++++++-- .../model/Version20201021125624.php | 49 +++++++++++++++++++ 10 files changed, 113 insertions(+), 12 deletions(-) create mode 100644 database/migrations/model/Version20201021125624.php diff --git a/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitSelectionPlanValidationRulesFactory.php b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitSelectionPlanValidationRulesFactory.php index 7884bb5b..d739273a 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitSelectionPlanValidationRulesFactory.php +++ b/app/Http/Controllers/Apis/Protected/Summit/Factories/SummitSelectionPlanValidationRulesFactory.php @@ -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', diff --git a/app/ModelSerializers/Summit/SelectionPlanSerializer.php b/app/ModelSerializers/Summit/SelectionPlanSerializer.php index 2f47c457..b207d1eb 100644 --- a/app/ModelSerializers/Summit/SelectionPlanSerializer.php +++ b/app/ModelSerializers/Summit/SelectionPlanSerializer.php @@ -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', ]; /** diff --git a/app/ModelSerializers/Summit/SummitEventSerializer.php b/app/ModelSerializers/Summit/SummitEventSerializer.php index 5c2df256..e3b295c1 100644 --- a/app/ModelSerializers/Summit/SummitEventSerializer.php +++ b/app/ModelSerializers/Summit/SummitEventSerializer.php @@ -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) { diff --git a/app/Models/Foundation/Summit/Events/SummitEvent.php b/app/Models/Foundation/Summit/Events/SummitEvent.php index d3c3af41..07dbf835 100644 --- a/app/Models/Foundation/Summit/Events/SummitEvent.php +++ b/app/Models/Foundation/Summit/Events/SummitEvent.php @@ -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; diff --git a/app/Models/Foundation/Summit/Factories/SummitSelectionPlanFactory.php b/app/Models/Foundation/Summit/Factories/SummitSelectionPlanFactory.php index 09757714..6ab37532 100644 --- a/app/Models/Foundation/Summit/Factories/SummitSelectionPlanFactory.php +++ b/app/Models/Foundation/Summit/Factories/SummitSelectionPlanFactory.php @@ -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'])); } diff --git a/app/Models/Foundation/Summit/SelectionPlan.php b/app/Models/Foundation/Summit/SelectionPlan.php index 55a1f020..8c60e18a 100644 --- a/app/Models/Foundation/Summit/SelectionPlan.php +++ b/app/Models/Foundation/Summit/SelectionPlan.php @@ -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; + } + } \ No newline at end of file diff --git a/app/Models/Foundation/Summit/Summit.php b/app/Models/Foundation/Summit/Summit.php index 2d31a6e9..9c8291fa 100644 --- a/app/Models/Foundation/Summit/Summit.php +++ b/app/Models/Foundation/Summit/Summit.php @@ -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; + } } diff --git a/app/Services/Model/Imp/PresentationService.php b/app/Services/Model/Imp/PresentationService.php index 70bd16ae..dab38fb6 100644 --- a/app/Services/Model/Imp/PresentationService.php +++ b/app/Services/Model/Imp/PresentationService.php @@ -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.")); } diff --git a/database/migrations/model/Version20201018045210.php b/database/migrations/model/Version20201018045210.php index 75ac6781..25f67b2c 100644 --- a/database/migrations/model/Version20201018045210.php +++ b/database/migrations/model/Version20201018045210.php @@ -1,10 +1,23 @@ -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'); + }); + } + } +}