Skip to content

Commit 008290c

Browse files
author
Bertrand Dunogier
committed
Prototyped permissions (#13)
The `_repository` field will only show up for users with at least one of content/edit, class/update or role/view. Can easily be extended to more granular items.
1 parent 21f1b25 commit 008290c

File tree

3 files changed

+46
-1
lines changed

3 files changed

+46
-1
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
namespace BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage;
3+
4+
use Overblog\GraphQLBundle\ExpressionLanguage\ExpressionFunction;
5+
6+
class HasAdminAccessFunction extends ExpressionFunction
7+
{
8+
public function __construct()
9+
{
10+
parent::__construct(
11+
'hasAdminAccess',
12+
function () {
13+
$accessList = [
14+
"section/view",
15+
"class/create",
16+
"role/read",
17+
];
18+
$mappedArray = array_map(
19+
function($policy) {
20+
list($module, $function) = explode('/', $policy);
21+
return sprintf(
22+
'(true === ($access = $pr->hasAccess("%s", "%s")) || is_array($access))',
23+
$module,
24+
$function
25+
);
26+
},
27+
$accessList
28+
);
29+
$ternary = implode('||', $mappedArray);
30+
$code = sprintf('(function() use ($globalVariable) {
31+
$pr = $globalVariable->get("container")
32+
->get("eZ\Publish\API\Repository\PermissionResolver");
33+
return %s;
34+
})()', $ternary);
35+
36+
return $code;
37+
}
38+
);
39+
}
40+
}

Resources/config/graphql/Platform.types.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ Platform:
55
_repository:
66
type: Repository
77
resolve: { }
8-
description: "eZ Platform repository API"
8+
description: "eZ Platform repository API"
9+
public: '@=hasAdminAccess()'
10+
public: '@=hasAdminAccess()'

Resources/config/services.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,6 @@ services:
2222
- { name: "overblog_graphql.mutation", alias: "DeleteSection", method: "deleteSection" }
2323

2424
BD\EzPlatformGraphQLBundle\GraphQL\InputMapper\SearchQueryMapper: ~
25+
26+
BD\EzPlatformGraphQLBundle\GraphQL\ExpressionLanguage\HasAdminAccessFunction:
27+
tags: ['overblog_graphql.expression_function']

0 commit comments

Comments
 (0)