From 40fe0d4e6af1c57272c837c6ca4a96a121cf7379 Mon Sep 17 00:00:00 2001 From: smarcet Date: Thu, 11 Mar 2021 13:37:33 -0300 Subject: [PATCH] Added missing endpoint to track chairs api export presentations to CSV Change-Id: I53db367a30a9cda24830aea6af422e46ecb14d7a Signed-off-by: smarcet --- ...Auth2SummitSelectionPlansApiController.php | 128 +++++++++++++++++- app/Http/routes.php | 1 + database/seeds/ApiEndpointsSeeder.php | 14 ++ tests/OAuth2SelectionPlansApiTest.php | 91 ++++++++++++- 4 files changed, 232 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSelectionPlansApiController.php b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSelectionPlansApiController.php index adeb6d2d..3c7f73c7 100644 --- a/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSelectionPlansApiController.php +++ b/app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSelectionPlansApiController.php @@ -12,6 +12,7 @@ * limitations under the License. **/ +use App\Http\Utils\EpochCellFormatter; use App\Models\Exceptions\AuthzException; use App\Models\Foundation\Summit\Repositories\ISummitCategoryChangeRepository; use App\Services\Model\ISummitSelectionPlanService; @@ -420,6 +421,126 @@ final class OAuth2SummitSelectionPlansApiController extends OAuth2ProtectedContr } } + /** + * @param $summit_id + * @param $selection_plan_id + * @return \Illuminate\Http\JsonResponse|mixed + */ + public function getSelectionPlanPresentationsCSV($summit_id, $selection_plan_id) + { + try { + + $summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id); + if (is_null($summit)) return $this->error404(); + + $member = $this->resource_server_context->getCurrentUser(); + + if (is_null($member)) + return $this->error403(); + + $authz = $summit->isTrackChair($member) || $summit->isTrackChairAdmin($member); + + if (!$authz) + return $this->error403(); + + return $this->_getAllCSV( + function () { + return [ + 'title' => ['=@', '=='], + 'abstract' => ['=@', '=='], + 'social_summary' => ['=@', '=='], + 'tags' => ['=@', '=='], + 'level' => ['=@', '=='], + 'summit_type_id' => ['=='], + 'event_type_id' => ['=='], + 'track_id' => ['=='], + 'speaker_id' => ['=='], + 'speaker' => ['=@', '=='], + 'speaker_email' => ['=@', '=='], + 'selection_status' => ['=='], + 'id' => ['=='], + 'selection_plan_id' => ['=='], + 'status' => ['=='], + 'is_chair_visible' => ['=='], + 'is_voting_visible' => ['=='], + 'track_chairs_status' => ['=='], + 'viewed_status' => ['=='], + ]; + }, + function () { + return [ + 'title' => 'sometimes|string', + 'abstract' => 'sometimes|string', + 'social_summary' => 'sometimes|string', + 'tags' => 'sometimes|string', + 'level' => 'sometimes|string', + 'summit_type_id' => 'sometimes|integer', + 'event_type_id' => 'sometimes|integer', + 'track_id' => 'sometimes|integer', + 'speaker_id' => 'sometimes|integer', + 'speaker' => 'sometimes|string', + 'speaker_email' => 'sometimes|string', + 'selection_status' => 'sometimes|string', + 'id' => 'sometimes|integer', + 'selection_plan_id' => 'sometimes|integer', + 'status' => 'sometimes|string', + 'is_chair_visible' => 'sometimes|boolean', + 'is_voting_visible' => 'sometimes|boolean', + 'track_chairs_status' => 'sometimes|string|in:voted,untouched,team_selected,selected,maybe,pass', + 'viewed_status' => 'sometimes|string|in:seen,unseen,moved', + ]; + }, + function () { + return [ + 'track' + ]; + }, + function ($filter) use ($summit, $selection_plan_id) { + if ($filter instanceof Filter) { + $filter->addFilterCondition(FilterElement::makeEqual('summit_id', $summit->getId())); + $filter->addFilterCondition(FilterElement::makeEqual('selection_plan_id', $selection_plan_id)); + $current_member = $this->resource_server_context->getCurrentUser(false); + if(!is_null($current_member)) { + $filter->addFilterCondition(FilterElement::makeEqual('current_member_id', $current_member->getId())); + } + } + return $filter; + }, + function () { + return IPresentationSerializerTypes::TrackChairs; + }, + function () { + return [ + 'created' => new EpochCellFormatter(), + 'last_edited' => new EpochCellFormatter(), + ]; + }, + function () { + return []; + }, + 'presentations-', + [], + function ($page, $per_page, $filter, $order, $applyExtraFilters) { + return $this->summit_event_repository->getAllByPage + ( + new PagingInfo($page, $per_page), + call_user_func($applyExtraFilters, $filter), + $order + ); + } + ); + } catch (ValidationException $ex) { + Log::warning($ex); + return $this->error412($ex->getMessages()); + } catch (EntityNotFoundException $ex) { + Log::warning($ex); + return $this->error404($ex->getMessage()); + } catch (Exception $ex) { + Log::error($ex); + return $this->error500($ex); + } + } + /** * @param $summit_id * @param $selection_plan_id @@ -437,8 +558,13 @@ final class OAuth2SummitSelectionPlansApiController extends OAuth2ProtectedContr if (is_null($selection_plan)) return $this->error404(); $presentation = $selection_plan->getPresentation(intval($presentation_id)); + if(is_null($presentation)) throw new EntityNotFoundException(); + + return $this->ok(SerializerRegistry::getInstance()->getSerializer + ( + $presentation + )->serialize(Request::input('expand', ''))); - return $this->ok(SerializerRegistry::getInstance()->getSerializer($presentation)->serialize(Request::input('expand', ''))); } catch (ValidationException $ex) { Log::warning($ex); return $this->error412($ex->getMessages()); diff --git a/app/Http/routes.php b/app/Http/routes.php index 1a66c23f..2676e617 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -246,6 +246,7 @@ Route::group([ Route::group(['prefix' => 'presentations'], function () { Route::get('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitSelectionPlansApiController@getSelectionPlanPresentations']); + Route::get('csv', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitSelectionPlansApiController@getSelectionPlanPresentationsCSV']); Route::group(['prefix' => 'all'], function () { // category-change-requests diff --git a/database/seeds/ApiEndpointsSeeder.php b/database/seeds/ApiEndpointsSeeder.php index 41fcb843..44f6b796 100644 --- a/database/seeds/ApiEndpointsSeeder.php +++ b/database/seeds/ApiEndpointsSeeder.php @@ -5162,6 +5162,20 @@ class ApiEndpointsSeeder extends Seeder IGroup::TrackChairsAdmins, ] ], + [ + 'name' => 'get-selection-plan-presentations-csv', + 'route' => '/api/v1/summits/{id}/selection-plans/{selection_plan_id}/presentations/csv', + 'http_method' => 'GET', + 'scopes' => [ + sprintf(SummitScopes::ReadSummitData, $current_realm) + ], + 'authz_groups' => [ + IGroup::SuperAdmins, + IGroup::Administrators, + IGroup::TrackChairs, + IGroup::TrackChairsAdmins, + ] + ], [ 'name' => 'get-selection-plan-presentation', 'route' => '/api/v1/summits/{id}/selection-plans/{selection_plan_id}/presentations/{presentation_id}', diff --git a/tests/OAuth2SelectionPlansApiTest.php b/tests/OAuth2SelectionPlansApiTest.php index 85296bf1..d4aeb188 100644 --- a/tests/OAuth2SelectionPlansApiTest.php +++ b/tests/OAuth2SelectionPlansApiTest.php @@ -403,6 +403,95 @@ final class OAuth2SelectionPlansApiTest extends ProtectedApiTest $this->assertTrue($presentations->total >= 1); } + public function testGetPresentationsBySelectionPlanAndConditionsCSV(){ + + $params = [ + 'id' => self::$summit->getId(), + 'track_id' => self::$defaultTrack->getId(), + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "POST", + "OAuth2SummitSelectedPresentationListApiController@createIndividualSelectionList", + $params, + [], + [], + [], + $headers, + "" + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + $selection_list = json_decode($content); + $this->assertTrue(!is_null($selection_list)); + + $params = [ + 'id' => self::$summit->getId(), + 'track_id' => self::$defaultTrack->getId(), + 'collection' => SummitSelectedPresentation::CollectionSelected, + 'presentation_id' => self::$presentations[0]->getId(), + 'expand' => 'selected_presentations,interested_presentations,' + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "POST", + "OAuth2SummitSelectedPresentationListApiController@assignPresentationToMyIndividualList", + $params, + [], + [], + [], + $headers, + "" + ); + + $content = $response->getContent(); + $this->assertResponseStatus(201); + $selection_list = json_decode($content); + $this->assertTrue(!is_null($selection_list)); + $this->assertTrue(count($selection_list->selected_presentations) > 0); + + + $params = [ + 'id' => self::$summit->getId(), + 'selection_plan_id' => self::$default_selection_plan->getId(), + 'filter' => [ + 'status==Received', + 'is_chair_visible==1', + 'track_chairs_status==voted' + ], + ]; + + $headers = [ + "HTTP_Authorization" => " Bearer " . $this->access_token, + "CONTENT_TYPE" => "application/json" + ]; + + $response = $this->action( + "GET", + "OAuth2SummitSelectionPlansApiController@getSelectionPlanPresentationsCSV", + $params, + [], + [], + [], + $headers + ); + + $content = $response->getContent(); + $this->assertResponseStatus(200); + $this->assertTrue(!empty($content)); + } + public function testGetPresentationsBySelectionPlanAndConditionsMoved(){ $params = [ @@ -720,7 +809,7 @@ final class OAuth2SelectionPlansApiTest extends ProtectedApiTest 'summit' => self::$summit->getId(), 'selection_plan_id' => self::$default_selection_plan->getId(), 'expand' => 'presentation, new_category, old_category', - 'order' => '+requester_fullname' + 'order' => '-old_category_name' ]; $response = $this->action(