Skip to content

Commit f452cc0

Browse files
committed
Set Field::flagAccessAPI to all fields before processing a request.
1 parent a106c9b commit f452cc0

File tree

3 files changed

+94
-1
lines changed

3 files changed

+94
-1
lines changed

ProcessGraphQL.module

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use GraphQL\GraphQL;
44
use GraphQL\Error\Debug;
5+
use ProcessWire\GraphQL\Permissions;
56
use ProcessWire\HookEvent;
67
use ProcessWire\GraphQL\Schema;
78
use Processwire\ProcessGraphQLConfig;
@@ -181,7 +182,8 @@ class ProcessGraphQL extends Process implements Module {
181182
}
182183

183184
// instantiating Processor and setting the schema
184-
$schema = Schema::getSchema();
185+
$schema = Schema::getSchema();
186+
Permissions::turnOnApiAccess();
185187
$result = GraphQL::executeQuery($schema, $payload, $this->pages, null, $variables);
186188
$debug = null;
187189
if ($this->config->debug) {

src/Permissions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,4 +416,12 @@ public static function getAddTemplates()
416416
return self::canAdd($template);
417417
});
418418
}
419+
420+
public static function turnOnApiAccess()
421+
{
422+
foreach (Utils::module()->legalFields as $fieldName) {
423+
$field = Utils::fields()->get($fieldName);
424+
$field->flags = $field->flags | Field::flagAccessAPI;
425+
}
426+
}
419427
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace ProcessWire\GraphQL\Test\Field\Page\Fieldtype;
4+
5+
use \ProcessWire\GraphQL\Test\GraphQLTestCase;
6+
use \ProcessWire\GraphQL\Test\Field\Page\Fieldtype\Traits\FieldtypeTestTrait;
7+
use \ProcessWire\GraphQL\Utils;
8+
9+
class FieldtypeRepeaterCaseFiveTest extends GraphQLTestCase {
10+
11+
const settings = [
12+
'login' => 'editor',
13+
'legalTemplates' => ['list-all'],
14+
'legalFields' => ['body', 'slides', 'title'],
15+
'access' => [
16+
'templates' => [
17+
[
18+
'name' => 'list-all',
19+
'roles' => ['editor']
20+
],
21+
],
22+
'fields' => [
23+
[
24+
'name' => 'body',
25+
'viewRoles' => ['editor']
26+
],
27+
[
28+
'name' => 'slides',
29+
'viewRoles' => ['editor']
30+
],
31+
[
32+
'name' => 'title',
33+
'viewRoles' => ['editor']
34+
],
35+
]
36+
]
37+
];
38+
39+
public function testValue()
40+
{
41+
$p = Utils::pages()->get("template=list-all, slides.count>0");
42+
$query = "{
43+
listAll (s: \"id=$p->id\") {
44+
list {
45+
title
46+
slides {
47+
list {
48+
id
49+
name
50+
title
51+
body
52+
}
53+
}
54+
}
55+
}
56+
}";
57+
58+
$res = self::execute($query);
59+
assertEquals(
60+
count($p->slides),
61+
count($res->data->listAll->list[0]->slides->list),
62+
'Returns correct repeater items count.'
63+
);
64+
assertEquals(
65+
$p->slides[0]->id,
66+
$res->data->listAll->list[0]->slides->list[0]->id,
67+
'Returns correct id for the first repeater item'
68+
);
69+
assertNotEmpty($p->slides[0]->title, '"title" field is empty for editor.');
70+
assertEquals(
71+
$p->slides[0]->title,
72+
$res->data->listAll->list[0]->slides->list[0]->title,
73+
'Returns correct title for the first repeater item'
74+
);
75+
assertNotEmpty($p->slides[0]->body, '"body" field is empty for editor.');
76+
assertEquals(
77+
$p->slides[0]->body,
78+
$res->data->listAll->list[0]->slides->list[0]->body,
79+
'Returns correct body for the first repeater item'
80+
);
81+
assertObjectNotHasAttribute('errors', $res, 'There are errors.');
82+
}
83+
}

0 commit comments

Comments
 (0)