Added new Bulk events endpoints
PUT /api/v1/summits/{id}/events PUT /api/v1/summits/{id}/events/publish DELETE /api/v1/summits/{id}/events/publish Change-Id: Ic6ae2fc72fd6e0b2305c031ae95eb10068b2eff5
This commit is contained in:
parent
e1546336a3
commit
b0182a519e
@ -283,16 +283,27 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
|
||||
|
||||
$rules = array
|
||||
(
|
||||
'title' => 'required|string|max:100',
|
||||
'description' => 'required|string',
|
||||
'social_summary' => 'sometimes|string|max:100',
|
||||
'location_id' => 'sometimes|required|integer',
|
||||
'start_date' => 'sometimes|required|date_format:U',
|
||||
'end_date' => 'sometimes|required_with:start_date|date_format:U|after:start_date',
|
||||
'allow_feedback' => 'sometimes|required|boolean',
|
||||
'type_id' => 'required|integer',
|
||||
'track_id' => 'required|integer',
|
||||
'tags' => 'sometimes|required|string_array',
|
||||
'title' => 'required|string|max:100',
|
||||
'description' => 'required|string',
|
||||
'type_id' => 'required|integer',
|
||||
'location_id' => 'sometimes|integer',
|
||||
'start_date' => 'sometimes|required|date_format:U',
|
||||
'end_date' => 'sometimes|required_with:start_date|date_format:U|after:start_date',
|
||||
'track_id' => 'required|integer',
|
||||
'rsvp_link' => 'sometimes|url',
|
||||
'head_count' => 'sometimes|integer',
|
||||
'social_description' => 'sometimes|string|max:100',
|
||||
'allow_feedback' => 'sometimes|boolean',
|
||||
'tags' => 'sometimes|string_array',
|
||||
'sponsors' => 'sometimes|int_array',
|
||||
// presentation rules
|
||||
'attendees_expected_learnt' => 'sometimes|string|max:100',
|
||||
'feature_cloud' => 'sometimes|boolean',
|
||||
'to_record' => 'sometimes|boolean',
|
||||
'speakers' => 'sometimes|int_array',
|
||||
'moderator_speaker_id' => 'sometimes|integer',
|
||||
// group event
|
||||
'groups' => 'sometimes|int_array',
|
||||
);
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
@ -348,16 +359,28 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
|
||||
$data = Input::json();
|
||||
|
||||
$rules = [
|
||||
'title' => 'sometimes|required|string|max:100',
|
||||
'description' => 'sometimes|string',
|
||||
'social_summary' => 'sometimes|string|max:100',
|
||||
'location_id' => 'sometimes|integer',
|
||||
'start_date' => 'sometimes|date_format:U',
|
||||
'end_date' => 'sometimes|required_with:start_date|date_format:U|after:start_date',
|
||||
'allow_feedback' => 'sometimes|boolean',
|
||||
'type_id' => 'sometimes|required|integer',
|
||||
'track_id' => 'sometimes|required|integer',
|
||||
'tags' => 'sometimes|string_array',
|
||||
// summit event rules
|
||||
'title' => 'sometimes|string|max:100',
|
||||
'description' => 'sometimes|string',
|
||||
'rsvp_link' => 'sometimes|url',
|
||||
'head_count' => 'sometimes|integer',
|
||||
'social_description' => 'sometimes|string|max:100',
|
||||
'location_id' => 'sometimes|integer',
|
||||
'start_date' => 'sometimes|date_format:U',
|
||||
'end_date' => 'sometimes|required_with:start_date|date_format:U|after:start_date',
|
||||
'allow_feedback' => 'sometimes|boolean',
|
||||
'type_id' => 'sometimes|required|integer',
|
||||
'track_id' => 'sometimes|required|integer',
|
||||
'tags' => 'sometimes|string_array',
|
||||
'sponsors' => 'sometimes|int_array',
|
||||
// presentation rules
|
||||
'attendees_expected_learnt' => 'sometimes|string|max:100',
|
||||
'feature_cloud' => 'sometimes|boolean',
|
||||
'to_record' => 'sometimes|boolean',
|
||||
'speakers' => 'sometimes|int_array',
|
||||
'moderator_speaker_id' => 'sometimes|integer',
|
||||
// group event
|
||||
'groups' => 'sometimes|int_array',
|
||||
];
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
@ -937,4 +960,139 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
|
||||
}
|
||||
}
|
||||
|
||||
public function unPublishEvents($summit_id){
|
||||
try {
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
if(!Request::isJson()) return $this->error403();
|
||||
|
||||
$data = Input::json();
|
||||
|
||||
$rules = [
|
||||
'events' => 'required|int_array',
|
||||
];
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($data->all(), $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$this->service->unPublishEvents($summit, $data->all());
|
||||
|
||||
return $this->deleted();
|
||||
}
|
||||
catch (ValidationException $ex1)
|
||||
{
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateAndPublishEvents($summit_id){
|
||||
try {
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
if(!Request::isJson()) return $this->error403();
|
||||
|
||||
$data = Input::json();
|
||||
|
||||
$rules = [
|
||||
'events' => 'required|event_dto_publish_array',
|
||||
];
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($data->all(), $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$this->service->updateAndPublishEvents($summit, $data->all());
|
||||
|
||||
return $this->updated();
|
||||
}
|
||||
catch (ValidationException $ex1)
|
||||
{
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
public function updateEvents($summit_id){
|
||||
try {
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
if(!Request::isJson()) return $this->error403();
|
||||
|
||||
$data = Input::json();
|
||||
|
||||
$rules = [
|
||||
'events' => 'required|event_dto_array',
|
||||
];
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($data->all(), $rules);
|
||||
|
||||
if ($validation->fails()) {
|
||||
$messages = $validation->messages()->toArray();
|
||||
|
||||
return $this->error412
|
||||
(
|
||||
$messages
|
||||
);
|
||||
}
|
||||
|
||||
$this->service->updateEvents($summit, $data->all());
|
||||
|
||||
return $this->updated();
|
||||
}
|
||||
catch (ValidationException $ex1)
|
||||
{
|
||||
Log::warning($ex1);
|
||||
return $this->error412(array($ex1->getMessage()));
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(array('message'=> $ex2->getMessage()));
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -32,15 +32,14 @@ abstract class RetrieveSummitEventsStrategy
|
||||
* @return PagingResponse
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function getEvents(array $params = array())
|
||||
public function getEvents(array $params = [])
|
||||
{
|
||||
$values = Input::all();
|
||||
|
||||
$rules = array
|
||||
(
|
||||
$rules = [
|
||||
'page' => 'integer|min:1',
|
||||
'per_page' => 'required_with:page|integer|min:5|max:100',
|
||||
);
|
||||
];
|
||||
|
||||
$validation = Validator::make($values, $rules);
|
||||
|
||||
@ -83,14 +82,14 @@ abstract class RetrieveSummitEventsStrategy
|
||||
$order = null;
|
||||
if (Input::has('order'))
|
||||
{
|
||||
$order = OrderParser::parse(Input::get('order'), array
|
||||
(
|
||||
$order = OrderParser::parse(Input::get('order'), [
|
||||
|
||||
'title',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'id',
|
||||
'created',
|
||||
));
|
||||
]);
|
||||
}
|
||||
return $order;
|
||||
}
|
||||
@ -107,8 +106,8 @@ abstract class RetrieveSummitEventsStrategy
|
||||
*/
|
||||
protected function getValidFilters()
|
||||
{
|
||||
return array
|
||||
(
|
||||
return [
|
||||
|
||||
'title' => ['=@', '=='],
|
||||
'abstract' => ['=@', '=='],
|
||||
'social_summary' => ['=@', '=='],
|
||||
@ -121,6 +120,7 @@ abstract class RetrieveSummitEventsStrategy
|
||||
'speaker' => ['=@', '=='],
|
||||
'speaker_email' => ['=@', '=='],
|
||||
'selection_status' => ['=='],
|
||||
);
|
||||
'id' => ['=='],
|
||||
];
|
||||
}
|
||||
}
|
@ -194,6 +194,11 @@ Route::group([
|
||||
Route::group(array('prefix' => 'events'), function () {
|
||||
|
||||
Route::get('', 'OAuth2SummitEventsApiController@getEvents');
|
||||
// bulk actions
|
||||
Route::delete('/publish', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@unPublishEvents']);
|
||||
Route::put('/publish', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@updateAndPublishEvents']);
|
||||
Route::put('', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@updateEvents']);
|
||||
|
||||
Route::group(array('prefix' => 'unpublished'), function () {
|
||||
Route::get('', 'OAuth2SummitEventsApiController@getUnpublishedEvents');
|
||||
//Route::get('{event_id}', 'OAuth2SummitEventsApiController@getUnpublisedEvent');
|
||||
|
@ -15,6 +15,71 @@ use Monolog\Handler\NativeMailerHandler;
|
||||
*/
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
|
||||
static $event_dto_fields = [
|
||||
'id',
|
||||
'title',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'type_id',
|
||||
'track_id',
|
||||
'location_id',
|
||||
'description',
|
||||
'rsvp_link',
|
||||
'head_count',
|
||||
'social_description',
|
||||
'allow_feedback',
|
||||
'tags',
|
||||
'sponsors',
|
||||
'attendees_expected_learnt',
|
||||
'level',
|
||||
'feature_cloud',
|
||||
'to_record',
|
||||
'speakers',
|
||||
'moderator_speaker_id',
|
||||
'groups'
|
||||
];
|
||||
|
||||
static $event_dto_fields_publish = [
|
||||
'id',
|
||||
'start_date',
|
||||
'end_date',
|
||||
'location_id',
|
||||
];
|
||||
|
||||
static $event_dto_publish_validation_rules = [
|
||||
'id' => 'required|integer',
|
||||
'location_id' => 'required|integer',
|
||||
'start_date' => 'required|date_format:U',
|
||||
'end_date' => 'required_with:start_date|date_format:U|after:start_date',
|
||||
];
|
||||
|
||||
static $event_dto_validation_rules = [
|
||||
// summit event rules
|
||||
'id' => 'required|integer',
|
||||
'title' => 'sometimes|string|max:100',
|
||||
'description' => 'sometimes|string',
|
||||
'rsvp_link' => 'sometimes|url',
|
||||
'head_count' => 'sometimes|integer',
|
||||
'social_description' => 'sometimes|string|max:100',
|
||||
'location_id' => 'sometimes|integer',
|
||||
'start_date' => 'sometimes|date_format:U',
|
||||
'end_date' => 'sometimes|required_with:start_date|date_format:U|after:start_date',
|
||||
'allow_feedback' => 'sometimes|boolean',
|
||||
'type_id' => 'sometimes|required|integer',
|
||||
'track_id' => 'sometimes|required|integer',
|
||||
'tags' => 'sometimes|string_array',
|
||||
'sponsors' => 'sometimes|int_array',
|
||||
// presentation rules
|
||||
'attendees_expected_learnt' => 'sometimes|string|max:100',
|
||||
'feature_cloud' => 'sometimes|boolean',
|
||||
'to_record' => 'sometimes|boolean',
|
||||
'speakers' => 'sometimes|int_array',
|
||||
'moderator_speaker_id' => 'sometimes|integer',
|
||||
// group event
|
||||
'groups' => 'sometimes|int_array',
|
||||
];
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
* @return void
|
||||
@ -51,6 +116,53 @@ class AppServiceProvider extends ServiceProvider
|
||||
return true;
|
||||
});
|
||||
|
||||
Validator::extend('event_dto_array', function($attribute, $value, $parameters, $validator)
|
||||
{
|
||||
$validator->addReplacer('event_dto_array', function($message, $attribute, $rule, $parameters) use ($validator) {
|
||||
return sprintf
|
||||
(
|
||||
"%s should be an array of event data {id : int, location_id: int, start_date: int (epoch), end_date: int (epoch)}",
|
||||
$attribute);
|
||||
});
|
||||
if(!is_array($value)) return false;
|
||||
foreach($value as $element)
|
||||
{
|
||||
foreach($element as $key => $element_val){
|
||||
if(!in_array($key, self::$event_dto_fields)) return false;
|
||||
}
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($element, self::$event_dto_validation_rules);
|
||||
|
||||
if($validation->fails()) return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
Validator::extend('event_dto_publish_array', function($attribute, $value, $parameters, $validator)
|
||||
{
|
||||
$validator->addReplacer('event_dto_publish_array', function($message, $attribute, $rule, $parameters) use ($validator) {
|
||||
return sprintf
|
||||
(
|
||||
"%s should be an array of event data {id : int, location_id: int, start_date: int (epoch), end_date: int (epoch)}",
|
||||
$attribute);
|
||||
});
|
||||
if(!is_array($value)) return false;
|
||||
foreach($value as $element)
|
||||
{
|
||||
foreach($element as $key => $element_val){
|
||||
if(!in_array($key, self::$event_dto_fields_publish)) return false;
|
||||
}
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make($element, self::$event_dto_publish_validation_rules);
|
||||
|
||||
if($validation->fails()) return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
|
||||
Validator::extend('text', function($attribute, $value, $parameters, $validator)
|
||||
{
|
||||
$validator->addReplacer('text', function($message, $attribute, $rule, $parameters) use ($validator) {
|
||||
|
@ -14,7 +14,7 @@
|
||||
**/
|
||||
|
||||
use Doctrine\ORM\QueryBuilder;
|
||||
|
||||
use Illuminate\Support\Facades\App;
|
||||
/**
|
||||
* Class SilverStripeDoctrineRepository
|
||||
* @package App\Repositories
|
||||
@ -46,4 +46,19 @@ abstract class SilverStripeDoctrineRepository extends DoctrineRepository
|
||||
protected function applyExtraFilters(QueryBuilder $query){
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group_code
|
||||
* @return bool
|
||||
*/
|
||||
protected static function isCurrentMemberOnGroup($group_code){
|
||||
$resource_server_ctx = App::make(\models\oauth2\IResourceServerContext::class);
|
||||
$member_repository = App::make(\models\main\IMemberRepository::class);
|
||||
$member_id = $resource_server_ctx->getCurrentUserExternalId();
|
||||
$member = $member_repository->getById($member_id);
|
||||
if (!is_null($member)){
|
||||
return $member->isOnGroup($group_code);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
* limitations under the License.
|
||||
**/
|
||||
use Doctrine\ORM\Tools\Pagination\Paginator;
|
||||
use models\main\Group;
|
||||
use models\summit\ISummitEventRepository;
|
||||
use models\summit\SummitEvent;
|
||||
use App\Repositories\SilverStripeDoctrineRepository;
|
||||
@ -34,6 +35,7 @@ final class DoctrineSummitEventRepository
|
||||
implements ISummitEventRepository
|
||||
{
|
||||
|
||||
|
||||
private static $forbidded_classes = [
|
||||
'models\\summit\\SummitGroupEvent'
|
||||
];
|
||||
@ -67,6 +69,7 @@ final class DoctrineSummitEventRepository
|
||||
protected function getFilterMappings()
|
||||
{
|
||||
return [
|
||||
'id' => 'e.id:json_int',
|
||||
'title' => 'e.title:json_string',
|
||||
'abstract' => 'e.abstract:json_string',
|
||||
'social_summary' => 'e.social_summary:json_string',
|
||||
@ -199,8 +202,14 @@ final class DoctrineSummitEventRepository
|
||||
$query = $query->leftJoin('sp.registration_request', "sprr", Join::LEFT_JOIN);
|
||||
}
|
||||
|
||||
$can_view_private_events = self::isCurrentMemberOnGroup(Group::SummitAdministrators);
|
||||
|
||||
if(!$can_view_private_events){
|
||||
$query = $query
|
||||
->andWhere("not e INSTANCE OF ('" . implode("','", self::$forbidded_classes) . "')");
|
||||
}
|
||||
|
||||
$query = $query
|
||||
->andWhere("not e INSTANCE OF ('" . implode("','", self::$forbidded_classes) . "')")
|
||||
->setFirstResult($paging_info->getOffset())
|
||||
->setMaxResults($paging_info->getPerPage());
|
||||
|
||||
@ -283,8 +292,15 @@ final class DoctrineSummitEventRepository
|
||||
$query = $query->leftJoin('sp.registration_request', "sprr", Join::LEFT_JOIN);
|
||||
}
|
||||
|
||||
|
||||
$can_view_private_events = self::isCurrentMemberOnGroup(Group::SummitAdministrators);
|
||||
|
||||
if(!$can_view_private_events){
|
||||
$query = $query
|
||||
->andWhere("not e INSTANCE OF ('" . implode("','", self::$forbidded_classes) . "')");
|
||||
}
|
||||
|
||||
$query = $query
|
||||
->andWhere("not e INSTANCE OF ('" . implode("','", self::$forbidded_classes) . "')")
|
||||
->setFirstResult($paging_info->getOffset())
|
||||
->setMaxResults($paging_info->getPerPage());
|
||||
|
||||
|
@ -24,4 +24,8 @@ final class SummitScopes
|
||||
|
||||
const WriteSummitData = '%s/summits/write';
|
||||
const WriteSpeakersData = '%s/speakers/write';
|
||||
|
||||
const PublishEventData = '%s/summits/publish-event';
|
||||
const WriteEventData = '%s/summits/write-event';
|
||||
const WriteVideoData = '%s/summits/write-videos';
|
||||
}
|
@ -169,4 +169,31 @@ interface ISummitService
|
||||
Summit $summit,
|
||||
Filter $filter
|
||||
);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
* @return bool
|
||||
*/
|
||||
public function unPublishEvents(Summit $summit, array $data);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
* @return bool
|
||||
*/
|
||||
public function updateAndPublishEvents(Summit $summit, array $data);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
* @return bool
|
||||
*/
|
||||
public function updateEvents(Summit $summit, array $data);
|
||||
}
|
@ -569,6 +569,24 @@ final class SummitService implements ISummitService
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SummitEventType $old_event_type
|
||||
* @param SummitEventType $event_type
|
||||
* @return bool
|
||||
*/
|
||||
private function canPerformEventTypeTransition(SummitEventType $old_event_type, SummitEventType $event_type){
|
||||
// cant upgrade from raw event to presentation and vice versa
|
||||
if($old_event_type->getClassName() != $event_type->getClassName()) return false;
|
||||
|
||||
if(!(SummitEventType::isPrivate($old_event_type->getType()) && SummitEventType::isPrivate($event_type->getType())))
|
||||
return false;
|
||||
|
||||
if(!($old_event_type->isAllowsAttachment() && $event_type->isAllowsAttachment()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
@ -606,27 +624,36 @@ final class SummitService implements ISummitService
|
||||
}
|
||||
}
|
||||
|
||||
if (is_null($event_id)) {
|
||||
$event = SummitEventFactory::build($event_type);
|
||||
} else {
|
||||
$event = null;
|
||||
// existing event
|
||||
|
||||
if (!is_null($event_id) && intval($event_id) > 0 ) {
|
||||
$event = $this->event_repository->getById($event_id);
|
||||
if (is_null($event))
|
||||
throw new ValidationException(sprintf("event id %s does not exists!", $event_id));
|
||||
$old_event_type = $event->getType();
|
||||
if($event_type != null && $old_event_type->getClassName() != $event_type->getClassName()){
|
||||
throw new ValidationException
|
||||
(
|
||||
sprintf
|
||||
|
||||
// check event type transition ...
|
||||
|
||||
if(!is_null($event_type) && !$this->canPerformEventTypeTransition($old_event_type, $event_type)){
|
||||
throw new ValidationException
|
||||
(
|
||||
"invalid event type transition for event id %s ( from %s to %s)",
|
||||
$event_id,
|
||||
$old_event_type->getClassName(),
|
||||
$event_type->getClassName()
|
||||
)
|
||||
);
|
||||
sprintf
|
||||
(
|
||||
"invalid event type transition for event id %s ( from %s to %s)",
|
||||
$event_id,
|
||||
$old_event_type->getType(),
|
||||
$event_type->getType()
|
||||
)
|
||||
);
|
||||
}
|
||||
if(is_null($event_type)) $event_type = $old_event_type;
|
||||
}
|
||||
|
||||
// new event
|
||||
if (is_null($event))
|
||||
$event = SummitEventFactory::build($event_type);
|
||||
|
||||
// main data
|
||||
|
||||
if (isset($data['title']))
|
||||
@ -1352,4 +1379,74 @@ final class SummitService implements ISummitService
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
* @return bool
|
||||
*/
|
||||
public function unPublishEvents(Summit $summit, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use
|
||||
(
|
||||
$summit,
|
||||
$data
|
||||
)
|
||||
{
|
||||
foreach ($data['events'] as $event_id){
|
||||
$this->unPublishEvent($summit, intval($event_id));
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
* @return bool
|
||||
*/
|
||||
public function updateAndPublishEvents(Summit $summit, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use
|
||||
(
|
||||
$summit,
|
||||
$data
|
||||
)
|
||||
{
|
||||
foreach ($data['events'] as $event_data){
|
||||
$this->updateEvent($summit, intval($event_data['id']), $event_data);
|
||||
$this->publishEvent($summit, intval($event_data['id']), $event_data);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param array $data
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
* @return bool
|
||||
*/
|
||||
public function updateEvents(Summit $summit, array $data)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use
|
||||
(
|
||||
$summit,
|
||||
$data
|
||||
)
|
||||
{
|
||||
foreach ($data['events'] as $event_data){
|
||||
$this->updateEvent($summit, intval($event_data['id']), $event_data);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
@ -133,19 +133,19 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'name' => 'add-event-attendee-schedule',
|
||||
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'delete-event-attendee-schedule',
|
||||
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'checking-event-attendee-schedule',
|
||||
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}/check-in',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
// speakers
|
||||
array(
|
||||
@ -203,7 +203,7 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'name' => 'add-speaker-feedback',
|
||||
'route' => '/api/v1/summits/{id}/speakers/{speaker_id}/presentations/{presentation_id}/feedback',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
// events
|
||||
array(
|
||||
@ -282,25 +282,43 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'name' => 'add-event',
|
||||
'route' => '/api/v1/summits/{id}/events',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write-event', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteEventData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'update-event',
|
||||
'route' => '/api/v1/summits/{id}/events/{event_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [sprintf('%s/summits/write-event', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteEventData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'update-events',
|
||||
'route' => '/api/v1/summits/{id}/events',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [sprintf(SummitScopes::WriteEventData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'publish-event',
|
||||
'route' => '/api/v1/summits/{id}/events/{event_id}/publish',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [sprintf('%s/summits/publish-event', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::PublishEventData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'publish-events',
|
||||
'route' => '/api/v1/summits/{id}/events/publish',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [sprintf(SummitScopes::PublishEventData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'unpublish-event',
|
||||
'route' => '/api/v1/summits/{id}/events/{event_id}/publish',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [sprintf('%s/summits/publish-event', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::PublishEventData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'unpublish-events',
|
||||
'route' => '/api/v1/summits/{id}/events/publish',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [sprintf(SummitScopes::PublishEventData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'delete-event',
|
||||
@ -312,25 +330,25 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'name' => 'add-event-feedback',
|
||||
'route' => '/api/v1/summits/{id}/events/{event_id}/feedback',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'add-event-attachment',
|
||||
'route' => '/api/v1/summits/{id}/events/{event_id}/attachment',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'add-event-feedback-v2',
|
||||
'route' => '/api/v2/summits/{id}/events/{event_id}/feedback',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'update-event-feedback-v2',
|
||||
'route' => '/api/v2/summits/{id}/events/{event_id}/feedback',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'get-event-feedback',
|
||||
@ -345,7 +363,7 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'name' => 'delete-rsvp',
|
||||
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}/rsvp',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
// locations
|
||||
array(
|
||||
@ -503,19 +521,19 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'name' => 'create-presentation-video',
|
||||
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteVideoData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'update-presentation-video',
|
||||
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos/{video_id}',
|
||||
'http_method' => 'PUT',
|
||||
'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteVideoData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'delete-presentation-video',
|
||||
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos/{video_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteVideoData, $current_realm)],
|
||||
),
|
||||
//members
|
||||
array(
|
||||
@ -540,7 +558,7 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'name' => 'delete-rsvp-member',
|
||||
'route' => '/api/v1/summits/{id}/members/{member_id}/schedule/{event_id}/rsvp',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'remove-from-own-member-favorites',
|
||||
@ -558,13 +576,13 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'name' => 'add-2-own-member-schedule',
|
||||
'route' => '/api/v1/summits/{id}/members/{member_id}/schedule/{event_id}',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'remove-from-own-member-schedule',
|
||||
'route' => '/api/v1/summits/{id}/members/{member_id}/schedule/{event_id}',
|
||||
'http_method' => 'DELETE',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
'scopes' => [sprintf(SummitScopes::WriteSummitData, $current_realm)],
|
||||
),
|
||||
// notifications
|
||||
array(
|
||||
|
95
tests/OAuth2SummitEventsBulkActionsTest.php
Normal file
95
tests/OAuth2SummitEventsBulkActionsTest.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2017 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 OAuth2SummitEventsBulkActionsTest extends ProtectedApiTest
|
||||
{
|
||||
public function testUpdateEvents()
|
||||
{
|
||||
$params = [
|
||||
'id' => 23,
|
||||
];
|
||||
|
||||
$data = [
|
||||
|
||||
'events' => [
|
||||
[
|
||||
'id' => 20420,
|
||||
'title' => 'Making OpenContrail an ubiquitous SDN for OpenStack and Kubernetes!'
|
||||
],
|
||||
[
|
||||
'id' => 20421,
|
||||
'title' => 'OpenContrail - from A to B, front to back, top to bottom, past to present, soup to nuts!'
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
|
||||
$headers = [
|
||||
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"PUT",
|
||||
"OAuth2SummitEventsApiController@updateEvents",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers,
|
||||
json_encode($data)
|
||||
);
|
||||
|
||||
$this->assertResponseStatus(204);
|
||||
$content = $response->getContent();
|
||||
}
|
||||
|
||||
public function testGetEventByIdOR()
|
||||
{
|
||||
$params = [
|
||||
'id' => 23,
|
||||
'filter' => [
|
||||
|
||||
'id==20420,id==20421,id==20427,id==20428',
|
||||
]
|
||||
];
|
||||
|
||||
$headers = [
|
||||
|
||||
"HTTP_Authorization" => " Bearer " . $this->access_token,
|
||||
"CONTENT_TYPE" => "application/json"
|
||||
];
|
||||
|
||||
$response = $this->action
|
||||
(
|
||||
"GET",
|
||||
"OAuth2SummitEventsApiController@getEvents",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$this->assertResponseStatus(200);
|
||||
|
||||
$events = json_decode($content);
|
||||
$this->assertTrue(!is_null($events));
|
||||
}
|
||||
|
||||
|
||||
}
|
41
tests/ValidatorTest.php
Normal file
41
tests/ValidatorTest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2017 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\Support\Facades\Validator;
|
||||
|
||||
class ValidatorTest extends TestCase
|
||||
{
|
||||
public function testSummitEventValidator(){
|
||||
$rules = [
|
||||
'title' => 'sometimes|required|string|max:100',
|
||||
'description' => 'sometimes|required|string',
|
||||
'social_summary' => 'sometimes|string|max:100',
|
||||
'location_id' => 'sometimes|integer',
|
||||
'start_date' => 'sometimes|date_format:U',
|
||||
'end_date' => 'sometimes|required_with:start_date|date_format:U|after:start_date',
|
||||
'allow_feedback' => 'sometimes|boolean',
|
||||
'type_id' => 'sometimes|required|integer',
|
||||
'track_id' => 'sometimes|required|integer',
|
||||
'tags' => 'sometimes|string_array',
|
||||
];
|
||||
|
||||
// Creates a Validator instance and validates the data.
|
||||
$validation = Validator::make(['title' => 'test','description'=> '' ], $rules);
|
||||
|
||||
$res = $validation->fails();
|
||||
if($res){
|
||||
$messages = $validation->messages()->toArray();
|
||||
echo $messages;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user