Skip to content

Commit 911a9a3

Browse files
committed
Do not serve templates & fields without Access Control enabled.
1 parent c37a4be commit 911a9a3

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/Config.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,27 @@ public function __construct(ProcessGraphQL $module)
2424

2525
public function get($key)
2626
{
27+
$super = Utils::user()->isSuperuser();
2728
switch ($key) {
2829
case 'maxLimit':
2930
case 'fullWidthGraphiQL':
3031
case 'legalPageFields':
3132
case 'legalPageFileFields':
3233
return $this->module->$key;
33-
case 'legalTemplates':
34-
return $this->getLegalTemplates();
3534
case 'legalViewTemplates':
35+
if ($super) return $this->getLegalTemplates();
3636
return $this->getLegalTemplatesForPermission('page-view');
3737
case 'legalCreateTemplates':
38+
if ($super) return $this->getLegalTemplates();
3839
return $this->getLegalTemplatesForPermission('page-create');
3940
case 'legalEditTemplates':
41+
if ($super) return $this->getLegalTemplates();
4042
return $this->getLegalTemplatesForPermission('page-edit');
41-
case 'legalFields':
42-
return $this->getLegalFields();
4343
case 'legalViewFields':
44+
if ($super) return $this->getLegalFields();
4445
return $this->getLegalFieldsForPermission('view');
4546
case 'legalEditFields':
47+
if ($super) return $this->getLegalFields();
4648
return $this->getLegalFieldsForPermission('edit');
4749
default:
4850
return parent::get($key);
@@ -52,13 +54,12 @@ public function get($key)
5254
protected function getLegalTemplates()
5355
{
5456
$legalTemplates = $this->module->legalTemplates;
55-
$templates = Utils::templates()->find("name=" . implode('|', $legalTemplates));
56-
return $templates;
57+
return Utils::templates()->find("name=" . implode('|', $legalTemplates));
5758
}
5859

5960
protected function getLegalTemplatesForPermission($permission = 'page-view')
6061
{
61-
$templates = $this->getLegalTemplates();
62+
$templates = $this->getLegalTemplates()->find("useRoles=1");
6263
foreach ($templates as $template) {
6364
if (!Utils::user()->hasTemplatePermission($permission, $template)) {
6465
$templates->remove($template);
@@ -70,14 +71,12 @@ protected function getLegalTemplatesForPermission($permission = 'page-view')
7071
protected function getLegalFields()
7172
{
7273
$legalFields = $this->module->legalFields;
73-
$fields = Utils::fields()->find("name=" . implode('|', $legalFields));
74-
if (Utils::user()->isSuperuser()) return $fields;
75-
return $fields->find("useRoles=1");
74+
return Utils::fields()->find("name=" . implode('|', $legalFields));
7675
}
7776

7877
protected function getLegalFieldsForPermission($permission = 'view')
7978
{
80-
$fields = $this->getLegalFields();
79+
$fields = $this->getLegalFields()->find("useRoles=1");
8180
$rolesType = $permission . "Roles";
8281
foreach ($fields as $field) {
8382
if (!$this->userHasPermission($field->$rolesType)) {

src/Type/InterfaceType/PageInterfaceType.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ public function build($config)
2323
{
2424
$fields = self::getPageFields();
2525
$legalPageFields = Utils::moduleConfig()->legalPageFields;
26-
26+
2727
foreach ($fields as $fieldName => $fieldClassName) {
2828
if (!in_array($fieldName, $legalPageFields)) continue;
2929
$className = "ProcessWire\\GraphQL\\Field\\Page\\$fieldClassName";
3030
$config->addField(new $className());
3131
}
3232

3333
// add global fields too
34-
$legalFields = Utils::moduleConfig()->legalFields;
34+
$legalFields = Utils::moduleConfig()->legalViewFields;
3535
foreach ($legalFields as $field) {
3636
if ($field->flags & Field::flagGlobal) {
3737
$className = "\\ProcessWire\\GraphQL\\Field\\Page\\Fieldtype\\" . $field->type->className();
@@ -72,4 +72,4 @@ public static function getPageFields()
7272
];
7373
}
7474

75-
}
75+
}

src/Type/Object/TemplatedPageType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function getDescription()
3737

3838
public function build($config)
3939
{
40-
$legalFields = Utils::moduleConfig()->legalFields;
40+
$legalFields = Utils::moduleConfig()->legalViewFields;
4141
$config->applyInterface(new PageInterfaceType());
4242
foreach ($this->template->fields as $field) {
4343
if (!$legalFields->has($field)) continue;
@@ -53,4 +53,4 @@ public function getInterfaces()
5353
return [new PageInterfaceType()];
5454
}
5555

56-
}
56+
}

0 commit comments

Comments
 (0)