Remove product literal strings in "pht()", part 12
[phabricator.git] / src / applications / auth / guidance / PhabricatorAuthProvidersGuidanceEngineExtension.php
blobd4d41f1d83853107f637c079b39d4bf3532f5694
1 <?php
3 final class PhabricatorAuthProvidersGuidanceEngineExtension
4 extends PhabricatorGuidanceEngineExtension {
6 const GUIDANCEKEY = 'core.auth.providers';
8 public function canGenerateGuidance(PhabricatorGuidanceContext $context) {
9 return ($context instanceof PhabricatorAuthProvidersGuidanceContext);
12 public function generateGuidance(PhabricatorGuidanceContext $context) {
13 $configs = id(new PhabricatorAuthProviderConfigQuery())
14 ->setViewer(PhabricatorUser::getOmnipotentUser())
15 ->withIsEnabled(true)
16 ->execute();
18 $allows_registration = false;
19 foreach ($configs as $config) {
20 $provider = $config->getProvider();
21 if ($provider->shouldAllowRegistration()) {
22 $allows_registration = true;
23 break;
27 // If no provider allows registration, we don't need provide any warnings
28 // about registration being too open.
29 if (!$allows_registration) {
30 return array();
33 $domains_key = 'auth.email-domains';
34 $domains_link = $this->renderConfigLink($domains_key);
35 $domains_value = PhabricatorEnv::getEnvConfig($domains_key);
37 $approval_key = 'auth.require-approval';
38 $approval_link = $this->renderConfigLink($approval_key);
39 $approval_value = PhabricatorEnv::getEnvConfig($approval_key);
41 $results = array();
43 if ($domains_value) {
44 $message = pht(
45 'This server is configured with an email domain whitelist (in %s), so '.
46 'only users with a verified email address at one of these %s '.
47 'allowed domain(s) will be able to register an account: %s',
48 $domains_link,
49 phutil_count($domains_value),
50 phutil_tag('strong', array(), implode(', ', $domains_value)));
52 $results[] = $this->newGuidance('core.auth.email-domains.on')
53 ->setMessage($message);
54 } else {
55 $message = pht(
56 'Anyone who can browse to this this server will be able to '.
57 'register an account. To add email domain restrictions, configure '.
58 '%s.',
59 $domains_link);
61 $results[] = $this->newGuidance('core.auth.email-domains.off')
62 ->setMessage($message);
65 if ($approval_value) {
66 $message = pht(
67 'Administrative approvals are enabled (in %s), so all new users must '.
68 'have their accounts approved by an administrator.',
69 $approval_link);
71 $results[] = $this->newGuidance('core.auth.require-approval.on')
72 ->setMessage($message);
73 } else {
74 $message = pht(
75 'Administrative approvals are disabled, so users who register will '.
76 'be able to use their accounts immediately. To enable approvals, '.
77 'configure %s.',
78 $approval_link);
80 $results[] = $this->newGuidance('core.auth.require-approval.off')
81 ->setMessage($message);
84 if (!$domains_value && !$approval_value) {
85 $message = pht(
86 'You can safely ignore these warnings if the install itself has '.
87 'access controls (for example, it is deployed on a VPN) or if all of '.
88 'the configured providers have access controls (for example, they are '.
89 'all private LDAP or OAuth servers).');
91 $results[] = $this->newWarning('core.auth.warning')
92 ->setMessage($message);
95 $locked_config_key = 'auth.lock-config';
96 $is_locked = PhabricatorEnv::getEnvConfig($locked_config_key);
97 if ($is_locked) {
98 $message = pht(
99 'Authentication provider configuration is locked, and can not be '.
100 'changed without being unlocked. See the configuration setting %s '.
101 'for details.',
102 phutil_tag(
103 'a',
104 array(
105 'href' => '/config/edit/'.$locked_config_key,
107 $locked_config_key));
109 $results[] = $this->newWarning('auth.locked-config')
110 ->setPriority(500)
111 ->setMessage($message);
114 return $results;
117 private function renderConfigLink($key) {
118 return phutil_tag(
119 'a',
120 array(
121 'href' => '/config/edit/'.$key.'/',
122 'target' => '_blank',
124 $key);