Skip to content

Commit 8f15573

Browse files
author
Bertrand Dunogier
committed
Changed expressions to explicitly list policies in 'public' call
1 parent b932c6f commit 8f15573

5 files changed

Lines changed: 50 additions & 16 deletions

File tree

GraphQL/ExpressionLanguage/HasAdminAccessFunction.php renamed to GraphQL/ExpressionLanguage/Access/BaseAccessFunction.php

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,11 @@
11
<?php
2-
namespace BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage;
2+
namespace BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage\Access;
33

44
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction;
55

6-
class HasAdminAccessFunction extends ExpressionFunction
6+
abstract class BaseAccessFunction extends ExpressionFunction
77
{
8-
public function __construct()
9-
{
10-
parent::__construct(
11-
'hasAdminAccess',
12-
function () {
13-
return $this->buildHasAccessCode(["section/view", "class/create", "role/read"]);
14-
}
15-
);
16-
}
17-
18-
private function buildHasAccessCode(array $policies)
8+
protected function buildHasAccessCode(array $policies)
199
{
2010
$checks = array_map(
2111
function($policy) {
@@ -34,4 +24,5 @@ function($policy) {
3424
return %s;
3525
})()', implode('||', $checks));
3626
}
27+
3728
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
namespace BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage\Access;
3+
4+
class HasAdminAccessFunction extends BaseAccessFunction
5+
{
6+
public function __construct()
7+
{
8+
parent::__construct(
9+
'hasAdminAccess',
10+
function () {
11+
return $this->buildHasAccessCode(["section/view", "class/create", "role/read"]);
12+
}
13+
);
14+
}
15+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
namespace BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage\Access;
3+
4+
/**
5+
* Expression language function that checks if the current user has access to at least one
6+
* of the given policies, with or without limitations.
7+
*/
8+
class HasEzAccessToOneOfFunction extends BaseAccessFunction
9+
{
10+
public function __construct()
11+
{
12+
parent::__construct(
13+
'hasEzAccessToOneOf',
14+
function () {
15+
return $this->buildHasAccessCode(
16+
array_map(
17+
function($value) {
18+
return str_replace('"', '', $value);
19+
},
20+
func_get_args()
21+
)
22+
);
23+
}
24+
);
25+
}
26+
}

Resources/config/graphql/Platform.types.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,4 @@ Platform:
66
type: Repository
77
resolve: { }
88
description: "eZ Platform repository API"
9-
public: '@=hasAdminAccess()'
10-
public: '@=hasAdminAccess()'
9+
public: "@=hasEzAccessToOneOf('section/view', 'class/create', 'role/read')"

Resources/config/services.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,8 @@ services:
2323

2424
BD\EzPlatformGraphQLBundle\GraphQL\InputMapper\SearchQueryMapper: ~
2525

26-
BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage\HasAdminAccessFunction:
26+
BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage\Access\HasAdminAccessFunction:
27+
tags: ['overblog_graphql.expression_function']
28+
29+
BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage\Access\HasEzAccessToOneOfFunction:
2730
tags: ['overblog_graphql.expression_function']

0 commit comments

Comments
 (0)