Summit Presentation Actions Types

Updates to Summit Serializer

* added new collection presentation_action_types

Presentation Action Types

GET /api/v1/summits/{id}/presentation-action-types

filtering

'label' => ['=@', '=='],

ordering

'id',
'order',
'label',

required scopes

%s/summits/read
%s/summits/read/all

auth groups

* SuperAdmins
* Administrators
* SummitAdministrators
* TrackChairsAdmins

GET /api/v1/summits/{id}/presentation-action-types/csv

filtering

'name' => ['=@', '=='],
'label' => ['=@', '=='],
'is_enabled' => ['=='],

ordering

'id',
'order',
'label',

required scopes

%s/summits/read
%s/summits/read/all

auth groups

* SuperAdmins
* Administrators
* SummitAdministrators
* TrackChairsAdmins

POST /api/v1/summits/{id}/presentation-action-types

payload

'label'       => 'required|string|max:255',

required scopes

%s/summits/write

auth groups

* SuperAdmins
* Administrators
* SummitAdministrators
* TrackChairsAdmins

PUT /api/v1/summits/{id}/presentation-action-types/{action_id}

payload

'label'       => 'sometimes|string|max:255',
'order'       => 'sometimes|integer|min:1',

required scopes

%s/summits/write

auth groups

* SuperAdmins
* Administrators
* SummitAdministrators
* TrackChairsAdmins

GET /api/v1/summits/{id}/presentation-action-types/{action_id}

required scopes

%s/summits/read
%s/summits/read/all

auth groups

* SuperAdmins
* Administrators
* SummitAdministrators
* TrackChairsAdmins

DELETE /api/v1/summits/{id}/presentation-action-types/{action_id}

required scopes

%s/summits/write

auth groups

* SuperAdmins
* Administrators
* SummitAdministrators
* TrackChairsAdmins

Change-Id: Ibec7591b88470b59d9f942a553a8335a57e9db9e
Signed-off-by: smarcet <smarcet@gmail.com>
This commit is contained in:
smarcet 2021-03-31 18:43:24 -03:00
parent 01dd8f3c15
commit 0d836a1b90
25 changed files with 1692 additions and 12 deletions

View File

@ -0,0 +1,41 @@
<?php namespace App\Events;
/**
* Copyright 2021 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 Illuminate\Queue\SerializesModels;
use models\summit\PresentationActionType;
/**
* Class PresentationActionTypeCreated
* @package App\Events
*/
final class PresentationActionTypeCreated extends Event
{
use SerializesModels;
/**
* @var PresentationActionType
*/
private $action_type;
/**
* PresentationMaterialCreated constructor.
* @param PresentationActionType $action_type
*/
public function __construct(PresentationActionType $action_type)
{
$this->action_type = $action_type;
}
public function getActionType():PresentationActionType{
return $this->action_type;
}
}

View File

@ -0,0 +1,40 @@
<?php namespace App\Http\Controllers;
/**
* Copyright 2021 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.
**/
/**
* Class SummitPresentationActionTypeValidationRulesFactory
* @package App\Http\Controllers
*/
final class SummitPresentationActionTypeValidationRulesFactory
{
/**
* @param array $data
* @param bool $update
* @return array
*/
public static function build(array $data, $update = false)
{
if ($update) {
return [
'label' => 'sometimes|string|max:255',
'order' => 'sometimes|integer|min:1',
];
}
return [
'label' => 'required|string|max:255',
];
}
}

View File

@ -0,0 +1,251 @@
<?php namespace App\Http\Controllers;
/**
* Copyright 2021 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 App\Http\Utils\EpochCellFormatter;
use App\Models\Foundation\Summit\Repositories\IPresentationActionTypeRepository;
use App\Services\Model\ISummitPresentationActionTypeService;
use Illuminate\Support\Facades\Input;
use models\exceptions\ValidationException;
use models\oauth2\IResourceServerContext;
use models\summit\ISummitRepository;
use models\summit\Summit;
use models\utils\IEntity;
use ModelSerializers\SerializerRegistry;
use utils\Filter;
use utils\FilterElement;
/**
* Class OAuth2SummitPresentationActionTypeApiController
* @package App\Http\Controllers
*/
final class OAuth2SummitPresentationActionTypeApiController
extends OAuth2ProtectedController
{
/**
* @var ISummitRepository
*/
private $summit_repository;
/**
* @var ISummitPresentationActionTypeService
*/
private $service;
/**
* OAuth2SummitPresentationActionTypeApiController constructor.
* @param ISummitPresentationActionTypeService $service
* @param IPresentationActionTypeRepository $repository
* @param ISummitRepository $summit_repository
* @param IResourceServerContext $resource_server_context
*/
public function __construct
(
ISummitPresentationActionTypeService $service,
IPresentationActionTypeRepository $repository,
ISummitRepository $summit_repository,
IResourceServerContext $resource_server_context
)
{
parent::__construct($resource_server_context);
$this->repository = $repository;
$this->summit_repository = $summit_repository;
$this->service = $service;
}
use ParametrizedGetAll;
use GetSummitChildElementById;
use AddSummitChildElement;
use UpdateSummitChildElement;
use DeleteSummitChildElement;
/**
* @inheritDoc
*/
protected function addChild(Summit $summit, array $payload): IEntity
{
return $this->service->add($summit, $payload);
}
/**
* @inheritDoc
*/
function getAddValidationRules(array $payload): array
{
return SummitPresentationActionTypeValidationRulesFactory::build($payload, false);
}
/**
* @inheritDoc
*/
protected function getSummitRepository(): ISummitRepository
{
return $this->summit_repository;
}
/**
* @inheritDoc
*/
protected function deleteChild(Summit $summit, $child_id): void
{
$this->service->delete($summit, $child_id);
}
/**
* @inheritDoc
*/
protected function getChildFromSummit(Summit $summit, $child_id): ?IEntity
{
return $summit->getPresentationActionTypeById($child_id);
}
/**
* @inheritDoc
*/
function getUpdateValidationRules(array $payload): array
{
return SummitPresentationActionTypeValidationRulesFactory::build($payload, true);
}
/**
* @inheritDoc
*/
protected function updateChild(Summit $summit, int $child_id, array $payload): IEntity
{
return $this->service->update($summit, $child_id, $payload);
}
/**
* @param $summit_id
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function getAllBySummit($summit_id)
{
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->getResourceServerContext())->find($summit_id);
if (is_null($summit)) return $this->error404();
return $this->_getAll(
function () {
return [
'name' => ['=@', '=='],
'label' => ['=@', '=='],
'is_enabled' => ['=='],
];
},
function () {
return [
'name' => 'sometimes|string',
'label' => 'sometimes|string',
'is_enabled' => 'sometimes|boolean',
];
},
function () {
return [
'id',
'name',
'order',
'label',
'is_enabled'
];
},
function ($filter) use ($summit) {
if ($filter instanceof Filter) {
$filter->addFilterCondition(FilterElement::makeEqual('summit_id', $summit->getId()));
}
return $filter;
},
function () {
return SerializerRegistry::SerializerType_Public;
}
);
}
/**
* @param $summit_id
* @return \Illuminate\Http\JsonResponse|mixed
*/
public function getAllBySummitCSV($summit_id)
{
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->getResourceServerContext())->find($summit_id);
if (is_null($summit)) return $this->error404();
return $this->_getAllCSV(
function () {
return [
'name' => ['=@', '=='],
'label' => ['=@', '=='],
'is_enabled' => ['=='],
];
},
function () {
return [
'name' => 'sometimes|string',
'label' => 'sometimes|string',
'is_enabled' => 'sometimes|boolean',
];
},
function () {
return [
'id',
'name',
'order',
'label',
'is_enabled'
];
},
function ($filter) use ($summit) {
if ($filter instanceof Filter) {
$filter->addFilterCondition(FilterElement::makeEqual('summit_id', $summit->getId()));
}
return $filter;
},
function () {
return SerializerRegistry::SerializerType_Public;
},
function () {
return [
'created' => new EpochCellFormatter(),
'last_edited' => new EpochCellFormatter(),
];
},
function () use ($summit) {
$allowed_columns = [
'id',
'created',
'last_edited',
'name',
'label',
'is_enabled',
'order',
];
$columns_param = Input::get("columns", "");
$columns = [];
if (!empty($columns_param))
$columns = explode(',', $columns_param);
$diff = array_diff($columns, $allowed_columns);
if (count($diff) > 0) {
throw new ValidationException(sprintf("columns %s are not allowed!", implode(",", $diff)));
}
if (empty($columns))
$columns = $allowed_columns;
return $columns;
},
sprintf('summit_presentation_action_types-%s', $summit_id)
);
}
}

View File

@ -1362,6 +1362,19 @@ Route::group([
Route::delete('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@removeFeatureSpeaker']);
});
});
// presentation action types
Route::group(['prefix' => 'presentation-action-types'], function(){
Route::get('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitPresentationActionTypeApiController@getAllBySummit']);
Route::get('csv', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitPresentationActionTypeApiController@getAllBySummitCSV']);
Route::post('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitPresentationActionTypeApiController@add']);
Route::group(['prefix' => '{action_id}'], function() {
Route::get('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitPresentationActionTypeApiController@get']);
Route::put('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitPresentationActionTypeApiController@update']);
Route::delete('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitPresentationActionTypeApiController@delete']);
});
});
});
});

View File

@ -0,0 +1,68 @@
<?php namespace App\Jobs;
/**
* Copyright 2021 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 Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use libs\utils\ITransactionService;
use models\exceptions\EntityNotFoundException;
use models\summit\ISummitRepository;
/**
* Class SynchAllPresentationActions
* @package App\Jobs
*/
class SynchAllPresentationActions implements ShouldQueue
{
public $tries = 2;
public $timeout = PHP_INT_MAX;
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* @var int
*/
private $summit_id;
/**
* SynchAllPresentationActions constructor.
* @param int $summit_id
*/
public function __construct(int $summit_id)
{
$this->summit_id = $summit_id;
}
/**
* @param ISummitRepository $repository
* @param ITransactionService $tx_service
* @throws \Exception
*/
public function handle(
ISummitRepository $repository,
ITransactionService $tx_service
)
{
Log::debug(sprintf("SynchAllPresentationActions::handle summit %s", $this->summit_id));
$tx_service->transaction(function() use($repository){
$summit = $repository->getById($this->summit_id);
if(is_null($summit))
throw new EntityNotFoundException(sprintf("Summit %s not found", $this->summit_id));
$summit->synchAllPresentationActions();
});
}
}

View File

@ -203,6 +203,8 @@ final class SerializerRegistry
$this->registry['SummitCategoryChange'] = SummitCategoryChangeSerializer::class;
$this->registry['PresentationActionType'] = PresentationActionTypeSerializer::class;
// track chairs
$this->registry['PresentationTrackChairView'] = PresentationTrackChairViewSerializer::class;
$this->registry['SummitSelectedPresentationList'] = SummitSelectedPresentationListSerializer::class;

View File

@ -0,0 +1,60 @@
<?php namespace ModelSerializers;
/**
* Copyright 2021 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 Libs\ModelSerializers\AbstractSerializer;
use models\summit\PresentationActionType;
/**
* Class PresentationActionTypeSerializer
* @package ModelSerializers
*/
final class PresentationActionTypeSerializer extends SilverStripeSerializer
{
protected static $array_mappings = [
'Name' => 'name:json_string',
'Label' => 'label:json_string',
'SummitId' => 'summit_id:json_int',
'Order' => 'order:json_int',
'Active' => 'is_active:json_boolean',
];
/**
* @param null $expand
* @param array $fields
* @param array $relations
* @param array $params
* @return array
*/
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array())
{
$action = $this->object;
if (!$action instanceof PresentationActionType) return [];
$values = parent::serialize($expand, $fields, $relations, $params);
if (!empty($expand)) {
$exp_expand = explode(',', $expand);
foreach ($exp_expand as $relation) {
switch (trim($relation)) {
case 'summit':
{
unset($values['summit_id']);
$values['summit'] = SerializerRegistry::getInstance()->getSerializer
(
$action->getSummit()
)->serialize(AbstractSerializer::filterExpandByPrefix($expand, $relation));
}
break;
}
}
}
return $values;
}
}

View File

@ -115,6 +115,7 @@ class SummitSerializer extends SilverStripeSerializer
'summit_documents',
'featured_speakers',
'dates_with_events',
'presentation_action_types',
];
/**
@ -312,6 +313,15 @@ class SummitSerializer extends SilverStripeSerializer
$values['featured_speakers'] = $featured_speakers;
}
// presentation_action_types
if (in_array('presentation_action_types', $relations)) {
$presentation_action_types = [];
foreach ($summit->getPresentationActionTypes() as $action) {
$presentation_action_types[] = SerializerRegistry::getInstance()->getSerializer($action)->serialize(AbstractSerializer::filterExpandByPrefix($expand, 'presentation_action_types'));
}
$values['presentation_action_types'] = $presentation_action_types;
}
if (!empty($expand)) {
foreach (explode(',', $expand) as $relation) {

View File

@ -0,0 +1,147 @@
<?php namespace models\summit;
/**
* Copyright 2021 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 models\main\Member;
use models\utils\SilverstripeBaseModel;
use Doctrine\ORM\Mapping AS ORM;
/**
* @ORM\Entity
* @ORM\Table(name="PresentationAction")
* Class PresentationAction
* @package models\summit
*/
class PresentationAction extends SilverstripeBaseModel
{
/**
* @ORM\Column(name="IsCompleted", type="boolean")
* @var boolean
*/
private $is_completed;
public function __construct()
{
parent::__construct();
$this->is_completed = false;
}
/**
* @ORM\ManyToOne(targetEntity="Presentation", inversedBy="actions", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(name="PresentationID", referencedColumnName="ID", onDelete="CASCADE")
* @var Presentation
*/
private $presentation;
/**
* @ORM\ManyToOne(targetEntity="PresentationActionType", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(name="TypeID", referencedColumnName="ID", onDelete="CASCADE")
* @var PresentationActionType
*/
private $type;
/**
* @ORM\ManyToOne(targetEntity="models\main\Member", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(name="CreatedByID", referencedColumnName="ID", onDelete="SET NULL")
* @var Member
*/
private $created_by;
/**
* @ORM\ManyToOne(targetEntity="models\main\Member", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(name="UpdateByID", referencedColumnName="ID", onDelete="SET NULL")
* @var Member
*/
private $updated_by;
/**
* @return bool
*/
public function isCompleted(): bool
{
return $this->is_completed;
}
/**
* @param bool $is_completed
*/
public function setIsCompleted(bool $is_completed): void
{
$this->is_completed = $is_completed;
}
/**
* @return Presentation
*/
public function getPresentation(): Presentation
{
return $this->presentation;
}
/**
* @param Presentation $presentation
*/
public function setPresentation(Presentation $presentation): void
{
$this->presentation = $presentation;
}
/**
* @return PresentationActionType
*/
public function getType(): PresentationActionType
{
return $this->type;
}
/**
* @param PresentationActionType $type
*/
public function setType(PresentationActionType $type): void
{
$this->type = $type;
}
/**
* @return Member
*/
public function getCreatedBy(): ?Member
{
return $this->created_by;
}
/**
* @param Member $created_by
*/
public function setCreatedBy(Member $created_by): void
{
$this->created_by = $created_by;
}
/**
* @return Member
*/
public function getUpdatedBy(): ?Member
{
return $this->updated_by;
}
/**
* @param Member $updated_by
*/
public function setUpdatedBy(Member $updated_by): void
{
$this->updated_by = $updated_by;
}
}

View File

@ -0,0 +1,96 @@
<?php namespace models\summit;
/**
* Copyright 2021 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 App\Events\PresentationActionTypeCreated;
use Doctrine\ORM\Mapping AS ORM;
use App\Models\Foundation\Main\IOrderable;
use Illuminate\Support\Facades\Event;
use models\utils\SilverstripeBaseModel;
/**
* @ORM\Entity(repositoryClass="App\Repositories\Summit\DoctrinePresentationActionTypeRepository")
* @ORM\Table(name="PresentationActionType")
* @ORM\AssociationOverrides({
* @ORM\AssociationOverride(
* name="summit",
* inversedBy="presentation_action_types"
* )
* })
* @ORM\HasLifecycleCallbacks
* Class PresentationActionType
* @package models\summit
*/
class PresentationActionType extends SilverstripeBaseModel
implements IOrderable
{
use SummitOwned;
/**
* @ORM\Column(name="Label", type="string")
* @var string
*/
private $label;
/**
* @ORM\Column(name="`Order`", type="integer")
* @var int
*/
private $order;
/**
* @return int
*/
public function getOrder(): int
{
return $this->order;
}
/**
* @param int $order
*/
public function setOrder($order): void
{
$this->order = $order;
}
/**
* @return string
*/
public function getLabel(): string
{
return $this->label;
}
/**
* @param string $label
*/
public function setLabel(string $label): void
{
$this->label = $label;
}
public function __construct()
{
parent::__construct();
$this->order = 1;
}
/**
* @ORM\PostPersist
*/
public function inserted($args)
{
Event::dispatch(new PresentationActionTypeCreated($this));
}
}

View File

@ -12,17 +12,16 @@
* limitations under the License.
**/
use App\Models\Foundation\Main\OrderableChilds;
use Illuminate\Support\Arr;
use models\summit\PresentationTrackChairView;
use Behat\Transliterator\Transliterator;
use Doctrine\ORM\Mapping AS ORM;
use App\Models\Foundation\Main\OrderableChilds;
use Behat\Transliterator\Transliterator;
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackAnswer;
use App\Models\Foundation\Summit\SelectionPlan;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ArrayCollection;
use App\Models\Foundation\Summit\Events\Presentations\TrackQuestions\TrackQuestionTemplate;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use models\exceptions\ValidationException;
use models\main\Member;
@ -131,7 +130,6 @@ class Presentation extends SummitEvent
*/
protected $moderator;
/**
* @ORM\ManyToOne(targetEntity="models\main\Member", fetch="EXTRA_LAZY")
* @ORM\JoinColumn(name="CreatorID", referencedColumnName="ID", onDelete="SET NULL")
@ -202,6 +200,12 @@ class Presentation extends SummitEvent
*/
private $category_changes_requests;
/**
* @ORM\OneToMany(targetEntity="models\summit\PresentationAction", mappedBy="presentation", cascade={"persist", "remove"}, orphanRemoval=true, fetch="EXTRA_LAZY")
* @var PresentationAction[]
*/
private $actions;
/**
* @return bool
*/
@ -241,6 +245,7 @@ class Presentation extends SummitEvent
$this->votes = new ArrayCollection();
$this->category_changes_requests = new ArrayCollection();
$this->selected_presentations = new ArrayCollection();
$this->actions = new ArrayCollection();
$this->to_record = false;
$this->attending_media = false;
}
@ -1425,4 +1430,64 @@ class Presentation extends SummitEvent
if(is_null($list) || !$list instanceof SummitSelectedPresentationList) return 0;
return $list->getAvailableSlots();
}
/**
* @param PresentationActionType $type
* @return bool
*/
public function hasActionByType(PresentationActionType $type):bool{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('type', $type));
return $this->actions->matching($criteria)->count() > 0;
}
/**
* @param PresentationActionType $type
* @return PresentationAction|null
*/
public function getActionByType(PresentationActionType $type):?PresentationAction {
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('type', $type));
$res = $this->actions->matching($criteria)->first();
return $res === false ? null : $res;
}
/**
* @param bool $complete
* @param PresentationActionType $type
* @return PresentationAction|null
*/
public function setCompletionByType(bool $complete, PresentationActionType $type):?PresentationAction{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('type', $type));
$res = $this->actions->matching($criteria)->first();
if($res === false) return null;
$res->setIsCompleted($complete);
return $res;
}
public function initializeActions():void {
Log::debug(sprintf("Presentation::initializeActions presentation %s", $this->id));
foreach ($this->summit->getPresentationActionTypes() as $presentationActionType){
if(!$this->hasActionByType($presentationActionType)){
// create it
Log::debug
(
sprintf
(
"Presentation::initializeActions creating new presentation action for type %s",
$presentationActionType->getName()
)
);
$action = new PresentationAction();
$action->setType($presentationActionType);
$action->setPresentation($this);
$this->actions->add($action);
}
}
}
public function getPresentationActions(){
return $this->actions;
}
}

View File

@ -0,0 +1,41 @@
<?php namespace App\Models\Foundation\Summit\Factories;
/**
* Copyright 2021 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 models\summit\PresentationActionType;
/**
* Class PresentationActionTypeFactory
* @package App\Models\Foundation\Summit\Factories
*/
final class PresentationActionTypeFactory
{
/**
* @param array $data
* @return PresentationActionType
*/
public static function build(array $data):PresentationActionType{
return self::populate(new PresentationActionType, $data);
}
/**
* @param PresentationActionType $action
* @param array $data
* @return PresentationActionType
*/
public static function populate(PresentationActionType $action, array $data):PresentationActionType{
if(isset($data['label']))
$action->setLabel(trim($data['label']));
return $action;
}
}

View File

@ -0,0 +1,23 @@
<?php namespace App\Models\Foundation\Summit\Repositories;
/**
* Copyright 2021 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 models\utils\IBaseRepository;
/**
* Interface IPresentationActionTypeRepository
* @package App\Models\Foundation\Summit\Repositories
*/
interface IPresentationActionTypeRepository extends IBaseRepository
{
}

View File

@ -151,7 +151,6 @@ class Summit extends SilverstripeBaseModel
*/
private $external_summit_id;
/**
* @ORM\Column(name="ScheduleDefaultStartDate", type="datetime")
* @var \DateTime
@ -579,7 +578,6 @@ class Summit extends SilverstripeBaseModel
*/
private $excluded_categories_for_accepted_presentations;
/**
* @ORM\ManyToMany(targetEntity="models\summit\PresentationSpeaker")
* @ORM\JoinTable(name="Summit_FeaturedSpeakers",
@ -656,6 +654,12 @@ class Summit extends SilverstripeBaseModel
*/
private $track_chairs;
/**
* @ORM\OneToMany(targetEntity="models\summit\PresentationActionType", mappedBy="summit", cascade={"persist","remove"}, orphanRemoval=true)
* @var PresentationActionType[]
*/
private $presentation_action_types;
/**
* @return string
*/
@ -976,7 +980,8 @@ class Summit extends SilverstripeBaseModel
$this->media_upload_types = new ArrayCollection();
$this->featured_speakers = new ArrayCollection();
$this->metrics = new ArrayCollection();
$this->track_chairs = new ArrayCollection();
$this->track_chairs = new ArrayCollection();
$this->presentation_action_types = new ArrayCollection();
}
/**
@ -1349,6 +1354,9 @@ class Summit extends SilverstripeBaseModel
return $this->events->matching($criteria);
}
/**
* @return Presentation[]
*/
public function getPresentations()
{
$query = $this->createQuery("SELECT p from models\summit\Presentation p JOIN p.summit s WHERE s.id = :summit_id");
@ -5192,4 +5200,64 @@ SQL;
if($member->isAdmin()) return true;
return $this->hasPermissionOnSummit($member) && $member->isOnGroup(IGroup::TrackChairsAdmins);
}
/**
* @param PresentationActionType $presentation_action_type
* @return $this
*/
public function addPresentationActionType(PresentationActionType $presentation_action_type)
{
if($this->presentation_action_types->contains($presentation_action_type)) return $this;
$presentation_action_type->setOrder($this->getPresentationActionTypeMaxOrder() + 1);
$this->presentation_action_types->add($presentation_action_type);
$presentation_action_type->setSummit($this);
return $this;
}
/**
* @return int
*/
public function getPresentationActionTypeMaxOrder():int{
$criteria = Criteria::create();
$criteria->orderBy(['order' => 'DESC']);
$action = $this->presentation_action_types->matching($criteria)->first();
return $action === false ? 0 : $action->getOrder();
}
/**
* @return ArrayCollection|\Doctrine\Common\Collections\Collection
*/
public function getPresentationActionTypes(){
$criteria = Criteria::create();
$criteria->orderBy(["order" => Criteria::ASC ]);
return $this->presentation_action_types->matching($criteria);
}
/**
* @param PresentationActionType $presentation_action_type
* @return $this
*/
public function removePresentationActionType(PresentationActionType $presentation_action_type){
if(!$this->presentation_action_types->contains($presentation_action_type)) return $this;
$this->presentation_action_types->removeElement($presentation_action_type);
$presentation_action_type->setSummit(null);
return $this;
}
/**
* @param int $action_id
* @return PresentationActionType|null
*/
public function getPresentationActionTypeById(int $action_id):?PresentationActionType{
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('id', $action_id));
$action = $this->presentation_action_types->matching($criteria)->first();
return $action === false ? null: $action;
}
public function synchAllPresentationActions():void{
foreach ($this-$this->getPresentations() as $presentation){
$presentation->initializeActions();
}
}
}

View File

@ -18,6 +18,7 @@ use App\EntityPersisters\EntityEventPersister;
use App\Events\NewMember;
use App\Events\OrderDeleted;
use App\Events\PaymentSummitRegistrationOrderConfirmed;
use App\Events\PresentationActionTypeCreated;
use App\Events\RequestedSummitAttendeeTicketRefund;
use App\Events\RequestedSummitOrderRefund;
use App\Events\RSVPCreated;
@ -66,6 +67,7 @@ use App\Jobs\Emails\BookableRooms\BookableRoomReservationRefundRequestedOwnerEma
use App\Jobs\Emails\BookableRooms\BookableRoomReservationCanceledEmail;
use App\Jobs\Emails\Schedule\RSVPRegularSeatMail;
use App\Jobs\Emails\Schedule\RSVPWaitListSeatMail;
use App\Jobs\SynchAllPresentationActions;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Event;
@ -601,5 +603,14 @@ final class EventServiceProvider extends ServiceProvider
}
});
Event::listen(PresentationActionTypeCreated::class, function($event){
if(!$event instanceof PresentationActionTypeCreated) return;
$summit = $event->getActionType()->getSummit();
SynchAllPresentationActions::dispatch($summit->getId());
});
}
}

View File

@ -28,6 +28,7 @@ use App\Models\Foundation\Summit\Locations\Banners\SummitLocationBanner;
use App\Models\Foundation\Summit\Repositories\IDefaultSummitEventTypeRepository;
use App\Models\Foundation\Summit\Repositories\IDefaultTrackTagGroupRepository;
use App\Models\Foundation\Summit\Repositories\IPaymentGatewayProfileRepository;
use App\Models\Foundation\Summit\Repositories\IPresentationActionTypeRepository;
use App\Models\Foundation\Summit\Repositories\IPresentationCategoryGroupRepository;
use App\Models\Foundation\Summit\Repositories\IPresentationSpeakerSummitAssistanceConfirmationRequestRepository;
use App\Models\Foundation\Summit\Repositories\IRSVPTemplateRepository;
@ -67,7 +68,6 @@ use App\Models\Foundation\Summit\SelectionPlan;
use App\Models\Foundation\Summit\Speakers\SpeakerEditPermissionRequest;
use App\Models\Foundation\Summit\TrackTagGroupAllowedTag;
use App\Models\ResourceServer\IApiRepository;
use App\Repositories\Summit\DoctrineSummitTrackChairRepository;
use Illuminate\Support\Facades\App;
use Illuminate\Support\ServiceProvider;
use LaravelDoctrine\ORM\Facades\EntityManager;
@ -85,6 +85,7 @@ use models\summit\ISponsorUserInfoGrantRepository;
use models\summit\ISummitRegistrationPromoCodeRepository;
use models\summit\ISummitTicketTypeRepository;
use models\summit\PaymentGatewayProfile;
use models\summit\PresentationActionType;
use models\summit\PresentationCategory;
use models\summit\PresentationCategoryGroup;
use models\summit\PresentationSpeakerSummitAssistanceConfirmationRequest;
@ -119,7 +120,6 @@ use models\summit\SummitTaxType;
use models\summit\SummitTicketType;
use models\summit\SummitTrackChair;
use repositories\main\DoctrineLegalDocumentRepository;
/**
* Class RepositoriesProvider
* @package repositories
@ -662,5 +662,12 @@ final class RepositoriesProvider extends ServiceProvider
return EntityManager::getRepository(SummitCategoryChange::class);
}
);
App::singleton(
IPresentationActionTypeRepository::class,
function(){
return EntityManager::getRepository(PresentationActionType::class);
}
);
}
}

View File

@ -0,0 +1,59 @@
<?php namespace App\Repositories\Summit;
/**
* Copyright 2021 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 App\Models\Foundation\Summit\Repositories\IPresentationActionTypeRepository;
use App\Repositories\SilverStripeDoctrineRepository;
use models\summit\PresentationActionType;
use utils\DoctrineLeftJoinFilterMapping;
/**
* Class DoctrinePresentationActionTypeRepository
* @package App\Repositories\Summit
*/
final class DoctrinePresentationActionTypeRepository
extends SilverStripeDoctrineRepository
implements IPresentationActionTypeRepository
{
/**
* @inheritDoc
*/
protected function getBaseEntity()
{
return PresentationActionType::class;
}
/**
* @return array
*/
protected function getFilterMappings()
{
return [
'label' => 'e.label:json_string',
'summit_id' => new DoctrineLeftJoinFilterMapping("e.summit", "s" ,"s.id :operator :value")
];
}
/**
* @return array
*/
protected function getOrderMappings()
{
return [
'id' => 'e.id',
'order' => 'e.order',
'label' => 'e.label',
];
}
}

View File

@ -0,0 +1,50 @@
<?php namespace App\Services\Model;
/**
* Copyright 2021 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 models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use models\summit\PresentationActionType;
use models\summit\Summit;
/**
* Interface ISummitPresentationActionTypeService
* @package App\Services\Model
*/
interface ISummitPresentationActionTypeService
{
/**
* @param Summit $summit
* @param array $payload
* @return PresentationActionType
* @throws ValidationException
*/
public function add(Summit $summit, array $payload):PresentationActionType;
/**
* @param Summit $summit
* @param int $action_type_id
* @param array $payload
* @return PresentationActionType|null
* @throws ValidationException
* @throws EntityNotFoundException
*/
public function update(Summit $summit, int $action_type_id, array $payload):?PresentationActionType;
/**
* @param Summit $summit
* @param int $action_type_id
* @throws ValidationException
* @throws EntityNotFoundException
*/
public function delete(Summit $summit, int $action_type_id):void;
}

View File

@ -0,0 +1,98 @@
<?php namespace App\Services\Model\Imp;
/**
* Copyright 2021 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 App\Models\Foundation\Main\OrderableChilds;
use App\Models\Foundation\Summit\Factories\PresentationActionTypeFactory;
use App\Models\Foundation\Summit\Repositories\IPresentationActionTypeRepository;
use App\Services\Model\AbstractService;
use App\Services\Model\ISummitPresentationActionTypeService;
use libs\utils\ITransactionService;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use models\summit\PresentationActionType;
use models\summit\Summit;
/**
* Class SummitPresentationActionTypeService
* @package App\Services\Model\Imp
*/
final class SummitPresentationActionTypeService
extends AbstractService
implements ISummitPresentationActionTypeService
{
use OrderableChilds;
/**
* @var IPresentationActionTypeRepository
*/
private $repository;
public function __construct
(
IPresentationActionTypeRepository $repository,
ITransactionService $tx_service
)
{
parent::__construct($tx_service);
$this->repository = $repository;
}
/**
* @inheritDoc
*/
public function add(Summit $summit, array $payload): PresentationActionType
{
return $this->tx_service->transaction(function() use($summit, $payload){
$action = PresentationActionTypeFactory::build($payload);
$max_order = $summit->getPresentationActionTypeMaxOrder();
$action->setOrder($max_order + 1);
$summit->addPresentationActionType($action);
return $action;
});
}
/**
* @inheritDoc
*/
public function update(Summit $summit, int $action_type_id, array $payload): ?PresentationActionType
{
return $this->tx_service->transaction(function() use($summit, $action_type_id, $payload){
$action = $summit->getPresentationActionTypeById($action_type_id);
if(is_null($action)){
throw new EntityNotFoundException(sprintf("PresentationActionType %s not found.", $action_type_id));
}
$action = PresentationActionTypeFactory::populate($action, $payload);
if (isset($payload['order']) && intval($payload['order']) != $action->getOrder()) {
// request to update order
self::recalculateOrderForCollection($summit->getPresentationActionTypes()->toArray(), $action, intval($payload['order']));
}
return $action;
});
}
/**
* @inheritDoc
*/
public function delete(Summit $summit, int $action_type_id): void
{
$this->tx_service->transaction(function() use($summit, $action_type_id){
$action = $summit->getPresentationActionTypeById($action_type_id);
if(is_null($action)){
throw new EntityNotFoundException(sprintf("PresentationActionType %s not found.", $action_type_id));
}
$summit->removePresentationActionType($action);
});
}
}

View File

@ -43,6 +43,7 @@ use App\Services\Model\Imp\SummitEmailEventFlowService;
use App\Services\Model\Imp\SummitMediaFileTypeService;
use App\Services\Model\Imp\SummitMediaUploadTypeService;
use App\Services\Model\Imp\SummitMetricService;
use App\Services\Model\Imp\SummitPresentationActionTypeService;
use App\Services\Model\Imp\SummitRegistrationInvitationService;
use App\Services\Model\Imp\SummitSelectedPresentationListService;
use App\Services\Model\Imp\TrackChairService;
@ -68,6 +69,7 @@ use App\Services\Model\ISummitMediaUploadTypeService;
use App\Services\Model\ISummitMetricService;
use App\Services\Model\ISummitOrderExtraQuestionTypeService;
use App\Services\Model\ISummitOrderService;
use App\Services\Model\ISummitPresentationActionTypeService;
use App\Services\Model\ISummitPushNotificationService;
use App\Services\Model\ISummitRefundPolicyTypeService;
use App\Services\Model\ISummitRegistrationInvitationService;
@ -420,6 +422,11 @@ final class ModelServicesProvider extends ServiceProvider
ITrackChairService::class,
TrackChairService::class
);
App::singleton(
ISummitPresentationActionTypeService::class,
SummitPresentationActionTypeService::class
);
}
/**
@ -482,6 +489,7 @@ final class ModelServicesProvider extends ServiceProvider
ISummitMetricService::class,
ISummitSelectedPresentationListService::class,
ITrackChairService::class,
ISummitPresentationActionTypeService::class,
];
}
}

View File

@ -0,0 +1,94 @@
<?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 Version20210326171114
* @package Database\Migrations\Model
*/
class Version20210326171114 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$builder = new Builder($schema);
if(!$schema->hasTable("PresentationActionType")) {
$builder->create('PresentationActionType', function (Table $table) {
$table->integer("ID", true, false);
$table->primary("ID");
$table->timestamp('Created');
$table->timestamp('LastEdited');
$table->string('ClassName')->setDefault("PresentationActionType");
$table->string('Label')->setNotnull(true)->setLength(255);
$table->integer('Order')->setDefault(1);
// FK
$table->integer("SummitID", false, false)->setNotnull(false)->setDefault('NULL');
$table->index("SummitID", "SummitID");
$table->foreign("Summit", "SummitID", "ID", ["onDelete" => "CASCADE"]);
$table->unique(["SummitID", "Label"]);
});
}
if(!$schema->hasTable("PresentationAction")) {
$builder->create('PresentationAction', function (Table $table) {
$table->integer("ID", true, false);
$table->primary("ID");
$table->timestamp('Created');
$table->timestamp('LastEdited');
$table->string('ClassName')->setDefault("PresentationAction");
$table->boolean('IsCompleted')->setDefault(false);
// FK
$table->integer("TypeID", false, false)->setNotnull(false)->setDefault('NULL');
$table->index("TypeID", "TypeID");
$table->foreign("PresentationActionType", "TypeID", "ID", ["onDelete" => "CASCADE"]);
$table->integer("PresentationID", false, false)->setNotnull(false)->setDefault('NULL');
$table->index("PresentationID", "PresentationID");
$table->foreign("Presentation", "PresentationID", "ID", ["onDelete" => "CASCADE"]);
$table->integer("CreatedByID", false, false)->setNotnull(false)->setDefault('NULL');
$table->index("CreatedByID", "CreatedByID");
$table->foreign("Member", "CreatedByID", "ID", ["onDelete" => "SET NULL"]);
$table->integer("UpdateByID", false, false)->setNotnull(false)->setDefault('NULL');
$table->index("UpdateByID", "UpdateByID");
$table->foreign("Member", "UpdateByID", "ID", ["onDelete" => "SET NULL"]);
$table->unique(["PresentationID", "TypeID"]);
});
}
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
}
}

View File

@ -0,0 +1,52 @@
<?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 Version20210326171117
* @package Database\Migrations\Model
*/
class Version20210326171117 extends AbstractMigration
{
/**
* @param Schema $schema
*/
public function up(Schema $schema)
{
$sql = <<<SQL
ALTER TABLE PresentationActionType MODIFY ClassName
enum(
'PresentationActionType'
) default 'PresentationActionType' null;
SQL;
$this->addSql($sql);
$sql = <<<SQL
ALTER TABLE PresentationAction MODIFY ClassName
enum(
'PresentationAction'
) default 'PresentationAction' null;
SQL;
$this->addSql($sql);
}
/**
* @param Schema $schema
*/
public function down(Schema $schema)
{
}
}

View File

@ -6445,6 +6445,93 @@ class ApiEndpointsSeeder extends Seeder
IGroup::SummitAdministrators,
]
],
[
'name' => 'get-presentation-action-types',
'route' => '/api/v1/summits/{id}/presentation-action-types',
'http_method' => 'GET',
'scopes' => [
sprintf(SummitScopes::ReadAllSummitData, $current_realm),
sprintf(SummitScopes::ReadSummitData, $current_realm)
],
'authz_groups' => [
IGroup::SuperAdmins,
IGroup::Administrators,
IGroup::SummitAdministrators,
IGroup::TrackChairsAdmins,
]
],
[
'name' => 'get-presentation-action-types-csv',
'route' => '/api/v1/summits/{id}/presentation-action-types/csv',
'http_method' => 'GET',
'scopes' => [
sprintf(SummitScopes::ReadAllSummitData, $current_realm),
sprintf(SummitScopes::ReadSummitData, $current_realm)
],
'authz_groups' => [
IGroup::SuperAdmins,
IGroup::Administrators,
IGroup::SummitAdministrators,
IGroup::TrackChairsAdmins,
]
],
[
'name' => 'add-presentation-action-types',
'route' => '/api/v1/summits/{id}/presentation-action-types',
'http_method' => 'POST',
'scopes' => [
sprintf(SummitScopes::WriteSummitData, $current_realm),
],
'authz_groups' => [
IGroup::SuperAdmins,
IGroup::Administrators,
IGroup::SummitAdministrators,
IGroup::TrackChairsAdmins,
]
],
[
'name' => 'get-presentation-action-type-by-id',
'route' => '/api/v1/summits/{id}/presentation-action-types/{action_id}',
'http_method' => 'GET',
'scopes' => [
sprintf(SummitScopes::ReadAllSummitData, $current_realm),
sprintf(SummitScopes::ReadSummitData, $current_realm)
],
'authz_groups' => [
IGroup::SuperAdmins,
IGroup::Administrators,
IGroup::SummitAdministrators,
IGroup::TrackChairsAdmins,
]
],
[
'name' => 'delete-presentation-action-type',
'route' => '/api/v1/summits/{id}/presentation-action-types/{action_id}',
'http_method' => 'DELETE',
'scopes' => [
sprintf(SummitScopes::WriteSummitData, $current_realm),
],
'authz_groups' => [
IGroup::SuperAdmins,
IGroup::Administrators,
IGroup::SummitAdministrators,
IGroup::TrackChairsAdmins,
]
],
[
'name' => 'update-presentation-action-type',
'route' => '/api/v1/summits/{id}/presentation-action-types/{action_id}',
'http_method' => 'PUT',
'scopes' => [
sprintf(SummitScopes::WriteSummitData, $current_realm),
],
'authz_groups' => [
IGroup::SuperAdmins,
IGroup::Administrators,
IGroup::SummitAdministrators,
IGroup::TrackChairsAdmins,
]
]
]
);
}

View File

@ -11,10 +11,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
/**
* Class TestSeeder
*/
@ -23,6 +22,14 @@ final class TestSeeder extends Seeder
public function run()
{
Model::unguard();
DB::setDefaultConnection("model");
DB::table('Summit')->delete();
DB::table('SummitEventType')->delete();
DB::table('PresentationType')->delete();
DB::table('SummitAbstractLocation')->delete();
DB::table('SummitGeoLocatedLocation')->delete();
DB::table('SummitVenue')->delete();
DB::setDefaultConnection("config");
$this->call('ApiSeeder');
$this->call('ApiScopesSeeder');
$this->call('ApiEndpointsSeeder');

View File

@ -0,0 +1,282 @@
<?php namespace Tests;
/**
* Copyright 2021 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 App\Models\Foundation\Main\IGroup;
use models\summit\PresentationActionType;
use ProtectedApiTest;
/**
* Class OAuth2SummitPresentationActionTypeApiTest
* @package Tests
*/
final class OAuth2SummitPresentationActionTypeApiTest extends ProtectedApiTest
{
use \InsertSummitTestData;
use \InsertMemberTestData;
static $action1 = null;
static $action2 = null;
protected function setUp()
{
$this->setCurrentGroup(IGroup::TrackChairs);
parent::setUp();
self::insertTestData();
self::$summit_permission_group->addMember(self::$member);
self::$em->persist(self::$summit);
self::$em->persist(self::$summit_permission_group);
self::$em->flush();
$track_chair = self::$summit->addTrackChair(self::$member, [ self::$defaultTrack ] );
self::$action1 = new PresentationActionType();
self::$action1->setLabel("ACTION1");
self::$action1->setOrder(1);
self::$summit->addPresentationActionType(self::$action1);
self::$action2 = new PresentationActionType();
self::$action2->setLabel("ACTION2");
self::$action2->setOrder(2);
self::$summit->addPresentationActionType(self::$action2);
self::$em->persist(self::$summit);
self::$em->flush();
}
protected function tearDown()
{
self::clearTestData();
parent::tearDown();
}
public function testGetAllPerSummit(){
$params = [
'summit_id' => self::$summit->getId(),
'page' => 1,
'per_page' => 10,
'order' => '+order',
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"GET",
"OAuth2SummitPresentationActionTypeApiController@getAllBySummit",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$page = json_decode($content);
$this->assertTrue(!is_null($page));
$this->assertTrue($page->total == 2);
}
public function testGetAllPerSummitWithFiltering(){
$params = [
'summit_id' => self::$summit->getId(),
'filter' => 'label==ACTION1',
'page' => 1,
'per_page' => 10,
'order' => '+order',
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"GET",
"OAuth2SummitPresentationActionTypeApiController@getAllBySummit",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$page = json_decode($content);
$this->assertTrue(!is_null($page));
$this->assertTrue($page->total == 1);
}
public function testGetActionTypeById(){
$params = [
'summit_id' => self::$summit->getId(),
'action_id' => self::$action1->getId(),
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"GET",
"OAuth2SummitPresentationActionTypeApiController@get",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$action = json_decode($content);
$this->assertTrue(!is_null($action));
$this->assertTrue($action->id == self::$action1->getId());
}
public function testReorderAction(){
$params = [
'summit_id' => self::$summit->getId(),
'action_id' => self::$action2->getId(),
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$payload = [
'order' => 1,
];
$response = $this->action(
"PUT",
"OAuth2SummitPresentationActionTypeApiController@update",
$params,
[],
[],
[],
$headers,
json_encode($payload)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$action = json_decode($content);
$this->assertTrue(!is_null($action));
$this->assertTrue($action->id == self::$action2->getId());
$this->assertTrue($action->order == 1);
}
public function testAddAction(){
$params = [
'summit_id' => self::$summit->getId(),
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$payload = [
'label' => "ACTION3",
];
$response = $this->action(
"POST",
"OAuth2SummitPresentationActionTypeApiController@add",
$params,
[],
[],
[],
$headers,
json_encode($payload)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$action = json_decode($content);
$this->assertTrue(!is_null($action));
$this->assertTrue($action->label == "ACTION3");
$this->assertTrue($action->order == 3);
}
public function testUpdateAction(){
$params = [
'summit_id' => self::$summit->getId(),
'action_id' => self::$action2->getId(),
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$payload = [
'label' => self::$action2->getLabel()." UPDATE",
];
$response = $this->action(
"PUT",
"OAuth2SummitPresentationActionTypeApiController@update",
$params,
[],
[],
[],
$headers,
json_encode($payload)
);
$content = $response->getContent();
$this->assertResponseStatus(201);
$action = json_decode($content);
$this->assertTrue(!is_null($action));
$this->assertTrue($action->id == self::$action2->getId());
$this->assertTrue($action->label == self::$action2->getLabel());
}
public function testDeleteAction(){
$params = [
'summit_id' => self::$summit->getId(),
'action_id' => self::$action2->getId(),
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"DELETE",
"OAuth2SummitPresentationActionTypeApiController@delete",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(204);
$this->assertTrue(empty($content));
}
}