Projet

Général

Profil

Révision bc175c27

Ajouté par Assos Assos il y a plus de 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_authorization/ldap_authorization.admin.test.inc
2 2

  
3 3
/**
4 4
 * @file
5
 * form to test a ldap authorization consumer configuration
5
 * Form to test a ldap authorization consumer configuration.
6 6
 */
7 7

  
8 8
/**
9
 * form for adding, updating, and deleting a single ldap authorization consumer configuration
9
 * Form for adding, updating, and deleting a single ldap authorization consumer configuration.
10
 *
11
 * @param mixed $form
12
 * @param mixed $form_state
10 13
 *
11
 * @param <type> $form
12
 * @param <type> $form_state
13 14
 * @return array drupal form array
14 15
 */
15

  
16

  
17 16
function ldap_authorization_test_form($form, &$form_state, $consumer_type) {
18 17
  $consumer = ldap_authorization_get_consumer_object($consumer_type);
19 18
  $consumer_tokens = ldap_authorization_tokens($consumer);
......
22 21
    $form['result'] = array(
23 22
      '#type' => 'item',
24 23
      '#markup' => $_SESSION['ldap_authorization_test_query']['result'],
25
      );
24
    );
26 25

  
27 26
    $form['pre-filtered'] = array(
28 27
      '#type' => 'fieldset',
......
31 30
      '#collapsed' => TRUE,
32 31
    );
33 32
    $form['pre-filtered']['overview'] = array(
34
     '#type' => 'item',
35
     '#markup' => t('Below are the "raw authorizations" and which strategy they are derived from.  If enabled, the mapping filter is applied to these.'),
33
      '#type' => 'item',
34
      '#markup' => t('Below are the "raw authorizations" and which strategy they are derived from.  If enabled, the mapping filter is applied to these.'),
36 35
    );
37 36

  
38 37
    if (isset($_SESSION['ldap_authorization_test_query']['maps'])) {
......
40 39
      foreach ($_SESSION['ldap_authorization_test_query']['maps'] as $map => $data) {
41 40
        $i++;
42 41
        $form['pre-filtered']['map' . $i] = array(
43
         '#type' => 'item',
44
         '#markup' => is_scalar($data) ?  "<h2>$map (without filter)</h2>" . $data : theme('item_list', array('items' => $data, 'type' => 'ul', 'title' => "$map (without filter)")),
42
          '#type' => 'item',
43
          '#markup' => is_scalar($data) ? "<h2>$map (without filter)</h2>" . $data : theme('item_list', array('items' => $data, 'type' => 'ul', 'title' => "$map (without filter)")),
45 44
        );
46 45
      }
47 46
    }
......
56 55
    if ($consumer->consumerConf->useFirstAttrAsGroupId) {
57 56
      if (isset($_SESSION['ldap_authorization_test_query']['useFirstAttrAsGroupId'])) {
58 57
        $form['use_first_attr_as_groupid']['data'] = array(
59
         '#type' => 'item',
60
         '#markup' => theme('item_list', array('items' => $_SESSION['ldap_authorization_test_query']['useFirstAttrAsGroupId'], 'type' => 'ul', 'title' => "Convert full dn to value of first attribute before mapping")),
58
          '#type' => 'item',
59
          '#markup' => theme('item_list', array('items' => $_SESSION['ldap_authorization_test_query']['useFirstAttrAsGroupId'], 'type' => 'ul', 'title' => "Convert full dn to value of first attribute before mapping")),
61 60
        );
62 61
      }
63 62
    }
64 63
    else {
65 64
      $form['use_first_attr_as_groupid']['data'] = array(
66
       '#type' => 'item',
67
       '#markup' => "Convert full dn to value of first attribute before mapping. NOT enabled",
65
        '#type' => 'item',
66
        '#markup' => "Convert full dn to value of first attribute before mapping. NOT enabled",
68 67
      );
69 68
    }
70 69

  
......
82 81

  
83 82
    $form['post mappings']['conf'] = array(
84 83
      '#type' => 'item',
85
      '#markup' => 'Use Mappings as Filter = ' . (int)$consumer->consumerConf->useMappingsAsFilter .
86
          theme('item_list', array(
87
          'items' =>  $maps,
88
          'type' => 'ul',
89
          'title' => 'Configured Mappings',
90
        )
84
      '#markup' => 'Use Mappings as Filter = ' . (int) $consumer->consumerConf->useMappingsAsFilter .
85
      theme('item_list', array(
86
        'items' => $maps,
87
        'type' => 'ul',
88
        'title' => 'Configured Mappings',
91 89
      )
90
      ),
92 91
    );
93 92
    if ($consumer->consumerConf->mappings) {
94 93
      $form['post mappings']['conf']['#markup'] =
95
      'Use Mappings as Filter = ' . (int)$consumer->consumerConf->useMappingsAsFilter .
94
      'Use Mappings as Filter = ' . (int) $consumer->consumerConf->useMappingsAsFilter .
96 95
          theme('item_list', array(
97
          'items' =>  $maps,
98
          'type' => 'ul',
99
          'title' => 'Configured Mappings',
100
        )
96
            'items' => $maps,
97
            'type' => 'ul',
98
            'title' => 'Configured Mappings',
99
          )
101 100
      );
102 101
    }
103 102
    else {
104 103
      $form['post mappings']['conf']['#markup'] =
105 104
      'Use Mappings as Filter = ' .
106
      (int)$consumer->consumerConf->useMappingsAsFilter .
105
      (int) $consumer->consumerConf->useMappingsAsFilter .
107 106
      '<br/>No Mappings Configured';
108 107
    }
109 108

  
110 109
    if (isset($_SESSION['ldap_authorization_test_query']['post mappings'])) {
111 110
      $form['post mappings']['data'] = array(
112
       '#type' => 'item',
113
       '#markup' => theme('item_list', array('items' => $_SESSION['ldap_authorization_test_query']['post mappings'], 'type' => 'ul', 'title' => "Results after any filtering and mappings applied")),
111
        '#type' => 'item',
112
        '#markup' => theme('item_list', array('items' => $_SESSION['ldap_authorization_test_query']['post mappings'], 'type' => 'ul', 'title' => "Results after any filtering and mappings applied")),
114 113
      );
115 114
    }
116 115

  
......
125 124
        '#collapsed' => TRUE,
126 125
      );
127 126
      $form[$title]['overview'] = array(
128
       '#type' => 'item',
129
       '#markup' => "<pre>" . print_r($data, TRUE) . "</pre>",
127
        '#type' => 'item',
128
        '#markup' => "<pre>" . print_r($data, TRUE) . "</pre>",
130 129
      );
131 130
    }
132 131
  }
133 132

  
134

  
135 133
  $form['intro'] = array(
136
      '#type' => 'item',
137
      '#markup' => t('<h1>Test LDAP to !consumer_name Configuration</h1>
134
    '#type' => 'item',
135
    '#markup' => t('<h1>Test LDAP to !consumer_name Configuration</h1>
138 136
      <p>This form will not actually grant any authorizations, its just to show
139 137
      what authorizations would be granted with this configuration.</p>', $consumer_tokens),
140 138
  );
......
182 180
  return $form;
183 181
}
184 182

  
185

  
186 183
/**
187
 * validate handler for the ldap_authorization_test
184
 * Validate handler for the ldap_authorization_test.
188 185
 */
189 186
function ldap_authorization_test_form_validate($form, &$form_state) {
190 187

  
......
196 193
}
197 194

  
198 195
/**
199
 * submit handler function for ldap_authorization_test
196
 * Submit handler function for ldap_authorization_test.
200 197
 */
201

  
202

  
203 198
function ldap_authorization_test_form_submit($form, &$form_state) {
204 199
  $consumer_type = $form_state['values']['consumer_type'];
205 200
  $consumer = ldap_authorization_get_consumer_object($consumer_type);
......
210 205
  $random_users = array();
211 206
  $_SESSION['ldap_authorization_test_query']['random_users'] = $form_state['values']['random_users'];
212 207
  $_SESSION['ldap_authorization_test_query']['usernames'] = $form_state['values']['usernames'];
213
  if ($form_state['values']['random_users']) {  // add 10 random usernames to test
214
    // not using user_load_multiple because need randomness outside of query
208
  // Add 10 random usernames to test.
209
  if ($form_state['values']['random_users']) {
210
    // Not using user_load_multiple because need randomness outside of query.
215 211
    $select = db_select('users', 'u');
216 212
    $select->fields('u');
217 213

  
218 214
    try {
219
      $random_users = $select->execute()->fetchAllAssoc('name',  PDO::FETCH_ASSOC);
215
      $random_users = $select->execute()->fetchAllAssoc('name', PDO::FETCH_ASSOC);
220 216
    }
221 217
    catch (Exception $e) {
222 218
      drupal_set_message(t('db users query failed. Message = %message, query= %query',
......
230 226
  foreach ($user_names as $username) {
231 227
    if ($username) {
232 228
      if (!$user = user_load_by_name($username)) {
233
        // if not existing user, create fake user assumed to be ldap authenticated
229
        // If not existing user, create fake user assumed to be ldap authenticated.
234 230
        $user = new stdClass();
235 231
        $user->name = $username;
236 232
        $user->ldap_test = TRUE;
......
250 246

  
251 247
      $action = ($form_state['values']['execute_authorizations'] == 1) ? "test_query_set" : 'test_query';
252 248
      list($results[$username], $notifications[$username]) = ldap_authorizations_user_authorizations($user, $action, $consumer_type, 'logon');
253
      // remove authorizations from other consumer types
249
      // Remove authorizations from other consumer types.
254 250
      $results[$username] = array($consumer_type => $results[$username][$consumer_type]);
255 251
      $i++;
256 252
      if ($i == 10) {
......
259 255
    }
260 256
  }
261 257

  
262
  $table =  theme('ldap_authorization_test_results', array('results' => $results, 'consumer' => $consumer, 'notifications' => $notifications));
258
  $table = theme('ldap_authorization_test_results', array('results' => $results, 'consumer' => $consumer, 'notifications' => $notifications));
263 259
  $_SESSION['ldap_authorization_test_query']['result'] = $table;
264 260
  $form_state['redirect'] = LDAP_SERVERS_MENU_BASE_PATH . '/authorization/test/' . $consumer->consumerType;
265 261

  

Formats disponibles : Unified diff