Projet

Général

Profil

Révision 32700c57

Ajouté par Assos Assos il y a environ 5 ans

Weekly update of contrib modules

Voir les différences:

drupal7/sites/all/modules/ldap/ldap_authorization/ldap_authorization.admin.test.inc
18 18
  $consumer_tokens = ldap_authorization_tokens($consumer);
19 19

  
20 20
  if (isset($_SESSION['ldap_authorization_test_query']['result'])) {
21
    $form['result'] = array(
21
    $form['result'] = [
22 22
      '#type' => 'item',
23 23
      '#markup' => $_SESSION['ldap_authorization_test_query']['result'],
24
    );
24
    ];
25 25

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

  
37 37
    if (isset($_SESSION['ldap_authorization_test_query']['maps'])) {
38 38
      $i = 0;
39 39
      foreach ($_SESSION['ldap_authorization_test_query']['maps'] as $map => $data) {
40 40
        $i++;
41
        $form['pre-filtered']['map' . $i] = array(
41
        $form['pre-filtered']['map' . $i] = [
42 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)")),
44
        );
43
          '#markup' => is_scalar($data) ? "<h2>$map (without filter)</h2>" . $data : theme('item_list', ['items' => $data, 'type' => 'ul', 'title' => "$map (without filter)"]),
44
        ];
45 45
      }
46 46
    }
47 47

  
48
    $form['use_first_attr_as_groupid'] = array(
48
    $form['use_first_attr_as_groupid'] = [
49 49
      '#type' => 'fieldset',
50 50
      '#title' => t('After "Convert full dn to value of first attribute before mapping"'),
51 51
      '#collapsible' => TRUE,
52 52
      '#collapsed' => TRUE,
53
    );
53
    ];
54 54

  
55 55
    if ($consumer->consumerConf->useFirstAttrAsGroupId) {
56 56
      if (isset($_SESSION['ldap_authorization_test_query']['useFirstAttrAsGroupId'])) {
57
        $form['use_first_attr_as_groupid']['data'] = array(
57
        $form['use_first_attr_as_groupid']['data'] = [
58 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")),
60
        );
59
          '#markup' => theme('item_list', ['items' => $_SESSION['ldap_authorization_test_query']['useFirstAttrAsGroupId'], 'type' => 'ul', 'title' => "Convert full dn to value of first attribute before mapping"]),
60
        ];
61 61
      }
62 62
    }
63 63
    else {
64
      $form['use_first_attr_as_groupid']['data'] = array(
64
      $form['use_first_attr_as_groupid']['data'] = [
65 65
        '#type' => 'item',
66 66
        '#markup' => "Convert full dn to value of first attribute before mapping. NOT enabled",
67
      );
67
      ];
68 68
    }
69 69

  
70
    $form['post mappings'] = array(
70
    $form['post mappings'] = [
71 71
      '#type' => 'fieldset',
72 72
      '#title' => t('After Mappings and Filters Applied'),
73 73
      '#collapsible' => TRUE,
74 74
      '#collapsed' => TRUE,
75
    );
75
    ];
76 76

  
77
    $maps = array();
77
    $maps = [];
78 78
    foreach ($consumer->consumerConf->mappings as $i => $mapping) {
79 79
      $maps[] = $mapping['from'] . '|' . $mapping['user_entered'];
80 80
    }
81 81

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

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

  
116 116
  }
117 117

  
118 118
  if (isset($_SESSION['ldap_authorization_test_query']['setting_data'])) {
119 119
    foreach ($_SESSION['ldap_authorization_test_query']['setting_data'] as $title => $data) {
120
      $form[$title] = array(
120
      $form[$title] = [
121 121
        '#type' => 'fieldset',
122 122
        '#title' => $title,
123 123
        '#collapsible' => TRUE,
124 124
        '#collapsed' => TRUE,
125
      );
126
      $form[$title]['overview'] = array(
125
      ];
126
      $form[$title]['overview'] = [
127 127
        '#type' => 'item',
128 128
        '#markup' => "<pre>" . print_r($data, TRUE) . "</pre>",
129
      );
129
      ];
130 130
    }
131 131
  }
132 132

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

  
140
  $form['consumer_type'] = array(
140
  $form['consumer_type'] = [
141 141
    '#type' => 'hidden',
142 142
    '#default_value' => $consumer_type,
143
  );
143
  ];
144 144

  
145
  $form['usernames'] = array(
145
  $form['usernames'] = [
146 146
    '#type' => 'textarea',
147 147
    '#title' => t('Drupal usernames to test !consumer_shortName authorizations results for.  One per line.', $consumer_tokens),
148
    '#default_value' => @$_SESSION['ldap_authorization_test_query']['usernames'] ,
148
    '#default_value' => @$_SESSION['ldap_authorization_test_query']['usernames'],
149 149
    '#cols' => 50,
150 150
    '#rows' => 6,
151 151
    '#description' => '',
152
  );
152
  ];
153 153

  
154
  $form['random_users'] = array(
154
  $form['random_users'] = [
155 155
    '#type' => 'checkbox',
156 156
    '#default_value' => @$_SESSION['ldap_authorization_test_form']['random_users'],
157 157
    '#title' => t('Use 10 random users', $consumer_tokens),
158
  );
158
  ];
159 159

  
160
  $form['execute_authorizations'] = array(
160
  $form['execute_authorizations'] = [
161 161
    '#type' => 'checkbox',
162 162
    '#default_value' => @$_SESSION['ldap_authorization_test_form']['execute_authorizations'],
163 163
    '#title' => t('Actually grant or revoke example authorizations.
164 164
      This will grant and revoke based on the ldap authorization configuration
165 165
      options such as whether to revoke or regrant manually applied authorizations.
166 166
      Try with this unchecked first, then check to see how authorizations are applied.', $consumer_tokens),
167
  );
167
  ];
168 168

  
169
  $form['user_data_clear'] = array(
169
  $form['user_data_clear'] = [
170 170
    '#type' => 'checkbox',
171 171
    '#default_value' => @$_SESSION['ldap_authorization_test_form']['user_data_clear'],
172 172
    '#title' => t('Clear <pre>$user->data[ldap_authorization][<consumer type>]</pre> data for test users.', $consumer_tokens),
173
  );
173
  ];
174 174

  
175
  $form['submit'] = array(
175
  $form['submit'] = [
176 176
    '#type' => 'submit',
177 177
    '#value' => 'test',
178
  );
178
  ];
179 179
  unset($_SESSION['ldap_authorization_test_query']);
180 180
  return $form;
181 181
}
......
200 200
  $consumer = ldap_authorization_get_consumer_object($consumer_type);
201 201
  $consumer_tokens = ldap_authorization_tokens($consumer);
202 202

  
203
  $results = array();
203
  $results = [];
204 204
  $users_listed = $array = preg_split('/[\n\r]+/', $form_state['values']['usernames']);
205
  $random_users = array();
205
  $random_users = [];
206 206
  $_SESSION['ldap_authorization_test_query']['random_users'] = $form_state['values']['random_users'];
207 207
  $_SESSION['ldap_authorization_test_query']['usernames'] = $form_state['values']['usernames'];
208 208
  // Add 10 random usernames to test.
......
216 216
    }
217 217
    catch (Exception $e) {
218 218
      drupal_set_message(t('db users query failed. Message = %message, query= %query',
219
        array('%message' => $e->getMessage(), '%query' => $e->query_string)), 'error');
219
        ['%message' => $e->getMessage(), '%query' => $e->query_string]), 'error');
220 220
      return "";
221 221
    }
222 222

  
......
241 241
      if ($form_state['values']['user_data_clear'] == 1) {
242 242
        $user_data = $user->data;
243 243
        unset($user_data['ldap_authorizations'][$consumer_type]);
244
        $user = user_save($user, array('data' => $user_data));
244
        $user = user_save($user, ['data' => $user_data]);
245 245
      }
246 246

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

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

  

Formats disponibles : Unified diff