|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace GraphQLAPI\GraphQLAPI\ModuleResolvers; |
|
6
|
|
|
|
|
7
|
|
|
use GraphQLAPI\GraphQLAPI\Plugin; |
|
8
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\ModuleResolverTrait; |
|
9
|
|
|
use GraphQLAPI\GraphQLAPI\ModuleResolvers\SchemaConfigurationFunctionalityModuleResolver; |
|
10
|
|
|
|
|
11
|
|
|
class AccessControlFunctionalityModuleResolver extends AbstractFunctionalityModuleResolver |
|
12
|
|
|
{ |
|
13
|
|
|
use ModuleResolverTrait { |
|
14
|
|
|
ModuleResolverTrait::hasDocumentation as upstreamHasDocumentation; |
|
15
|
|
|
} |
|
16
|
|
|
|
|
17
|
|
|
public const ACCESS_CONTROL = Plugin::NAMESPACE . '\access-control'; |
|
18
|
|
|
public const ACCESS_CONTROL_RULE_DISABLE_ACCESS = Plugin::NAMESPACE . '\access-control-rule-disable-access'; |
|
19
|
|
|
public const ACCESS_CONTROL_RULE_USER_STATE = Plugin::NAMESPACE . '\access-control-rule-user-state'; |
|
20
|
|
|
public const ACCESS_CONTROL_RULE_USER_ROLES = Plugin::NAMESPACE . '\access-control-rule-user-roles'; |
|
21
|
|
|
public const ACCESS_CONTROL_RULE_USER_CAPABILITIES = Plugin::NAMESPACE . '\access-control-rule-user-capabilities'; |
|
22
|
|
|
|
|
23
|
|
|
public static function getModulesToResolve(): array |
|
24
|
|
|
{ |
|
25
|
|
|
return [ |
|
26
|
|
|
self::ACCESS_CONTROL, |
|
27
|
|
|
self::ACCESS_CONTROL_RULE_DISABLE_ACCESS, |
|
28
|
|
|
self::ACCESS_CONTROL_RULE_USER_STATE, |
|
29
|
|
|
self::ACCESS_CONTROL_RULE_USER_ROLES, |
|
30
|
|
|
self::ACCESS_CONTROL_RULE_USER_CAPABILITIES, |
|
31
|
|
|
]; |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Enable to customize a specific UI for the module |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getModuleSubtype(string $module): ?string |
|
38
|
|
|
{ |
|
39
|
|
|
return 'accesscontrol'; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function getDependedModuleLists(string $module): array |
|
43
|
|
|
{ |
|
44
|
|
|
switch ($module) { |
|
45
|
|
|
case self::ACCESS_CONTROL: |
|
46
|
|
|
return [ |
|
47
|
|
|
[ |
|
48
|
|
|
SchemaConfigurationFunctionalityModuleResolver::SCHEMA_CONFIGURATION, |
|
49
|
|
|
], |
|
50
|
|
|
]; |
|
51
|
|
|
case self::ACCESS_CONTROL_RULE_DISABLE_ACCESS: |
|
52
|
|
|
case self::ACCESS_CONTROL_RULE_USER_STATE: |
|
53
|
|
|
case self::ACCESS_CONTROL_RULE_USER_ROLES: |
|
54
|
|
|
case self::ACCESS_CONTROL_RULE_USER_CAPABILITIES: |
|
55
|
|
|
return [ |
|
56
|
|
|
[ |
|
57
|
|
|
self::ACCESS_CONTROL, |
|
58
|
|
|
], |
|
59
|
|
|
]; |
|
60
|
|
|
} |
|
61
|
|
|
return parent::getDependedModuleLists($module); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function getName(string $module): string |
|
65
|
|
|
{ |
|
66
|
|
|
$names = [ |
|
67
|
|
|
self::ACCESS_CONTROL => \__('Access Control', 'graphql-api'), |
|
68
|
|
|
self::ACCESS_CONTROL_RULE_DISABLE_ACCESS => \__('Access Control Rule: Disable Access', 'graphql-api'), |
|
69
|
|
|
self::ACCESS_CONTROL_RULE_USER_STATE => \__('Access Control Rule: User State', 'graphql-api'), |
|
70
|
|
|
self::ACCESS_CONTROL_RULE_USER_ROLES => \__('Access Control Rule: User Roles', 'graphql-api'), |
|
71
|
|
|
self::ACCESS_CONTROL_RULE_USER_CAPABILITIES => \__('Access Control Rule: User Capabilities', 'graphql-api'), |
|
72
|
|
|
]; |
|
73
|
|
|
return $names[$module] ?? $module; |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
public function getDescription(string $module): string |
|
77
|
|
|
{ |
|
78
|
|
|
switch ($module) { |
|
79
|
|
|
case self::ACCESS_CONTROL: |
|
80
|
|
|
return \__('Set-up rules to define who can access the different fields and directives from a schema', 'graphql-api'); |
|
81
|
|
|
case self::ACCESS_CONTROL_RULE_DISABLE_ACCESS: |
|
82
|
|
|
return \__('Remove access to the fields and directives', 'graphql-api'); |
|
83
|
|
|
case self::ACCESS_CONTROL_RULE_USER_STATE: |
|
84
|
|
|
return \__('Allow or reject access to the fields and directives based on the user being logged-in or not', 'graphql-api'); |
|
85
|
|
|
case self::ACCESS_CONTROL_RULE_USER_ROLES: |
|
86
|
|
|
return \__('Allow or reject access to the fields and directives based on the user having a certain role', 'graphql-api'); |
|
87
|
|
|
case self::ACCESS_CONTROL_RULE_USER_CAPABILITIES: |
|
88
|
|
|
return \__('Allow or reject access to the fields and directives based on the user having a certain capability', 'graphql-api'); |
|
89
|
|
|
} |
|
90
|
|
|
return parent::getDescription($module); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* Does the module have HTML Documentation? |
|
95
|
|
|
*/ |
|
96
|
|
|
public function hasDocumentation(string $module): bool |
|
97
|
|
|
{ |
|
98
|
|
|
switch ($module) { |
|
99
|
|
|
case self::ACCESS_CONTROL_RULE_DISABLE_ACCESS: |
|
100
|
|
|
case self::ACCESS_CONTROL_RULE_USER_STATE: |
|
101
|
|
|
case self::ACCESS_CONTROL_RULE_USER_ROLES: |
|
102
|
|
|
case self::ACCESS_CONTROL_RULE_USER_CAPABILITIES: |
|
103
|
|
|
return false; |
|
104
|
|
|
} |
|
105
|
|
|
return $this->upstreamHasDocumentation($module); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|