Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/3.0' into 3
Browse files Browse the repository at this point in the history
  • Loading branch information
chillu committed Feb 11, 2019
2 parents c994549 + a8b4a0e commit c691a47
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
23 changes: 19 additions & 4 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use SilverStripe\Core\Injector\Injector;
use SilverStripe\GraphQL\Auth\Handler;
use SilverStripe\GraphQL\Scaffolding\StaticSchema;
use SilverStripe\ORM\Connect\DatabaseException;
use SilverStripe\Security\Member;
use SilverStripe\Security\Permission;
use SilverStripe\Security\SecurityToken;
Expand Down Expand Up @@ -451,10 +452,24 @@ public static function flush()
foreach ($routes as $pattern => $controllerInfo) {
$routeClass = (is_string($controllerInfo)) ? $controllerInfo : $controllerInfo['Controller'];
if (stristr($routeClass, Controller::class) !== false) {
$inst = Injector::inst()->convertServiceProperty($routeClass);
if ($inst instanceof Controller) {
/* @var Controller $inst */
$inst->processTypeCaching();
try {
$inst = Injector::inst()->convertServiceProperty($routeClass);
if ($inst instanceof Controller) {
/* @var Controller $inst */
$inst->processTypeCaching();
}
} catch (DatabaseException $e) {
// Allow failures on table doesn't exist or no database selected as we're flushing in first DB build
$messageByLine = explode(PHP_EOL, $e->getMessage());

// Get the last line
$last = array_pop($messageByLine);

if (strpos($last, 'No database selected') === false
&& !preg_match('/\s*(table|relation) .* does(n\'t| not) exist/i', $last)
) {
throw $e;
}
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions src/Scaffolding/Scaffolders/CRUD/ReadOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,21 @@ protected function createDefaultArgs(Manager $manager)
*/
public function resolve($object, array $args, $context, ResolveInfo $info)
{
if (!$this->getDataObjectInstance()->canView($context['currentUser'])) {
// get as a list so extensions can influence it pre-query
$list = DataList::create($this->getDataObjectClass())
->filter('ID', $args['ID']);
$this->extend('updateList', $list, $args, $context, $info);

// Fall back to getting an empty singleton to use for permission checking
$item = $list->first() ?: $this->getDataObjectInstance();

// Check permissions on the individual item as some permission checks may investigate saved state
if (!$item->canView($context['currentUser'])) {
throw new Exception(sprintf(
'Cannot view %s',
$this->getDataObjectClass()
));
}
// get as a list so extensions can influence it pre-query
$list = DataList::create($this->getDataObjectClass())
->filter('ID', $args['ID']);
$this->extend('updateList', $list, $args, $context, $info);

return $list->first();
}
Expand Down

0 comments on commit c691a47

Please sign in to comment.