|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\ModuleResolvers; |
|
6
|
|
|
|
|
7
|
|
|
use GraphQLAPI\GraphQLAPI\Plugin; |
|
8
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleSettings\Properties; |
|
9
|
|
|
use GraphQLAPI\GraphQLAPI\Security\UserAuthorization; |
|
10
|
|
|
use GraphQLAPI\GraphQLAPI\Facades\ModuleRegistryFacade; |
|
11
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ModuleResolverTrait; |
|
12
|
|
|
|
|
13
|
|
|
class PluginManagementFunctionalityModuleResolver extends AbstractFunctionalityModuleResolver |
|
14
|
|
|
{ |
|
15
|
|
|
use ModuleResolverTrait; |
|
16
|
|
|
|
|
17
|
|
|
public const SCHEMA_EDITING_ACCESS = Plugin::NAMESPACE . '\schema-editing-access'; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Setting options |
|
21
|
|
|
*/ |
|
22
|
|
|
public const OPTION_EDITING_ACCESS_SCHEME = 'editing-access-scheme'; |
|
23
|
|
|
|
|
24
|
|
|
public static function getModulesToResolve(): array |
|
25
|
|
|
{ |
|
26
|
|
|
return [ |
|
27
|
|
|
self::SCHEMA_EDITING_ACCESS, |
|
28
|
|
|
]; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
// public function canBeDisabled(string $module): bool |
|
32
|
|
|
// { |
|
33
|
|
|
// switch ($module) { |
|
34
|
|
|
// case self::SCHEMA_EDITING_ACCESS: |
|
35
|
|
|
// return false; |
|
36
|
|
|
// } |
|
37
|
|
|
// return parent::canBeDisabled($module); |
|
38
|
|
|
// } |
|
39
|
|
|
|
|
40
|
|
|
public function getName(string $module): string |
|
41
|
|
|
{ |
|
42
|
|
|
$names = [ |
|
43
|
|
|
self::SCHEMA_EDITING_ACCESS => \__('Schema Editing Access', 'graphql-api'), |
|
44
|
|
|
]; |
|
45
|
|
|
return $names[$module] ?? $module; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getDescription(string $module): string |
|
49
|
|
|
{ |
|
50
|
|
|
switch ($module) { |
|
51
|
|
|
case self::SCHEMA_EDITING_ACCESS: |
|
52
|
|
|
return \__('Grant access to users other than admins to edit the GraphQL schema', 'graphql-api'); |
|
53
|
|
|
} |
|
54
|
|
|
return parent::getDescription($module); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Default value for an option set by the module |
|
59
|
|
|
* |
|
60
|
|
|
* @param string $module |
|
61
|
|
|
* @param string $option |
|
62
|
|
|
* @return mixed Anything the setting might be: an array|string|bool|int|null |
|
63
|
|
|
*/ |
|
64
|
|
|
public function getSettingsDefaultValue(string $module, string $option) |
|
65
|
|
|
{ |
|
66
|
|
|
$defaultValues = [ |
|
67
|
|
|
self::SCHEMA_EDITING_ACCESS => [ |
|
68
|
|
|
self::OPTION_EDITING_ACCESS_SCHEME => UserAuthorization::ACCESS_SCHEME_ADMIN_ONLY, |
|
69
|
|
|
], |
|
70
|
|
|
]; |
|
71
|
|
|
return $defaultValues[$module][$option]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Array with the inputs to show as settings for the module |
|
76
|
|
|
* |
|
77
|
|
|
* @param string $module |
|
78
|
|
|
* @return array |
|
79
|
|
|
*/ |
|
80
|
|
|
public function getSettings(string $module): array |
|
81
|
|
|
{ |
|
82
|
|
|
$moduleSettings = parent::getSettings($module); |
|
83
|
|
|
$moduleRegistry = ModuleRegistryFacade::getInstance(); |
|
|
|
|
|
|
84
|
|
|
// Do the if one by one, so that the SELECT do not get evaluated unless needed |
|
85
|
|
|
if ($module == self::SCHEMA_EDITING_ACCESS) { |
|
86
|
|
|
/** |
|
87
|
|
|
* Write Access Scheme |
|
88
|
|
|
* If `"admin"`, only the admin can compose a GraphQL query and endpoint |
|
89
|
|
|
* If `"post"`, the workflow from creating posts is employed (i.e. Author role can create |
|
90
|
|
|
* but not publish the query, Editor role can publish it, etc) |
|
91
|
|
|
*/ |
|
92
|
|
|
$option = self::OPTION_EDITING_ACCESS_SCHEME; |
|
93
|
|
|
$moduleSettings[] = [ |
|
94
|
|
|
Properties::INPUT => $option, |
|
95
|
|
|
Properties::NAME => $this->getSettingOptionName( |
|
96
|
|
|
$module, |
|
97
|
|
|
$option |
|
98
|
|
|
), |
|
99
|
|
|
Properties::TITLE => \__('Editing Access Scheme', 'graphql-api'), |
|
100
|
|
|
Properties::DESCRIPTION => \__('Scheme to decide which users can edit the schema (Persisted Queries, Custom Endpoints and related post types) and with what permissions', 'graphql-api'), |
|
101
|
|
|
Properties::TYPE => Properties::TYPE_STRING, |
|
102
|
|
|
Properties::POSSIBLE_VALUES => [ |
|
103
|
|
|
UserAuthorization::ACCESS_SCHEME_ADMIN_ONLY => \__('Admin user(s) only', 'graphql-api'), |
|
104
|
|
|
UserAuthorization::ACCESS_SCHEME_POST => \__('Use same access workflow as for editing posts', 'graphql-api'), |
|
105
|
|
|
], |
|
106
|
|
|
]; |
|
107
|
|
|
} |
|
108
|
|
|
return $moduleSettings; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|