diff --git a/userprotect.module b/userprotect.module index 36fd40e..40e2364 100644 --- a/userprotect.module +++ b/userprotect.module @@ -228,8 +228,14 @@ function userprotect_form_alter(&$form, &$form_state, $form_id) { // Views bulk operations. if (isset($form_state['operation']) && $form_state['operation'] instanceof ViewsBulkOperationsAction) { if ($form_state['operation']->entityType == 'user') { - $form['#validate'] = isset($form['#validate']) ? $form['#validate'] : array(); - array_unshift($form['#validate'], 'userprotect_user_admin_account_validate'); + if (isset($form['actions']['submit'])) { + $form['actions']['submit']['#validate'] = isset($form['actions']['submit']['#validate']) ? $form['actions']['submit']['#validate'] : array(); + $form['actions']['submit']['#validate'][] = 'userprotect_user_admin_account_validate'; + } + else { + $form['#validate'] = isset($form['#validate']) ? $form['#validate'] : array(); + array_unshift($form['#validate'], 'userprotect_user_admin_account_validate'); + } } } } @@ -639,10 +645,29 @@ function userprotect_user_admin_account_validate($form, &$form_state) { // VBO module compatibility. case 'action::views_bulk_operations_modify_action': + // First check against all edits. if (!userprotect_check_bypass('up_edit') && userprotect_get_user_protection($account, 'up_edit')) { drupal_set_message(t('%user is protected from any changes, and was not updated.', array('%user' => $account->name)), 'error'); unset($uids[$uid]); unset($form_state['selection'][$key]); + // Continue to the next user. + continue; + } + + // Check which properties are changed. + $properties = $form_state['selected']['properties']; + foreach ($properties as $property) { + if (in_array($property, array('name', 'mail', 'status', 'roles', 'openid'))) { + // Check protection. + $protection = 'up_' . $property; + if (!userprotect_check_bypass($protection) && userprotect_get_user_protection($account, $protection)) { + drupal_set_message(t('%user is protected from @property changes, and was not updated.', array('%user' => $account->name, '@property' => $property)), 'error'); + unset($uids[$uid]); + unset($form_state['selection'][$key]); + // Continue to the next user. + continue 2; + } + } } break; }