1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* Copyright Humbly Arrogant Ltd 2020-2022. |
7
|
|
|
* |
8
|
|
|
* Use of this software is governed by the Business Source License included in the LICENSE file and at https://getparthenon.com/docs/next/license. |
9
|
|
|
* |
10
|
|
|
* Change Date: TBD ( 3 years after 2.0.0 release ) |
11
|
|
|
* |
12
|
|
|
* On the date above, in accordance with the Business Source License, use of this software will be governed by the open source license specified in the LICENSE file. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Parthenon\DependencyInjection\Modules; |
16
|
|
|
|
17
|
|
|
use Parthenon\Common\Exception\NonExistentClass; |
18
|
|
|
use Parthenon\Common\Exception\ParameterNotSetException; |
19
|
|
|
use Parthenon\User\Entity\TeamInterface; |
20
|
|
|
use Parthenon\User\Entity\UserInterface; |
21
|
|
|
use Parthenon\User\Gdpr\Deletion\DeleterInterface; |
22
|
|
|
use Parthenon\User\Gdpr\Deletion\VoterInterface; |
23
|
|
|
use Parthenon\User\Gdpr\Export\ExporterInterface; |
24
|
|
|
use Parthenon\User\Gdpr\Export\FormatterInterface; |
25
|
|
|
use Symfony\Component\Config\Definition\Builder\NodeBuilder; |
26
|
|
|
use Symfony\Component\Config\FileLocator; |
27
|
|
|
use Symfony\Component\DependencyInjection\ContainerBuilder; |
|
|
|
|
28
|
|
|
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; |
|
|
|
|
29
|
|
|
|
30
|
|
|
final class User implements ModuleConfigurationInterface |
31
|
|
|
{ |
32
|
|
|
public function addConfig(NodeBuilder $nodeBuilder): void |
33
|
|
|
{ |
34
|
|
|
$nodeBuilder |
35
|
|
|
->arrayNode('user') |
36
|
|
|
->children() |
37
|
|
|
->booleanNode('enabled')->defaultValue(false)->end() |
38
|
|
|
->scalarNode('user_class')->end() |
|
|
|
|
39
|
|
|
->booleanNode('confirm_email')->defaultValue(false)->end() |
40
|
|
|
->booleanNode('user_invites_enabled')->defaultValue(false)->end() |
41
|
|
|
->scalarNode('login_route')->defaultValue('parthenon_user_login')->end() |
42
|
|
|
->scalarNode('login_redirect_route')->defaultValue('parthenon_user_profile')->end() |
43
|
|
|
->scalarNode('signup_success_route')->defaultValue('parthenon_user_signed_up')->end() |
44
|
|
|
->booleanNode('teams_enabled')->defaultValue(false)->end() |
45
|
|
|
->booleanNode('teams_invites_enabled')->defaultValue(false)->end() |
46
|
|
|
->booleanNode('self_signup_enabled')->defaultValue(true)->end() |
47
|
|
|
->scalarNode('team_class')->end() |
48
|
|
|
->arrayNode('roles') |
49
|
|
|
->children() |
50
|
|
|
->scalarNode('default_role')->defaultValue('ROLE_USER')->end() |
51
|
|
|
->arrayNode('user_assignable') |
52
|
|
|
->useAttributeAsKey('name') |
53
|
|
|
->scalarPrototype()->end() |
54
|
|
|
->end() |
55
|
|
|
->arrayNode('athena_assignable') |
56
|
|
|
->useAttributeAsKey('name') |
57
|
|
|
->scalarPrototype()->end() |
58
|
|
|
->end() |
59
|
|
|
->end() |
60
|
|
|
->end() |
61
|
|
|
->arrayNode('gdpr') |
62
|
|
|
->children() |
63
|
|
|
->arrayNode('export') |
64
|
|
|
->children() |
65
|
|
|
->scalarNode('export_format')->end() |
66
|
|
|
->end() |
67
|
|
|
->end() |
68
|
|
|
->end() |
69
|
|
|
->end() |
70
|
|
|
->end() |
71
|
|
|
->end(); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function handleDefaultParameters(ContainerBuilder $container): void |
75
|
|
|
{ |
76
|
|
|
$container->setParameter('parthenon_user_login_route', 'parthenon_user_login'); |
77
|
|
|
$container->setParameter('parthenon_user_signup_success_route', 'parthenon_user_signed_up'); |
78
|
|
|
$container->setParameter('parthenon_user_users_invites_enabled', false); |
79
|
|
|
$container->setParameter('parthenon_user_teams_enabled', false); |
80
|
|
|
$container->setParameter('parthenon_user_team_class', null); |
81
|
|
|
$container->setParameter('parthenon_user_teams_invites_enabled', false); |
82
|
|
|
$container->setParameter('parthenon_user_gdpr_formatter_type', 'json'); |
83
|
|
|
$container->setParameter('parthenon_user_roles_default_role', 'ROLE_USER'); |
84
|
|
|
$container->setParameter('parthenon_user_roles_user_assignable_roles', []); |
85
|
|
|
$container->setParameter('parthenon_user_roles_athena_assignable_roles', []); |
86
|
|
|
$container->setParameter('parthenon_user_self_signup_enabled', true); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function handleConfiguration(array $config, ContainerBuilder $container): void |
90
|
|
|
{ |
91
|
|
|
if (!isset($config['user']) || !isset($config['user']['enabled']) || false == $config['user']['enabled']) { |
92
|
|
|
return; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../../Resources/config')); |
96
|
|
|
$bundles = $container->getParameter('kernel.bundles'); |
97
|
|
|
|
98
|
|
|
$this->configureMongoDb($bundles, $loader); |
99
|
|
|
$this->configureDoctrine($bundles, $loader); |
100
|
|
|
|
101
|
|
|
$loader->load('services/user.xml'); |
102
|
|
|
|
103
|
|
|
$this->configureAutotagging($container); |
104
|
|
|
$config = $this->configureUserClass($config, $container); |
105
|
|
|
$config = $this->configureSignupSuccessRoute($config, $container); |
106
|
|
|
$config = $this->configureLoginRoute($config, $container); |
107
|
|
|
$config = $this->configureUserInvitesEnabled($config, $container); |
108
|
|
|
$config = $this->configureTeamsInviteEnabled($config, $container); |
109
|
|
|
$config = $this->configureGdprFormatterType($config, $container); |
110
|
|
|
$config = $this->configureRoles($config, $container); |
111
|
|
|
$config = $this->configureSelfSignup($config, $container); |
112
|
|
|
|
113
|
|
|
$this->configureTeams($config, $container); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* @throws NonExistentClass |
118
|
|
|
* @throws ParameterNotSetException |
119
|
|
|
*/ |
120
|
|
|
private function configureTeams(array $config, ContainerBuilder $container): void |
121
|
|
|
{ |
122
|
|
|
if (isset($config['user']['teams_enabled']) && $config['user']['teams_enabled']) { |
123
|
|
|
$container->setParameter('parthenon_user_teams_enabled', $config['user']['teams_enabled']); |
124
|
|
|
if (!isset($config['user']['team_class']) || empty($config['user']['team_class'])) { |
125
|
|
|
throw new ParameterNotSetException('When the user module is enabled and teams are enabled the team_class must be defined'); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
if (!class_exists($config['user']['team_class'])) { |
129
|
|
|
throw new NonExistentClass(sprintf("The class '%s' does not exist.", $config['user']['team_class'])); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
$teamDdfinition = $container->getDefinition(TeamInterface::class); |
133
|
|
|
$teamDdfinition->setClass($config['user']['team_class']); |
134
|
|
|
$container->setDefinition(TeamInterface::class, $teamDdfinition); |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
private function configureGdprFormatterType(array $config, ContainerBuilder $container): array |
139
|
|
|
{ |
140
|
|
|
if (isset($config['user']['gdpr']['export']['formatter_type']) && !empty($config['user']['gdpr']['export']['formatter_type'])) { |
141
|
|
|
$container->setParameter('parthenon_user_gdpr_formatter_type', $config['user']['gdpr']['export']['formatter_type']); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
return $config; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
private function configureTeamsInviteEnabled(array $config, ContainerBuilder $container): array |
148
|
|
|
{ |
149
|
|
|
if (isset($config['user']['teams_invites_enabled'])) { |
150
|
|
|
$container->setParameter('parthenon_user_teams_invites_enabled', $config['user']['teams_invites_enabled']); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
return $config; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
private function configureUserInvitesEnabled(array $config, ContainerBuilder $container): array |
157
|
|
|
{ |
158
|
|
|
if (isset($config['user']['user_invites_enabled'])) { |
159
|
|
|
$container->setParameter('parthenon_user_users_invites_enabled', $config['user']['user_invites_enabled']); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $config; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
private function configureRoles(array $config, ContainerBuilder $containerBuilder): array |
166
|
|
|
{ |
167
|
|
|
if (!isset($config['user']['roles'])) { |
168
|
|
|
return $config; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
$containerBuilder->setParameter('parthenon_user_roles_default_role', $config['user']['roles']['default_role'] ?? 'ROLE_USER'); |
172
|
|
|
$containerBuilder->setParameter('parthenon_user_roles_user_assignable_roles', $config['user']['roles']['user_assignable'] ?? []); |
173
|
|
|
$containerBuilder->setParameter('parthenon_user_roles_athena_assignable_roles', $config['user']['roles']['athena_assignable'] ?? []); |
174
|
|
|
|
175
|
|
|
return $config; |
176
|
|
|
} |
177
|
|
|
|
178
|
|
|
private function configureLoginRoute(array $config, ContainerBuilder $container): array |
179
|
|
|
{ |
180
|
|
|
if (isset($config['user']['login_route'])) { |
181
|
|
|
$container->setParameter('parthenon_user_login_route', $config['user']['login_route']); |
182
|
|
|
} |
183
|
|
|
|
184
|
|
|
return $config; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
private function configureSignupSuccessRoute(array $config, ContainerBuilder $container): array |
188
|
|
|
{ |
189
|
|
|
if (isset($config['user']['signup_success_route'])) { |
190
|
|
|
$container->setParameter('parthenon_user_signup_success_route', $config['user']['signup_success_route']); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
return $config; |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
private function configureSelfSignup(array $config, ContainerBuilder $container): array |
197
|
|
|
{ |
198
|
|
|
if (isset($config['user']['self_signup_enabled'])) { |
199
|
|
|
$container->setParameter('parthenon_user_self_signup_enabled', $config['user']['self_signup_enabled']); |
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
return $config; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
private function configureAutotagging(ContainerBuilder $container): void |
206
|
|
|
{ |
207
|
|
|
$container->registerForAutoconfiguration(ExporterInterface::class)->addTag('parthenon.user.gdpr.export.exporter'); |
208
|
|
|
$container->registerForAutoconfiguration(FormatterInterface::class)->addTag('parthenon.user.gdpr.export.formatter'); |
209
|
|
|
$container->registerForAutoconfiguration(DeleterInterface::class)->addTag('parthenon.user.gdpr.delete.deleter'); |
210
|
|
|
$container->registerForAutoconfiguration(VoterInterface::class)->addTag('parthenon.user.gdpr.delete.voter'); |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* @throws \Exception |
215
|
|
|
*/ |
216
|
|
|
private function configureDoctrine(float|array|bool|int|string|null $bundles, XmlFileLoader $loader): string|int|bool|array|null|float |
217
|
|
|
{ |
218
|
|
|
if (isset($bundles['DoctrineBundle'])) { |
219
|
|
|
$loader->load('services/orm/user.xml'); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
return $bundles; |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
/** |
226
|
|
|
* @throws \Exception |
227
|
|
|
*/ |
228
|
|
|
private function configureMongoDb(float|int|bool|array|string|null $bundles, XmlFileLoader $loader): void |
229
|
|
|
{ |
230
|
|
|
if (isset($bundles['DoctrineMongoDBBundle'])) { |
231
|
|
|
$loader->load('services/odm/user.xml'); |
232
|
|
|
} |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
/** |
236
|
|
|
* @throws NonExistentClass |
237
|
|
|
* @throws ParameterNotSetException |
238
|
|
|
*/ |
239
|
|
|
private function configureUserClass(array $config, ContainerBuilder $container): array |
240
|
|
|
{ |
241
|
|
|
if (!isset($config['user']['user_class']) || empty($config['user']['user_class'])) { |
242
|
|
|
throw new ParameterNotSetException('When the user module is enabled the user_class must be defined'); |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
if (!class_exists($config['user']['user_class'])) { |
246
|
|
|
throw new NonExistentClass(sprintf("The class '%s' does not exist.", $config['user']['user_class'])); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
$userDefintion = $container->getDefinition(UserInterface::class); |
250
|
|
|
$userDefintion->setClass($config['user']['user_class']); |
251
|
|
|
$container->setDefinition(UserInterface::class, $userDefintion); |
252
|
|
|
|
253
|
|
|
return $config; |
254
|
|
|
} |
255
|
|
|
} |
256
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths