added new endpoint delete my presentation

DELETE /api/v1/summits/{id}/presentations/{presentation_id}

scopes

%s/summits/write
%s/summits/write-event
%s/summits/write-presentation

Change-Id: Ib23576a9f1e023c2570d6c39c3a084a6935f8b1d
This commit is contained in:
Sebastian Marcet 2018-09-20 12:35:29 -03:00
parent 7492438d7a
commit 76b206edbe
10 changed files with 119 additions and 10 deletions

View File

@ -404,4 +404,35 @@ final class OAuth2PresentationApiController extends OAuth2ProtectedController
return $this->error500($ex);
}
}
/**
* @param $presentation_id
* @return mixed
*/
public function deletePresentation($presentation_id){
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();
$this->presentation_service->deletePresentation($member, $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

@ -74,7 +74,6 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
*/
private $serializer_type_selector;
/**
* @var ISelectionPlanRepository
*/
@ -948,5 +947,4 @@ final class OAuth2SummitSpeakersApiController extends OAuth2ProtectedController
}
}
}

View File

@ -288,6 +288,8 @@ Route::group([
// opened without role CFP - valid selection plan on CFP status
Route::put('', 'OAuth2PresentationApiController@updatePresentationSubmission');
Route::delete('', 'OAuth2PresentationApiController@deletePresentation');
Route::group(['prefix' => 'videos'], function () {
Route::get('', 'OAuth2PresentationApiController@getPresentationVideos');
@ -604,6 +606,7 @@ Route::group([
Route::group(['prefix' => 'presentations'], function(){
Route::group(['prefix' => '{presentation_id}'], function(){
Route::group(['prefix' => 'speakers'], function(){
Route::put('{speaker_id}', 'OAuth2SummitSpeakersApiController@addSpeakerToMyPresentation');
Route::delete('{speaker_id}', 'OAuth2SummitSpeakersApiController@removeSpeakerFromMyPresentation');

View File

@ -67,4 +67,13 @@ interface IPresentationService
* @throws EntityNotFoundException
*/
public function updatePresentationSubmission(Summit $summit, $presentation_id, Member $member, array $data);
/**
* @param Member $member
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function deletePresentation(Member $member, $presentation_id);
}

View File

@ -261,5 +261,6 @@ interface ISummitService
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeakerFromModerator($current_member_id, $speaker_id, $presentation_id);
public function removeModeratorFromPresentation($current_member_id, $speaker_id, $presentation_id);
}

View File

@ -211,10 +211,14 @@ final class PresentationService
$current_speaker = $this->speaker_repository->getByMember($member);
if (is_null($current_speaker))
throw new ValidationException(trans());
throw new ValidationException(trans(
'validation_errors.PresentationService.submitPresentation.NotValidSpeaker'
));
if (is_null($current_selection_plan))
throw new ValidationException(trans());
throw new ValidationException(trans(
'validation_errors.PresentationService.submitPresentation.NotValidSelectionPlan'
));
// check qty
@ -267,15 +271,29 @@ final class PresentationService
$current_speaker = $this->speaker_repository->getByMember($member);
if (is_null($current_speaker))
throw new ValidationException(trans());
throw new ValidationException(trans(
'validation_errors.PresentationService.updatePresentationSubmission.NotValidSpeaker'
));
if (is_null($current_selection_plan))
throw new ValidationException(trans());
throw new ValidationException(trans(
'validation_errors.PresentationService.updatePresentationSubmission.NotValidSelectionPlan'
));
$presentation = $summit->getEvent($presentation_id);
if (is_null($current_selection_plan))
throw new EntityNotFoundException(trans());
if (is_null($presentation))
throw new EntityNotFoundException(trans(
'not_found_errors.PresentationService.updatePresentationSubmission.PresentationNotFound',
['presentation_id' => $presentation_id]
));
if(!$presentation->canEdit($current_speaker))
throw new ValidationException(trans(
'validation_errors.PresentationService.updatePresentationSubmission.CurrentSpeakerCanNotEditPresentation',
['presentation_id' => $presentation_id]
));
return $this->saveOrUpdatePresentation
(
@ -426,4 +444,36 @@ final class PresentationService
return $presentation;
});
}
/**
* @param Member $member
* @param int $presentation_id
* @throws ValidationException
* @throws EntityNotFoundException
* @return void
*/
public function deletePresentation(Member $member, $presentation_id)
{
return $this->tx_service->transaction(function () use ($member, $presentation_id) {
$current_speaker = $this->speaker_repository->getByMember($member);
if(is_null($current_speaker))
throw new EntityNotFoundException(sprintf("member %s does not has a speaker profile", $member->getId()));
$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",
$member->getId(),
$presentation_id
));
$this->event_repository->delete($presentation);
});
}
}

View File

@ -1784,7 +1784,7 @@ final class SummitService extends AbstractService implements ISummitService
* @throws EntityNotFoundException
* @return void
*/
public function removeSpeakerFromModerator($current_member_id, $speaker_id, $presentation_id)
public function removeModeratorFromPresentation($current_member_id, $speaker_id, $presentation_id)
{
return $this->tx_service->transaction(function () use ($current_member_id, $speaker_id, $presentation_id) {
@ -1816,4 +1816,5 @@ final class SummitService extends AbstractService implements ISummitService
$presentation->unsetModerator();
});
}
}

View File

@ -1471,6 +1471,16 @@ class ApiEndpointsSeeder extends Seeder
sprintf(SummitScopes::WritePresentationData, $current_realm)
],
],
[
'name' => 'delete-submit-presentation',
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}',
'http_method' => 'DELETE',
'scopes' => [
sprintf(SummitScopes::WriteSummitData, $current_realm),
sprintf(SummitScopes::WriteEventData, $current_realm),
sprintf(SummitScopes::WritePresentationData, $current_realm)
],
],
//videos
[
'name' => 'get-presentation-videos',

View File

@ -87,6 +87,7 @@ return [
'PresentationService.saveOrUpdatePresentation.trackNotFound' => 'track :track_id not found.',
'PresentationService.submitPresentation.eventTypeNotFound' => 'event type :type_id not found.',
'PresentationService.saveOrUpdatePresentation.trackQuestionNotFound' => 'extra question :question_id not found.',
'PresentationService.updatePresentationSubmission.PresentationNotFound' => 'presentation :presentation_id not found',
// track tag groups
'SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupNotFound' => 'track tag group :track_tag_group_id not found on summit :summit_id',
'SummitTrackTagGroupService.deleteTrackTagGroup.TrackTagGroupNotFound' => 'track tag group :track_tag_group_id not found on summit :summit_id',

View File

@ -84,6 +84,11 @@ return [
'PresentationService.saveOrUpdatePresentation.trackDontBelongToSelectionPlan' => 'track :track_id does not belongs to selection plan :selection_plan_id',
'PresentationService.submitPresentation.limitReached' => 'You reached the limit :limit of presentations.',
'PresentationService.saveOrUpdatePresentation.MaxAllowedLinks' => 'max. links quantity allowed is :max_allowed_links.',
'PresentationService.submitPresentation.NotValidSpeaker' => 'Current Member not has a valid speaker profile',
'PresentationService.submitPresentation.NotValidSelectionPlan' => 'Current Summit not has a valid selection plan',
'PresentationService.updatePresentationSubmission.NotValidSpeaker' => 'Current Member not has a valid speaker profile',
'PresentationService.updatePresentationSubmission.NotValidSelectionPlan' => 'Current Summit not has a valid selection plan',
'PresentationService.updatePresentationSubmission.CurrentSpeakerCanNotEditPresentation' => 'Current Speaker can not edit :presentation_id presentation',
// organizations
'OrganizationService.addOrganization.alreadyExistName' => 'Organization name :name already exists!',
// track tag groups