-
Notifications
You must be signed in to change notification settings - Fork 8
/
stanford_ssp.install
124 lines (112 loc) · 3.74 KB
/
stanford_ssp.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
/**
* @file
* stanford_ssp.install
*/
use Drupal\Core\Entity\Entity\EntityFormDisplay;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\stanford_ssp\Service\StanfordSSPDrupalAuth;
/**
* Implements hook_install().
*/
function stanford_ssp_install() {
$config = \Drupal::configFactory()
->getEditable('simplesamlphp_auth.settings');
$config->set('activate', TRUE);
$config->set('login_link_display_name', 'SUNetID Login');
$config->set('mail_attr', 'mail');
$config->set('unique_id', 'uid');
$config->set('user_name', 'uid');
$config->set('auth_source', 'default-sp');
$config->set('secure', TRUE);
$config->set('httponly', FALSE);
$config->set('register_users', TRUE);
$config->set('autoenablesaml', TRUE);
$config->set('header_no_cache', TRUE);
$config->set('role.eval_every_time', StanfordSSPDrupalAuth::ROLE_ADDITIVE);
$config->set('allow.default_login', TRUE);
$config->set('allow.set_drupal_pwd', FALSE);
$config->save();
}
/**
* Create display name field on user entity type.
*/
function stanford_ssp_update_8001() {
\Drupal::configFactory()
->getEditable('simplesamlphp_auth.settings')
->set('user_name', 'uid')
->save();
$set_form = FALSE;
if (!FieldStorageConfig::load('user.su_display_name')) {
FieldStorageConfig::create([
'id' => 'user.su_display_name',
'field_name' => 'su_display_name',
'entity_type' => 'user',
'type' => 'string',
'module' => 'core',
])->save();
$set_form = TRUE;
}
if (!FieldConfig::load('user.user.su_display_name')) {
FieldConfig::create([
'id' => 'user.user.su_display_name',
'field_name' => 'su_display_name',
'entity_type' => 'user',
'bundle' => 'user',
'label' => 'Display Name',
'field_type' => 'string',
])->save();
$set_form = TRUE;
}
if ($set_form) {
EntityFormDisplay::load('user.user.default')
->setComponent('su_display_name')->save();
EntityViewDisplay::load('user.user.default')
->setComponent('su_display_name')->save();
}
}
/**
* Migrate stanford_ssp.settings config to the new key values.
*/
function stanford_ssp_update_8107() {
$config = \Drupal::configFactory()->getEditable('stanford_ssp.settings');
$config->set('allowed_groups', $config->get('whitelist_groups'))
->set('allowed_users', $config->get('whitelist_users'))
->clear('whitelist_groups')
->clear('whitelist_users')
->save();
}
/**
* Remove workgroup api from configs since it is hardcoded.
*/
function stanford_ssp_update_8108() {
$config = \Drupal::configFactory()->getEditable('stanford_ssp.settings');
/** @var \Drupal\stanford_ssp\Service\StanfordSSPWorkgroupApiInterface $api */
$api = \Drupal::service('stanford_ssp.workgroup_api');
if ($config->get('use_workgroup_api') && !$api->connectionSuccessful()) {
throw new \Exception('Workgroup API connection is enabled but is unable to connect to the API. Please check your certificate credentials or disable the workgroup API.');
}
$config->clear('workgroup_api_url')->save();
}
/**
* Adjust configs to the new schema.
*/
function stanford_ssp_update_8200() {
$config = \Drupal::configFactory()->getEditable('stanford_ssp.settings');
$original_data = $config->getRawData();
$allowed = [
'affiliations' => [],
'users' => $original_data['allowed_users'],
'groups' => $original_data['allowed_groups'],
];
$config->set('allowed', $allowed)->save();
}
/**
* Update settings to exclude jsonapi paths from 403 redirect.
*/
function stanford_ssp_update_8201() {
$config = \Drupal::configFactory()->getEditable('stanford_ssp.settings');
$config->set('exclude_redirect', ['/jsonapi', '/jsonapi/*'])->save();
}