Added new endpoints to get speaker active involvements

and organization roles

GET /api/v1/speakers/active-involvements

scopes

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

GET /api/v1/speakers/organizational-roles

scopes

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

Change-Id: I25a53b87228e9e9766693c8e0ab802a520c9b93e
This commit is contained in:
Sebastian Marcet 2018-10-17 14:16:30 -03:00
parent 71e076e2a3
commit 08098c2157
10 changed files with 294 additions and 9 deletions

View File

@ -0,0 +1,74 @@
<?php namespace App\Http\Controllers;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Models\Foundation\Summit\Repositories\ISpeakerActiveInvolvementRepository;
use models\oauth2\IResourceServerContext;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Log;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use utils\PagingResponse;
/**
* Class OAuth2SpeakerActiveInvolvementApiController
* @package App\Http\Controllers
*/
final class OAuth2SpeakerActiveInvolvementApiController extends OAuth2ProtectedController
{
/**
* OAuth2SpeakerActiveInvolvementApiController constructor.
* @param ISpeakerActiveInvolvementRepository $repository
* @param IResourceServerContext $resource_server_context
*/
public function __construct
(
ISpeakerActiveInvolvementRepository $repository,
IResourceServerContext $resource_server_context
)
{
parent::__construct($resource_server_context);
$this->repository = $repository;
}
/**
* @return mixed
*/
public function getAll(){
try {
$involvements = $this->repository->getDefaultOnes();
$response = new PagingResponse
(
count($involvements),
count($involvements),
1,
1,
$involvements
);
return $this->ok($response->toArray($expand = Input::get('expand','')));
}
catch (ValidationException $ex1) {
Log::warning($ex1);
return $this->error412(array($ex1->getMessage()));
}
catch(EntityNotFoundException $ex2)
{
Log::warning($ex2);
return $this->error404(array('message'=> $ex2->getMessage()));
}
catch (\Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
}

View File

@ -0,0 +1,71 @@
<?php namespace App\Http\Controllers;
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use App\Models\Foundation\Summit\Repositories\ISpeakerOrganizationalRoleRepository;
use models\oauth2\IResourceServerContext;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Log;
use models\exceptions\EntityNotFoundException;
use models\exceptions\ValidationException;
use utils\PagingResponse;
/**
* Class OAuth2SpeakerOrganizationalRoleApiController
* @package App\Http\Controllers
*/
final class OAuth2SpeakerOrganizationalRoleApiController extends OAuth2ProtectedController
{
/**
* OAuth2SpeakerOrganizationalRoleApiController constructor.
* @param ISpeakerOrganizationalRoleRepository $repository
* @param IResourceServerContext $resource_server_context
*/
public function __construct
(
ISpeakerOrganizationalRoleRepository $repository,
IResourceServerContext $resource_server_context
)
{
parent::__construct($resource_server_context);
$this->repository = $repository;
}
/**
* @return mixed
*/
public function getAll()
{
try {
$roles = $this->repository->getDefaultOnes();
$response = new PagingResponse
(
count($roles),
count($roles),
1,
1,
$roles
);
return $this->ok($response->toArray($expand = Input::get('expand', '')));
} catch (ValidationException $ex1) {
Log::warning($ex1);
return $this->error412(array($ex1->getMessage()));
} catch (EntityNotFoundException $ex2) {
Log::warning($ex2);
return $this->error404(array('message' => $ex2->getMessage()));
} catch (\Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
}

View File

@ -602,6 +602,14 @@ Route::group([
Route::post('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators', 'uses' => 'OAuth2SummitSpeakersApiController@addSpeaker']);
Route::put('merge/{speaker_from_id}/{speaker_to_id}', 'OAuth2SummitSpeakersApiController@merge');
Route::group(['prefix' => 'active-involvements'], function(){
Route::get('', 'OAuth2SpeakerActiveInvolvementApiController@getAll');
});
Route::group(['prefix' => 'organizational-roles'], function(){
Route::get('', 'OAuth2SpeakerOrganizationalRoleApiController@getAll');
});
Route::group(['prefix' => 'me'], function(){
Route::get('', 'OAuth2SummitSpeakersApiController@getMySpeaker');
Route::post('', 'OAuth2SummitSpeakersApiController@createMySpeaker');

View File

@ -11,6 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use models\summit\SpeakerActiveInvolvement;
use models\utils\IBaseRepository;
/**
* Interface ISpeakerActiveInvolvementRepository
@ -18,5 +19,8 @@ use models\utils\IBaseRepository;
*/
interface ISpeakerActiveInvolvementRepository extends IBaseRepository
{
/**
* @return SpeakerActiveInvolvement[]
*/
public function getDefaultOnes();
}

View File

@ -24,4 +24,9 @@ interface ISpeakerOrganizationalRoleRepository extends IBaseRepository
* @return SpeakerOrganizationalRole|null
*/
public function getByRole($role);
/**
* @return SpeakerOrganizationalRole[]
*/
public function getDefaultOnes();
}

View File

@ -30,4 +30,12 @@ final class DoctrineSpeakerActiveInvolvementRepository
{
return SpeakerActiveInvolvement::class;
}
/**
* @return SpeakerActiveInvolvement[]
*/
public function getDefaultOnes()
{
return $this->findBy(["is_default" => true]);
}
}

View File

@ -24,6 +24,14 @@ final class DoctrineSpeakerOrganizationalRoleRepository
implements ISpeakerOrganizationalRoleRepository
{
/**
* @return SpeakerOrganizationalRole[]
*/
public function getDefaultOnes()
{
return $this->findBy(["is_default" => true]);
}
/**
* @return string
*/

View File

@ -253,7 +253,7 @@ class ApiEndpointsSeeder extends Seeder
],
],
// speakers
array(
[
'name' => 'get-speakers',
'route' => '/api/v1/summits/{id}/speakers',
'http_method' => 'GET',
@ -261,7 +261,7 @@ class ApiEndpointsSeeder extends Seeder
sprintf(SummitScopes::ReadSummitData, $current_realm),
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
],
),
],
array(
'name' => 'add-speaker-by-summit',
'route' => '/api/v1/summits/{id}/speakers',
@ -286,22 +286,22 @@ class ApiEndpointsSeeder extends Seeder
sprintf(SummitScopes::WriteSpeakersData, $current_realm),
],
),
array(
[
'name' => 'add-speaker',
'route' => '/api/v1/speakers',
'http_method' => 'POST',
'scopes' => [
sprintf(SummitScopes::WriteSpeakersData, $current_realm),
],
),
array(
],
[
'name' => 'update-speaker',
'route' => '/api/v1/speakers/{speaker_id}',
'http_method' => 'PUT',
'scopes' => [
sprintf(SummitScopes::WriteSpeakersData, $current_realm),
],
),
],
array(
'name' => 'delete-speaker',
'route' => '/api/v1/speakers/{speaker_id}',
@ -310,7 +310,7 @@ class ApiEndpointsSeeder extends Seeder
sprintf(SummitScopes::WriteSpeakersData, $current_realm),
],
),
array(
[
'name' => 'get-all-speakers',
'route' => '/api/v1/speakers',
'http_method' => 'GET',
@ -318,7 +318,25 @@ class ApiEndpointsSeeder extends Seeder
sprintf(SummitScopes::ReadSummitData, $current_realm),
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
],
),
],
[
'name' => 'get-speakers-active-involvements',
'route' => '/api/v1/speakers/active-involvements',
'http_method' => 'GET',
'scopes' => [
sprintf(SummitScopes::ReadSummitData, $current_realm),
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
],
],
[
'name' => 'get-speakers-organizational-roles',
'route' => '/api/v1/speakers/organizational-roles',
'http_method' => 'GET',
'scopes' => [
sprintf(SummitScopes::ReadSummitData, $current_realm),
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
],
],
array(
'name' => 'get-speaker',
'route' => '/api/v1/speakers/{speaker_id}',

View File

@ -0,0 +1,46 @@
<?php
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
/**
* Class OAuth2SpeakerActiveInvolvementApiTest
*/
final class OAuth2SpeakerActiveInvolvementApiTest extends ProtectedApiTest
{
public function testGelAll(){
$params = [
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"GET",
"OAuth2SpeakerActiveInvolvementApiController@getAll",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$involvements = json_decode($content);
$this->assertTrue(!is_null($involvements));
return $involvements;
}
}

View File

@ -0,0 +1,43 @@
<?php
/**
* Copyright 2018 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
final class OAuth2SpeakerOrganizationalRoleApiTest extends ProtectedApiTest
{
public function testGelAll(){
$params = [
];
$headers = [
"HTTP_Authorization" => " Bearer " . $this->access_token,
"CONTENT_TYPE" => "application/json"
];
$response = $this->action(
"GET",
"OAuth2SpeakerOrganizationalRoleApiController@getAll",
$params,
[],
[],
[],
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$roles = json_decode($content);
$this->assertTrue(!is_null($roles));
return $roles;
}
}