Added new endpoints to seed tags on summit tracks
seed allowed tag on all summit tracks POST /api/v1/summits/{id}/track-tag-groups/all/allowed-tags/{tag_id}/seed-on-tracks scopes %s/summits/write %s/tracks/write seed tag track group allowed tags on particular track POST /api/v1/summits/{id}/track-tag-groups/{track_tag_group_id}/allowed-tags/all/copy/tracks/{track_id} scopes %s/summits/write %s/tracks/write Change-Id: Ib0d58f5e34de54c86ad5377fb1a20657c246f908
This commit is contained in:
parent
62188c7815
commit
20d96d7182
|
@ -387,4 +387,59 @@ final class OAuth2SummitTrackTagGroupsApiController extends OAuth2ProtectedContr
|
|||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $tag_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function seedTagOnAllTracks($summit_id, $tag_id){
|
||||
try{
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
$this->track_tag_group_service->seedTagOnAllTrack($summit, $tag_id);
|
||||
return $this->updated();
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412([$ex1->getMessage()]);
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $summit_id
|
||||
* @param $track_tag_group_id
|
||||
* @param $track_id
|
||||
* @return mixed
|
||||
*/
|
||||
public function seedTagTrackGroupOnTrack($summit_id, $track_tag_group_id, $track_id){
|
||||
try{
|
||||
$summit = SummitFinderStrategyFactory::build($this->summit_repository, $this->resource_server_context)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
$this->track_tag_group_service->seedTagTrackGroupTagsOnTrack($summit, $track_tag_group_id, $track_id);
|
||||
return $this->updated();
|
||||
}
|
||||
catch (ValidationException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error412([$ex1->getMessage()]);
|
||||
}
|
||||
catch(EntityNotFoundException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error404(['message'=> $ex2->getMessage()]);
|
||||
}
|
||||
catch (\Exception $ex) {
|
||||
Log::error($ex);
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -563,12 +563,29 @@ Route::group([
|
|||
Route::delete('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@deleteTrackTagGroup']);
|
||||
|
||||
Route::group(['prefix' => 'allowed-tags'], function(){
|
||||
|
||||
Route::group(['prefix' => 'all'], function(){
|
||||
Route::post('copy/tracks/{track_id}',
|
||||
[ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@seedTagTrackGroupOnTrack']);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'all'], function(){
|
||||
Route::group(['prefix' => 'allowed-tags'], function(){
|
||||
|
||||
Route::get('', [ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@getAllowedTags']);
|
||||
|
||||
|
||||
Route::group(['prefix' => '{tag_id}'], function(){
|
||||
Route::post('seed-on-tracks',
|
||||
[ 'middleware' => 'auth.user:administrators|summit-front-end-administrators',
|
||||
'uses' => 'OAuth2SummitTrackTagGroupsApiController@seedTagOnAllTracks']);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -256,16 +256,22 @@ class PresentationCategory extends SilverstripeBaseModel
|
|||
|
||||
/**
|
||||
* @param PresentationCategoryGroup $group
|
||||
* @return $this
|
||||
*/
|
||||
public function addToGroup(PresentationCategoryGroup $group){
|
||||
if($this->groups->contains($group)) return $this;
|
||||
$this->groups->add($group);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PresentationCategoryGroup $group
|
||||
* @return $this
|
||||
*/
|
||||
public function removeFromGroup(PresentationCategoryGroup $group){
|
||||
if(!$this->groups->contains($group)) return $this;
|
||||
$this->groups->removeElement($group);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -281,10 +287,12 @@ class PresentationCategory extends SilverstripeBaseModel
|
|||
|
||||
/**
|
||||
* @param Tag $tag
|
||||
* @return $this
|
||||
*/
|
||||
public function addAllowedTag(Tag $tag){
|
||||
if($this->allowed_tags->contains($tag)) return;
|
||||
if($this->allowed_tags->contains($tag)) return $this;
|
||||
$this->allowed_tags->add($tag);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -54,6 +54,28 @@ interface ISummitTrackTagGroupService
|
|||
/**
|
||||
* @param Summit $summit
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function seedDefaultTrackTagGroups(Summit $summit);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $tag_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function seedTagOnAllTrack(Summit $summit, $tag_id);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $track_tag_group_id
|
||||
* @param int $track_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function seedTagTrackGroupTagsOnTrack(Summit $summit, $track_tag_group_id, $track_id);
|
||||
|
||||
}
|
|
@ -208,7 +208,7 @@ implements ISummitTrackTagGroupService
|
|||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function seedDefaultTrackTagGroups(Summit $summit)
|
||||
{
|
||||
|
@ -232,4 +232,88 @@ implements ISummitTrackTagGroupService
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $tag_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function seedTagOnAllTrack(Summit $summit, $tag_id)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $tag_id) {
|
||||
|
||||
$tag = $this->tag_repository->getById($tag_id);
|
||||
if(is_null($tag))
|
||||
throw new EntityNotFoundException(
|
||||
trans(
|
||||
"not_found_errors.SummitTrackTagGroupService.seedTagOnAllTrack.TagNotFound",
|
||||
[
|
||||
'tag_id' => $tag_id
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
$tag_track_group = $summit->getTrackTagGroupForTag($tag);
|
||||
|
||||
if(is_null($tag_track_group))
|
||||
throw new ValidationException(
|
||||
trans(
|
||||
'validation_errors.SummitTrackTagGroupService.seedTagOnAllTrack.TagDoesNotBelongToTrackTagGroup',
|
||||
[
|
||||
'tag_id' => $tag_id,
|
||||
'summit_id' => $summit->getId()
|
||||
]
|
||||
)
|
||||
);
|
||||
|
||||
foreach ($summit->getPresentationCategories() as $track){
|
||||
$track->addAllowedTag($tag);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $track_tag_group_id
|
||||
* @param int $track_id
|
||||
* @return void
|
||||
* @throws EntityNotFoundException
|
||||
* @throws ValidationException
|
||||
*/
|
||||
public function seedTagTrackGroupTagsOnTrack(Summit $summit, $track_tag_group_id, $track_id)
|
||||
{
|
||||
return $this->tx_service->transaction(function() use($summit, $track_tag_group_id, $track_id) {
|
||||
|
||||
$track_tag_group = $summit->getTrackTagGroup($track_tag_group_id);
|
||||
|
||||
if(is_null($track_tag_group)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans("not_found_errors.SummitTrackTagGroupService.seedTagTrackGroupTagsOnTrack.TrackTagGroupNotFound", [
|
||||
'summit_id' => $summit->getId(),
|
||||
'track_tag_group_id' => $track_tag_group_id,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
$track = $summit->getPresentationCategory($track_id);
|
||||
|
||||
if(is_null($track)){
|
||||
throw new EntityNotFoundException
|
||||
(
|
||||
trans("not_found_errors.SummitTrackTagGroupService.seedTagTrackGroupTagsOnTrack.TrackNotFound", [
|
||||
'summit_id' => $summit->getId(),
|
||||
'track_id' => $track_id,
|
||||
])
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($track_tag_group->getAllowedTags() as $allowedTag){
|
||||
$track->addAllowedTag($allowedTag->getTag());
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1804,7 +1804,16 @@ class ApiEndpointsSeeder extends Seeder
|
|||
'route' => '/api/v1/summits/{id}/track-tag-groups/all/allowed-tags',
|
||||
'http_method' => 'GET',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::ReadAllSummitData, $current_realm)
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm)
|
||||
],
|
||||
],
|
||||
[
|
||||
'name' => 'seed-track-tag-groups-allowed-tags',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups/all/allowed-tags/{tag_id}/seed-on-tracks',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTracksData, $current_realm),
|
||||
],
|
||||
],
|
||||
[
|
||||
|
@ -1850,7 +1859,16 @@ class ApiEndpointsSeeder extends Seeder
|
|||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTrackTagGroupsData, $current_realm)
|
||||
]
|
||||
]
|
||||
],
|
||||
[
|
||||
'name' => 'copy-track-tag-group-allowed-tags-to-track',
|
||||
'route' => '/api/v1/summits/{id}/track-tag-groups/{track_tag_group_id}/allowed-tags/all/copy/tracks/{track_id}',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [
|
||||
sprintf(SummitScopes::WriteSummitData, $current_realm),
|
||||
sprintf(SummitScopes::WriteTracksData, $current_realm)
|
||||
]
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -90,6 +90,9 @@ return [
|
|||
// 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',
|
||||
'SummitTrackTagGroupService.seedTagOnAllTrack.TagNotFound' => 'tag :tag_id not found',
|
||||
'SummitTrackTagGroupService.seedTagTrackGroupTagsOnTrack.TrackTagGroupNotFound' => 'track tag group :track_tag_group_id not found on summit :summit_id',
|
||||
'SummitTrackTagGroupService.seedTagTrackGroupTagsOnTrack.TrackNotFound' => 'track :track_id not found on summit :summit_id',
|
||||
// track question templates
|
||||
'TrackQuestionTemplateService.updateTrackQuestionTemplate.TrackQuestionTemplateNotFound' => 'track question template :track_question_template_id not found',
|
||||
'TrackQuestionTemplateService.deleteTrackQuestionTemplate.TrackQuestionTemplateNotFound' => 'track question template :track_question_template_id not found',
|
||||
|
|
|
@ -90,6 +90,7 @@ return [
|
|||
'SummitTrackTagGroupService.addTrackTagGroup.TrackTagGroupNameAlreadyExists' => 'track tag group name already exist on summit :summit_id',
|
||||
'SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupLabelAlreadyExists' => 'track tag group label already exist on summit :summit_id',
|
||||
'SummitTrackTagGroupService.updateTrackTagGroup.TrackTagGroupNameAlreadyExists' => 'track tag group name already exist on summit :summit_id',
|
||||
'SummitTrackTagGroupService.seedTagOnAllTrack.TagDoesNotBelongToTrackTagGroup' => 'tag :tag_id does not belongs to any track tag group on summit :summit_id',
|
||||
// track question templates
|
||||
'TrackQuestionTemplateService.addTrackQuestionTemplate.TrackQuestionTemplateLabelAlreadyExist' => 'track question template label already exists',
|
||||
'TrackQuestionTemplateService.addTrackQuestionTemplate.TrackQuestionTemplateNameAlreadyExist' => 'track question template name already exists',
|
||||
|
|
|
@ -206,4 +206,87 @@ final class OAuth2TrackTagGroupsApiTest extends ProtectedApiTest
|
|||
$this->assertTrue(!is_null($tags));
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
|
||||
public function testSeedDefaultTrackTagGroups($summit_id = 25)
|
||||
{
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitTrackTagGroupsApiController@seedDefaultTrackTagGroups",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$tags = json_decode($content);
|
||||
$this->assertTrue(!is_null($tags));
|
||||
$this->assertResponseStatus(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @param int $tag_id
|
||||
*/
|
||||
public function testSeedTagOnAllTracks($summit_id = 25, $tag_id = 4590)
|
||||
{
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'tag_id' => $tag_id,
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitTrackTagGroupsApiController@seedTagOnAllTracks",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$response = json_decode($content);
|
||||
$this->assertResponseStatus(201);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $summit_id
|
||||
* @param int $track_tag_group_id
|
||||
* @param $track_id
|
||||
*/
|
||||
public function testSeedTagTrackGroupOnTrack($summit_id = 25, $track_tag_group_id = 6, $track_id = 268)
|
||||
{
|
||||
|
||||
$params = [
|
||||
'id' => $summit_id,
|
||||
'track_tag_group_id' => $track_tag_group_id,
|
||||
'track_id' => $track_id,
|
||||
];
|
||||
|
||||
$headers = ["HTTP_Authorization" => " Bearer " . $this->access_token];
|
||||
$response = $this->action(
|
||||
"POST",
|
||||
"OAuth2SummitTrackTagGroupsApiController@seedTagTrackGroupOnTrack",
|
||||
$params,
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
$headers
|
||||
);
|
||||
|
||||
$content = $response->getContent();
|
||||
$response = json_decode($content);
|
||||
$this->assertResponseStatus(201);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue