Skip to content
This repository has been archived by the owner on Dec 19, 2023. It is now read-only.

Commit

Permalink
Role delegation 7.x-1.2->7.x-1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
stankut committed Apr 7, 2022
1 parent d12939c commit 4aa0a6f
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ core = 7.x
files[] = role_delegation.module
files[] = role_delegation.test

; Information added by Drupal.org packaging script on 2019-07-31
version = "7.x-1.2"
test_dependencies[] = admin_views
test_dependencies[] = views_bulk_operations

; Information added by Drupal.org packaging script on 2022-03-22
version = "7.x-1.3"
core = "7.x"
project = "role_delegation"
datestamp = "1564594388"
datestamp = "1647986804"
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,18 @@ function role_delegation_delegate_roles_action_form($context) {
$form['#tree'] = TRUE;
$form['#theme'] = 'role_delegation_delegate_roles_action_form';
foreach (_role_delegation_roles() as $rid => $role_name) {
$form['role_change'][$rid] = array(
'#type' => 'select',
'#title' => check_plain($role_name),
'#default_value' => isset($context['roles_change'][$rid]) ? $context['roles_change'][$rid] : -1,
'#options' => array(
-1 => t('Do not change'),
1 => t('Add this role'),
0 => t('Remove this role'),
),
);
if (user_access('assign all roles') || user_access("assign $role_name role")) {
$form['role_change'][$rid] = array(
'#type' => 'select',
'#title' => check_plain($role_name),
'#default_value' => isset($context['roles_change'][$rid]) ? $context['roles_change'][$rid] : -1,
'#options' => array(
-1 => t('Do not change'),
1 => t('Add this role'),
0 => t('Remove this role'),
),
);
}
}
return $form;
}
Expand All @@ -366,15 +368,17 @@ function theme_role_delegation_delegate_roles_action_form($variables) {
t('Role'),
t('Operation'),
);
foreach (element_children($form['role_change']) as $key) {
$role = $form['role_change'][$key]['#title'];
unset($form['role_change'][$key]['#title']);
$operation = drupal_render($form['role_change'][$key]);
$row = array(
array('data' => $role),
array('data' => $operation),
);
$rows[] = $row;
if (!empty($form['role_change'])) {
foreach (element_children($form['role_change']) as $key) {
$role = $form['role_change'][$key]['#title'];
unset($form['role_change'][$key]['#title']);
$operation = drupal_render($form['role_change'][$key]);
$row = array(
array('data' => $role),
array('data' => $operation),
);
$rows[] = $row;
}
}
$output = drupal_render($form['actions_label']);
$output .= theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'role-delegation-table')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,82 @@ class RoleDelegationRoleEditingTestCase extends RoleDelegationTestCase {
);
}
}


/**
* Functional tests for integration with views bulk operations module.
*/
class RoleDelegationViewsBulkOperationsTestCase extends RoleDelegationTestCase {

public static function getInfo() {
return array(
'name' => t('Views Bulk Operations Integration'),
'description' => t('Check that role assignment work in combination with views bulk operations.'),
'group' => t('Role Delegation'),
'dependencies' => array(
'views_bulk_operations',
'admin_views'
),
);
}

public function setUp(array $modules = array('role_delegation')) {
parent::setUp(array('role_delegation', 'admin_views', 'views_bulk_operations'));

$view = views_get_view('admin_views_user');
$item = $view->get_item('system_1', 'field', 'views_bulk_operations');

$item['vbo_operations']['action::role_delegation_delegate_roles_action'] = array(
'selected' => 1,
'skip_confirmation' => 0,
'override_label' => 0,
'postpone_processing' => 0,
);

$view->set_item('system_1', 'field', 'views_bulk_operations', $item);
views_save_view($view);
}

/**
* Check that the right combination of Add and Remove role
* operations is present in the vbo delegate role action.
*/
public function testVboDelegateRoleAssignment() {
$this->drupalLogin($this->user_low);
$this->drupalGet('/admin/people');

$edit = array(
'views_bulk_operations[0]' => TRUE,
'operation' => 'action::role_delegation_delegate_roles_action',
);
$this->drupalPost('/admin/people', $edit, 'Execute');

$this->assertNoFieldByName('role_change[' . $this->rid_low . ']', NULL, t('!user user can\'t delegate the !role role.', array(
'!user' => 'low',
'!role' => 'low',
)));
$this->assertNoFieldByName('role_change[' . $this->rid_high . ']', NULL, t('!user user can\'t delegate the !role role.', array(
'!user' => 'low',
'!role' => 'high',
)));

$this->drupalLogin($this->user_high);
$this->drupalGet('/admin/people');

$edit = array(
'views_bulk_operations[0]' => TRUE,
'operation' => 'action::role_delegation_delegate_roles_action',
);
$this->drupalPost('/admin/people', $edit, 'Execute');

$this->assertFieldByName('role_change[' . $this->rid_low . ']', NULL, t('!user user can delegate the !role role.', array(
'!user' => 'high',
'!role' => 'low',
)));
$this->assertNoFieldByName('role_change[' . $this->rid_high . ']', NULL, t('!user user can\'t delegate the !role role.', array(
'!user' => 'high',
'!role' => 'high',
)));
}

}

0 comments on commit 4aa0a6f

Please sign in to comment.