diff --git a/app/Factories/CalendarAdminActionSyncWorkRequest/AdminSummitLocationActionSyncWorkRequestFactory.php b/app/Factories/CalendarAdminActionSyncWorkRequest/AdminSummitLocationActionSyncWorkRequestFactory.php index 7b6601e2..e388d78d 100644 --- a/app/Factories/CalendarAdminActionSyncWorkRequest/AdminSummitLocationActionSyncWorkRequestFactory.php +++ b/app/Factories/CalendarAdminActionSyncWorkRequest/AdminSummitLocationActionSyncWorkRequestFactory.php @@ -29,21 +29,17 @@ final class AdminSummitLocationActionSyncWorkRequestFactory * @return AdminSummitLocationActionSyncWorkRequest */ public static function build(LocationAction $event, $type){ - $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; - - $request = new AdminSummitLocationActionSyncWorkRequest; + $resource_server_context = App::make(IResourceServerContext::class); + $current_member = $resource_server_context->getCurrentUser(); + $request = new AdminSummitLocationActionSyncWorkRequest; $request->setLocationId($event->getLocationId()); $request->setType($type); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - $request->setCreatedBy($member); + if(!is_null($current_member)){ + $request->setCreatedBy($current_member); } return $request; diff --git a/app/Factories/CalendarAdminActionSyncWorkRequest/SummitEventDeletedCalendarSyncWorkRequestFactory.php b/app/Factories/CalendarAdminActionSyncWorkRequest/SummitEventDeletedCalendarSyncWorkRequestFactory.php index 6ab38624..84edbe77 100644 --- a/app/Factories/CalendarAdminActionSyncWorkRequest/SummitEventDeletedCalendarSyncWorkRequestFactory.php +++ b/app/Factories/CalendarAdminActionSyncWorkRequest/SummitEventDeletedCalendarSyncWorkRequestFactory.php @@ -33,22 +33,16 @@ final class SummitEventDeletedCalendarSyncWorkRequestFactory $args = $event->getArgs(); $params = $args->getParams(); $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - } - $request = null; + $current_member = $resource_server_context->getCurrentUser(); + $request = null; if(isset($params['published']) && $params['published']){ // just record the published state at the moment of the update - $request = new AdminSummitEventActionSyncWorkRequest(); $request->setSummitEventId ($params['id']); $request->setType(AbstractCalendarSyncWorkRequest::TypeRemove); - if($owner_id > 0){ - $request->setCreatedBy($member); + if(!is_null($current_member)){ + $request->setCreatedBy($current_member); } - } return $request; } diff --git a/app/Factories/CalendarAdminActionSyncWorkRequest/SummitEventUpdatedCalendarSyncWorkRequestFactory.php b/app/Factories/CalendarAdminActionSyncWorkRequest/SummitEventUpdatedCalendarSyncWorkRequestFactory.php index 47a2ab29..02d85db1 100644 --- a/app/Factories/CalendarAdminActionSyncWorkRequest/SummitEventUpdatedCalendarSyncWorkRequestFactory.php +++ b/app/Factories/CalendarAdminActionSyncWorkRequest/SummitEventUpdatedCalendarSyncWorkRequestFactory.php @@ -27,20 +27,16 @@ final class SummitEventUpdatedCalendarSyncWorkRequestFactory */ public static function build(SummitEventUpdated $event){ $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); $args = $event->getArgs(); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; + $current_member = $resource_server_context->getCurrentUser(); // sync request from admin $request = new AdminSummitEventActionSyncWorkRequest(); $request->setSummitEvent($event->getSummitEvent()) ; $request->setType(AbstractCalendarSyncWorkRequest::TypeUpdate); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - $request->setCreatedBy($member); + if(!is_null($current_member)){ + $request->setCreatedBy($current_member); } - if($args->hasChangedField('published')){ $pub_old = intval($args->getOldValue('published')); $pub_new = intval($args->getNewValue('published')); diff --git a/app/Factories/EntityEvents/FloorActionEntityEventFactory.php b/app/Factories/EntityEvents/FloorActionEntityEventFactory.php index 739d31d0..3cc0d027 100644 --- a/app/Factories/EntityEvents/FloorActionEntityEventFactory.php +++ b/app/Factories/EntityEvents/FloorActionEntityEventFactory.php @@ -32,21 +32,17 @@ final class FloorActionEntityEventFactory public static function build(FloorAction $event, $type = 'UPDATE') { $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); $summit_repository = App::make(ISummitRepository::class); $summit = $summit_repository->getById($event->getSummitId()); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - - if (is_null($owner_id)) $owner_id = 0; + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent; $entity_event->setEntityClassName('SummitVenueFloor'); $entity_event->setEntityId($event->getFloorId()); $entity_event->setType($type); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($summit); diff --git a/app/Factories/EntityEvents/LocationActionEntityEventFactory.php b/app/Factories/EntityEvents/LocationActionEntityEventFactory.php index 572e8379..a3cd0681 100644 --- a/app/Factories/EntityEvents/LocationActionEntityEventFactory.php +++ b/app/Factories/EntityEvents/LocationActionEntityEventFactory.php @@ -32,21 +32,17 @@ final class LocationActionEntityEventFactory public static function build(LocationAction $event, $type = 'UPDATE') { $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); $summit_repository = App::make(ISummitRepository::class); $summit = $summit_repository->getById($event->getSummitId()); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - - if (is_null($owner_id)) $owner_id = 0; + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent; $entity_event->setEntityClassName($event->getLocationClassName()); $entity_event->setEntityId($event->getLocationId()); $entity_event->setType($type); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $metadata = ''; diff --git a/app/Factories/EntityEvents/LocationImageActionEntityEventFactory.php b/app/Factories/EntityEvents/LocationImageActionEntityEventFactory.php index 687df930..ee621d79 100644 --- a/app/Factories/EntityEvents/LocationImageActionEntityEventFactory.php +++ b/app/Factories/EntityEvents/LocationImageActionEntityEventFactory.php @@ -28,21 +28,17 @@ final class LocationImageActionEntityEventFactory public static function build(LocationImageAction $event, $type = 'UPDATE') { $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); $summit_repository = App::make(ISummitRepository::class); $summit = $summit_repository->getById($event->getSummitId()); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - - if (is_null($owner_id)) $owner_id = 0; + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent; $entity_event->setEntityClassName($event->getImageType()); $entity_event->setEntityId($event->getEntityId()); $entity_event->setType($type); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $metadata = json_encode( ['location_id' => $event->getLocationId()]); diff --git a/app/Factories/EntityEvents/PresentationMaterialCreatedEntityEventFactory.php b/app/Factories/EntityEvents/PresentationMaterialCreatedEntityEventFactory.php index 28c06e77..2ce03701 100644 --- a/app/Factories/EntityEvents/PresentationMaterialCreatedEntityEventFactory.php +++ b/app/Factories/EntityEvents/PresentationMaterialCreatedEntityEventFactory.php @@ -25,19 +25,16 @@ final class PresentationMaterialCreatedEntityEventFactory * @return SummitEntityEvent */ public static function build(PresentationMaterialCreated $event){ - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); - $entity_event = new SummitEntityEvent(); + $entity_event = new SummitEntityEvent(); $entity_event->setEntityClassName($event->getMaterial()->getClassName()); $entity_event->setEntityId($event->getMaterial()->getId()); $entity_event->setType('INSERT'); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit()); diff --git a/app/Factories/EntityEvents/PresentationMaterialDeletedEntityEventFactory.php b/app/Factories/EntityEvents/PresentationMaterialDeletedEntityEventFactory.php index 3a62f82e..ed20e655 100644 --- a/app/Factories/EntityEvents/PresentationMaterialDeletedEntityEventFactory.php +++ b/app/Factories/EntityEvents/PresentationMaterialDeletedEntityEventFactory.php @@ -26,19 +26,16 @@ final class PresentationMaterialDeletedEntityEventFactory */ public static function build(PresentationMaterialDeleted $event){ - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent(); $entity_event->setEntityClassName($event->getClassName()); $entity_event->setEntityId($event->getMaterialId()); $entity_event->setType('DELETE'); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($event->getPresentation()->getSummit()); diff --git a/app/Factories/EntityEvents/PresentationMaterialUpdatedEntityEventFactory.php b/app/Factories/EntityEvents/PresentationMaterialUpdatedEntityEventFactory.php index 644b2ebc..896646fe 100644 --- a/app/Factories/EntityEvents/PresentationMaterialUpdatedEntityEventFactory.php +++ b/app/Factories/EntityEvents/PresentationMaterialUpdatedEntityEventFactory.php @@ -25,19 +25,16 @@ final class PresentationMaterialUpdatedEntityEventFactory * @return SummitEntityEvent */ public static function build(PresentationMaterialUpdated $event){ - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); + $entity_event = new SummitEntityEvent(); - $entity_event = new SummitEntityEvent(); $entity_event->setEntityClassName($event->getMaterial()->getClassName()); $entity_event->setEntityId($event->getMaterial()->getId()); $entity_event->setType('UPDATE'); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($event->getMaterial()->getPresentation()->getSummit()); diff --git a/app/Factories/EntityEvents/PresentationSpeakerCreatedEntityEventFactory.php b/app/Factories/EntityEvents/PresentationSpeakerCreatedEntityEventFactory.php index 9588d3d1..575aada5 100644 --- a/app/Factories/EntityEvents/PresentationSpeakerCreatedEntityEventFactory.php +++ b/app/Factories/EntityEvents/PresentationSpeakerCreatedEntityEventFactory.php @@ -26,10 +26,8 @@ final class PresentationSpeakerCreatedEntityEventFactory */ public static function build(PresentationSpeakerCreated $event){ $list = []; - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); foreach($event->getPresentationSpeaker()->getRelatedSummits() as $summit) { @@ -38,9 +36,8 @@ final class PresentationSpeakerCreatedEntityEventFactory $entity_event->setEntityId($event->getPresentationSpeaker()->getId()); $entity_event->setType('INSERT'); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($summit); diff --git a/app/Factories/EntityEvents/PresentationSpeakerDeletedEntityEventFactory.php b/app/Factories/EntityEvents/PresentationSpeakerDeletedEntityEventFactory.php index ed7bb098..35e390c7 100644 --- a/app/Factories/EntityEvents/PresentationSpeakerDeletedEntityEventFactory.php +++ b/app/Factories/EntityEvents/PresentationSpeakerDeletedEntityEventFactory.php @@ -25,13 +25,11 @@ final class PresentationSpeakerDeletedEntityEventFactory * @return SummitEntityEvent[] */ public static function build(PresentationSpeakerDeleted $event){ - $list = []; - $args = $event->getArgs(); - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; - $params = $args->getParams(); + $list = []; + $args = $event->getArgs(); + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); + $params = $args->getParams(); foreach($params['summits'] as $summit) { @@ -40,9 +38,8 @@ final class PresentationSpeakerDeletedEntityEventFactory $entity_event->setEntityId($params['id']); $entity_event->setType('DELETE'); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($summit); diff --git a/app/Factories/EntityEvents/PresentationSpeakerUpdatedEntityEventFactory.php b/app/Factories/EntityEvents/PresentationSpeakerUpdatedEntityEventFactory.php index 75a141fa..5cb751d7 100644 --- a/app/Factories/EntityEvents/PresentationSpeakerUpdatedEntityEventFactory.php +++ b/app/Factories/EntityEvents/PresentationSpeakerUpdatedEntityEventFactory.php @@ -25,11 +25,9 @@ final class PresentationSpeakerUpdatedEntityEventFactory * @return SummitEntityEvent[] */ public static function build(PresentationSpeakerUpdated $event){ - $list = []; - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; + $list = []; + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); foreach($event->getPresentationSpeaker()->getRelatedSummits() as $summit) { @@ -38,9 +36,8 @@ final class PresentationSpeakerUpdatedEntityEventFactory $entity_event->setEntityId($event->getPresentationSpeaker()->getId()); $entity_event->setType('UPDATE'); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($summit); diff --git a/app/Factories/EntityEvents/SummitActionEntityEventFactory.php b/app/Factories/EntityEvents/SummitActionEntityEventFactory.php index 1fecabbb..9f66a54e 100644 --- a/app/Factories/EntityEvents/SummitActionEntityEventFactory.php +++ b/app/Factories/EntityEvents/SummitActionEntityEventFactory.php @@ -31,23 +31,19 @@ final class SummitActionEntityEventFactory public static function build(SummitAction $event, $type = 'UPDATE') { $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); $summit_repository = App::make(ISummitRepository::class); $summit = $summit_repository->getById($event->getSummitId()); - - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if (is_null($owner_id)) $owner_id = 0; - + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent; $entity_event->setEntityClassName('Summit'); $entity_event->setEntityId($event->getSummitId()); $entity_event->setType($type); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } + if(!is_null($summit)) $entity_event->setSummit($summit); diff --git a/app/Factories/EntityEvents/SummitEventCreatedEntityEventFactory.php b/app/Factories/EntityEvents/SummitEventCreatedEntityEventFactory.php index 81e28479..aaf22a45 100644 --- a/app/Factories/EntityEvents/SummitEventCreatedEntityEventFactory.php +++ b/app/Factories/EntityEvents/SummitEventCreatedEntityEventFactory.php @@ -26,19 +26,16 @@ final class SummitEventCreatedEntityEventFactory */ public static function build(SummitEventCreated $event) { - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); + $entity_event = new SummitEntityEvent(); - $entity_event = new SummitEntityEvent(); $entity_event->setEntityClassName($event->getSummitEvent()->getClassName()); $entity_event->setEntityId($event->getSummitEvent()->getId()); $entity_event->setType('INSERT'); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($event->getSummitEvent()->getSummit()); diff --git a/app/Factories/EntityEvents/SummitEventDeletedEntityEventFactory.php b/app/Factories/EntityEvents/SummitEventDeletedEntityEventFactory.php index c8072cf9..d8117ab7 100644 --- a/app/Factories/EntityEvents/SummitEventDeletedEntityEventFactory.php +++ b/app/Factories/EntityEvents/SummitEventDeletedEntityEventFactory.php @@ -28,10 +28,8 @@ final class SummitEventDeletedEntityEventFactory public static function build(SummitEventDeleted $event){ $args = $event->getArgs(); - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); $params = $args->getParams(); $entity_event = new SummitEntityEvent(); @@ -39,9 +37,8 @@ final class SummitEventDeletedEntityEventFactory $entity_event->setEntityId($params['id']); $entity_event->setType('DELETE'); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($params['summit']); diff --git a/app/Factories/EntityEvents/SummitEventTypeActionEntityEventFactory.php b/app/Factories/EntityEvents/SummitEventTypeActionEntityEventFactory.php index e5a0c894..a2837491 100644 --- a/app/Factories/EntityEvents/SummitEventTypeActionEntityEventFactory.php +++ b/app/Factories/EntityEvents/SummitEventTypeActionEntityEventFactory.php @@ -33,22 +33,17 @@ final class SummitEventTypeActionEntityEventFactory public static function build(SummitEventTypeAction $event, $type = 'UPDATE') { $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); $summit_repository = App::make(ISummitRepository::class); $summit = $summit_repository->getById($event->getSummitId()); - - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if (is_null($owner_id)) $owner_id = 0; - + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent; $entity_event->setEntityClassName($event->getClassName()); $entity_event->setEntityId($event->getEventTypeId()); $entity_event->setType($type); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($summit); diff --git a/app/Factories/EntityEvents/SummitEventUpdatedEntityEventFactory.php b/app/Factories/EntityEvents/SummitEventUpdatedEntityEventFactory.php index 02f86368..0039447e 100644 --- a/app/Factories/EntityEvents/SummitEventUpdatedEntityEventFactory.php +++ b/app/Factories/EntityEvents/SummitEventUpdatedEntityEventFactory.php @@ -29,20 +29,15 @@ final class SummitEventUpdatedEntityEventFactory $args = $event->getArgs(); if(!$args instanceof PreUpdateEventArgs) return; - $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); - $member_repository = App::make(\models\main\IMemberRepository::class); - - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if(is_null($owner_id)) $owner_id = 0; - - $entity_event = new SummitEntityEvent(); + $resource_server_context = App::make(\models\oauth2\IResourceServerContext::class); + $owner = $resource_server_context->getCurrentUser(); + $entity_event = new SummitEntityEvent(); $entity_event->setEntityClassName($event->getSummitEvent()->getClassName()); $entity_event->setEntityId($event->getSummitEvent()->getId()); $entity_event->setType('UPDATE'); - if($owner_id > 0){ - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($event->getSummitEvent()->getSummit()); diff --git a/app/Factories/EntityEvents/SummitTicketTypeActionEntityEventFactory.php b/app/Factories/EntityEvents/SummitTicketTypeActionEntityEventFactory.php index 02406857..cdf32b7e 100644 --- a/app/Factories/EntityEvents/SummitTicketTypeActionEntityEventFactory.php +++ b/app/Factories/EntityEvents/SummitTicketTypeActionEntityEventFactory.php @@ -31,22 +31,17 @@ final class SummitTicketTypeActionEntityEventFactory public static function build(SummitTicketTypeAction $event, $type = 'UPDATE') { $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); $summit_repository = App::make(ISummitRepository::class); $summit = $summit_repository->getById($event->getSummitId()); - - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if (is_null($owner_id)) $owner_id = 0; - + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent; $entity_event->setEntityClassName('SummitTicketType'); $entity_event->setEntityId($event->getTicketTypeId()); $entity_event->setType($type); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($summit); diff --git a/app/Factories/EntityEvents/TrackActionEntityEventFactory.php b/app/Factories/EntityEvents/TrackActionEntityEventFactory.php index b22452f7..199c8fd6 100644 --- a/app/Factories/EntityEvents/TrackActionEntityEventFactory.php +++ b/app/Factories/EntityEvents/TrackActionEntityEventFactory.php @@ -33,22 +33,17 @@ final class TrackActionEntityEventFactory public static function build(TrackAction $event, $type = 'UPDATE') { $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository::class); $summit_repository = App::make(ISummitRepository::class); $summit = $summit_repository->getById($event->getSummitId()); - - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if (is_null($owner_id)) $owner_id = 0; - + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent; $entity_event->setEntityClassName('PresentationCategory'); $entity_event->setEntityId($event->getTrackId()); $entity_event->setType($type); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($summit); diff --git a/app/Factories/EntityEvents/TrackGroupActionActionEntityEventFactory.php b/app/Factories/EntityEvents/TrackGroupActionActionEntityEventFactory.php index 052c133c..5cfc3a5a 100644 --- a/app/Factories/EntityEvents/TrackGroupActionActionEntityEventFactory.php +++ b/app/Factories/EntityEvents/TrackGroupActionActionEntityEventFactory.php @@ -31,21 +31,17 @@ final class TrackGroupActionActionEntityEventFactory public static function build(TrackGroupAction $event, $type = 'UPDATE') { $resource_server_context = App::make(IResourceServerContext::class); - $member_repository = App::make(IMemberRepository ::class); $summit_repository = App::make(ISummitRepository::class); $summit = $summit_repository->getById($event->getSummitId()); - - $owner_id = $resource_server_context->getCurrentUserExternalId(); - if (is_null($owner_id)) $owner_id = 0; + $owner = $resource_server_context->getCurrentUser(); $entity_event = new SummitEntityEvent; $entity_event->setEntityClassName($event->getClassName()); $entity_event->setEntityId($event->getTrackGroupId()); $entity_event->setType($type); - if ($owner_id > 0) { - $member = $member_repository->getById($owner_id); - $entity_event->setOwner($member); + if (!is_null($owner)) { + $entity_event->setOwner($owner); } $entity_event->setSummit($summit); diff --git a/app/Http/Controllers/Apis/Protected/Main/OAuth2MembersApiController.php b/app/Http/Controllers/Apis/Protected/Main/OAuth2MembersApiController.php index 7c26ba9d..a8518740 100644 --- a/app/Http/Controllers/Apis/Protected/Main/OAuth2MembersApiController.php +++ b/app/Http/Controllers/Apis/Protected/Main/OAuth2MembersApiController.php @@ -171,10 +171,7 @@ final class OAuth2MembersApiController extends OAuth2ProtectedController */ public function getMyMember(){ - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->repository->getById($current_member_id); + $current_member = $this->resource_server_context->getCurrentUser(); if (is_null($current_member)) return $this->error404(); $fields = Request::input('fields', null); @@ -207,10 +204,9 @@ final class OAuth2MembersApiController extends OAuth2ProtectedController public function getMemberAffiliations($member_id){ try { - if(strtolower($member_id) == 'me'){ - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - } - $member = $this->repository->getById($member_id); + $member = (strtolower($member_id) == 'me') ? + $this->resource_server_context->getCurrentUser() : + $this->repository->getById($member_id); if(is_null($member)) return $this->error404(); $affiliations = $member->getAffiliations()->toArray(); @@ -261,11 +257,10 @@ final class OAuth2MembersApiController extends OAuth2ProtectedController if(!Request::isJson()) return $this->error400(); $data = Input::json(); - if(strtolower($member_id) == 'me'){ - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - } + $member = (strtolower($member_id) == 'me') ? + $this->resource_server_context->getCurrentUser() : + $this->repository->getById($member_id); - $member = $this->repository->getById($member_id); if(is_null($member)) return $this->error404(); $rules = [ @@ -330,11 +325,10 @@ final class OAuth2MembersApiController extends OAuth2ProtectedController if(!Request::isJson()) return $this->error400(); $data = Input::json(); - if(strtolower($member_id) == 'me'){ - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - } + $member = (strtolower($member_id) == 'me') ? + $this->resource_server_context->getCurrentUser() : + $this->repository->getById($member_id); - $member = $this->repository->getById($member_id); if(is_null($member)) return $this->error404(); $rules = [ @@ -392,11 +386,10 @@ final class OAuth2MembersApiController extends OAuth2ProtectedController public function deleteAffiliation($member_id, $affiliation_id){ try{ - if(strtolower($member_id) == 'me'){ - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - } + $member = (strtolower($member_id) == 'me') ? + $this->resource_server_context->getCurrentUser() : + $this->repository->getById($member_id); - $member = $this->repository->getById($member_id); if(is_null($member)) return $this->error404(); $this->member_service->deleteAffiliation($member, $affiliation_id); diff --git a/app/Http/Controllers/Apis/Protected/Main/OAuth2TeamInvitationsApiController.php b/app/Http/Controllers/Apis/Protected/Main/OAuth2TeamInvitationsApiController.php index f17e6061..348daff8 100644 --- a/app/Http/Controllers/Apis/Protected/Main/OAuth2TeamInvitationsApiController.php +++ b/app/Http/Controllers/Apis/Protected/Main/OAuth2TeamInvitationsApiController.php @@ -55,10 +55,10 @@ final class OAuth2TeamInvitationsApiController extends OAuth2ProtectedController public function getMyInvitations(){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $invitations = $this->repository->getInvitationsByInvitee($current_member_id); + $invitations = $this->repository->getInvitationsByInvitee($current_member->getId()); $response = new PagingResponse ( @@ -92,10 +92,10 @@ final class OAuth2TeamInvitationsApiController extends OAuth2ProtectedController public function getMyPendingInvitations(){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $invitations = $this->repository->getPendingInvitationsByInvitee($current_member_id); + $invitations = $this->repository->getPendingInvitationsByInvitee($current_member->getId()); $response = new PagingResponse ( @@ -129,10 +129,10 @@ final class OAuth2TeamInvitationsApiController extends OAuth2ProtectedController public function getMyAcceptedInvitations(){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $invitations = $this->repository->getAcceptedInvitationsByInvitee($current_member_id); + $invitations = $this->repository->getAcceptedInvitationsByInvitee($current_member->getId()); $response = new PagingResponse ( @@ -166,10 +166,10 @@ final class OAuth2TeamInvitationsApiController extends OAuth2ProtectedController */ public function acceptInvitation($invitation_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $team_member = $this->service->acceptInvitation($invitation_id, $current_member_id); + $team_member = $this->service->acceptInvitation($invitation_id, $current_member->getId()); return $this->created(SerializerRegistry::getInstance()->getSerializer($team_member)->serialize($expand = '')); } catch (ValidationException $ex1) { @@ -193,9 +193,9 @@ final class OAuth2TeamInvitationsApiController extends OAuth2ProtectedController */ public function declineInvitation($invitation_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - $this->service->declineInvitation($invitation_id, $current_member_id); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); + $this->service->declineInvitation($invitation_id, $current_member->getId()); return $this->deleted(); } catch (ValidationException $ex1) { diff --git a/app/Http/Controllers/Apis/Protected/Main/OAuth2TeamsApiController.php b/app/Http/Controllers/Apis/Protected/Main/OAuth2TeamsApiController.php index 3bd656d8..a612e283 100644 --- a/app/Http/Controllers/Apis/Protected/Main/OAuth2TeamsApiController.php +++ b/app/Http/Controllers/Apis/Protected/Main/OAuth2TeamsApiController.php @@ -82,11 +82,8 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController public function getMyTeams(){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->member_repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $teams = $this->repository->getTeamsByMember($current_member); @@ -135,10 +132,7 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController public function getMyTeam($team_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->member_repository->getById($current_member_id); + $current_member = $this->resource_server_context->getCurrentUser(); if (is_null($current_member)) return $this->error403(); $team = $this->repository->getById($team_id); @@ -213,11 +207,8 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController 'description', ); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->member_repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $team = $this->service->addTeam(HTMLCleaner::cleanData($data->all(), $fields), $current_member); @@ -245,8 +236,8 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController public function deleteTeam($team_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $this->service->deleteTeam($team_id); @@ -303,8 +294,8 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController 'description', ); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $team = $this->service->updateTeam(HTMLCleaner::cleanData($data->all(), $fields), $team_id); @@ -382,10 +373,7 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController if(is_null($filter)) $filter = new Filter(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->member_repository->getById($current_member_id); + $current_member = $this->resource_server_context->getCurrentUser(); if (is_null($current_member)) return $this->error403(); $team = $this->repository->getById($team_id); @@ -450,8 +438,8 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController ); } - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); if(!isset($values['priority'])) $values['priority'] = PushNotificationMessagePriority::Normal; @@ -504,8 +492,8 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController ); } - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $invitation = $this->service->addMember2Team($team_id, $member_id, $values['permission']); return $this->created(SerializerRegistry::getInstance()->getSerializer($invitation)->serialize($expand = 'team,inviter,invitee')); @@ -534,8 +522,8 @@ final class OAuth2TeamsApiController extends OAuth2ProtectedController public function removedMemberFromMyTeam($team_id, $member_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $this->service->removeMemberFromTeam($team_id, $member_id); diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationApiController.php index f14b493a..499af5f8 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationApiController.php @@ -310,14 +310,8 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController if(!Request::isJson()) return $this->error400(); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if(is_null($member_id)) - return $this->error403(); - - $member = $this->member_repository->getById($member_id); - - if(is_null($member)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $data = Input::json(); @@ -353,7 +347,7 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController 'attendees_expected_learnt', ]; - $presentation = $this->presentation_service->submitPresentation($summit, $member, HTMLCleaner::cleanData($data, $fields)); + $presentation = $this->presentation_service->submitPresentation($summit, $current_member, HTMLCleaner::cleanData($data, $fields)); return $this->created(SerializerRegistry::getInstance()->getSerializer($presentation)->serialize()); } @@ -387,14 +381,8 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController if(!Request::isJson()) return $this->error400(); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if(is_null($member_id)) - return $this->error403(); - - $member = $this->member_repository->getById($member_id); - - if(is_null($member)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $data = Input::json(); @@ -433,7 +421,7 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController $presentation = $this->presentation_service->updatePresentationSubmission( $summit, $presentation_id, - $member, + $current_member, HTMLCleaner::cleanData($data, $fields) ); @@ -467,20 +455,14 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if(is_null($member_id)) - return $this->error403(); - - $member = $this->member_repository->getById($member_id); - - if(is_null($member)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $presentation = $this->presentation_service->completePresentationSubmission ( $summit, $presentation_id, - $member + $current_member ); return $this->updated(SerializerRegistry::getInstance()->getSerializer($presentation)->serialize()); @@ -513,16 +495,10 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $member = $this->member_repository->getById($current_member_id); - - if(is_null($member)) - return $this->error403(); - - $this->presentation_service->deletePresentation($summit, $member, $presentation_id); + $this->presentation_service->deletePresentation($summit, $current_member, $presentation_id); return $this->deleted(); @@ -620,16 +596,15 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - $member = $this->member_repository->getById($member_id); - if(is_null($member) || !$member instanceof Member) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - if(!$member->isAdmin()){ + if(!$current_member->isAdmin()){ // check if we could edit presentation $presentation = $summit->getEvent($presentation_id); if(is_null($presentation) || !$presentation instanceof Presentation) return $this->error404(); - if(!$member->hasSpeaker() || !$presentation->canEdit($member->getSpeaker())) + if(!$current_member->hasSpeaker() || !$presentation->canEdit($current_member->getSpeaker())) return $this->error403(); } @@ -699,16 +674,15 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController if (is_null($summit)) return $this->error404(); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - $member = $this->member_repository->getById($member_id); - if(is_null($member) || !$member instanceof Member) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - if(!$member->isAdmin()){ + if(!$current_member->isAdmin()){ // check if we could edit presentation $presentation = $summit->getEvent($presentation_id); if(is_null($presentation) || !$presentation instanceof Presentation) return $this->error404(); - if(!$member->hasSpeaker() || !$presentation->canEdit($member->getSpeaker())) + if(!$current_member->hasSpeaker() || !$presentation->canEdit($current_member->getSpeaker())) return $this->error403(); } diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php index 43f60a3c..06feffe1 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php @@ -353,6 +353,9 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); + $last_event_id = Request::input('last_event_id', null); $from_date = Request::input('from_date', null); $limit = Request::input('limit', 25); @@ -400,7 +403,7 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController list($last_event_id, $last_event_date, $list) = $this->summit_service->getSummitEntityEvents ( $summit, - $this->resource_server_context->getCurrentUserExternalId(), + $current_member->getId(), $from_date, intval($last_event_id), intval($limit) @@ -461,17 +464,15 @@ final class OAuth2SummitApiController extends OAuth2ProtectedController try { $summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($member_id)) { - throw new \HTTP401UnauthorizedException; - } + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) throw new \HTTP401UnauthorizedException; $attendee = $this->summit_service->confirmExternalOrderAttendee ( new ConfirmationExternalOrderRequest ( $summit, - intval($member_id), + $current_member->getId(), trim($external_order_id), trim($external_attendee_id) ) diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitEventsApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitEventsApiController.php index b674eee8..adaf3645 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitEventsApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitEventsApiController.php @@ -416,11 +416,8 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController if(!Request::isJson()) return $this->error400(); $data = Input::json(); - $current_member = null; - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (!is_null($member_id)){ - $current_member = $this->member_repository->getById($member_id); - } + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $rules = [ // summit event rules @@ -650,10 +647,10 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController if (!is_null($attendee_id)) // add filter by attendee, this case me { if($attendee_id !== 'me') return $this->error403(); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($member_id)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $filter = FilterParser::parse('owner_id=='.$member_id, array + $filter = FilterParser::parse('owner_id=='.$current_member->getId(), array ( 'owner_id' => array('=='), )); @@ -902,11 +899,10 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController } $data = $data->all(); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - if (is_null($member_id)) return $this->error400(); - - $data['member_id'] = intval($member_id); + $data['member_id'] = $current_member->getId(); return [$summit, $event, $data]; } diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitMembersApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitMembersApiController.php index f0aab816..91865f35 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitMembersApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitMembersApiController.php @@ -65,11 +65,8 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $fields = Request::input('fields', null); $relations = Request::input('relations', null); @@ -93,11 +90,8 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $favorites = array(); foreach ($current_member->getFavoritesSummitEventsBySummit($summit) as $favorite_event) @@ -151,11 +145,8 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $this->summit_service->addEventToMemberFavorites($summit, $current_member, intval($event_id)); @@ -196,11 +187,8 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $this->summit_service->removeEventFromMemberFavorites($summit, $current_member, intval($event_id)); @@ -238,13 +226,10 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $current_member = $this->repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); - - $schedule = array(); + $schedule = []; foreach ($current_member->getScheduleBySummit($summit) as $schedule_event) { if(!$summit->isEventOnSchedule($schedule_event->getEvent()->getId())) continue; @@ -296,11 +281,8 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $this->summit_service->addEventToMemberSchedule($summit, $current_member, intval($event_id)); @@ -341,11 +323,8 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $this->summit_service->removeEventFromMemberSchedule($summit, $current_member, intval($event_id)); @@ -386,11 +365,8 @@ final class OAuth2SummitMembersApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) return $this->error403(); - - $current_member = $this->repository->getById($current_member_id); - if (is_null($current_member)) return $this->error404(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $event = $summit->getScheduleEvent(intval($event_id)); diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitNotificationsApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitNotificationsApiController.php index b2008f01..83c4b20d 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitNotificationsApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitNotificationsApiController.php @@ -306,12 +306,7 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member = null; - if(!is_null($this->resource_server_context->getCurrentUserExternalId())){ - $current_member = $this->member_repository->getById($this->resource_server_context->getCurrentUserExternalId()); - } - - $notification = $this->push_notification_service->approveNotification($summit, $current_member, $notification_id); + $notification = $this->push_notification_service->approveNotification($summit, $this->resource_server_context->getCurrentUser(), $notification_id); return $this->updated(SerializerRegistry::getInstance()->getSerializer($notification)->serialize( Request::input('expand', ''))); } catch (ValidationException $ex1) { Log::warning($ex1); @@ -335,12 +330,7 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); if (is_null($summit)) return $this->error404(); - $current_member = null; - if(!is_null($this->resource_server_context->getCurrentUserExternalId())){ - $current_member = $this->member_repository->getById($this->resource_server_context->getCurrentUserExternalId()); - } - - $notification = $this->push_notification_service->unApproveNotification($summit, $current_member, $notification_id); + $notification = $this->push_notification_service->unApproveNotification($summit, $this->resource_server_context->getCurrentUser(), $notification_id); return $this->updated(SerializerRegistry::getInstance()->getSerializer($notification)->serialize( Request::input('expand', ''))); } catch (ValidationException $ex1) { Log::warning($ex1); @@ -380,12 +370,7 @@ class OAuth2SummitNotificationsApiController extends OAuth2ProtectedController ); } - $current_member = null; - if(!is_null($this->resource_server_context->getCurrentUserExternalId())){ - $current_member = $this->member_repository->getById($this->resource_server_context->getCurrentUserExternalId()); - } - - $notification = $this->push_notification_service->addPushNotification($summit, $current_member, $data->all()); + $notification = $this->push_notification_service->addPushNotification($summit, $this->resource_server_context->getCurrentUser(), $data->all()); return $this->created(SerializerRegistry::getInstance()->getSerializer($notification)->serialize()); } diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitPromoCodesApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitPromoCodesApiController.php index f3b7057b..b7870f5c 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitPromoCodesApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitPromoCodesApiController.php @@ -384,12 +384,7 @@ final class OAuth2SummitPromoCodesApiController extends OAuth2ProtectedControlle ); } - $current_member = null; - if(!is_null($this->resource_server_context->getCurrentUserExternalId())){ - $current_member = $this->member_repository->getById($this->resource_server_context->getCurrentUserExternalId()); - } - - $promo_code = $this->promo_code_service->addPromoCode($summit, $data->all(), $current_member); + $promo_code = $this->promo_code_service->addPromoCode($summit, $data->all(), $this->resource_server_context->getCurrentUser()); return $this->created(SerializerRegistry::getInstance()->getSerializer($promo_code)->serialize()); } @@ -435,14 +430,10 @@ final class OAuth2SummitPromoCodesApiController extends OAuth2ProtectedControlle ); } - $current_member = null; - if (!is_null($this->resource_server_context->getCurrentUserExternalId())) { - $current_member = $this->member_repository->getById($this->resource_server_context->getCurrentUserExternalId()); - } - - $promo_code = $this->promo_code_service->updatePromoCode($summit, $promo_code_id, $data->all(), $current_member); + $promo_code = $this->promo_code_service->updatePromoCode($summit, $promo_code_id, $data->all(), $this->resource_server_context->getCurrentUser()); return $this->updated(SerializerRegistry::getInstance()->getSerializer($promo_code)->serialize()); + } catch (ValidationException $ex1) { Log::warning($ex1); return $this->error412(array($ex1->getMessage())); diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php index bab381a3..e31e8a2c 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php @@ -288,12 +288,7 @@ final class OAuth2SummitRSVPTemplatesApiController extends OAuth2ProtectedContro ); } - $current_member = null; - if(!is_null($this->resource_server_context->getCurrentUserExternalId())){ - $current_member = $this->member_repository->getById($this->resource_server_context->getCurrentUserExternalId()); - } - - $template = $this->rsvp_template_service->addTemplate($summit, $current_member, $payload); + $template = $this->rsvp_template_service->addTemplate($summit, $this->resource_server_context->getCurrentUser(), $payload); return $this->created(SerializerRegistry::getInstance()->getSerializer($template)->serialize()); } diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSpeakersApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSpeakersApiController.php index ef9b0c50..d74615c5 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSpeakersApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSpeakersApiController.php @@ -359,15 +359,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController public function getMySpeaker() { try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $member = $this->member_repository->getById($current_member_id); - if (is_null($member)) - return $this->error403(); - - $speaker = $this->speaker_repository->getByMember($member); + $speaker = $this->speaker_repository->getByMember($current_member); if (is_null($speaker)) return $this->error404(); $serializer_type = $this->serializer_type_selector->getSerializerType(); @@ -401,22 +396,17 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController public function createMySpeaker() { try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); - - $member = $this->member_repository->getById($current_member_id); - if (is_null($member)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); // set data from current member ... $speaker = $this->service->addSpeaker([ - 'member_id' => $member->getIdentifier(), - 'first_name' => $member->getFirstName(), - 'last_name' => $member->getLastName(), - 'bio' => $member->getBio(), - 'twitter' => $member->getTwitterHandle(), - 'irc' => $member->getIrcHandle(), + 'member_id' => $current_member->getId(), + 'first_name' => $current_member->getFirstName(), + 'last_name' => $current_member->getLastName(), + 'bio' => $current_member->getBio(), + 'twitter' => $current_member->getTwitterHandle(), + 'irc' => $current_member->getIrcHandle(), ]); $serializer_type = $this->serializer_type_selector->getSerializerType(); @@ -450,15 +440,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController public function updateMySpeaker() { try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $member = $this->member_repository->getById($current_member_id); - if (is_null($member)) - return $this->error403(); - - $speaker = $this->speaker_repository->getByMember($member); + $speaker = $this->speaker_repository->getByMember($current_member); if (is_null($speaker)) return $this->error404(); return $this->updateSpeaker($speaker->getId()); @@ -667,15 +652,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController public function addMySpeakerPhoto(LaravelRequest $request){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $member = $this->member_repository->getById($current_member_id); - if (is_null($member)) - return $this->error403(); - - $speaker = $this->speaker_repository->getByMember($member); + $speaker = $this->speaker_repository->getByMember($current_member); if (is_null($speaker)) return $this->error404(); return $this->addSpeakerPhoto($request, $speaker->getId()); @@ -702,18 +682,13 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); - - $member = $this->member_repository->getById($current_member_id); - if (is_null($member)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $speaker = $this->speaker_repository->getById($speaker_id); if (is_null($speaker)) return $this->error404(); - if(!$speaker->canBeEditedBy($member)){ + if(!$speaker->canBeEditedBy($current_member)){ return $this->error403(); } @@ -782,13 +757,8 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController if (!Request::isJson()) return $this->error400(); $data = Input::json(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); - - $creator = $this->member_repository->getById($current_member_id); - if (is_null($creator)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $rules = [ 'title' => 'required|string|max:100', @@ -834,7 +804,7 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController 'notes' ]; - $speaker = $this->service->addSpeaker(HTMLCleaner::cleanData($data->all(), $fields), $creator); + $speaker = $this->service->addSpeaker(HTMLCleaner::cleanData($data->all(), $fields), $current_member); return $this->created(SerializerRegistry::getInstance()->getSerializer($speaker, SerializerRegistry::SerializerType_Private)->serialize()); } catch (ValidationException $ex1) { @@ -859,18 +829,13 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController if (!Request::isJson()) return $this->error400(); $data = Input::json(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); - - $member = $this->member_repository->getById($current_member_id); - if (is_null($member)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); $speaker = $this->speaker_repository->getById($speaker_id); if (is_null($speaker)) return $this->error404(); - if(!$speaker->canBeEditedBy($member)){ + if(!$speaker->canBeEditedBy($current_member)){ return $this->error403(); } @@ -965,15 +930,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController public function getMySpeakerPresentationsByRoleAndBySelectionPlan($role, $selection_plan_id) { try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $member = $this->member_repository->getById($current_member_id); - if (is_null($member)) - return $this->error403(); - - $speaker = $this->speaker_repository->getByMember($member); + $speaker = $this->speaker_repository->getByMember($current_member); if (is_null($speaker)) return $this->error403(); @@ -1024,15 +984,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController public function getMySpeakerPresentationsByRoleAndBySummit($role, $summit_id) { try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $member = $this->member_repository->getById($current_member_id); - if (is_null($member)) - return $this->error403(); - - $speaker = $this->speaker_repository->getByMember($member); + $speaker = $this->speaker_repository->getByMember($current_member); if (is_null($speaker)) return $this->error403(); @@ -1082,11 +1037,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController */ public function addSpeakerToMyPresentation($presentation_id, $speaker_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $this->summit_service->addSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id); + $this->summit_service->addSpeaker2Presentation($current_member->getId(), $speaker_id, $presentation_id); return $this->updated(); @@ -1109,11 +1063,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController */ public function addModeratorToMyPresentation($presentation_id, $speaker_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $this->summit_service->addModerator2Presentation($current_member_id, $speaker_id, $presentation_id); + $this->summit_service->addModerator2Presentation($current_member->getId(), $speaker_id, $presentation_id); return $this->updated(); @@ -1136,11 +1089,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController */ public function removeSpeakerFromMyPresentation($presentation_id, $speaker_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $this->summit_service->removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id); + $this->summit_service->removeSpeakerFromPresentation($current_member->getId(), $speaker_id, $presentation_id); return $this->deleted(); @@ -1163,11 +1115,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController */ public function removeModeratorFromMyPresentation($presentation_id, $speaker_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $this->summit_service->removeModeratorFromPresentation($current_member_id, $speaker_id, $presentation_id); + $this->summit_service->removeModeratorFromPresentation($current_member->getId(), $speaker_id, $presentation_id); return $this->deleted(); @@ -1189,11 +1140,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController */ public function requestSpeakerEditPermission($speaker_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $request = $this->service->requestSpeakerEditPermission($current_member_id, $speaker_id); + $request = $this->service->requestSpeakerEditPermission($current_member->getId(), $speaker_id); return $this->created( SerializerRegistry::getInstance()->getSerializer($request) @@ -1217,11 +1167,10 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController */ public function getSpeakerEditPermission($speaker_id){ try { - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) - return $this->error403(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $this->error403(); - $request = $this->service->getSpeakerEditPermission($current_member_id, $speaker_id); + $request = $this->service->getSpeakerEditPermission($current_member->getId(), $speaker_id); return $this->ok( SerializerRegistry::getInstance()->getSerializer($request)->serialize() diff --git a/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMeAttendeeStrategy.php b/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMeAttendeeStrategy.php index 994e68be..891edabb 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMeAttendeeStrategy.php +++ b/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMeAttendeeStrategy.php @@ -46,11 +46,11 @@ class CheckMeAttendeeStrategy implements ICheckAttendeeStrategy public function check($attendee_id, Summit $summit) { if (strtolower($attendee_id) === 'me') { - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($member_id)) { + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) { return null; } - return $summit->getAttendeeByMemberId($member_id); + return $summit->getAttendeeByMemberId($current_member->getId()); } return null; } diff --git a/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMeSpeakerStrategy.php b/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMeSpeakerStrategy.php index 73df9a46..c59d9f84 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMeSpeakerStrategy.php +++ b/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMeSpeakerStrategy.php @@ -45,11 +45,11 @@ class CheckMeSpeakerStrategy implements ICheckSpeakerStrategy public function check($speaker_id, Summit $summit) { if (strtolower($speaker_id) === 'me') { - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($member_id)) { + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) { return null; } - return $summit->getSpeakerByMemberId($member_id, false); + return $summit->getSpeakerByMemberId($current_member->getId(), false); } return $summit->getSpeaker(intval($speaker_id, false)); } diff --git a/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMyOwnAttendeeStrategy.php b/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMyOwnAttendeeStrategy.php index 71caca86..ab355dcc 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMyOwnAttendeeStrategy.php +++ b/app/Http/Controllers/Apis/Protected/Summit/Strategies/CheckMyOwnAttendeeStrategy.php @@ -32,8 +32,8 @@ final class CheckMyOwnAttendeeStrategy extends CheckMeAttendeeStrategy implement $attendee = parent::check($attendee_id, $summit); if(!$attendee) return null; $attendee_member_id = intval($attendee->getMember()->getId()); - $member_id = $this->resource_server_context->getCurrentUserExternalId(); - if(is_null($member_id) || ($attendee_member_id !== $member_id)) + $current_member = $this->resource_server_context->getCurrentUser(); + if(is_null($current_member) || ($attendee_member_id !== $current_member->getId())) throw new \HTTP401UnauthorizedException; return $attendee; } diff --git a/app/Http/Controllers/Apis/Protected/Summit/Traits/SummitBookableVenueRoomApi.php b/app/Http/Controllers/Apis/Protected/Summit/Traits/SummitBookableVenueRoomApi.php index b4cc983f..ec1e6b35 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/Traits/SummitBookableVenueRoomApi.php +++ b/app/Http/Controllers/Apis/Protected/Summit/Traits/SummitBookableVenueRoomApi.php @@ -514,8 +514,9 @@ trait SummitBookableVenueRoomApi try { if(!Request::isJson()) return $this->error400(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) + $current_member = $this->resource_server_context->getCurrentUser(); + + if (is_null($current_member)) return $this->error403(); $summit = $summit_id === 'current' ? $this->repository->getCurrent() : $this->repository->getById(intval($summit_id)); @@ -527,7 +528,7 @@ trait SummitBookableVenueRoomApi return $this->error404(); $payload = Input::json()->all(); - $payload['owner_id'] = $current_member_id; + $payload['owner_id'] = $current_member->getId(); $rules = SummitRoomReservationValidationRulesFactory::build($payload); // Creates a Validator instance and validates the data. $validation = Validator::make($payload, $rules); @@ -572,18 +573,16 @@ trait SummitBookableVenueRoomApi */ public function getMyBookableVenueRoomReservations($summit_id){ try{ - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) + $current_member = $this->resource_server_context->getCurrentUser(); + + if (is_null($current_member)) return $this->error403(); $summit = $summit_id === 'current' ? $this->repository->getCurrent() : $this->repository->getById(intval($summit_id)); if (is_null($summit)) return $this->error404(); - $member = $this->member_repository->getById($current_member_id); - if(is_null($member)) - return $this->error403(); - $reservations = $member->getReservationsBySummit($summit); + $reservations = $current_member->getReservationsBySummit($summit); $response = new PagingResponse ( @@ -628,18 +627,15 @@ trait SummitBookableVenueRoomApi */ public function cancelMyBookableVenueRoomReservation($summit_id, $reservation_id){ try{ - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) + $current_member = $this->resource_server_context->getCurrentUser(); + + if (is_null($current_member)) return $this->error403(); $summit = $summit_id === 'current' ? $this->repository->getCurrent() : $this->repository->getById(intval($summit_id)); if (is_null($summit)) return $this->error404(); - $member = $this->member_repository->getById($current_member_id); - if(is_null($member)) - return $this->error403(); - - $reservation = $this->location_service->cancelReservation($summit, $member, $reservation_id); + $reservation = $this->location_service->cancelReservation($summit, $current_member, $reservation_id); return $this->updated(SerializerRegistry::getInstance()->getSerializer($reservation)->serialize()); } diff --git a/app/Http/Middleware/CacheMiddleware.php b/app/Http/Middleware/CacheMiddleware.php index f34852ea..c1e2e894 100644 --- a/app/Http/Middleware/CacheMiddleware.php +++ b/app/Http/Middleware/CacheMiddleware.php @@ -75,7 +75,9 @@ final class CacheMiddleware if (str_contains($request->getPathInfo(), '/me')) { - $key .= ':' . $this->context->getCurrentUserExternalId(); + $current_member = $this->context->getCurrentUser(); + if(!is_null($current_member)) + $key .= ':' .$current_member->getId(); } $data = $this->cache_service->getSingleValue($key); diff --git a/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php b/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php index 6efc3c43..4d90bff3 100644 --- a/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php +++ b/app/Http/Middleware/OAuth2BearerAccessTokenRequestValidator.php @@ -185,19 +185,22 @@ class OAuth2BearerAccessTokenRequestValidator } Log::debug('setting resource server context ...'); //set context for api and continue processing - $context = array - ( + $context = [ 'access_token' => $access_token_value, 'expires_in' => $token_info->getLifetime(), 'client_id' => $token_info->getClientId(), 'scope' => $token_info->getScope(), 'application_type' => $token_info->getApplicationType() - ); + ]; if (!is_null($token_info->getUserId())) { $context['user_id'] = $token_info->getUserId(); $context['user_external_id'] = $token_info->getUserExternalId(); + $context['user_identifier'] = $token_info->getUserIdentifier(); + $context['user_email'] = $token_info->getUserEmail(); + $context['user_first_name'] = $token_info->getUserFirstName(); + $context['user_last_name'] = $token_info->getUserLastName(); } $this->context->setAuthorizationContext($context); diff --git a/app/Http/Middleware/UserAuthEndpoint.php b/app/Http/Middleware/UserAuthEndpoint.php index 839981d8..edc26e32 100644 --- a/app/Http/Middleware/UserAuthEndpoint.php +++ b/app/Http/Middleware/UserAuthEndpoint.php @@ -11,12 +11,10 @@ * See the License for the specific language governing permissions and * limitations under the License. **/ - use Closure; use Illuminate\Support\Facades\Response; use models\main\IMemberRepository; use models\oauth2\IResourceServerContext; - /** * Class UserAuthEndpoint * @package App\Http\Middleware @@ -34,6 +32,11 @@ final class UserAuthEndpoint */ private $member_repository; + /** + * UserAuthEndpoint constructor. + * @param IResourceServerContext $context + * @param IMemberRepository $member_repository + */ public function __construct ( IResourceServerContext $context, @@ -44,21 +47,22 @@ final class UserAuthEndpoint $this->member_repository = $member_repository; } + /** + * @param $request + * @param Closure $next + * @param $required_groups + * @return \Illuminate\Http\JsonResponse|mixed + */ public function handle($request, Closure $next, $required_groups) { - $member_id = $this->context->getCurrentUserExternalId(); - if (is_null($member_id)) return $next($request); - $member = $this->member_repository->getById($member_id); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) return $next($request); - if (is_null($member)){ - $http_response = Response::json(['error' => 'member not found'], 403); - return $http_response; - } $required_groups = explode('|', $required_groups); foreach ($required_groups as $required_group) { - if($member->isOnGroup($required_group)) + if($current_member->isOnGroup($required_group)) return $next($request); } diff --git a/app/ModelSerializers/BaseSerializerTypeSelector.php b/app/ModelSerializers/BaseSerializerTypeSelector.php index b023b46e..3002bfbb 100644 --- a/app/ModelSerializers/BaseSerializerTypeSelector.php +++ b/app/ModelSerializers/BaseSerializerTypeSelector.php @@ -53,9 +53,9 @@ final class BaseSerializerTypeSelector implements ISerializerTypeSelector public function getSerializerType() { $serializer_type = SerializerRegistry::SerializerType_Public; - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if(!is_null($current_member_id) && $member = $this->member_repository->getById($current_member_id)){ - if($member->isOnGroup(IGroup::SummitAdministrators)){ + $current_member = $this->resource_server_context->getCurrentUser(); + if(!is_null($current_member)){ + if($current_member->isOnGroup(IGroup::SummitAdministrators)){ $serializer_type = SerializerRegistry::SerializerType_Private; } } diff --git a/app/Models/Foundation/Main/Member.php b/app/Models/Foundation/Main/Member.php index 23f8aa45..0080d7e7 100644 --- a/app/Models/Foundation/Main/Member.php +++ b/app/Models/Foundation/Main/Member.php @@ -140,6 +140,13 @@ class Member extends SilverstripeBaseModel */ private $email_verified_date; + /** + * + * @ORM\Column(name="ExternalUserId", type="integer") + * @var int + */ + private $user_external_id; + /** * @ORM\ManyToOne(targetEntity="models\main\File") * @ORM\JoinColumn(name="PhotoID", referencedColumnName="ID") @@ -1277,4 +1284,20 @@ SQL; } } + /** + * @return int + */ + public function getUserExternalId(): int + { + return $this->user_external_id; + } + + /** + * @param int $user_external_id + */ + public function setUserExternalId(int $user_external_id): void + { + $this->user_external_id = $user_external_id; + } + } \ No newline at end of file diff --git a/app/Models/Foundation/Main/Repositories/IMemberRepository.php b/app/Models/Foundation/Main/Repositories/IMemberRepository.php index 38ccd583..5c85024e 100644 --- a/app/Models/Foundation/Main/Repositories/IMemberRepository.php +++ b/app/Models/Foundation/Main/Repositories/IMemberRepository.php @@ -42,4 +42,10 @@ interface IMemberRepository extends IBaseRepository * @return PagingResponse */ public function getAllByPage(PagingInfo $paging_info, Filter $filter = null, Order $order = null); + + /** + * @param int $external_id + * @return Member|null + */ + public function getByExternalId(int $external_id):?Member; } \ No newline at end of file diff --git a/app/Models/OAuth2/AccessToken.php b/app/Models/OAuth2/AccessToken.php index d647bc30..85988f8b 100644 --- a/app/Models/OAuth2/AccessToken.php +++ b/app/Models/OAuth2/AccessToken.php @@ -1,24 +1,24 @@ value = $value; - $instance->scope = $scope; - $instance->client_id = $client_id; - $instance->user_id = $user_id; - $instance->user_external_id = $user_external_id; + $instance->value = $token_info['access_token']; + $instance->scope = $token_info['scope']; + $instance->client_id = $token_info['client_id']; + $instance->user_id = self::getValueFromInfo('user_id', $token_info); + $instance->user_external_id = self::getValueFromInfo('user_external_id', $token_info); + $instance->user_identifier = self::getValueFromInfo('user_identifier', $token_info); + $instance->user_email = self::getValueFromInfo('user_email', $token_info); + $instance->user_first_name = self::getValueFromInfo('user_first_name', $token_info); + $instance->user_last_name = self::getValueFromInfo('user_last_name', $token_info); $instance->auth_code = null; - $instance->audience = $audience; + $instance->audience = $token_info['audience']; $instance->refresh_token = null; - $instance->lifetime = intval($lifetime); + $instance->lifetime = intval($token_info['expires_in']); $instance->is_hashed = false; - $instance->allowed_return_uris = $allowed_return_uris; - $instance->application_type = $application_type; - $instance->allowed_origins = $allowed_origins; + $instance->allowed_return_uris = self::getValueFromInfo('allowed_return_uris', $token_info); + $instance->application_type = $token_info['application_type']; + $instance->allowed_origins = self::getValueFromInfo('allowed_origins', $token_info); return $instance; } @@ -140,4 +147,36 @@ class AccessToken extends Token { } + + /** + * @return null|string + */ + public function getUserIdentifier(): ?string + { + return $this->user_identifier; + } + + /** + * @return null|string + */ + public function getUserEmail(): ?string + { + return $this->user_email; + } + + /** + * @return null|string + */ + public function getUserFirstName(): ?string + { + return $this->user_first_name; + } + + /** + * @return null|string + */ + public function getUserLastName(): ?string + { + return $this->user_last_name; + } } \ No newline at end of file diff --git a/app/Models/OAuth2/IResourceServerContext.php b/app/Models/OAuth2/IResourceServerContext.php index e3d2725b..591edf93 100644 --- a/app/Models/OAuth2/IResourceServerContext.php +++ b/app/Models/OAuth2/IResourceServerContext.php @@ -1,5 +1,7 @@ member_repository = $member_repository; + $this->tx_service = $tx_service; + } + /** * @var array */ @@ -36,7 +60,7 @@ final class ResourceServerContext implements IResourceServerContext */ public function getCurrentAccessToken() { - return isset($this->auth_context['access_token']) ? $this->auth_context['access_token'] : null; + return $this->getAuthContextVar('access_token'); } @@ -45,7 +69,7 @@ final class ResourceServerContext implements IResourceServerContext */ public function getCurrentAccessTokenLifetime() { - return isset($this->auth_context['expires_in']) ? $this->auth_context['expires_in'] : null; + return $this->getAuthContextVar('expires_in'); } /** @@ -53,7 +77,7 @@ final class ResourceServerContext implements IResourceServerContext */ public function getCurrentClientId() { - return isset($this->auth_context['client_id']) ? $this->auth_context['client_id'] : null; + return $this->getAuthContextVar('client_id'); } /** @@ -61,7 +85,7 @@ final class ResourceServerContext implements IResourceServerContext */ public function getCurrentUserId() { - return isset($this->auth_context['user_id']) ? intval($this->auth_context['user_id']) : null; + return $this->getAuthContextVar('user_id'); } /** @@ -74,11 +98,11 @@ final class ResourceServerContext implements IResourceServerContext } /** - * @return int + * @return int|null */ public function getCurrentUserExternalId() { - return isset($this->auth_context['user_external_id']) ? intval($this->auth_context['user_external_id']) : null; + return $this->getAuthContextVar('user_external_id'); } /** @@ -86,6 +110,55 @@ final class ResourceServerContext implements IResourceServerContext */ public function getApplicationType() { - return isset($this->auth_context['application_type']) ? $this->auth_context['application_type'] : null; + return $this->getAuthContextVar('application_type'); + } + + private function getAuthContextVar(string $varName){ + return isset($this->auth_context[$varName]) ? $this->auth_context[$varName] : null; + } + + /** + * @return Member|null + * @throws \Exception + */ + public function getCurrentUser(): ?Member + { + return $this->tx_service->transaction(function() { + $member = null; + // legacy test + $id = $this->getCurrentUserExternalId(); + if(is_null($id)) return null; + // get by id ( legacy test) + $member = $this->member_repository->getById(intval($id)); + // is null + if(is_null($member)){ + $id = $this->getCurrentUserId(); + if(is_null($id)) return null; + $member = $this->member_repository->getById(intval($id)); + } + + if(is_null($member)){ + + $user_external_id = $this->getAuthContextVar('user_id'); + $user_first_name = $this->getAuthContextVar('user_first_name'); + $user_last_name = $this->getAuthContextVar('user_last_name'); + $user_email = $this->getAuthContextVar('user_email'); + // at last resort try to get by email + $member = $this->member_repository->getByEmail($user_email); + + if(is_null($member)) // user exist on IDP but not in our local DB, proceed to create it + $member = new Member(); + + $member->setEmail($user_email); + $member->setFirstName($user_first_name); + $member->setLastName($user_last_name); + $member->setUserExternalId($user_external_id); + + if($member->getId() == 0) + $this->member_repository->add($member); + } + + return $member; + }); } } \ No newline at end of file diff --git a/app/Models/ResourceServer/AccessTokenService.php b/app/Models/ResourceServer/AccessTokenService.php index fb53c4d6..76969ef9 100644 --- a/app/Models/ResourceServer/AccessTokenService.php +++ b/app/Models/ResourceServer/AccessTokenService.php @@ -1,5 +1,4 @@ cache_service->getHash(md5($token_value),[ - 'access_token', - 'scope', - 'client_id', - 'audience', - 'user_id', - 'user_external_id', - 'expires_in', - 'application_type', - 'allowed_return_uris', - 'allowed_origins' - ]); + $token_info = $this->cache_service->getHash(md5($token_value), self::$access_token_keys); if (count($token_info) === 0) { @@ -109,19 +114,8 @@ final class AccessTokenService implements IAccessTokenService * @return AccessToken */ private function unSerializeToken(array $token_info){ - $token = AccessToken::createFromParams - ( - $token_info['access_token'], - $token_info['scope'], - $token_info['client_id'], - $token_info['audience'], - isset($token_info['user_id'])? intval($token_info['user_id']):null, - isset($token_info['user_external_id'])? intval($token_info['user_external_id']) : null, - (int)$token_info['expires_in'], - $token_info['application_type'], - isset($token_info['allowed_return_uris']) ? $token_info['allowed_return_uris'] : null, - isset($token_info['allowed_origins']) ? $token_info['allowed_origins'] : null - ); + + $token = AccessToken::createFromParams($token_info); $str_token_info = ""; foreach($token_info as $k => $v){ @@ -140,7 +134,29 @@ final class AccessTokenService implements IAccessTokenService Log::debug("getting token from remote call ..."); $cache_lifetime = intval(Config::get('server.access_token_cache_lifetime', 300)); $token_info = $this->doIntrospectionRequest($token_value); - $this->cache_service->storeHash(md5($token_value), $token_info, $cache_lifetime ); + + // legacy fix + if(!array_key_exists("user_external_id" , $token_info)){ + $token_info['user_external_id'] = null; + } + + if(!array_key_exists("user_identifier" , $token_info)){ + $token_info['user_identifier'] = null; + } + + if(!array_key_exists("user_email" , $token_info)){ + $token_info['user_email'] = null; + } + + if(!array_key_exists("user_first_name" , $token_info)){ + $token_info['user_first_name'] = null; + } + + if(!array_key_exists("user_last_name" , $token_info)){ + $token_info['user_last_name'] = null; + } + + $this->cache_service->storeHash(md5($token_value), $token_info, $cache_lifetime); return $token_info; } @@ -194,10 +210,7 @@ final class AccessTokenService implements IAccessTokenService // invalid content type throw new \Exception($response->getBody()); } - $token_info = json_decode($response->getBody()->getContents(), true); - - return $token_info; - + return json_decode($response->getBody()->getContents(), true); } catch (RequestException $ex) { diff --git a/app/Repositories/SilverStripeDoctrineRepository.php b/app/Repositories/SilverStripeDoctrineRepository.php index 7586e48a..1b256e1b 100644 --- a/app/Repositories/SilverStripeDoctrineRepository.php +++ b/app/Repositories/SilverStripeDoctrineRepository.php @@ -66,13 +66,9 @@ abstract class SilverStripeDoctrineRepository extends DoctrineRepository */ 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(); - if(is_null($member_id)) return false; - $member = $member_repository->getById($member_id); - if (!is_null($member)){ + $member = $resource_server_ctx->getCurrentUser(); + if(is_null($member)) return false; return $member->isOnGroup($group_code); - } return false; } } \ No newline at end of file diff --git a/app/Repositories/Summit/DoctrineMemberRepository.php b/app/Repositories/Summit/DoctrineMemberRepository.php index f4de85bf..7315f501 100644 --- a/app/Repositories/Summit/DoctrineMemberRepository.php +++ b/app/Repositories/Summit/DoctrineMemberRepository.php @@ -152,4 +152,15 @@ final class DoctrineMemberRepository ->getQuery() ->getOneOrNullResult(); } + + /** + * @param int $external_id + * @return Member|null + */ + public function getByExternalId(int $external_id): ?Member + { + return $this->findOneBy([ + 'user_external_id' => $external_id + ]); + } } \ No newline at end of file diff --git a/app/Services/Model/ChatTeamService.php b/app/Services/Model/ChatTeamService.php index ccd6840b..d2b3c913 100644 --- a/app/Services/Model/ChatTeamService.php +++ b/app/Services/Model/ChatTeamService.php @@ -117,10 +117,8 @@ final class ChatTeamService implements IChatTeamService */ function updateTeam(array $data, $team_id){ return $this->tx_service->transaction(function () use($data, $team_id){ - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) throw new EntityNotFoundException(); - $current_member = $this->member_repository->getById($current_member_id); + $current_member = $this->resource_server_context->getCurrentUser(); if (is_null($current_member)) throw new EntityNotFoundException(); $team = $this->repository->getById($team_id); @@ -146,10 +144,7 @@ final class ChatTeamService implements IChatTeamService { $this->tx_service->transaction(function() use($team_id){ - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) throw new EntityNotFoundException(); - - $current_member = $this->member_repository->getById($current_member_id); + $current_member = $this->resource_server_context->getCurrentUser(); if (is_null($current_member)) throw new EntityNotFoundException(); $team = $this->repository->getById($team_id); @@ -176,10 +171,10 @@ final class ChatTeamService implements IChatTeamService $team = $this->repository->getById($team_id); if(is_null($team)) throw new EntityNotFoundException(); - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) throw new EntityNotFoundException(); + $current_member = $this->resource_server_context->getCurrentUser(); + if (is_null($current_member)) throw new EntityNotFoundException(); - $inviter = $this->member_repository->getById($current_member_id); + $inviter = $this->member_repository->getById($current_member->getId()); if (is_null($inviter)) throw new EntityNotFoundException(); $invitee = $this->member_repository->getById($invitee_id); @@ -284,10 +279,7 @@ final class ChatTeamService implements IChatTeamService { $this->tx_service->transaction(function() use($member_id, $team_id){ - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) throw new EntityNotFoundException(); - - $current_member = $this->member_repository->getById($current_member_id); + $current_member = $this->resource_server_context->getCurrentUser(); if (is_null($current_member)) throw new EntityNotFoundException(); $team_member = $this->member_repository->getById($member_id); @@ -318,10 +310,7 @@ final class ChatTeamService implements IChatTeamService { return $this->tx_service->transaction(function() use($team_id, $values){ - $current_member_id = $this->resource_server_context->getCurrentUserExternalId(); - if (is_null($current_member_id)) throw new EntityNotFoundException(); - - $current_member = $this->member_repository->getById($current_member_id); + $current_member = $this->resource_server_context->getCurrentUser(); if (is_null($current_member)) throw new EntityNotFoundException(); $team = $this->repository->getById($team_id); diff --git a/database/migrations/model/Version20190728200547.php b/database/migrations/model/Version20190728200547.php new file mode 100644 index 00000000..bd24a4c6 --- /dev/null +++ b/database/migrations/model/Version20190728200547.php @@ -0,0 +1,51 @@ +hasTable("Member") && !$builder->hasColumn("Member", "ExternalUserId")) { + $builder->table('Member', function (Table $table) { + $table->integer("ExternalUserId")->setNotnull(false); + $table->text("ExternalUserIdentifier")->setNotnull(false); + }); + } + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $builder = new Builder($schema); + if($schema->hasTable("Member") && $builder->hasColumn("Member", "ExternalUserId")) { + $builder->table('Member', function (Table $table) { + $table->dropColumn("ExternalUserId")->setNotnull(false); + $table->dropColumn("ExternalUserIdentifier")->setNotnull(false); + }); + } + } +} diff --git a/tests/ProtectedApiTest.php b/tests/ProtectedApiTest.php index eaf51c66..18d4a55a 100644 --- a/tests/ProtectedApiTest.php +++ b/tests/ProtectedApiTest.php @@ -71,7 +71,20 @@ class AccessTokenServiceStub implements IAccessTokenService sprintf(SummitScopes::WriteMyBookableRoomsReservationData, $url), ); - return AccessToken::createFromParams('123456789', implode(' ', $scopes), '1', $realm, '1','11624', 3600, 'WEB_APPLICATION', '', ''); + return AccessToken::createFromParams( + [ + 'access_token' => '123456789', + 'scope' => implode(' ', $scopes), + 'client_id' => '1', + 'audience' => $realm, + 'user_id' => '1', + 'user_external_id' => '11624', + 'expires_in' => 3600, + 'application_type' => 'WEB_APPLICATION', + 'allowed_return_uris' => '', + 'allowed_origins' => '' + ] + ); } } @@ -125,7 +138,20 @@ class AccessTokenServiceStub2 implements IAccessTokenService sprintf(SummitScopes::WriteMyBookableRoomsReservationData, $url), ); - return AccessToken::createFromParams('123456789', implode(' ', $scopes), '1', $realm, null,null, 3600, 'SERVICE', '', ''); + return AccessToken::createFromParams( + [ + 'access_token' => '123456789', + 'scope' => implode(' ', $scopes), + 'client_id' => '1', + 'audience' => $realm, + 'user_id' => null, + 'user_external_id' => null, + 'expires_in' => 3600, + 'application_type' => 'SERVICE', + 'allowed_return_uris' => '', + 'allowed_origins' => '' + ] + ); } } /**