added endpoints for my presentations moderators

PUT /api/v1/speakers/me/presentations/{presentation_id}/moderators/{speaker_id}
DELETE /api/v1/speakers/me/presentations/{presentation_id}/moderators/{speaker_id}

Change-Id: I2b46246bdf2fbfd62d89ab0fd1449ad63c6bc419
This commit is contained in:
Sebastian Marcet 2018-09-18 13:04:24 -03:00
parent 8860cee7d8
commit fa96c4c1a0
7 changed files with 188 additions and 33 deletions

View File

@ -872,13 +872,40 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
* @param $speaker_id
* @return mixed
*/
public function removeSpeakerToMyPresentation($presentation_id, $speaker_id){
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();
$this->summit_service->removeSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id);
$this->summit_service->addModerator2Presentation($current_member_id, $speaker_id, $presentation_id);
return $this->updated();
} catch (ValidationException $ex1) {
Log::warning($ex1);
return $this->error412(array($ex1->getMessage()));
} catch (EntityNotFoundException $ex2) {
Log::warning($ex2);
return $this->error404(array('message' => $ex2->getMessage()));
} catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
/**
* @param $presentation_id
* @param $speaker_id
* @return mixed
*/
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();
$this->summit_service->removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id);
return $this->deleted();
@ -893,4 +920,33 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
return $this->error500($ex);
}
}
/**
* @param $presentation_id
* @param $speaker_id
* @return mixed
*/
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();
$this->summit_service->removeModeratorFromPresentation($current_member_id, $speaker_id, $presentation_id);
return $this->deleted();
} catch (ValidationException $ex1) {
Log::warning($ex1);
return $this->error412(array($ex1->getMessage()));
} catch (EntityNotFoundException $ex2) {
Log::warning($ex2);
return $this->error404(array('message' => $ex2->getMessage()));
} catch (Exception $ex) {
Log::error($ex);
return $this->error500($ex);
}
}
}

View File

@ -607,10 +607,11 @@ Route::group([
Route::group(['prefix' => '{presentation_id}'], function(){
Route::group(['prefix' => 'speakers'], function(){
Route::put('{speaker_id}', 'OAuth2SummitSpeakersApiController@addSpeakerToMyPresentation');
Route::delete('{speaker_id}', 'OAuth2SummitSpeakersApiController@removeSpeakerToMyPresentation');
Route::delete('{speaker_id}', 'OAuth2SummitSpeakersApiController@removeSpeakerFromMyPresentation');
});
Route::group(['prefix' => 'moderators'], function(){
Route::put('{speaker_id}', 'OAuth2SummitSpeakersApiController@addModeratorToMyPresentation');
Route::delete('{speaker_id}', 'OAuth2SummitSpeakersApiController@removeModeratorFromMyPresentation');
});
});
Route::group(['prefix' => '{role}'], function(){

View File

@ -23,12 +23,6 @@ use Doctrine\ORM\Mapping AS ORM;
class DefaultTrackTagGroupAllowedTag extends BaseEntity
{
/**
* @ORM\Column(name="IsDefault", type="boolean")
* @var boolean
*/
private $is_default;
/**
* @ORM\ManyToOne(targetEntity="models\main\Tag")
* @ORM\JoinColumn(name="TagID", referencedColumnName="ID")
@ -38,7 +32,7 @@ class DefaultTrackTagGroupAllowedTag extends BaseEntity
/**
* @ORM\ManyToOne(targetEntity="DefaultTrackTagGroup", inversedBy="allowed_tags")
* @ORM\JoinColumn(name="TrackTagGroupID", referencedColumnName="ID")
* @ORM\JoinColumn(name="DefaultTrackTagGroupID", referencedColumnName="ID")
* @var DefaultTrackTagGroup
*/
private $track_tag_group;
@ -67,23 +61,6 @@ class DefaultTrackTagGroupAllowedTag extends BaseEntity
}
}
/**
* @return bool
*/
public function isDefault()
{
return $this->is_default;
}
/**
* @param bool $is_default
*/
public function setIsDefault($is_default)
{
$this->is_default = $is_default;
}
/**
* @return Tag
*/

View File

@ -241,5 +241,25 @@ interface ISummitService
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id);
public function addModerator2Presentation($current_member_id, $speaker_id, $presentation_id);
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id);
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeakerFromModerator($current_member_id, $speaker_id, $presentation_id);
}

View File

@ -1703,7 +1703,7 @@ final class SummitService extends AbstractService implements ISummitService
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeaker2Presentation($current_member_id, $speaker_id, $presentation_id)
public function removeSpeakerFromPresentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
@ -1735,4 +1735,85 @@ final class SummitService extends AbstractService implements ISummitService
$presentation->removeSpeaker($speaker);
});
}
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function addModerator2Presentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
throw new EntityNotFoundException(sprintf("member %s not found", $current_member_id));
$current_speaker = $this->speaker_repository->getByMember($current_member);
if(is_null($current_speaker))
throw new EntityNotFoundException(sprintf("member %s does not has a speaker profile", $current_member_id));
$presentation = $this->event_repository->getById($presentation_id);
if(is_null($presentation))
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation instanceof Presentation)
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation->canEdit($current_speaker))
throw new ValidationException(sprintf("member %s can not edit presentation %s",
$current_member_id,
$presentation_id
));
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker))
throw new EntityNotFoundException(sprintf('speaker %s not found', $speaker_id));
$presentation->setModerator($speaker);
});
}
/**
* @param int $current_member_id
* @param int $speaker_id
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeakerFromModerator($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
$current_member = $this->member_repository->getById($current_member_id);
if(is_null($current_member))
throw new EntityNotFoundException(sprintf("member %s not found", $current_member_id));
$current_speaker = $this->speaker_repository->getByMember($current_member);
if(is_null($current_speaker))
throw new EntityNotFoundException(sprintf("member %s does not has a speaker profile", $current_member_id));
$presentation = $this->event_repository->getById($presentation_id);
if(is_null($presentation))
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation instanceof Presentation)
throw new EntityNotFoundException(sprintf("presentation %s not found", $presentation_id));
if(!$presentation->canEdit($current_speaker))
throw new ValidationException(sprintf("member %s can not edit presentation %s",
$current_member_id,
$presentation_id
));
$speaker = $this->speaker_repository->getById(intval($speaker_id));
if (is_null($speaker))
throw new EntityNotFoundException(sprintf('speaker %s not found', $speaker_id));
$presentation->unsetModerator();
});
}
}

View File

@ -357,7 +357,7 @@ class ApiEndpointsSeeder extends Seeder
],
],
[
'name' => 'remove-speaker-2-my-presentation',
'name' => 'remove-speaker-from-my-presentation',
'route' => '/api/v1/speakers/me/presentations/{presentation_id}/speakers/{speaker_id}',
'http_method' => 'DELETE',
'scopes' => [
@ -366,6 +366,26 @@ class ApiEndpointsSeeder extends Seeder
sprintf(SummitScopes::WriteMySpeakersData, $current_realm)
],
],
[
'name' => 'add-moderator-2-my-presentation',
'route' => '/api/v1/speakers/me/presentations/{presentation_id}/moderators/{speaker_id}',
'http_method' => 'PUT',
'scopes' => [
sprintf(SummitScopes::WriteSummitData, $current_realm),
sprintf(SummitScopes::WriteSpeakersData, $current_realm),
sprintf(SummitScopes::WriteMySpeakersData, $current_realm)
],
],
[
'name' => 'remove-moderators-from-my-presentation',
'route' => '/api/v1/speakers/me/presentations/{presentation_id}/moderators/{speaker_id}',
'http_method' => 'DELETE',
'scopes' => [
sprintf(SummitScopes::WriteSummitData, $current_realm),
sprintf(SummitScopes::WriteSpeakersData, $current_realm),
sprintf(SummitScopes::WriteMySpeakersData, $current_realm)
],
],
array(
'name' => 'create-my-speaker',
'route' => '/api/v1/speakers/me',

View File

@ -207,7 +207,7 @@ final class OAuth2TrackTagGroupsApiTest extends ProtectedApiTest
$this->assertResponseStatus(200);
}
public function testSeedDefaultTrackTagGroups($summit_id = 25)
public function testSeedDefaultTrackTagGroups($summit_id = 26)
{
$params = [
@ -228,7 +228,7 @@ final class OAuth2TrackTagGroupsApiTest extends ProtectedApiTest
$content = $response->getContent();
$tags = json_decode($content);
$this->assertTrue(!is_null($tags));
$this->assertResponseStatus(200);
$this->assertResponseStatus(201);
}
/**