Added new Upload Summit Event Attachment Endpoint
POST api/v1/summits/{:summit_id}/events/{:event_id}/attachment Change-Id: I41bdb5b9551165682c0fd6ea5eb0b0d21c792ba0
This commit is contained in:
parent
412c5d63cf
commit
615b3dbf7c
@ -62,3 +62,9 @@ SS_ENCRYPT_CYPHER=AES-256-CBC
|
||||
GOOGLE_CLIENT_ID=""
|
||||
GOOGLE_CLIENT_SECRET=""
|
||||
GOOGLE_SCOPES=""
|
||||
|
||||
SSH_USER=
|
||||
SSH_PUBLIC_KEY=
|
||||
SSH_PRIVATE_KEY=
|
||||
SCP_HOST=
|
||||
SCP_REMOTE_BASE_PATH=/tmp
|
73
app/Events/FileCreated.php
Normal file
73
app/Events/FileCreated.php
Normal file
@ -0,0 +1,73 @@
|
||||
<?php namespace App\Events;
|
||||
/**
|
||||
* Copyright 2017 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 Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class FileCreated
|
||||
* @package App\Events
|
||||
*/
|
||||
final class FileCreated extends Event
|
||||
{
|
||||
use SerializesModels;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $local_path;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $file_name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $folder_name;
|
||||
|
||||
|
||||
public function __construct($local_path, $file_name, $folder_name)
|
||||
{
|
||||
$this->local_path = $local_path;
|
||||
$this->file_name = $file_name;
|
||||
$this->folder_name = $folder_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getLocalPath()
|
||||
{
|
||||
return $this->local_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFileName()
|
||||
{
|
||||
return $this->file_name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFolderName()
|
||||
{
|
||||
return $this->folder_name;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -821,4 +821,42 @@ final class OAuth2SummitEventsApiController extends OAuth2ProtectedController
|
||||
return [$summit, $event, $data];
|
||||
}
|
||||
|
||||
|
||||
public function addEventAttachment(LaravelRequest $request, $summit_id, $event_id){
|
||||
|
||||
try {
|
||||
|
||||
$file = $request->file('file');
|
||||
if (is_null($file)) {
|
||||
return $this->error412(array('file param not set!'));
|
||||
}
|
||||
|
||||
$summit = SummitFinderStrategyFactory::build($this->repository)->find($summit_id);
|
||||
if (is_null($summit)) return $this->error404();
|
||||
|
||||
$res = $this->service->addEventAttachment($summit, $event_id, $file);
|
||||
|
||||
return !is_null($res) ? $this->created($res->getId()) : $this->error400();
|
||||
}
|
||||
catch (EntityNotFoundException $ex1) {
|
||||
Log::warning($ex1);
|
||||
return $this->error404();
|
||||
}
|
||||
catch(ValidationException $ex2)
|
||||
{
|
||||
Log::warning($ex2);
|
||||
return $this->error412(array($ex2->getMessage()));
|
||||
}
|
||||
catch(\HTTP401UnauthorizedException $ex3)
|
||||
{
|
||||
Log::warning($ex3);
|
||||
return $this->error401();
|
||||
}
|
||||
catch (Exception $ex) {
|
||||
Log::error($ex);
|
||||
|
||||
return $this->error500($ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -12,5 +12,5 @@ use Illuminate\Foundation\Auth\Access\AuthorizesResources;
|
||||
*/
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, AuthorizesResources, DispatchesJobs, ValidatesRequests;
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
}
|
||||
|
@ -85,22 +85,22 @@ abstract class JsonController extends Controller
|
||||
return $res;
|
||||
}
|
||||
|
||||
protected function error400($data)
|
||||
protected function error400($data = ['message' => 'Bad Request'])
|
||||
{
|
||||
return Response::json($data, 400);
|
||||
}
|
||||
|
||||
protected function error404($data = array('message' => 'Entity Not Found'))
|
||||
protected function error404($data = ['message' => 'Entity Not Found'])
|
||||
{
|
||||
return Response::json($data, 404);
|
||||
}
|
||||
|
||||
protected function error403($data = array('message' => 'Forbidden'))
|
||||
protected function error403($data = ['message' => 'Forbidden'])
|
||||
{
|
||||
return Response::json($data, 403);
|
||||
}
|
||||
|
||||
protected function error401($data = array('message' => 'You don\'t have access to this item through the API.'))
|
||||
protected function error401($data = ['message' => 'You don\'t have access to this item through the API.'])
|
||||
{
|
||||
return Response::json($data, 401);
|
||||
}
|
||||
|
53
app/Http/Utils/FileUploader.php
Normal file
53
app/Http/Utils/FileUploader.php
Normal file
@ -0,0 +1,53 @@
|
||||
<?php namespace App\Http\Utils;
|
||||
/**
|
||||
* Copyright 2017 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\Events\FileCreated;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use models\main\File;
|
||||
use models\main\IFolderRepository;
|
||||
|
||||
/**
|
||||
* Class FileUploader
|
||||
* @package App\Http\Utils
|
||||
*/
|
||||
final class FileUploader
|
||||
{
|
||||
/**
|
||||
* @var IFolderRepository
|
||||
*/
|
||||
private $folder_repository;
|
||||
|
||||
public function __construct(IFolderRepository $folder_repository){
|
||||
$this->folder_repository = $folder_repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param UploadedFile $file
|
||||
* @param $folder_name
|
||||
* @return File
|
||||
*/
|
||||
public function build(UploadedFile $file, $folder_name){
|
||||
$attachment = new File();
|
||||
$local_path = Storage::putFileAs(sprintf('/public/%s', $folder_name), $file, $file->getClientOriginalName());
|
||||
$folder = $this->folder_repository->getFolderByName($folder_name);
|
||||
$attachment->setParent($folder);
|
||||
$attachment->setName($file->getClientOriginalName());
|
||||
$attachment->setFilename(sprintf("assets/%s/%s",$folder_name, $file->getClientOriginalName()));
|
||||
$attachment->setTitle(str_replace(array('-','_'),' ', preg_replace('/\.[^.]+$/', '', $file->getClientOriginalName())));
|
||||
$attachment->setShowInSearch(true);
|
||||
Event::fire(new FileCreated($local_path, $file->getClientOriginalName(), $folder_name));
|
||||
return $attachment;
|
||||
}
|
||||
}
|
@ -194,6 +194,7 @@ Route::group([
|
||||
Route::put('/publish', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@publishEvent']);
|
||||
Route::delete('/publish', [ 'middleware' => 'auth.user:administrators', 'uses' => 'OAuth2SummitEventsApiController@unPublishEvent']);
|
||||
Route::post('/feedback', 'OAuth2SummitEventsApiController@addEventFeedback');
|
||||
Route::post('/attachment', 'OAuth2SummitEventsApiController@addEventAttachment');
|
||||
Route::get('/feedback/{attendee_id?}', ['middleware' => 'cache:'.Config::get('cache_api_response.get_event_feedback_response_lifetime', 300), 'uses' => 'OAuth2SummitEventsApiController@getEventFeedback'] )->where('attendee_id', 'me|[0-9]+');
|
||||
});
|
||||
});
|
||||
|
109
app/Models/Foundation/Main/AssetsSyncRequest.php
Normal file
109
app/Models/Foundation/Main/AssetsSyncRequest.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php namespace models\main;
|
||||
/**
|
||||
* Copyright 2017 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 models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* @ORM\Entity(repositoryClass="repositories\main\DoctrineAssetsSyncRequestRepository")
|
||||
* @ORM\Table(name="AssetsSyncRequest")
|
||||
* Class File
|
||||
* @package models\main
|
||||
*/
|
||||
class AssetsSyncRequest extends SilverstripeBaseModel
|
||||
{
|
||||
/**
|
||||
* @ORM\Column(name="`From`", type="string")
|
||||
*/
|
||||
private $from;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="`To`", type="string")
|
||||
*/
|
||||
private $to;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Processed", type="boolean")
|
||||
*/
|
||||
private $processed;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="ProcessedDate", type="datetime")
|
||||
*/
|
||||
private $processed_date;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getFrom()
|
||||
{
|
||||
return $this->from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $from
|
||||
*/
|
||||
public function setFrom($from)
|
||||
{
|
||||
$this->from = $from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getTo()
|
||||
{
|
||||
return $this->to;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $to
|
||||
*/
|
||||
public function setTo($to)
|
||||
{
|
||||
$this->to = $to;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getProcessed()
|
||||
{
|
||||
return $this->processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $processed
|
||||
*/
|
||||
public function setProcessed($processed)
|
||||
{
|
||||
$this->processed = $processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DateTime
|
||||
*/
|
||||
public function getProcessedDate()
|
||||
{
|
||||
return $this->processed_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param DateTime $processed_date
|
||||
*/
|
||||
public function setProcessedDate($processed_date)
|
||||
{
|
||||
$this->processed_date = $processed_date;
|
||||
}
|
||||
}
|
@ -11,12 +11,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
**/
|
||||
|
||||
use models\utils\SilverstripeBaseModel;
|
||||
use Doctrine\ORM\Mapping AS ORM;
|
||||
|
||||
/**
|
||||
* @ORM\Entity
|
||||
* @ORM\Entity(repositoryClass="repositories\main\DoctrineFolderRepository")
|
||||
* @ORM\Table(name="File")
|
||||
* Class File
|
||||
* @package models\main
|
||||
@ -28,20 +26,15 @@ class File extends SilverstripeBaseModel
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(){ return $this->name;}
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Title", type="string")
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @ORM\Column(name="Content", type="string")
|
||||
*/
|
||||
public function getTitle(){ return $this->title;}
|
||||
private $content;
|
||||
|
||||
/**
|
||||
* @ORM\Column(name="Filename", type="string")
|
||||
@ -49,7 +42,134 @@ class File extends SilverstripeBaseModel
|
||||
private $filename;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
* @ORM\Column(name="ShowInSearch", type="boolean")
|
||||
* @var bool
|
||||
*/
|
||||
public function getFilename(){ return $this->filename;}
|
||||
private $show_in_search;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\File")
|
||||
* @ORM\JoinColumn(name="ParentID", referencedColumnName="ID")
|
||||
* @var File
|
||||
*/
|
||||
private $parent;
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\Member")
|
||||
* @ORM\JoinColumn(name="OwnerID", referencedColumnName="ID")
|
||||
* @var Member
|
||||
*/
|
||||
private $owner;
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $name
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getTitle()
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $title
|
||||
*/
|
||||
public function setTitle($title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getContent()
|
||||
{
|
||||
return $this->content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $content
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$this->content = $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getFilename()
|
||||
{
|
||||
return $this->filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $filename
|
||||
*/
|
||||
public function setFilename($filename)
|
||||
{
|
||||
$this->filename = $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isShowInSearch()
|
||||
{
|
||||
return $this->show_in_search;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $show_in_search
|
||||
*/
|
||||
public function setShowInSearch($show_in_search)
|
||||
{
|
||||
$this->show_in_search = $show_in_search;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return File
|
||||
*/
|
||||
public function getParent()
|
||||
{
|
||||
return $this->parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param File $parent
|
||||
*/
|
||||
public function setParent($parent)
|
||||
{
|
||||
$this->parent = $parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Member
|
||||
*/
|
||||
public function getOwner()
|
||||
{
|
||||
return $this->owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Member $owner
|
||||
*/
|
||||
public function setOwner($owner)
|
||||
{
|
||||
$this->owner = $owner;
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
<?php namespace models\main;
|
||||
/**
|
||||
* Copyright 2017 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 models\utils\IBaseRepository;
|
||||
/**
|
||||
* Interface IAssetsSyncRequestRepository
|
||||
* @package models\main
|
||||
*/
|
||||
interface IAssetsSyncRequestRepository extends IBaseRepository
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
<?php namespace models\main;
|
||||
/**
|
||||
* Copyright 2017 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 models\utils\IBaseRepository;
|
||||
/**
|
||||
* Interface IFolderRepository
|
||||
* @package models\main
|
||||
*/
|
||||
interface IFolderRepository extends IBaseRepository
|
||||
{
|
||||
/**
|
||||
* @param string $folder_name
|
||||
* @return File
|
||||
*/
|
||||
public function getFolderByName($folder_name);
|
||||
}
|
@ -31,7 +31,7 @@ class SummitEventWithFile extends SummitEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* @ORM\ManyToOne(targetEntity="models\main\File")
|
||||
* @ORM\ManyToOne(targetEntity="models\main\File",cascade={"persist"})
|
||||
* @ORM\JoinColumn(name="AttachmentID", referencedColumnName="ID")
|
||||
* @var File
|
||||
*/
|
||||
|
@ -19,12 +19,11 @@ class AuthServiceProvider extends ServiceProvider
|
||||
/**
|
||||
* Register any application authentication / authorization services.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Access\Gate $gate
|
||||
* @return void
|
||||
*/
|
||||
public function boot(GateContract $gate)
|
||||
public function boot()
|
||||
{
|
||||
$this->registerPolicies($gate);
|
||||
$this->registerPolicies();
|
||||
|
||||
//
|
||||
}
|
||||
|
@ -1,5 +1,16 @@
|
||||
<?php namespace App\Providers;
|
||||
|
||||
/**
|
||||
* Copyright 2017 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\Events\MyFavoritesAdd;
|
||||
use App\Events\SummitEventCreated;
|
||||
use App\Events\SummitEventDeleted;
|
||||
@ -7,13 +18,17 @@ use App\Events\SummitEventUpdated;
|
||||
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
|
||||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use LaravelDoctrine\ORM\Facades\Registry;
|
||||
use models\main\AssetsSyncRequest;
|
||||
use models\summit\SummitEntityEvent;
|
||||
use App\Events\MyScheduleAdd;
|
||||
use App\Events\MyScheduleRemove;
|
||||
use Doctrine\ORM\Event\PreUpdateEventArgs;
|
||||
use models\utils\PreRemoveEventArgs;
|
||||
use IDCT\Networking\Ssh\SftpClient;
|
||||
use IDCT\Networking\Ssh\Credentials;
|
||||
|
||||
/**
|
||||
* Class EventServiceProvider
|
||||
@ -35,12 +50,11 @@ class EventServiceProvider extends ServiceProvider
|
||||
|
||||
/**
|
||||
* Register any other events for your application.
|
||||
* @param \Illuminate\Contracts\Events\Dispatcher $events
|
||||
* @return void
|
||||
*/
|
||||
public function boot(DispatcherContract $events)
|
||||
public function boot()
|
||||
{
|
||||
parent::boot($events);
|
||||
parent::boot();
|
||||
|
||||
Event::listen(\App\Events\MyScheduleAdd::class, function($event)
|
||||
{
|
||||
@ -276,5 +290,39 @@ class EventServiceProvider extends ServiceProvider
|
||||
|
||||
});
|
||||
|
||||
Event::listen(\App\Events\FileCreated::class, function($event)
|
||||
{
|
||||
|
||||
$storage_path = storage_path();
|
||||
$local_path = $event->getLocalPath();
|
||||
$file_name = $event->getFileName();
|
||||
$folder_name = $event->getFolderName();
|
||||
$remote_base_path = Config::get('scp.scp_remote_base_path', null);
|
||||
$client = new SftpClient();
|
||||
$host = Config::get('scp.scp_host', null);
|
||||
|
||||
$credentials = Credentials::withPublicKey
|
||||
(
|
||||
Config::get('scp.ssh_user', null),
|
||||
Config::get('scp.ssh_public_key', null),
|
||||
Config::get('scp.ssh_private_key', null)
|
||||
);
|
||||
|
||||
$client->setCredentials($credentials);
|
||||
$client->connect($host);
|
||||
$remote_destination = sprintf("%s/%s",$remote_base_path, $file_name);
|
||||
$client->scpUpload(sprintf("%s/app/%s", $storage_path, $local_path), $remote_destination);
|
||||
$client->close();
|
||||
|
||||
$asset_sync_request = new AssetsSyncRequest();
|
||||
$asset_sync_request->setFrom($remote_destination);
|
||||
$asset_sync_request->setTo(sprintf("%s/%s", $folder_name, $file_name));
|
||||
$asset_sync_request->setProcessed(false);
|
||||
$em = Registry::getManager('ss');
|
||||
$em->persist($asset_sync_request);
|
||||
$em->flush();
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,12 @@ class RouteServiceProvider extends ServiceProvider
|
||||
/**
|
||||
* Define your route model bindings, pattern filters, etc.
|
||||
*
|
||||
* @param \Illuminate\Routing\Router $router
|
||||
* @return void
|
||||
*/
|
||||
public function boot(Router $router)
|
||||
public function boot()
|
||||
{
|
||||
//
|
||||
|
||||
parent::boot($router);
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -0,0 +1,36 @@
|
||||
<?php namespace repositories\main;
|
||||
|
||||
|
||||
/**
|
||||
* Copyright 2017 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\Repositories\SilverStripeDoctrineRepository;
|
||||
use models\main\AssetsSyncRequest;
|
||||
use models\main\IAssetsSyncRequestRepository;
|
||||
|
||||
/**
|
||||
* Class DoctrineAssetsSyncRequestRepository
|
||||
* @package repositories\main
|
||||
*/
|
||||
class DoctrineAssetsSyncRequestRepository
|
||||
extends SilverStripeDoctrineRepository
|
||||
implements IAssetsSyncRequestRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return AssetsSyncRequest::class;
|
||||
}
|
||||
}
|
56
app/Repositories/Main/DoctrineFolderRepository.php
Normal file
56
app/Repositories/Main/DoctrineFolderRepository.php
Normal file
@ -0,0 +1,56 @@
|
||||
<?php namespace repositories\main;
|
||||
/**
|
||||
* Copyright 2017 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\Repositories\SilverStripeDoctrineRepository;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
use models\main\File;
|
||||
use models\main\IFolderRepository;
|
||||
/**
|
||||
* Class DoctrineFolderRepository
|
||||
* @package repositories\main
|
||||
*/
|
||||
final class DoctrineFolderRepository
|
||||
extends SilverStripeDoctrineRepository
|
||||
implements IFolderRepository
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $folder_name
|
||||
* @return File
|
||||
*/
|
||||
public function getFolderByName($folder_name)
|
||||
{
|
||||
|
||||
$query = <<<SQL
|
||||
select * from File where ClassName = 'Folder' AND
|
||||
Name = :folder_name
|
||||
SQL;
|
||||
|
||||
// build rsm here
|
||||
$rsm = new ResultSetMappingBuilder($this->_em);
|
||||
$rsm->addRootEntityFromClassMetadata(\models\main\File::class, 'f');
|
||||
$native_query = $this->_em->createNativeQuery($query, $rsm);
|
||||
|
||||
$native_query->setParameter("folder_name", $folder_name);
|
||||
|
||||
return $native_query->getSingleResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseEntity()
|
||||
{
|
||||
return File::class;
|
||||
}
|
||||
}
|
@ -14,6 +14,9 @@
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use LaravelDoctrine\ORM\Facades\EntityManager;
|
||||
use models\main\AssetsSyncRequest;
|
||||
use models\main\File;
|
||||
|
||||
/**
|
||||
* Class RepositoriesProvider
|
||||
* @package repositories
|
||||
@ -181,5 +184,17 @@ final class RepositoriesProvider extends ServiceProvider
|
||||
function(){
|
||||
return EntityManager::getRepository(\App\Models\Foundation\Marketplace\RemoteCloudService::class);
|
||||
});
|
||||
|
||||
App::singleton(
|
||||
'models\main\IFolderRepository',
|
||||
function(){
|
||||
return EntityManager::getRepository(File::class);
|
||||
});
|
||||
|
||||
App::singleton(
|
||||
'models\main\IAssetsSyncRequestRepository',
|
||||
function(){
|
||||
return EntityManager::getRepository(AssetsSyncRequest::class);
|
||||
});
|
||||
}
|
||||
}
|
@ -1,7 +1,9 @@
|
||||
<?php namespace services\model;
|
||||
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\main\File;
|
||||
use models\main\Member;
|
||||
use models\summit\ConfirmationExternalOrderRequest;
|
||||
use models\summit\Summit;
|
||||
@ -146,4 +148,15 @@ interface ISummitService
|
||||
* @return bool
|
||||
*/
|
||||
public function unRSVPEvent(Summit $summit ,Member $member, $event_id);
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $event_id
|
||||
* @param UploadedFile $file
|
||||
* @param int $max_file_size
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
* @return File
|
||||
*/
|
||||
public function addEventAttachment(Summit $summit, $event_id, UploadedFile $file, $max_file_size = 10485760);
|
||||
}
|
@ -15,11 +15,16 @@ use App\Events\MyFavoritesAdd;
|
||||
use App\Events\MyFavoritesRemove;
|
||||
use App\Events\MyScheduleAdd;
|
||||
use App\Events\MyScheduleRemove;
|
||||
use App\Http\Utils\FileUploader;
|
||||
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
||||
use GuzzleHttp\Exception\ClientException;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use models\exceptions\EntityNotFoundException;
|
||||
use models\exceptions\ValidationException;
|
||||
use models\main\File;
|
||||
use models\main\IFolderRepository;
|
||||
use models\main\IMemberRepository;
|
||||
use models\main\ITagRepository;
|
||||
use Models\foundation\summit\EntityEvents\EntityEventTypeFactory;
|
||||
@ -42,6 +47,7 @@ use models\summit\SummitAttendeeTicket;
|
||||
use models\summit\SummitEvent;
|
||||
use models\summit\SummitEventFactory;
|
||||
use models\summit\SummitEventFeedback;
|
||||
use models\summit\SummitEventWithFile;
|
||||
use services\apis\IEventbriteAPI;
|
||||
use libs\utils\ITransactionService;
|
||||
use Exception;
|
||||
@ -113,6 +119,11 @@ final class SummitService implements ISummitService
|
||||
*/
|
||||
private $calendar_sync_work_request_repository;
|
||||
|
||||
/**
|
||||
* @var IFolderRepository
|
||||
*/
|
||||
private $folder_repository;
|
||||
|
||||
/**
|
||||
* SummitService constructor.
|
||||
* @param ISummitEventRepository $event_repository
|
||||
@ -122,9 +133,10 @@ final class SummitService implements ISummitService
|
||||
* @param ISummitAttendeeRepository $attendee_repository
|
||||
* @param IMemberRepository $member_repository
|
||||
* @param ITagRepository $tag_repository
|
||||
* @param IRSVPRepository $rsvp_repository,
|
||||
* @param IRSVPRepository $rsvp_repository
|
||||
* @param IAbstractCalendarSyncWorkRequestRepository $calendar_sync_work_request_repository
|
||||
* @param IEventbriteAPI $eventbrite_api
|
||||
* @param IFolderRepository $folder_repository
|
||||
* @param ITransactionService $tx_service
|
||||
*/
|
||||
public function __construct
|
||||
@ -139,6 +151,7 @@ final class SummitService implements ISummitService
|
||||
IRSVPRepository $rsvp_repository,
|
||||
IAbstractCalendarSyncWorkRequestRepository $calendar_sync_work_request_repository,
|
||||
IEventbriteAPI $eventbrite_api,
|
||||
IFolderRepository $folder_repository,
|
||||
ITransactionService $tx_service
|
||||
)
|
||||
{
|
||||
@ -152,6 +165,7 @@ final class SummitService implements ISummitService
|
||||
$this->rsvp_repository = $rsvp_repository;
|
||||
$this->calendar_sync_work_request_repository = $calendar_sync_work_request_repository;
|
||||
$this->eventbrite_api = $eventbrite_api;
|
||||
$this->folder_repository = $folder_repository;
|
||||
$this->tx_service = $tx_service;
|
||||
}
|
||||
|
||||
@ -985,4 +999,46 @@ final class SummitService implements ISummitService
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Summit $summit
|
||||
* @param int $event_id
|
||||
* @param UploadedFile $file
|
||||
* @param int $max_file_size
|
||||
* @throws ValidationException
|
||||
* @throws EntityNotFoundException
|
||||
* @return File
|
||||
*/
|
||||
public function addEventAttachment(Summit $summit, $event_id, UploadedFile $file, $max_file_size = 10485760)
|
||||
{
|
||||
return $this->tx_service->transaction(function () use ($summit, $event_id, $file, $max_file_size) {
|
||||
|
||||
$allowed_extensions = ['png','jpg','jpeg','gif','pdf'];
|
||||
|
||||
$event = $summit->getEvent($event_id);
|
||||
|
||||
if (is_null($event)) {
|
||||
throw new EntityNotFoundException('event not found on summit!');
|
||||
}
|
||||
|
||||
if(!$event instanceof SummitEventWithFile){
|
||||
throw new ValidationException(sprintf("event id %s does not allow attachments!", $event_id));
|
||||
}
|
||||
|
||||
if(!in_array($file->extension(), $allowed_extensions)){
|
||||
throw new ValidationException("file does not has a valid extension ('png','jpg','jpeg','gif','pdf').");
|
||||
}
|
||||
|
||||
if($file->getSize() > $max_file_size)
|
||||
{
|
||||
throw new ValidationException(sprintf( "file exceeds max_file_size (%s MB).", ($max_file_size/1024)/1024));
|
||||
}
|
||||
|
||||
$uploader = new FileUploader($this->folder_repository);
|
||||
$attachment = $uploader->build($file, 'summit-event-attachments');
|
||||
$event->setAttachment($attachment);
|
||||
|
||||
return $attachment;
|
||||
});
|
||||
}
|
||||
}
|
32
bindep.txt
Normal file
32
bindep.txt
Normal file
@ -0,0 +1,32 @@
|
||||
mcrypt
|
||||
|
||||
php [platform:ubuntu-xenial]
|
||||
php5 [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-cli [platform:rpm platform:ubuntu-xenial]
|
||||
php5-cli [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-common [platform:ubuntu-xenial]
|
||||
php5-common [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-curl [platform:rpm platform:ubuntu-xenial]
|
||||
php5-curl [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-gd [platform:rpm platform:ubuntu-xenial]
|
||||
php5-gd [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-json [platform:rpm platform:ubuntu-xenial]
|
||||
php5-json [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-mysql [platform:rpm platform:ubuntu-xenial]
|
||||
php5-mysql [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-gmp [platform:rpm platform:ubuntu-xenial]
|
||||
php5-gmp [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-mcrypt [platform:ubuntu-xenial]
|
||||
php5-mcrypt [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
||||
php-ssh2 [platform:ubuntu-xenial]
|
||||
php5-ssh2 [platform:dpkg !platform:ubuntu-xenial]
|
||||
|
@ -9,7 +9,7 @@
|
||||
"type": "project",
|
||||
"require": {
|
||||
"php": ">=5.5.9",
|
||||
"laravel/framework": "5.2.*",
|
||||
"laravel/framework": "5.3.*",
|
||||
"predis/predis": "1.0.1",
|
||||
"ezyang/htmlpurifier": "4.7.0",
|
||||
"glenscott/url-normalizer" : "^1.4",
|
||||
@ -24,8 +24,8 @@
|
||||
"require-dev": {
|
||||
"fzaninotto/faker": "~1.4",
|
||||
"phpunit/phpunit": "~4.0",
|
||||
"symfony/css-selector": "2.8.*|3.0.*",
|
||||
"symfony/dom-crawler": "2.8.*|3.0.*",
|
||||
"symfony/css-selector": "3.1.*",
|
||||
"symfony/dom-crawler": "3.1.*",
|
||||
"mockery/mockery": "^0.9.9"
|
||||
},
|
||||
"autoload": {
|
||||
|
469
composer.lock
generated
469
composer.lock
generated
File diff suppressed because it is too large
Load Diff
22
config/scp.php
Normal file
22
config/scp.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright 2017 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.
|
||||
**/
|
||||
|
||||
return
|
||||
[
|
||||
'ssh_user' => env('SSH_USER', ''),
|
||||
'ssh_public_key' => env('SSH_PUBLIC_KEY', ''),
|
||||
'ssh_private_key' => env('SSH_PRIVATE_KEY', ''),
|
||||
'scp_host' => env('SCP_HOST', ''),
|
||||
'scp_remote_base_path' => env('SCP_REMOTE_BASE_PATH', ''),
|
||||
];
|
@ -230,6 +230,12 @@ class ApiEndpointsSeeder extends Seeder
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'add-event-attachment',
|
||||
'route' => '/api/v1/summits/{id}/events/{event_id}/attachment',
|
||||
'http_method' => 'POST',
|
||||
'scopes' => [sprintf('%s/summits/write', $current_realm)],
|
||||
),
|
||||
array(
|
||||
'name' => 'add-event-feedback-v2',
|
||||
'route' => '/api/v2/summits/{id}/events/{event_id}/feedback',
|
||||
|
Loading…
x
Reference in New Issue
Block a user