Added doctrine L2 cache

in order to improve query performance
added L2 cache configuration to some
queries and classes.
also updated doctrine version.

Change-Id: I86ac24b65a28919de411b024c7ad175747630f6e
This commit is contained in:
Sebastian Marcet 2016-11-04 17:07:57 -03:00
parent dd9318a29b
commit 470dc12f5c
41 changed files with 5644 additions and 1010 deletions

3
.gitignore vendored
View File

@ -1,7 +1,6 @@
/vendor /vendor
/node_modules /node_modules
composer.phar composer.phar
composer.lock
.DS_Storeapp/storage .DS_Storeapp/storage
.idea/* .idea/*
app/config/dev/* app/config/dev/*
@ -23,5 +22,5 @@ doc/build
*.egg-info *.egg-info
.env.testing .env.testing
.env .env
storage/logs/* storage/*
*.log *.log

View File

@ -0,0 +1,54 @@
<?php namespace libs\utils;
/**
* Copyright 2016 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 Doctrine\Common\Persistence\ManagerRegistry;
use Illuminate\Contracts\Container\Container;
use LaravelDoctrine\ORM\BootChain;
use LaravelDoctrine\ORM\DoctrineServiceProvider;
use LaravelDoctrine\ORM\IlluminateRegistry;
/**
* Class CustomDoctrineServiceProvider
* @package libs\utils
*/
final class CustomDoctrineServiceProvider extends DoctrineServiceProvider
{
/**
* Register the manager registry
*/
protected function registerManagerRegistry()
{
$this->app->singleton('registry', function ($app) {
$registry = new IlluminateRegistry($app, $app->make(CustomEntityManagerFactory::class));
// Add all managers into the registry
foreach ($app->make('config')->get('doctrine.managers', []) as $manager => $settings) {
$registry->addManager($manager, $settings);
}
return $registry;
});
// Once the registry get's resolved, we will call the resolve callbacks which were waiting for the registry
$this->app->afterResolving('registry', function (ManagerRegistry $registry, Container $container) {
$this->bootExtensionManager();
BootChain::boot($registry);
});
$this->app->alias('registry', ManagerRegistry::class);
$this->app->alias('registry', IlluminateRegistry::class);
}
}

View File

@ -0,0 +1,88 @@
<?php namespace libs\utils;
/**
* Copyright 2016 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 Doctrine\ORM\Cache\DefaultCacheFactory;
use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger;
use Doctrine\ORM\Cache\RegionsConfiguration;
use Doctrine\ORM\Configuration;
use LaravelDoctrine\ORM\EntityManagerFactory;
/**
* Class CustomEntityManagerFactory
* @package libs\utils
*/
final class CustomEntityManagerFactory extends EntityManagerFactory
{
/**
* @param Configuration $configuration
*/
protected function setSecondLevelCaching(Configuration $configuration)
{
$second_level_cache_config = $this->config->get('doctrine.cache.second_level', []);
if (!is_array($second_level_cache_config)) return;
if (!isset($second_level_cache_config['enabled'])) return;
if (!$second_level_cache_config['enabled']) return;
$configuration->setSecondLevelCacheEnabled(true);
$cacheConfig = $configuration->getSecondLevelCacheConfiguration();
$regions_config = isset($second_level_cache_config['regions']) ? $second_level_cache_config['regions'] : [];
if (is_array($regions_config) && count($regions_config) > 0) {
$regions_configuration = new RegionsConfiguration
(
isset($second_level_cache_config['region_lifetime']) ? $second_level_cache_config['region_lifetime'] : 3600,
isset($second_level_cache_config['region_lock_lifetime']) ? $second_level_cache_config['region_lock_lifetime'] : 60
);
foreach ($regions_config as $region_name => $region_config) {
if (isset($region_config['lifetime']))
$regions_configuration->setLifetime($region_name, $region_config['lifetime']);
if (isset($region_config['lock_lifetime']))
$regions_configuration->setLockLifetime($region_name, $region_config['lock_lifetime']);
}
$cacheConfig->setRegionsConfiguration($regions_configuration);
}
// Cache logger
if (isset($second_level_cache_config['log_enabled']) && $second_level_cache_config['log_enabled']){
$logger = new StatisticsCacheLogger();
$cacheConfig->setCacheLogger($logger);
}
$factory = new DefaultCacheFactory
(
$cacheConfig->getRegionsConfiguration(),
$this->cache->driver()
);
$file_lock_region_directory = isset($second_level_cache_config['file_lock_region_directory']) ?
$second_level_cache_config['file_lock_region_directory'] :
'/tmp';
$factory->setFileLockRegionDirectory($file_lock_region_directory);
$cacheConfig->setCacheFactory
(
$factory
);
}
}

View File

@ -14,8 +14,8 @@
use Closure; use Closure;
use libs\utils\ICacheService; use libs\utils\ICacheService;
use models\resource_server\IApiEndpoint; use App\Models\ResourceServer\IApiEndpoint;
use models\resource_server\IApiEndpointRepository; use App\Models\ResourceServer\IApiEndpointRepository;
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
@ -23,7 +23,6 @@ use Carbon\Carbon;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use libs\utils\RequestUtils; use libs\utils\RequestUtils;
/** /**
* *
* @package App\Http\Middleware\ * @package App\Http\Middleware\
@ -90,6 +89,11 @@ class CORSMiddleware
*/ */
private $cache_service; private $cache_service;
/**
* CORSMiddleware constructor.
* @param IApiEndpointRepository $endpoint_repository
* @param ICacheService $cache_service
*/
public function __construct(IApiEndpointRepository $endpoint_repository, ICacheService $cache_service) public function __construct(IApiEndpointRepository $endpoint_repository, ICacheService $cache_service)
{ {
$this->endpoint_repository = $endpoint_repository; $this->endpoint_repository = $endpoint_repository;
@ -130,6 +134,7 @@ class CORSMiddleware
public function preProcess(Request $request) public function preProcess(Request $request)
{ {
$actual_request = false; $actual_request = false;
if ($this->isValidCORSRequest($request)) if ($this->isValidCORSRequest($request))
{ {
if (!$this->testOriginHeaderScrutiny($request)) if (!$this->testOriginHeaderScrutiny($request))
@ -159,7 +164,7 @@ class CORSMiddleware
return $response; return $response;
} }
// ----Step 2b: Store pre-flight request data in the Cache to keep (mark) the request as correctly followed the request pre-flight process // ----Step 2b: Store pre-flight request data in the Cache to keep (mark) the request as correctly followed the request pre-flight process
$data = new CORSRequestPreflightData($request, $this->current_endpoint->supportCredentials()); $data = new CORSRequestPreflightData($request, $this->current_endpoint->isAllowCredentials());
$cache_id = $this->generatePreflightCacheKey($request); $cache_id = $this->generatePreflightCacheKey($request);
$this->cache_service->storeHash($cache_id, $data->toArray(), CORSRequestPreflightData::$cache_lifetime); $this->cache_service->storeHash($cache_id, $data->toArray(), CORSRequestPreflightData::$cache_lifetime);
// ----Step 2c: Return corresponding response - This part should be customized with application specific constraints..... // ----Step 2c: Return corresponding response - This part should be customized with application specific constraints.....
@ -186,7 +191,7 @@ class CORSMiddleware
if ($request->getMethod() === $data['expected_method']) if ($request->getMethod() === $data['expected_method'])
{ {
// ------Finish with custom HTTP headers (use an method to avoid manual iteration on collection to increase the speed)... // ------Finish with custom HTTP headers (use an method to avoid manual iteration on collection to increase the speed)...
$x_headers = self::getCustomHeaders($request); $x_headers = self::getCustomHeaders($request);
$x_headers_pre = explode(',', $data['expected_custom_headers']); $x_headers_pre = explode(',', $data['expected_custom_headers']);
sort($x_headers); sort($x_headers);
sort($x_headers_pre); sort($x_headers_pre);
@ -292,7 +297,7 @@ class CORSMiddleware
// The Access-Control-Allow-Credentials header indicates whether the response to request // The Access-Control-Allow-Credentials header indicates whether the response to request
// can be exposed when the omit credentials flag is unset. When part of the response to a preflight request // can be exposed when the omit credentials flag is unset. When part of the response to a preflight request
// it indicates that the actual request can include user credentials. // it indicates that the actual request can include user credentials.
if ( $this->current_endpoint->supportCredentials()) if ( $this->current_endpoint->isAllowCredentials())
{ {
$response->headers->set('Access-Control-Allow-Credentials', 'true'); $response->headers->set('Access-Control-Allow-Credentials', 'true');
} }
@ -433,7 +438,7 @@ class CORSMiddleware
{ {
return false; return false;
} }
if (!$this->current_endpoint->supportCORS() || !$this->current_endpoint->isActive()) if (!$this->current_endpoint->isAllowCors() || !$this->current_endpoint->isActive())
{ {
return false; return false;
} }

View File

@ -25,8 +25,8 @@ use libs\oauth2\OAuth2ResourceServerException;
use libs\oauth2\OAuth2WWWAuthenticateErrorResponse; use libs\oauth2\OAuth2WWWAuthenticateErrorResponse;
use libs\utils\RequestUtils; use libs\utils\RequestUtils;
use models\oauth2\IResourceServerContext; use models\oauth2\IResourceServerContext;
use models\resource_server\IAccessTokenService; use App\Models\ResourceServer\IAccessTokenService;
use models\resource_server\IApiEndpointRepository; use App\Models\ResourceServer\IApiEndpointRepository;
use URL\Normalizer; use URL\Normalizer;
/** /**
@ -67,10 +67,10 @@ class OAuth2BearerAccessTokenRequestValidator
IApiEndpointRepository $endpoint_repository, IApiEndpointRepository $endpoint_repository,
IAccessTokenService $token_service IAccessTokenService $token_service
) { ) {
$this->context = $context; $this->context = $context;
$this->headers = $this->getHeaders(); $this->headers = $this->getHeaders();
$this->endpoint_repository = $endpoint_repository; $this->endpoint_repository = $endpoint_repository;
$this->token_service = $token_service; $this->token_service = $token_service;
} }
/** /**
@ -152,7 +152,7 @@ class OAuth2BearerAccessTokenRequestValidator
throw new OAuth2ResourceServerException( throw new OAuth2ResourceServerException(
403, 403,
OAuth2Protocol::OAuth2Protocol_Error_UnauthorizedClient, OAuth2Protocol::OAuth2Protocol_Error_UnauthorizedClient,
sprintf('invalid origin %s - allowed ones (%s)',$origin, $token_info->getAllowedOrigins()) sprintf('invalid origin %s - allowed ones (%s)', $origin, $token_info->getAllowedOrigins())
); );
} }
//check scopes //check scopes

View File

@ -17,7 +17,7 @@ use Closure;
use Illuminate\Support\Facades\Response; use Illuminate\Support\Facades\Response;
use libs\utils\ICacheService; use libs\utils\ICacheService;
use libs\utils\RequestUtils; use libs\utils\RequestUtils;
use models\resource_server\IApiEndpointRepository; use App\Models\ResourceServer\IApiEndpointRepository;
/** /**
* Class RateLimitMiddleware * Class RateLimitMiddleware
@ -63,11 +63,11 @@ final class RateLimitMiddleware
$url = $request->getRequestUri(); $url = $request->getRequestUri();
try { try {
$route = RequestUtils::getCurrentRoutePath($request); $route = RequestUtils::getCurrentRoutePath($request);
$method = $request->getMethod(); $method = $request->getMethod();
$endpoint = $this->endpoint_repository->getApiEndpointByUrlAndMethod($route, $method); $endpoint = $this->endpoint_repository->getApiEndpointByUrlAndMethod($route, $method);
if (!is_null($endpoint->rate_limit) && ($requestsPerHour = (int)$endpoint->rate_limit) > 0) { if (!is_null($endpoint->getRateLimit()) && ($requestsPerHour = (int)$endpoint->getRateLimit()) > 0) {
//do rate limit checking //do rate limit checking
$key = sprintf('rate.limit.%s_%s_%s', $url, $method, $request->getClientIp()); $key = sprintf('rate.limit.%s_%s_%s', $url, $method, $request->getClientIp());
// Add if doesn't exist // Add if doesn't exist

View File

@ -1,17 +1,17 @@
<?php namespace ModelSerializers; <?php namespace ModelSerializers;
/** /**
* Copyright 2016 OpenStack Foundation * Copyright 2016 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
use libs\utils\JsonUtils; use libs\utils\JsonUtils;
@ -23,8 +23,8 @@ final class SummitEventFeedbackSerializer extends SilverStripeSerializer
{ {
protected static $array_mappings = array protected static $array_mappings = array
( (
'Rate' => 'rate:json_int', 'Rate' => 'rate:json_int',
'Note' => 'note:json_string', 'Note' => 'note:json_string',
'Created' => 'created_date:datetime_epoch', 'Created' => 'created_date:datetime_epoch',
'EventId' => 'event_id:json_int', 'EventId' => 'event_id:json_int',
); );
@ -39,14 +39,11 @@ final class SummitEventFeedbackSerializer extends SilverStripeSerializer
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array()) public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array())
{ {
$feedback = $this->object; $feedback = $this->object;
$values = parent::serialize($expand, $fields, $relations, $params); $values = parent::serialize($expand, $fields, $relations, $params);
$event = $feedback->getEvent(); $member = $feedback->hasOwner() ? $feedback->getOwner() : null;
$member = $feedback->hasOwner() ? $feedback->getOwner() : null;
if (is_null($member)) return $values; if (is_null($member)) return $values;
$summit = $event->getSummit();
$attendee = $summit->getAttendeeByMemberId($member->getId());
if (!empty($expand)) { if (!empty($expand)) {
foreach (explode(',', $expand) as $relation) { foreach (explode(',', $expand) as $relation) {
@ -55,24 +52,20 @@ final class SummitEventFeedbackSerializer extends SilverStripeSerializer
$owner = array $owner = array
( (
'id' => intval($member->getId()), 'id' => intval($member->getId()),
'first_name' => JsonUtils::toJsonString($member->getFirstName()), 'first_name' => JsonUtils::toJsonString($member->getFirstName()),
'last_name' => JsonUtils::toJsonString($member->getLastName()) 'last_name' => JsonUtils::toJsonString($member->getLastName())
); );
if (!is_null($attendee))
$owner['attendee_id'] = intval($attendee->getId());
$values['owner'] = $owner; $values['owner'] = $owner;
} }
break; break;
} }
} }
} }
if(!isset($values['owner'])) { if (!isset($values['owner'])) {
$values['member_id'] = intval($member->getId()); $values['member_id'] = intval($member->getId());
if (!is_null($attendee)) $values['attendee_id'] = intval($attendee->getId());
} }
return $values; return $values;

View File

@ -19,6 +19,7 @@ use models\utils\SilverstripeBaseModel;
/** /**
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="Company") * @ORM\Table(name="Company")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="sponsors_region")
* Class Company * Class Company
* @package models\main * @package models\main
*/ */

View File

@ -23,6 +23,7 @@ use Doctrine\Common\Collections\ArrayCollection;
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="PresentationSpeaker") * @ORM\Table(name="PresentationSpeaker")
* @ORM\Entity(repositoryClass="repositories\summit\DoctrineSpeakerRepository") * @ORM\Entity(repositoryClass="repositories\summit\DoctrineSpeakerRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="speakers_region")
* Class PresentationSpeaker * Class PresentationSpeaker
* @package models\summit * @package models\summit
*/ */

View File

@ -551,6 +551,7 @@ class SummitEvent extends SilverstripeBaseModel
/** /**
* @ORM\OneToMany(targetEntity="models\summit\SummitEventFeedback", mappedBy="event", cascade={"persist"}) * @ORM\OneToMany(targetEntity="models\summit\SummitEventFeedback", mappedBy="event", cascade={"persist"})
* @ORM\Cache("NONSTRICT_READ_WRITE")
* @var SummitEventFeedback[] * @var SummitEventFeedback[]
*/ */
protected $feedback; protected $feedback;

View File

@ -21,6 +21,7 @@ use models\main\Member;
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="SummitEventFeedback") * @ORM\Table(name="SummitEventFeedback")
* @ORM\Entity(repositoryClass="repositories\summit\DoctrineEventFeedbackRepository") * @ORM\Entity(repositoryClass="repositories\summit\DoctrineEventFeedbackRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="summit_event_feedback_region")
* Class SummitEventFeedback * Class SummitEventFeedback
* @package models\summit * @package models\summit
*/ */

View File

@ -12,12 +12,12 @@
* limitations under the License. * limitations under the License.
**/ **/
use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Cache;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use models\main\File; use models\main\File;
use models\main\Member; use models\main\Member;
use models\utils\SilverstripeBaseModel; use models\utils\SilverstripeBaseModel;
use Doctrine\ORM\Mapping AS ORM; use Doctrine\ORM\Mapping AS ORM;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ArrayCollection; use Doctrine\Common\Collections\ArrayCollection;
use DateTimeZone; use DateTimeZone;
use DateTime; use DateTime;
@ -27,6 +27,7 @@ use models\main\Company;
* @ORM\Entity * @ORM\Entity
* @ORM\Table(name="Summit") * @ORM\Table(name="Summit")
* @ORM\Entity(repositoryClass="repositories\summit\DoctrineSummitRepository") * @ORM\Entity(repositoryClass="repositories\summit\DoctrineSummitRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="summit_region")
* Class Summit * Class Summit
* @package models\summit * @package models\summit
*/ */
@ -678,6 +679,9 @@ class Summit extends SilverstripeBaseModel
->from('models\summit\PresentationSpeaker','ps') ->from('models\summit\PresentationSpeaker','ps')
->join('ps.moderated_presentations','p') ->join('ps.moderated_presentations','p')
->join('p.summit','s') ->join('p.summit','s')
->setCacheable(true)
->setCacheRegion('speakers_region')
->setCacheMode(Cache::MODE_NORMAL)
->where("s.id = :summit_id and p.published = 1") ->where("s.id = :summit_id and p.published = 1")
->setParameter('summit_id', $this->getId()); ->setParameter('summit_id', $this->getId());
} }
@ -691,6 +695,9 @@ class Summit extends SilverstripeBaseModel
->from('models\summit\PresentationSpeaker','ps') ->from('models\summit\PresentationSpeaker','ps')
->join('ps.presentations','p') ->join('ps.presentations','p')
->join('p.summit','s') ->join('p.summit','s')
->setCacheable(true)
->setCacheRegion('speakers_region')
->setCacheMode(Cache::MODE_NORMAL)
->where("s.id = :summit_id and p.published = 1") ->where("s.id = :summit_id and p.published = 1")
->setParameter('summit_id', $this->getId()); ->setParameter('summit_id', $this->getId());
} }
@ -788,6 +795,9 @@ class Summit extends SilverstripeBaseModel
->from('models\main\Company','c') ->from('models\main\Company','c')
->join('c.sponsorships','sp') ->join('c.sponsorships','sp')
->join('sp.summit','s') ->join('sp.summit','s')
->setCacheable(true)
->setCacheRegion('sponsors_region')
->setCacheMode(Cache::MODE_NORMAL)
->where('s.id = :summit_id and sp.published = 1') ->where('s.id = :summit_id and sp.published = 1')
->setParameter('summit_id', $this->getId())->getQuery()->getResult(); ->setParameter('summit_id', $this->getId())->getQuery()->getResult();
} }

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
@ -26,7 +26,7 @@ use Illuminate\Support\Facades\Log;
/** /**
* Class AccessTokenService * Class AccessTokenService
* @package models\resource_server * @package App\Models\ResourceServer
*/ */
final class AccessTokenService implements IAccessTokenService final class AccessTokenService implements IAccessTokenService
{ {
@ -141,7 +141,7 @@ final class AccessTokenService implements IAccessTokenService
private function doIntrospection($token_value){ private function doIntrospection($token_value){
Log::debug("getting token from remote call ..."); Log::debug("getting token from remote call ...");
$cache_lifetime = intval(Config::get('server.access_token_cache_lifetime', 300)); $cache_lifetime = intval(Config::get('server.access_token_cache_lifetime', 300));
$token_info = $this->makeRemoteCall($token_value); $token_info = $this->doIntrospectionRequest($token_value);
$this->cache_service->storeHash(md5($token_value), $token_info, $cache_lifetime ); $this->cache_service->storeHash(md5($token_value), $token_info, $cache_lifetime );
return $token_info; return $token_info;
} }
@ -154,7 +154,7 @@ final class AccessTokenService implements IAccessTokenService
* @throws OAuth2InvalidIntrospectionResponse * @throws OAuth2InvalidIntrospectionResponse
* @throws \Exception * @throws \Exception
*/ */
private function makeRemoteCall($token_value) private function doIntrospectionRequest($token_value)
{ {
try { try {
@ -185,7 +185,7 @@ final class AccessTokenService implements IAccessTokenService
$response = $client->post( $response = $client->post(
$auth_server_url . '/oauth2/token/introspection', $auth_server_url . '/oauth2/token/introspection',
[ [
'query' => ['token' => $token_value], 'body' => ['token' => $token_value],
'headers' => ['Authorization' => " Basic " . base64_encode($client_id . ':' . $client_secret)] 'headers' => ['Authorization' => " Basic " . base64_encode($client_id . ':' . $client_secret)]
] ]
); );

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -12,50 +12,136 @@
* limitations under the License. * limitations under the License.
**/ **/
use models\utils\BaseModelEloquent; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;
/** /**
* Class Api * @ORM\Entity
* @package models\resource_server * @ORM\Table(name="apis")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="resource_server_region")
* Class Api
* @package App\Models\ResourceServer
*/ */
class Api extends BaseModelEloquent implements IApi class Api extends ResourceServerEntity implements IApi
{ {
protected $table = 'apis'; /**
* @ORM\OneToMany(targetEntity="ApiScope", mappedBy="api", cascade={"persist"})
*/
private $scopes;
protected $fillable = array('name','description','active'); /**
* @ORM\OneToMany(targetEntity="ApiEndpoint", mappedBy="api", cascade={"persist"})
*/
private $endpoints;
/**
* @ORM\Column(name="name", type="string")
* @var string
*/
private $name;
/** /**
* @return IApiScope[] * @ORM\Column(name="description", type="string")
*/ * @var string
public function scopes() */
{ private $description;
return $this->hasMany('models\resource_server\ApiScope', 'api_id');
}
/** /**
* @return IApiEndpoint[] * @ORM\Column(name="active", type="boolean")
*/ * @var bool
public function endpoints() */
{ private $active;
return $this->hasMany('models\resource_server\ApiEndpoint', 'api_id');
}
/** /**
* @return string * Api constructor.
*/ */
public function getName() public function __construct()
{ {
return $this->name; parent::__construct();
} $this->scopes = new ArrayCollection();
$this->endpoints = new ArrayCollection();
}
/** /**
* @return string * @return ApiScope[]
*/ */
public function getDescription() public function getScopes()
{ {
return $this->description; return $this->scopes;
} }
/**
* @param mixed $scopes
*/
public function setScopes($scopes)
{
$this->scopes = $scopes;
}
/**
* @return ApiEndpoint[]
*/
public function getEndpoints()
{
return $this->endpoints;
}
/**
* @param mixed $endpoints
*/
public function setEndpoints($endpoints)
{
$this->endpoints = $endpoints;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return boolean
*/
public function isActive()
{
return $this->active;
}
/**
* @param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/** /**
* @return string * @return string
@ -63,38 +149,16 @@ class Api extends BaseModelEloquent implements IApi
public function getScope() public function getScope()
{ {
$scope = ''; $scope = '';
foreach ($this->scopes()->get() as $s) foreach ($this->getScopes() as $s)
{ {
if (!$s->active) if (!$s->isActive())
{ {
continue; continue;
} }
$scope = $scope .$s->name.' '; $scope = $scope .$s->getName().' ';
} }
$scope = trim($scope); $scope = trim($scope);
return $scope; return $scope;
} }
/**
* @return bool
*/
public function isActive()
{
return $this->active;
}
public function setName($name)
{
$this->name = $name;
}
public function setDescription($description)
{
$this->description = $description;
}
public function setStatus($active)
{
$this->active = $active;
}
} }

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -12,132 +12,276 @@
* limitations under the License. * limitations under the License.
**/ **/
use models\utils\BaseModelEloquent; use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;
/** /**
* Class ApiEndpoint * @ORM\Entity(repositoryClass="repositories\resource_server\DoctrineApiEndpointRepository")
* @package models\resource_server * @ORM\Table(name="api_endpoints")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="resource_server_region")
* Class ApiEndpoint
* @package App\Models\ResourceServer
*/ */
class ApiEndpoint extends BaseModelEloquent implements IApiEndpoint class ApiEndpoint extends ResourceServerEntity implements IApiEndpoint
{ {
protected $table = 'api_endpoints'; /**
* @return Api
*/
public function getApi()
{
return $this->api;
}
protected $fillable = array( /**
'description', * @param Api $api
'active', */
'allow_cors', public function setApi($api)
'allow_credentials', {
'name','route', $this->api = $api;
'http_method', }
'api_id',
'rate_limit'
);
/** /**
* @return IApi * @return ApiScope[]
*/ */
public function api() public function getScopes()
{ {
return $this->belongsTo('models\resource_server\Api', 'api_id'); return $this->scopes;
} }
/** /**
* @return IApiScope[] * @param ApiScope[] $scopes
*/ */
public function scopes() public function setScopes($scopes)
{ {
return $this->belongsToMany('models\resource_server\ApiScope', 'endpoint_api_scopes', 'api_endpoint_id', 'scope_id'); $this->scopes = $scopes;
} }
public function getRoute() /**
{ * @return string
return $this->route; */
} public function getName()
{
return $this->name;
}
public function getHttpMethod() /**
{ * @param string $name
return $this->http_method; */
} public function setName($name)
{
$this->name = $name;
}
public function setRoute($route) /**
{ * @return string
$this->route = $route; */
} public function getDescription()
{
return $this->description;
}
public function setHttpMethod($http_method) /**
{ * @param string $description
$this->http_method = $http_method; */
} public function setDescription($description)
{
$this->description = $description;
}
/** /**
* @return boolean
*/
public function isActive()
{
return $this->active;
}
/**
* @param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* @return boolean
*/
public function isAllowCors()
{
return $this->allow_cors;
}
/**
* @param boolean $allow_cors
*/
public function setAllowCors($allow_cors)
{
$this->allow_cors = $allow_cors;
}
/**
* @return boolean
*/
public function isAllowCredentials()
{
return $this->allow_credentials;
}
/**
* @param boolean $allow_credentials
*/
public function setAllowCredentials($allow_credentials)
{
$this->allow_credentials = $allow_credentials;
}
/**
* @return string
*/
public function getRoute()
{
return $this->route;
}
/**
* @param string $route
*/
public function setRoute($route)
{
$this->route = $route;
}
/**
* @return string
*/
public function getHttpMethod()
{
return $this->http_method;
}
/**
* @param string $http_method
*/
public function setHttpMethod($http_method)
{
$this->http_method = $http_method;
}
/**
* @ORM\ManyToOne(targetEntity="Api", cascade={"persist"})
* @ORM\JoinColumn(name="api_id", referencedColumnName="id")
* @var Api
*/
private $api;
/**
* @ORM\ManyToMany(targetEntity="ApiScope")
* @ORM\JoinTable(name="endpoint_api_scopes",
* joinColumns={@ORM\JoinColumn(name="api_endpoint_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
* )
* @var ApiScope[]
*/
private $scopes;
/**
* @ORM\Column(name="name", type="string")
* @var string
*/
private $name;
/**
* @ORM\Column(name="description", type="string")
* @var string
*/
private $description;
/**
* @ORM\Column(name="active", type="boolean")
* @var bool
*/
private $active;
/**
* @ORM\Column(name="allow_cors", type="boolean")
* @var bool
*/
private $allow_cors;
/**
* @ORM\Column(name="allow_credentials", type="boolean")
* @var bool
*/
private $allow_credentials;
/**
* @ORM\Column(name="route", type="string")
* @var string
*/
private $route;
/**
* @ORM\Column(name="http_method", type="string")
* @var string
*/
private $http_method;
/**
* @ORM\Column(name="rate_limit", type="integer")
* @var int
*/
private $rate_limit;
/**
* ApiEndpoint constructor.
*/
public function __construct()
{
parent::__construct();
$this->rate_limit = 0;
$this->scopes = new ArrayCollection();
}
/**
* @return string * @return string
*/ */
public function getScope() public function getScope()
{ {
$scope = ''; $scope = '';
foreach ($this->scopes()->get() as $s) foreach ($this->scopes as $s)
{ {
if (!$s->active) if (!$s->isActive())
{ {
continue; continue;
} }
$scope = $scope .$s->name.' '; $scope = $scope .$s->getName().' ';
} }
$scope = trim($scope); $scope = trim($scope);
return $scope; return $scope;
} }
public function isActive() /**
{ * @param IApiScope $scope
return $this->active; */
} public function addScope(IApiScope $scope){
$this->scopes->add($scope);
}
/** /**
* @param bool $active * @return int
*/ */
public function setStatus($active) public function getRateLimit()
{ {
$this->active = $active; return $this->rate_limit;
} }
/** /**
* @return string * @param int $rate_limit
*/ */
public function getName() public function setRateLimit($rate_limit)
{ {
return $this->name; $this->rate_limit = $rate_limit;
} }
/**
* @param string $name
*/
public function setName($name)
{
$this->name= $name;
}
/**
* @return bool
*/
public function supportCORS()
{
return $this->allow_cors;
}
/**
* @return bool
*/
public function supportCredentials()
{
return (bool)$this->allow_credentials;
}
/**
* @return int
*/
public function getIdentifier()
{
return (int)$this->id;
}
} }

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -12,46 +12,147 @@
* limitations under the License. * limitations under the License.
**/ **/
use models\utils\BaseModelEloquent; use Doctrine\ORM\Mapping AS ORM;
/** /**
* Class ApiScope * @ORM\Entity
* @package models\resource_server * @ORM\Table(name="api_scopes")
*/ * @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="resource_server_region")
class ApiScope extends BaseModelEloquent implements IApiScope * Class ApiScope
* @package App\Models\ResourceServer
*/
class ApiScope extends ResourceServerEntity implements IApiScope
{ {
/**
* @return IApi
*/
public function getApi()
{
return $this->api;
}
protected $table = 'api_scopes'; /**
* @param Api $api
*/
public function setApi(Api $api)
{
$this->api = $api;
}
protected $hidden = array(''); /**
* @ORM\ManyToOne(targetEntity="Api", cascade={"persist"})
* @ORM\JoinColumn(name="api_id", referencedColumnName="id")
* @var Api
*/
private $api;
protected $fillable = array('name' ,'short_description', 'description','active','default','system', 'api_id'); /**
* @return string
*/
public function getName()
{
return $this->name;
}
/** /**
* @return IApi * @param string $name
*/ */
public function api() public function setName($name)
{ {
return $this->belongsTo('models\resource_server\Api', 'api_id'); $this->name = $name;
} }
public function getShortDescription() /**
{ * @return string
return $this->short_description; */
} public function getDescription()
{
return $this->description;
}
public function getName() /**
{ * @param string $description
return $this->name; */
} public function setDescription($description)
{
$this->description = $description;
}
public function getDescription() /**
{ * @return string
return $this->description; */
} public function getShortDescription()
{
return $this->short_description;
}
public function isActive() /**
{ * @param string $short_description
return $this->active; */
} public function setShortDescription($short_description)
{
$this->short_description = $short_description;
}
/**
* @return boolean
*/
public function isActive()
{
return $this->active;
}
/**
* @param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* @ORM\Column(name="name", type="string")
* @var string
*/
private $name;
/**
* @ORM\Column(name="description", type="string")
* @var string
*/
private $description;
/**
* @return boolean
*/
public function isDefault()
{
return $this->default;
}
/**
* @param boolean $default
*/
public function setDefault($default)
{
$this->default = $default;
}
/**
* @ORM\Column(name="short_description", type="string")
* @var string
*/
private $short_description;
/**
* @ORM\Column(name="active", type="boolean")
* @var bool
*/
private $active;
/**
* @ORM\Column(name="`default`", type="boolean")
* @var bool
*/
private $default;
} }

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
@ -18,7 +18,7 @@ use models\oauth2\AccessToken;
/** /**
* Interface IAccessTokenService * Interface IAccessTokenService
* @package models\resource_server * @package App\Models\ResourceServer
*/ */
interface IAccessTokenService interface IAccessTokenService
{ {

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -14,11 +14,10 @@
/** /**
* Interface IApi * Interface IApi
* @package models\resource_server * @package App\Models\ResourceServer
*/ */
interface IApi interface IApi
{ {
/** /**
* @return string * @return string
*/ */
@ -55,16 +54,16 @@ interface IApi
* @param bool $active * @param bool $active
* @return void * @return void
*/ */
public function setStatus($active); public function setActive($active);
/** /**
* @return IApiEndpoint[] * @return IApiEndpoint[]
*/ */
public function endpoints(); public function getEndpoints();
/** /**
* @return IApiScope[] * @return IApiScope[]
*/ */
public function scopes(); public function getScopes();
} }

View File

@ -1,22 +1,22 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
use models\utils\IEntity; use models\utils\IEntity;
/** /**
* Interface IApiEndpoint * Interface IApiEndpoint
* @package models\resource_server * @package App\Models\ResourceServer
*/ */
interface IApiEndpoint extends IEntity interface IApiEndpoint extends IEntity
{ {
@ -68,26 +68,36 @@ interface IApiEndpoint extends IEntity
* @param bool $active * @param bool $active
* @return void * @return void
*/ */
public function setStatus($active); public function setActive($active);
/** /**
* @return bool * @return bool
*/ */
public function supportCORS(); public function isAllowCors();
/** /**
* @return bool * @return bool
*/ */
public function supportCredentials(); public function isAllowCredentials();
/** /**
* @return IApi * @return IApi
*/ */
public function api(); public function getApi();
/** /**
* @return IApiScope[] * @return IApiScope[]
*/ */
public function scopes(); public function getScopes();
/**
* @param IApiScope $scope
*/
public function addScope(IApiScope $scope);
/**
* @return int
*/
public function getRateLimit();
} }

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -16,7 +16,7 @@ use models\utils\IBaseRepository;
/** /**
* Interface IApiEndpointRepository * Interface IApiEndpointRepository
* @package models\resource_server * @package App\Models\ResourceServer
*/ */
interface IApiEndpointRepository extends IBaseRepository interface IApiEndpointRepository extends IBaseRepository
{ {

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server; <?php namespace App\Models\ResourceServer;
/** /**
* Copyright 2015 OpenStack Foundation * Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -15,7 +15,7 @@
/** /**
* Interface IApiScope * Interface IApiScope
* http://tools.ietf.org/html/rfc6749#section-3.3 * http://tools.ietf.org/html/rfc6749#section-3.3
* @package oauth2\models * @package App\Models\ResourceServer
*/ */
interface IApiScope interface IApiScope
{ {
@ -39,8 +39,8 @@ interface IApiScope
*/ */
public function isActive(); public function isActive();
/** /**
* @return IApi * @return IApi
*/ */
public function api(); public function getApi();
} }

View File

@ -0,0 +1,96 @@
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2016 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\IEntity;
use Doctrine\ORM\Mapping AS ORM;
/***
* @ORM\MappedSuperclass
* Class ResourceServerEntity
* @package App\Models\ResourceServer
*/
class ResourceServerEntity implements IEntity
{
const DefaultTimeZone = 'America/Chicago';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer", unique=true, nullable=false)
*/
protected $id;
/**
* @ORM\Column(name="created_at", type="datetime")
*/
protected $created;
/**
* @ORM\Column(name="updated_at", type="datetime")
*/
protected $last_edited;
/**
* @return int
*/
public function getIdentifier()
{
return (int)$this->id;
}
public function getId(){
return $this->getIdentifier();
}
/**
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* @param \DateTime $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* @return \DateTime
*/
public function getLastEdited()
{
return $this->last_edited;
}
/**
* @param \DateTime $last_edited
*/
public function setLastEdited($last_edited)
{
$this->last_edited = $last_edited;
}
public function __construct()
{
$now = new \DateTime('now', new \DateTimeZone(self::DefaultTimeZone));
$this->created = $now;
$this->last_edited = $now;
}
}

View File

@ -14,10 +14,10 @@
use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping AS ORM; use Doctrine\ORM\Mapping AS ORM;
use Doctrine\ORM\NativeQuery;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder; use Doctrine\ORM\QueryBuilder;
use Registry; use Registry;
/*** /***
* @ORM\MappedSuperclass * @ORM\MappedSuperclass
* Class SilverstripeBaseModel * Class SilverstripeBaseModel
@ -26,8 +26,9 @@ use Registry;
class SilverstripeBaseModel implements IEntity class SilverstripeBaseModel implements IEntity
{ {
const DefaultTimeZone = 'America/Chicago'; const DefaultTimeZone = 'America/Chicago';
/** /**
* @return mixed * @return \DateTime
*/ */
public function getCreated() public function getCreated()
{ {
@ -35,7 +36,7 @@ class SilverstripeBaseModel implements IEntity
} }
/** /**
* @param mixed $created * @param \DateTime $created
*/ */
public function setCreated($created) public function setCreated($created)
{ {
@ -43,7 +44,7 @@ class SilverstripeBaseModel implements IEntity
} }
/** /**
* @return mixed * @return \DateTime
*/ */
public function getLastEdited() public function getLastEdited()
{ {
@ -51,7 +52,7 @@ class SilverstripeBaseModel implements IEntity
} }
/** /**
* @param mixed $last_edited * @param \DateTime $last_edited
*/ */
public function setLastEdited($last_edited) public function setLastEdited($last_edited)
{ {

View File

@ -105,9 +105,9 @@ class AppServiceProvider extends ServiceProvider
public function register() public function register()
{ {
App::singleton('models\\oauth2\\IResourceServerContext', 'models\\oauth2\\ResourceServerContext'); App::singleton('models\\oauth2\\IResourceServerContext', 'models\\oauth2\\ResourceServerContext');
App::singleton('models\resource_server\\IAccessTokenService', 'models\resource_server\\AccessTokenService'); App::singleton('App\Models\ResourceServer\IAccessTokenService', 'App\Models\ResourceServer\AccessTokenService');
App::singleton('models\\resource_server\\IApi', 'models\\resource_server\\Api'); App::singleton('App\Models\ResourceServer\IApi', 'models\\resource_server\\Api');
App::singleton('models\\resource_server\\IApiEndpoint', 'models\\resource_server\\ApiEndpoint'); App::singleton('App\Models\ResourceServer\IApiEndpoint', 'models\\resource_server\\ApiEndpoint');
App::singleton('models\\resource_server\\IApiScope', 'models\\resource_server\\ApiScope'); App::singleton('App\Models\ResourceServer\IApiScope', 'models\\resource_server\\ApiScope');
} }
} }

View File

@ -44,10 +44,12 @@ class RepositoriesProvider extends ServiceProvider
'models\marketplace\IConsultantRepository', 'models\marketplace\IConsultantRepository',
'repositories\marketplace\EloquentConsultantRepository' 'repositories\marketplace\EloquentConsultantRepository'
); );
App::singleton( App::singleton(
'models\resource_server\IApiEndpointRepository', 'App\Models\ResourceServer\IApiEndpointRepository',
'repositories\resource_server\EloquentApiEndpointRepository' function(){
); return EntityManager::getRepository(\App\Models\ResourceServer\ApiEndpoint::class);
});
App::singleton( App::singleton(
'models\summit\ISummitRepository', 'models\summit\ISummitRepository',
@ -80,7 +82,6 @@ class RepositoriesProvider extends ServiceProvider
}); });
App::singleton( App::singleton(
'models\main\IMemberRepository', 'models\main\IMemberRepository',
function(){ function(){

View File

@ -0,0 +1,52 @@
<?php namespace repositories\resource_server;
/**
* Copyright 2016 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\ResourceServer\IApiEndpoint;
use App\Models\ResourceServer\IApiEndpointRepository;
use repositories\DoctrineRepository;
use Illuminate\Support\Facades\Log;
/**
* Class DoctrineApiEndpointRepository
* @package repositories\resource_server
*/
final class DoctrineApiEndpointRepository extends DoctrineRepository implements IApiEndpointRepository
{
/**
* @param string $url
* @param string $http_method
* @return IApiEndpoint
*/
public function getApiEndpointByUrlAndMethod($url, $http_method)
{
try {
return $this->getEntityManager()->createQueryBuilder()
->select("e")
->from(\App\Models\ResourceServer\ApiEndpoint::class, "e")
->where('e.route = :route')
->andWhere('e.http_method = :http_method')
->setParameter('route', trim($url))
->setParameter('http_method', trim($http_method))
->setCacheable(true)
->setCacheRegion('resource_server_region')
->getQuery()
->getOneOrNullResult();
}
catch(\Exception $ex){
Log::error($ex);
return null;
}
}
}

View File

@ -13,10 +13,9 @@
* limitations under the License. * limitations under the License.
**/ **/
use models\resource_server\IApiEndpoint; use App\Models\ResourceServer\IApiEndpoint;
use models\resource_server\IApiEndpointRepository; use App\Models\ResourceServer\IApiEndpointRepository;
use models\utils\EloquentBaseRepository; use models\utils\EloquentBaseRepository;
use models\utils\IEntity;
/** /**
* Class EloquentApiEndpointRepository * Class EloquentApiEndpointRepository

View File

@ -12,6 +12,7 @@
* limitations under the License. * limitations under the License.
**/ **/
use Doctrine\ORM\Cache;
use models\summit\IEventFeedbackRepository; use models\summit\IEventFeedbackRepository;
use repositories\SilverStripeDoctrineRepository; use repositories\SilverStripeDoctrineRepository;
use models\summit\SummitEvent; use models\summit\SummitEvent;
@ -38,13 +39,16 @@ final class DoctrineEventFeedbackRepository extends SilverStripeDoctrineReposito
*/ */
public function getByEvent(SummitEvent $event, PagingInfo $paging_info, Filter $filter = null, Order $order = null) public function getByEvent(SummitEvent $event, PagingInfo $paging_info, Filter $filter = null, Order $order = null)
{ {
$query = $this->getEntityManager()->createQueryBuilder() $query = $this->getEntityManager()
->select("f") ->createQueryBuilder()
->from(\models\summit\SummitEventFeedback::class, "f") ->select("f")
->join('f.event', 'e', Join::WITH, " e.id = :event_id") ->from(\models\summit\SummitEventFeedback::class, "f")
->join('f.owner', 'o') ->join('f.event', 'e', Join::WITH, " e.id = :event_id")
->setParameter('event_id', $event->getId()); ->join('f.owner', 'o')
->setParameter('event_id', $event->getId())
->setCacheable(true)
->setCacheMode(Cache::MODE_GET)
->setCacheRegion('summit_event_feedback_region');
if(!is_null($filter)){ if(!is_null($filter)){

View File

@ -14,8 +14,8 @@
"guzzlehttp/guzzle": "5.3.0", "guzzlehttp/guzzle": "5.3.0",
"ezyang/htmlpurifier": "4.7.0", "ezyang/htmlpurifier": "4.7.0",
"glenscott/url-normalizer" : "^1.4", "glenscott/url-normalizer" : "^1.4",
"laravel-doctrine/orm":"1.1.*", "laravel-doctrine/orm":"1.2.*",
"laravel-doctrine/extensions": "^1.0", "laravel-doctrine/extensions": "1.0.*",
"cocur/slugify": "^2.3" "cocur/slugify": "^2.3"
}, },
"require-dev": { "require-dev": {

4346
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -162,7 +162,7 @@ return [
\repositories\RepositoriesProvider::class, \repositories\RepositoriesProvider::class,
\services\ServicesProvider::class, \services\ServicesProvider::class,
\factories\FactoriesProvider::class, \factories\FactoriesProvider::class,
\LaravelDoctrine\ORM\DoctrineServiceProvider::class, \libs\utils\CustomDoctrineServiceProvider::class,
\LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider::class, \LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider::class,
], ],

View File

@ -213,7 +213,20 @@ return [
'cache' => [ 'cache' => [
'default' => env('DOCTRINE_CACHE', 'redis'), 'default' => env('DOCTRINE_CACHE', 'redis'),
'namespace' => null, 'namespace' => null,
'second_level' => true, 'second_level' => [
'enabled' => true,
'region_lifetime' => 3600,
'region_lock_lifetime' => 60,
'regions' => [
'summit_event_feedback_region' => [
'lifetime' => 300,
'lock_lifetime' => 60
]
],
'log_enabled' => true,
'file_lock_region_directory' => '/tmp'
]
], ],
/* /*
|-------------------------------------------------------------------------- |--------------------------------------------------------------------------

View File

@ -14,9 +14,8 @@
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use models\resource_server\Api; use App\Models\ResourceServer\ApiEndpoint;
use models\resource_server\ApiEndpoint; use LaravelDoctrine\ORM\Facades\EntityManager;
use models\resource_server\ApiScope;
/** /**
* Class ApiEndpointsSeeder * Class ApiEndpointsSeeder
@ -34,762 +33,417 @@ class ApiEndpointsSeeder extends Seeder
$this->seedSummitEndpoints(); $this->seedSummitEndpoints();
} }
/**
* @param string $api_name
* @param array $endpoints_info
*/
private function seedApiEndpoints($api_name, array $endpoints_info){
$api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => $api_name]);
if(is_null($api)) return;
foreach($endpoints_info as $endpoint_info){
$endpoint = new ApiEndpoint();
$endpoint->setName($endpoint_info['name']);
$endpoint->setRoute($endpoint_info['route']);
$endpoint->setHttpMethod($endpoint_info['http_method']);
$endpoint->setActive(true);
$endpoint->setAllowCors(true);
$endpoint->setAllowCredentials(true);
$endpoint->setApi($api);
foreach($endpoint_info['scopes'] as $scope_name){
$scope = EntityManager::getRepository(\App\Models\ResourceServer\ApiScope::class)->findOneBy(['name' => $scope_name]);
if(is_null($scope)) continue;
$endpoint->addScope($scope);
}
EntityManager::persist($endpoint);
}
EntityManager::flush();
}
private function seedPublicCloudsEndpoints() private function seedPublicCloudsEndpoints()
{ {
$public_clouds = Api::where('name', '=', 'public-clouds')->first();
$current_realm = Config::get('app.url'); $current_realm = Config::get('app.url');
// endpoints scopes
ApiEndpoint::create( $this->seedApiEndpoints('public-clouds', [
array( array(
'name' => 'get-public-clouds', 'name' => 'get-public-clouds',
'active' => true, 'active' => true,
'api_id' => $public_clouds->id,
'route' => '/api/v1/marketplace/public-clouds', 'route' => '/api/v1/marketplace/public-clouds',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [
); sprintf('%s/public-clouds/read', $current_realm),
],
ApiEndpoint::create( ),
array( array(
'name' => 'get-public-cloud', 'name' => 'get-public-cloud',
'active' => true, 'active' => true,
'api_id' => $public_clouds->id,
'route' => '/api/v1/marketplace/public-clouds/{id}', 'route' => '/api/v1/marketplace/public-clouds/{id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [
); sprintf('%s/public-clouds/read', $current_realm),
],
ApiEndpoint::create( ),
array( array(
'name' => 'get-public-cloud-datacenters', 'name' => 'get-public-cloud-datacenters',
'active' => true, 'active' => true,
'api_id' => $public_clouds->id,
'route' => '/api/v1/marketplace/public-clouds/{id}/data-centers', 'route' => '/api/v1/marketplace/public-clouds/{id}/data-centers',
'http_method' => 'GET' 'http_method' => 'GET',
'scopes' => [
sprintf('%s/public-clouds/read', $current_realm),
],
) )
); ]);
$public_cloud_read_scope = ApiScope::where('name', '=',
sprintf('%s/public-clouds/read', $current_realm))->first();
$endpoint_get_public_clouds = ApiEndpoint::where('name', '=', 'get-public-clouds')->first();
$endpoint_get_public_clouds->scopes()->attach($public_cloud_read_scope->id);
$endpoint_get_public_cloud = ApiEndpoint::where('name', '=', 'get-public-cloud')->first();
$endpoint_get_public_cloud->scopes()->attach($public_cloud_read_scope->id);
$endpoint_get_public_cloud_datacenters = ApiEndpoint::where('name', '=',
'get-public-cloud-datacenters')->first();
$endpoint_get_public_cloud_datacenters->scopes()->attach($public_cloud_read_scope->id);
} }
private function seedPrivateCloudsEndpoints() private function seedPrivateCloudsEndpoints()
{ {
$private_clouds = Api::where('name', '=', 'private-clouds')->first();
$current_realm = Config::get('app.url'); $current_realm = Config::get('app.url');
// endpoints scopes // endpoints scopes
ApiEndpoint::create( $this->seedApiEndpoints('private-clouds', [
array( array(
'name' => 'get-private-clouds', 'name' => 'get-private-clouds',
'active' => true,
'api_id' => $private_clouds->id,
'route' => '/api/v1/marketplace/private-clouds', 'route' => '/api/v1/marketplace/private-clouds',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/private-clouds/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-private-cloud', 'name' => 'get-private-cloud',
'active' => true,
'api_id' => $private_clouds->id,
'route' => '/api/v1/marketplace/private-clouds/{id}', 'route' => '/api/v1/marketplace/private-clouds/{id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/private-clouds/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-private-cloud-datacenters', 'name' => 'get-private-cloud-datacenters',
'active' => true,
'api_id' => $private_clouds->id,
'route' => '/api/v1/marketplace/private-clouds/{id}/data-centers', 'route' => '/api/v1/marketplace/private-clouds/{id}/data-centers',
'http_method' => 'GET' 'http_method' => 'GET',
'scopes' => [sprintf('%s/private-clouds/read', $current_realm)],
) )
); ]);
$private_cloud_read_scope = ApiScope::where('name', '=',
sprintf('%s/private-clouds/read', $current_realm))->first();
$endpoint_get_private_clouds = ApiEndpoint::where('name', '=', 'get-private-clouds')->first();
$endpoint_get_private_clouds->scopes()->attach($private_cloud_read_scope->id);
$endpoint_get_private_cloud = ApiEndpoint::where('name', '=', 'get-private-cloud')->first();
$endpoint_get_private_cloud->scopes()->attach($private_cloud_read_scope->id);
$endpoint_get_private_cloud_datacenters = ApiEndpoint::where('name', '=',
'get-private-cloud-datacenters')->first();
$endpoint_get_private_cloud_datacenters->scopes()->attach($private_cloud_read_scope->id);
} }
private function seedConsultantsEndpoints() private function seedConsultantsEndpoints()
{ {
$consultants = Api::where('name', '=', 'consultants')->first();
$current_realm = Config::get('app.url'); $current_realm = Config::get('app.url');
// endpoints scopes
ApiEndpoint::create( $this->seedApiEndpoints('consultants', [
array( array(
'name' => 'get-consultants', 'name' => 'get-consultants',
'active' => true,
'api_id' => $consultants->id,
'route' => '/api/v1/marketplace/consultants', 'route' => '/api/v1/marketplace/consultants',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/consultants/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-consultant', 'name' => 'get-consultant',
'active' => true,
'api_id' => $consultants->id,
'route' => '/api/v1/marketplace/consultants/{id}', 'route' => '/api/v1/marketplace/consultants/{id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/consultants/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-consultant-offices', 'name' => 'get-consultant-offices',
'active' => true,
'api_id' => $consultants->id,
'route' => '/api/v1/marketplace/consultants/{id}/offices', 'route' => '/api/v1/marketplace/consultants/{id}/offices',
'http_method' => 'GET' 'http_method' => 'GET',
'scopes' => [sprintf('%s/consultants/read', $current_realm)],
) )
); ]);
$consultant_read_scope = ApiScope::where('name', '=', sprintf('%s/consultants/read', $current_realm))->first();
$endpoint = ApiEndpoint::where('name', '=', 'get-consultants')->first();
$endpoint->scopes()->attach($consultant_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-consultant')->first();
$endpoint->scopes()->attach($consultant_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-consultant-offices')->first();
$endpoint->scopes()->attach($consultant_read_scope->id);
} }
private function seedSummitEndpoints() private function seedSummitEndpoints()
{ {
$summit = Api::where('name', '=', 'summits')->first();
$current_realm = Config::get('app.url'); $current_realm = Config::get('app.url');
// endpoints scopes
$this->seedApiEndpoints('summits', [
ApiEndpoint::create( // summits
array( array(
'name' => 'get-summits', 'name' => 'get-summits',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits', 'route' => '/api/v1/summits',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-summit', 'name' => 'get-summit',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}', 'route' => '/api/v1/summits/{id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-summit-entity-events', 'name' => 'get-summit-entity-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/entity-events', 'route' => '/api/v1/summits/{id}/entity-events',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
// attendees
// attendees
ApiEndpoint::create
(
array( array(
'name' => 'get-attendees', 'name' => 'get-attendees',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees', 'route' => '/api/v1/summits/{id}/attendees',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-attendee', 'name' => 'get-attendee',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-attendee-schedule', 'name' => 'get-attendee-schedule',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'add-event-attendee-schedule', 'name' => 'add-event-attendee-schedule',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}',
'http_method' => 'POST' 'http_method' => 'POST',
) 'scopes' => [sprintf('%s/summits/write', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'delete-event-attendee-schedule', 'name' => 'delete-event-attendee-schedule',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}',
'http_method' => 'DELETE' 'http_method' => 'DELETE',
) 'scopes' => [sprintf('%s/summits/write', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'checking-event-attendee-schedule', 'name' => 'checking-event-attendee-schedule',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}/check-in', 'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}/check-in',
'http_method' => 'PUT' 'http_method' => 'PUT',
) 'scopes' => [sprintf('%s/summits/write', $current_realm)],
); ),
// speakers
// speakers
ApiEndpoint::create(
array( array(
'name' => 'get-speakers', 'name' => 'get-speakers',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/speakers', 'route' => '/api/v1/summits/{id}/speakers',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-speaker', 'name' => 'get-speaker',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/speakers/{speaker_id}', 'route' => '/api/v1/summits/{id}/speakers/{speaker_id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'add-speaker-feedback', 'name' => 'add-speaker-feedback',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/speakers/{speaker_id}/presentations/{presentation_id}/feedback', 'route' => '/api/v1/summits/{id}/speakers/{speaker_id}/presentations/{presentation_id}/feedback',
'http_method' => 'POST' 'http_method' => 'POST',
) 'scopes' => [sprintf('%s/summits/write', $current_realm)],
); ),
// events
// events
ApiEndpoint::create(
array( array(
'name' => 'get-events', 'name' => 'get-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events', 'route' => '/api/v1/summits/{id}/events',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-published-events', 'name' => 'get-published-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/published', 'route' => '/api/v1/summits/{id}/events/published',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-all-events', 'name' => 'get-all-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/events', 'route' => '/api/v1/summits/events',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-all-published-events', 'name' => 'get-all-published-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/events/published', 'route' => '/api/v1/summits/events/published',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-event', 'name' => 'get-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}', 'route' => '/api/v1/summits/{id}/events/{event_id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-published-event', 'name' => 'get-published-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/published', 'route' => '/api/v1/summits/{id}/events/{event_id}/published',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'add-event', 'name' => 'add-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events', 'route' => '/api/v1/summits/{id}/events',
'http_method' => 'POST' 'http_method' => 'POST',
) 'scopes' => [sprintf('%s/summits/write-event', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'update-event', 'name' => 'update-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}', 'route' => '/api/v1/summits/{id}/events/{event_id}',
'http_method' => 'PUT' 'http_method' => 'PUT',
) 'scopes' => [sprintf('%s/summits/write-event', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'publish-event', 'name' => 'publish-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/publish', 'route' => '/api/v1/summits/{id}/events/{event_id}/publish',
'http_method' => 'PUT' 'http_method' => 'PUT',
) 'scopes' => [sprintf('%s/summits/publish-event', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'unpublish-event', 'name' => 'unpublish-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/publish', 'route' => '/api/v1/summits/{id}/events/{event_id}/publish',
'http_method' => 'DELETE' 'http_method' => 'DELETE',
) 'scopes' => [sprintf('%s/summits/publish-event', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'delete-event', 'name' => 'delete-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}', 'route' => '/api/v1/summits/{id}/events/{event_id}',
'http_method' => 'DELETE' 'http_method' => 'DELETE',
) 'scopes' => [sprintf('%s/summits/delete-event', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'add-event-feedback', 'name' => 'add-event-feedback',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/feedback', 'route' => '/api/v1/summits/{id}/events/{event_id}/feedback',
'http_method' => 'POST' 'http_method' => 'POST',
) 'scopes' => [sprintf('%s/summits/write', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'add-event-feedback-v2', 'name' => 'add-event-feedback-v2',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v2/summits/{id}/events/{event_id}/feedback', 'route' => '/api/v2/summits/{id}/events/{event_id}/feedback',
'http_method' => 'POST' 'http_method' => 'POST',
) 'scopes' => [sprintf('%s/summits/write', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-event-feedback', 'name' => 'get-event-feedback',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/feedback/{attendee_id?}', 'route' => '/api/v1/summits/{id}/events/{event_id}/feedback/{attendee_id?}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
// locations
// locations array(
'name' => 'get-locations',
ApiEndpoint::create( 'route' => '/api/v1/summits/{id}/locations',
array( 'http_method' => 'GET',
'name' => 'get-locations', 'scopes' => [sprintf('%s/summits/read', $current_realm)],
'active' => true, ),
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
array( array(
'name' => 'get-venues', 'name' => 'get-venues',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/venues', 'route' => '/api/v1/summits/{id}/locations/venues',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-external-locations', 'name' => 'get-external-locations',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/external-locations', 'route' => '/api/v1/summits/{id}/locations/external-locations',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-hotels', 'name' => 'get-hotels',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/hotels', 'route' => '/api/v1/summits/{id}/locations/hotels',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-airports', 'name' => 'get-airports',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/airports', 'route' => '/api/v1/summits/{id}/locations/airports',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-location', 'name' => 'get-location',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/{location_id}', 'route' => '/api/v1/summits/{id}/locations/{location_id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-location-events', 'name' => 'get-location-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/{location_id}/events', 'route' => '/api/v1/summits/{id}/locations/{location_id}/events',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-location-published-events', 'name' => 'get-location-published-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/{location_id}/events/published', 'route' => '/api/v1/summits/{id}/locations/{location_id}/events/published',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
// event types
// event types
ApiEndpoint::create(
array( array(
'name' => 'get-event-types', 'name' => 'get-event-types',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/event-types', 'route' => '/api/v1/summits/{id}/event-types',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
//summit types
//summit types
ApiEndpoint::create(
array( array(
'name' => 'get-summit-types', 'name' => 'get-summit-types',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/summit-types', 'route' => '/api/v1/summits/{id}/summit-types',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
//external orders
//external orders
ApiEndpoint::create(
array( array(
'name' => 'get-external-order', 'name' => 'get-external-order',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/external-orders/{external_order_id}', 'route' => '/api/v1/summits/{id}/external-orders/{external_order_id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read-external-orders', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'confirm-external-order', 'name' => 'confirm-external-order',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/external-orders/{external_order_id}/external-attendees/{external_attendee_id}/confirm', 'route' => '/api/v1/summits/{id}/external-orders/{external_order_id}/external-attendees/{external_attendee_id}/confirm',
'http_method' => 'POST' 'http_method' => 'POST',
) 'scopes' => [sprintf('%s/summits/confirm-external-orders', $current_realm)],
); ),
//videos
//videos
ApiEndpoint::create(
array( array(
'name' => 'get-presentation-videos', 'name' => 'get-presentation-videos',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos', 'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'get-presentation-video', 'name' => 'get-presentation-video',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/video/{video_id}', 'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/video/{video_id}',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/summits/read', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'create-presentation-video', 'name' => 'create-presentation-video',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos', 'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos',
'http_method' => 'POST' 'http_method' => 'POST',
) 'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'update-presentation-video', 'name' => 'update-presentation-video',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos/{video_id}', 'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos/{video_id}',
'http_method' => 'PUT' 'http_method' => 'PUT',
) 'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
); ),
ApiEndpoint::create(
array( array(
'name' => 'delete-presentation-video', 'name' => 'delete-presentation-video',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos/{video_id}', 'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos/{video_id}',
'http_method' => 'DELETE' 'http_method' => 'DELETE',
) 'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
); ),
//members
//members
ApiEndpoint::create(
array( array(
'name' => 'get-own-member', 'name' => 'get-own-member',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/members/me', 'route' => '/api/v1/summits/{id}/members/me',
'http_method' => 'GET' 'http_method' => 'GET',
) 'scopes' => [sprintf('%s/me/read', $current_realm)],
); ),
// notifications
// notifications
ApiEndpoint::create(
array( array(
'name' => 'get-notifications', 'name' => 'get-notifications',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/notifications', 'route' => '/api/v1/summits/{id}/notifications',
'http_method' => 'GET' 'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read-notifications', $current_realm)],
) )
); ]);
$member_read_scope = ApiScope::where('name', '=', sprintf('%s/me/read', $current_realm))->first();
$summit_read_scope = ApiScope::where('name', '=', sprintf('%s/summits/read', $current_realm))->first();
$summit_write_scope = ApiScope::where('name', '=', sprintf('%s/summits/write', $current_realm))->first();
$summit_write_event_scope = ApiScope::where('name', '=', sprintf('%s/summits/write-event', $current_realm))->first();
$summit_publish_event_scope = ApiScope::where('name', '=', sprintf('%s/summits/publish-event', $current_realm))->first();
$summit_delete_event_scope = ApiScope::where('name', '=', sprintf('%s/summits/delete-event', $current_realm))->first();
$summit_external_order_read = ApiScope::where('name', '=', sprintf('%s/summits/read-external-orders', $current_realm))->first();
$summit_external_order_confirm = ApiScope::where('name', '=', sprintf('%s/summits/confirm-external-orders', $current_realm))->first();
$write_videos_scope = ApiScope::where('name', '=', sprintf('%s/summits/write-videos', $current_realm))->first();
$read_notifications = ApiScope::where('name', '=', sprintf('%s/summits/read-notifications', $current_realm))->first();
// read
$endpoint = ApiEndpoint::where('name', '=', 'get-summits')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-own-member')->first();
$endpoint->scopes()->attach($member_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-summit')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-summit-entity-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-attendees')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-attendee')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-attendee-schedule')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'add-event-attendee-schedule')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-speakers')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-speaker')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-published-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-all-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-all-published-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-event')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-published-event')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-event-feedback')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-locations')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-venues')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-hotels')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-airports')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-external-locations')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-location')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-event-types')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-summit-types')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-location-published-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-location-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-presentation-videos')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-presentation-video')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
// read external orders
$endpoint = ApiEndpoint::where('name', '=', 'get-external-order')->first();
$endpoint->scopes()->attach($summit_external_order_read->id);
// read notifications
$endpoint = ApiEndpoint::where('name', '=', 'get-notifications')->first();
$endpoint->scopes()->attach($read_notifications->id);
// write
$endpoint = ApiEndpoint::where('name', '=', 'delete-event-attendee-schedule')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'checking-event-attendee-schedule')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'add-speaker-feedback')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'add-event-feedback')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'add-event-feedback-v2')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
// write events
$endpoint = ApiEndpoint::where('name', '=', 'add-event')->first();
$endpoint->scopes()->attach($summit_write_event_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'update-event')->first();
$endpoint->scopes()->attach($summit_write_event_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'publish-event')->first();
$endpoint->scopes()->attach($summit_publish_event_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'unpublish-event')->first();
$endpoint->scopes()->attach($summit_publish_event_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'delete-event')->first();
$endpoint->scopes()->attach($summit_delete_event_scope->id);
//confirm external order
$endpoint = ApiEndpoint::where('name', '=', 'confirm-external-order')->first();
$endpoint->scopes()->attach($summit_external_order_confirm->id);
//write videos
$endpoint = ApiEndpoint::where('name', '=', 'create-presentation-video')->first();
$endpoint->scopes()->attach($write_videos_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'update-presentation-video')->first();
$endpoint->scopes()->attach($write_videos_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'delete-presentation-video')->first();
$endpoint->scopes()->attach($write_videos_scope->id);
} }

View File

@ -13,14 +13,15 @@
**/ **/
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;;
use models\resource_server\Api; use App\Models\ResourceServer\ApiScope;
use models\resource_server\ApiScope; use LaravelDoctrine\ORM\Facades\EntityManager;
use Illuminate\Support\Facades\DB;
/** /**
* Class ApiScopesSeeder * Class ApiScopesSeeder
*/ */
class ApiScopesSeeder extends Seeder final class ApiScopesSeeder extends Seeder
{ {
public function run() public function run()
@ -38,158 +39,128 @@ class ApiScopesSeeder extends Seeder
{ {
$current_realm = Config::get('app.url'); $current_realm = Config::get('app.url');
$public_clouds = Api::where('name', '=', 'public-clouds')->first(); $api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => 'public-clouds']);
ApiScope::create( $scope = new ApiScope();
array( $scope->setName(sprintf('%s/public-clouds/read', $current_realm));
'name' => sprintf('%s/public-clouds/read', $current_realm), $scope->setShortDescription('Read Public Clouds Data');
'short_description' => 'Get Public Clouds', $scope->setDescription('Grants read only access for Public Clouds');
'description' => 'Grants read only access for Public Clouds', $scope->setActive(true);
'api_id' => $public_clouds->id, $scope->setDefault(false);
'system' => false $scope->setApi($api);
)
); EntityManager::persist($scope);
EntityManager::flush();
} }
private function seedPrivateCloudScopes() private function seedPrivateCloudScopes()
{ {
$current_realm = Config::get('app.url'); $current_realm = Config::get('app.url');
$private_clouds = Api::where('name', '=', 'private-clouds')->first(); $api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => 'private-clouds']);
ApiScope::create( $scope = new ApiScope();
array( $scope->setName(sprintf('%s/private-clouds/read', $current_realm));
'name' => sprintf('%s/private-clouds/read', $current_realm), $scope->setShortDescription('Read Private Clouds Data');
'short_description' => 'Get Private Clouds', $scope->setDescription('Grants read only access for Private Clouds');
'description' => 'Grants read only access for Private Clouds', $scope->setActive(true);
'api_id' => $private_clouds->id, $scope->setDefault(false);
'system' => false $scope->setApi($api);
)
); EntityManager::persist($scope);
EntityManager::flush();
} }
private function seedConsultantScopes() private function seedConsultantScopes()
{ {
$current_realm = Config::get('app.url'); $current_realm = Config::get('app.url');
$consultants = Api::where('name', '=', 'consultants')->first(); $api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => 'consultants']);
ApiScope::create( $scope = new ApiScope();
array( $scope->setName(sprintf('%s/consultants/read', $current_realm));
'name' => sprintf('%s/consultants/read', $current_realm), $scope->setShortDescription('Read Consultants Data');
'short_description' => 'Get Consultants', $scope->setDescription('Grants read only access for Consultants');
'description' => 'Grants read only access for Consultants', $scope->setActive(true);
'api_id' => $consultants->id, $scope->setDefault(false);
'system' => false $scope->setApi($api);
)
); EntityManager::persist($scope);
EntityManager::flush();
} }
private function seedSummitScopes() private function seedSummitScopes()
{ {
$current_realm = Config::get('app.url'); $current_realm = Config::get('app.url');
$summits = Api::where('name', '=', 'summits')->first(); $api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => 'summits']);
ApiScope::create( $scopes = [
array( array(
'name' => sprintf('%s/summits/read', $current_realm), 'name' => sprintf('%s/summits/read', $current_realm),
'short_description' => 'Get Summit Data', 'short_description' => 'Get Summit Data',
'description' => 'Grants read only access for Summits Data', 'description' => 'Grants read only access for Summits Data',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/me/read', $current_realm), 'name' => sprintf('%s/me/read', $current_realm),
'short_description' => 'Get own member data', 'short_description' => 'Get own member data',
'description' => 'Grants read only access for our own member data', 'description' => 'Grants read only access for our own member data',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/summits/write', $current_realm), 'name' => sprintf('%s/summits/write', $current_realm),
'short_description' => 'Write Summit Data', 'short_description' => 'Write Summit Data',
'description' => 'Grants write access for Summits Data', 'description' => 'Grants write access for Summits Data',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/summits/write-event', $current_realm), 'name' => sprintf('%s/summits/write-event', $current_realm),
'short_description' => 'Write Summit Events', 'short_description' => 'Write Summit Events',
'description' => 'Grants write access for Summits Events', 'description' => 'Grants write access for Summits Events',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/summits/delete-event', $current_realm), 'name' => sprintf('%s/summits/delete-event', $current_realm),
'short_description' => 'Delete Summit Events', 'short_description' => 'Delete Summit Events',
'description' => 'Grants delete access for Summits Events', 'description' => 'Grants delete access for Summits Events',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/summits/publish-event', $current_realm), 'name' => sprintf('%s/summits/publish-event', $current_realm),
'short_description' => 'Publish/UnPublish Summit Events', 'short_description' => 'Publish/UnPublish Summit Events',
'description' => 'Grants Publish/UnPublish access for Summits Events', 'description' => 'Grants Publish/UnPublish access for Summits Events',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/summits/read-external-orders', $current_realm), 'name' => sprintf('%s/summits/read-external-orders', $current_realm),
'short_description' => 'Allow to read External Orders', 'short_description' => 'Allow to read External Orders',
'description' => 'Allow to read External Orders', 'description' => 'Allow to read External Orders',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/summits/confirm-external-orders', $current_realm), 'name' => sprintf('%s/summits/confirm-external-orders', $current_realm),
'short_description' => 'Allow to confirm External Orders', 'short_description' => 'Allow to confirm External Orders',
'description' => 'Allow to confirm External Orders', 'description' => 'Allow to confirm External Orders',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/summits/write-videos', $current_realm), 'name' => sprintf('%s/summits/write-videos', $current_realm),
'short_description' => 'Allow to write presentation videos', 'short_description' => 'Allow to write presentation videos',
'description' => 'Allow to write presentation videos', 'description' => 'Allow to write presentation videos',
'api_id' => $summits->id, ),
'system' => false
)
);
ApiScope::create(
array( array(
'name' => sprintf('%s/summits/read-notifications', $current_realm), 'name' => sprintf('%s/summits/read-notifications', $current_realm),
'short_description' => 'Allow to read summit notifications', 'short_description' => 'Allow to read summit notifications',
'description' => 'Allow to read summit notifications', 'description' => 'Allow to read summit notifications',
'api_id' => $summits->id,
'system' => false
) )
); ];
foreach ($scopes as $scope_info) {
$scope = new ApiScope();
$scope->setName($scope_info['name']);
$scope->setShortDescription($scope_info['short_description']);
$scope->setDescription($scope_info['description']);
$scope->setActive(true);
$scope->setDefault(false);
$scope->setApi($api);
EntityManager::persist($scope);
}
EntityManager::flush();
} }
} }

View File

@ -11,8 +11,11 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use models\resource_server\Api; use App\Models\ResourceServer\Api;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Illuminate\Support\Facades\DB;
/** /**
* Class ApisTableSeeder * Class ApisTableSeeder
@ -27,37 +30,43 @@ final class ApiSeeder extends Seeder
DB::table('api_scopes')->delete(); DB::table('api_scopes')->delete();
DB::table('api_endpoints')->delete(); DB::table('api_endpoints')->delete();
DB::table('apis')->delete(); DB::table('apis')->delete();
// public clouds // public clouds
Api::create( $api = new Api();
array( $api->setName('public-clouds');
'name' => 'public-clouds', $api->setActive(true);
'active' => true, $api->setDescription('Marketplace Public Clouds API');
'Description' => 'Marketplace Public Clouds'
) EntityManager::persist($api);
);
// private clouds // private clouds
Api::create(
array( $api = new Api();
'name' => 'private-clouds', $api->setName('private-clouds');
'active' => true, $api->setActive(true);
'Description' => 'Marketplace Private Clouds' $api->setDescription('Marketplace Private Clouds API');
)
); EntityManager::persist($api);
// consultants // consultants
Api::create(
array( $api = new Api();
'name' => 'consultants', $api->setName('consultants');
'active' => true, $api->setActive(true);
'Description' => 'Marketplace Consultants' $api->setDescription('Marketplace Consultants API');
)
); EntityManager::persist($api);
// summit // summit
Api::create(
array( $api = new Api();
'name' => 'summits', $api->setName('summits');
'active' => true, $api->setActive(true);
'Description' => 'Summits' $api->setDescription('Summit API');
)
); EntityManager::persist($api);
EntityManager::flush();
} }
} }

View File

@ -3,7 +3,10 @@
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder /**
* Class DatabaseSeeder
*/
final class DatabaseSeeder extends Seeder
{ {
/** /**
* Run the database seeds. * Run the database seeds.
@ -13,7 +16,7 @@ class DatabaseSeeder extends Seeder
public function run() public function run()
{ {
// $this->call(UsersTableSeeder::class); // $this->call(UsersTableSeeder::class);
Model::unguard(); Model::unguard();
$this->call('ApiSeeder'); $this->call('ApiSeeder');
$this->call('ApiScopesSeeder'); $this->call('ApiScopesSeeder');
$this->call('ApiEndpointsSeeder'); $this->call('ApiEndpointsSeeder');

View File

@ -18,7 +18,7 @@ use Illuminate\Database\Seeder;
/** /**
* Class TestSeeder * Class TestSeeder
*/ */
class TestSeeder extends Seeder final class TestSeeder extends Seeder
{ {
public function run() public function run()
{ {

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -140,7 +140,7 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
public function testCurrentSummitMyAttendeeFail404() public function testCurrentSummitMyAttendeeFail404()
{ {
App::singleton('models\resource_server\IAccessTokenService', 'AccessTokenServiceStub2'); App::singleton('App\Models\ResourceServer\IAccessTokenService', 'AccessTokenServiceStub2');
$params = array $params = array
( (
@ -1095,8 +1095,8 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
{ {
$params = array $params = array
( (
'id' => 6, 'id' => 7,
'event_id' => 15027, 'event_id' => 17300,
); );
$headers = array $headers = array
@ -1112,7 +1112,6 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
'attendee_id' => 'me' 'attendee_id' => 'me'
); );
$response = $this->action $response = $this->action
( (
"POST", "POST",
@ -1360,12 +1359,12 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
public function testGetEventFeedback() public function testGetEventFeedback()
{ {
$this->testAddFeedback2Event(); //$this->testAddFeedback2Event();
$params = array $params = array
( (
'id' => 6, 'id' => 7,
'event_id' => 9454, 'event_id' => 17300,
); );
$headers = array $headers = array
@ -1390,6 +1389,23 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
$feedback = json_decode($content); $feedback = json_decode($content);
$this->assertTrue(!is_null($feedback)); $this->assertTrue(!is_null($feedback));
$response = $this->action
(
"GET",
"OAuth2SummitEventsApiController@getEventFeedback",
$params,
array('expand' => 'owner'),
array(),
array(),
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$feedback = json_decode($content);
$this->assertTrue(!is_null($feedback));
} }
public function testGetMeEventFeedback() public function testGetMeEventFeedback()

View File

@ -15,7 +15,7 @@
use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use models\oauth2\AccessToken; use models\oauth2\AccessToken;
use models\resource_server\IAccessTokenService; use App\Models\ResourceServer\IAccessTokenService;
/** /**
* Class AccessTokenServiceStub * Class AccessTokenServiceStub
@ -102,7 +102,7 @@ abstract class ProtectedApiTest extends TestCase
public function createApplication() public function createApplication()
{ {
$app = parent::createApplication(); $app = parent::createApplication();
App::singleton('models\resource_server\IAccessTokenService', 'AccessTokenServiceStub'); App::singleton('App\Models\ResourceServer\IAccessTokenService', 'AccessTokenServiceStub');
return $app; return $app;
} }

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
class ServicesTest extends TestCase class ServicesTest extends TestCase
{ {
public function testAccessTokenService(){ public function testAccessTokenService(){
$cache = App::make('libs\utils\ICacheService'); $cache = App::make('libs\utils\ICacheService');
@ -32,7 +32,7 @@ class ServicesTest extends TestCase
]; ];
$cache->storeHash(md5($token_value), $token_info, $cache_lifetime ); $cache->storeHash(md5($token_value), $token_info, $cache_lifetime );
sleep(10); sleep(10);
$service = App::make('models\resource_server\IAccessTokenService'); $service = App::make('App\Models\ResourceServer\IAccessTokenService');
$service->get($token_value); $service->get($token_value);
} }
} }