updated webform, webform_localization, profile2, term_merge, search_api_saved_pages, rules, redirect, overide_node_options

This commit is contained in:
2019-05-13 18:47:27 +02:00
parent 58cd990c8c
commit 9adc940a67
281 changed files with 28658 additions and 7138 deletions

View File

@@ -0,0 +1,45 @@
CONTENTS OF THIS FILE
---------------------
* Introduction
* Requirements
* Installation
* Configuration
* Maintainers
INTRODUCTION
------------
The Override Node Options module allows permissions to be set to each field
within the Authoring information and Publishing options fieldsets on the node
add/edit form so that they can be configued by non-admin users.
REQUIREMENTS
------------
No special requirements.
INSTALLATION
------------
Install as you would normally install a contributed Drupal module. Visit
https://www.drupal.org/docs/7/extending-drupal-7/installing-drupal-7-contributed-modules
for further information.
CONFIGURATION
-------------
* Adjust module settings in admin/config/content/override-node-options to
enable general and/or content type specific permissions.
* Assign permissions in admin/people/permissions#module-override_node_options.
MAINTAINERS
-----------
Current maintainers:
* Oliver Davies (opdavies) - https://www.drupal.org/u/opdavies

View File

@@ -2,11 +2,12 @@ name = Override node options
description = "Allow non-admins to override the default publishing options for nodes they can edit."
core = 7.x
package = Permissions
configure = admin/config/content/override-node-options
files[] = override_node_options.test
; Information added by Drupal.org packaging script on 2014-09-19
version = "7.x-1.13"
; Information added by Drupal.org packaging script on 2018-03-31
version = "7.x-1.14"
core = "7.x"
project = "override_node_options"
datestamp = "1411157931"
datestamp = "1522482188"

View File

@@ -9,27 +9,28 @@
* Implements hook_install().
*/
function override_node_options_install() {
db_update('system')->fields(array(
'weight' => -1
))
->condition('name', 'override_node_options', '=')
->execute();
}
/**
* Implements hook_uninstall().
*/
function override_node_options_uninstall() {
db_query("DELETE FROM {variable} WHERE name LIKE 'override_node_options_%'");
db_update('system')
->fields(array('weight' => 1))
->condition('name', 'override_node_options', '=')
->execute();
}
/**
* Implements hook_update_N().
*/
function override_node_options_update_7113() {
db_update('system')->fields(array(
'weight' => -1
))
->condition('name', 'override_node_options', '=')
->execute();
db_update('system')
->fields(array('weight' => -1))
->condition('name', 'override_node_options', '=')
->execute();
}
/**
* Update the module weight.
*/
function override_node_options_update_7114() {
db_update('system')
->fields(array('weight' => 1))
->condition('name', 'override_node_options', '=')
->execute();
}

View File

@@ -2,19 +2,62 @@
/**
* @file
* Main module file for override_node_options.
*
* Allow users to override the default publishing options for nodes they can
* edit without giving them the 'administer nodes' permission.
*/
/**
* Implements hook_permisson().
* Implements hook_permission().
*/
function override_node_options_permission() {
$permissions = array();
// Global permissions which apply to all node types.
$permissions = array(
'administer override node options' => array(
'title' => t('Administer override node options.'),
),
);
// Generate override node permissions for all applicable node types.
foreach (node_permissions_get_configured_types() as $type) {
$permissions += override_node_options_list_permissions($type);
$show_perms = variable_get('override_node_options_permissions', array('general', 'specific'));
if (in_array('general', $show_perms, TRUE)) {
$permissions += array(
'override all published option' => array(
'title' => t('Override published option for all node types.'),
),
'override all promote to front page option' => array(
'title' => t('Override promote to front page option for all node types.'),
),
'override all sticky option' => array(
'title' => t('Override sticky option for all node types.'),
),
'override all revision option' => array(
'title' => t('Override revision option for all node types.'),
),
'enter all revision log entry' => array(
'title' => t('Enter revision log entry for all node types.'),
),
'override all authored on option' => array(
'title' => t('Override authored on option for all node types.'),
),
'override all authored by option' => array(
'title' => t('Override authored by option for all node types.'),
),
);
if (module_exists('comment')) {
$permissions += array(
'override all comment setting option' => array(
'title' => t('Override comment setting option for all node types.'),
),
);
}
}
if (in_array('specific', $show_perms, TRUE)) {
// Generate override node permissions for all applicable node types.
foreach (node_permissions_get_configured_types() as $type) {
$permissions += override_node_options_list_permissions($type);
}
}
return $permissions;
@@ -23,13 +66,16 @@ function override_node_options_permission() {
/**
* Helper function to generate override node permission list for a given type.
*
* @param $type
* @param string $type
* The machine-readable name of the node type.
* @return
*
* @return array
* An array of permission names and description.
*/
function override_node_options_list_permissions($type) {
$name = node_type_get_name($type);
function override_node_options_list_permissions($type, $name = NULL) {
if (!$name) {
$name = node_type_get_name($type);
}
$type = check_plain($type);
$permissions = array(
@@ -56,63 +102,177 @@ function override_node_options_list_permissions($type) {
),
);
if (module_exists('comment')) {
$permissions += array(
"override $type comment setting option" => array(
'title' => t('Override %type_name comment setting option.', array('%type_name' => $name)),
),
);
}
return $permissions;
}
/**
* Implements hook_menu().
*/
function override_node_options_menu() {
$items['admin/config/content/override-node-options'] = array(
'title' => 'Override Node Options Settings',
'page callback' => 'drupal_get_form',
'page arguments' => array('override_node_options_settings_form'),
'access arguments' => array('administer override node options'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Settings form.
*/
function override_node_options_settings_form($form, &$form_values) {
$form = array();
$form['override_node_options_permissions'] = array(
'#type' => 'checkboxes',
'#title' => t('Provide the following permissions:'),
'#options' => array(
'general' => t('General permissions, accross all node types'),
'specific' => t('Specific permissions, for each individual node type'),
),
'#default_value' => variable_get('override_node_options_permissions', array('general', 'specific')),
);
$form['#submit'][] = 'override_node_options_settings_form_submit';
return system_settings_form($form);
}
/**
* Submit handler for settings form.
*/
function override_node_options_settings_form_submit(&$form, &$form_state) {
// Get old perms to compare.
$old_perms = variable_get('override_node_options_permissions', array('general', 'specific'));
$new_perms = $form_state['values']['override_node_options_permissions'];
// Clean up saved permissions.
$role_names = user_roles();
$revoke = array();
if (!in_array('specific', $new_perms, TRUE) && in_array('specific', $old_perms, TRUE)) {
$alert = TRUE;
$permissions = array();
foreach (node_permissions_get_configured_types() as $type) {
$permissions += override_node_options_list_permissions($type);
}
foreach ($permissions as $permission => $description) {
$revoke[$permission] = FALSE;
}
// Be sure to clear the cache.
cache_clear_all();
}
if (!in_array('general', $new_perms, TRUE) && in_array('general', $old_perms, TRUE)) {
$alert = TRUE;
$revoke = array(
'override all published option' => FALSE,
'override all promote to front page option' => FALSE,
'override all sticky option' => FALSE,
'override all revision option' => FALSE,
'enter all revision log entry' => FALSE,
'override all authored on option' => FALSE,
'override all authored by option' => FALSE,
);
if (module_exists('comment')) {
$revoke['override all comment setting option'] = FALSE;
}
}
// Any specific grants not used anymore need to be deleted.
if (!empty($revoke)) {
foreach ($role_names as $rid => $name) {
user_role_change_permissions($rid, $revoke);
}
}
// Set a helpful message.
$message = 'Configuration saved.';
$arguments = array();
$status = 'status';
if ($alert) {
if (user_access('administer permissions')) {
$arguments = array('!permissions' => l(t('the permissions page'), 'admin/config/people/permissions', array('fragment' => 'module-override_node_options')));
$message .= t(' Please visit !permissions and double check access.');
$status = 'warning';
}
else {
$message .= t(' Please visit the permissions page and double check access.');
}
}
drupal_set_message(t($message, $arguments), $status);
}
/**
* Implements hook_form_alter().
*/
function override_node_options_form_alter(&$form, $form_state, $form_id) {
function override_node_options_form_alter(&$form, &$form_state, $form_id) {
if (!empty($form['#node_edit_form']) && !user_access('administer nodes')) {
// Get a copy of the current node object.
$node = $form['#node'];
// Add access to the 'Revision information: log message' field
$form['revision_information']['log']['#access'] = user_access('enter ' . $node->type . ' revision log entry');
// Add access to the 'Revision information: log message' field.
$form['revision_information']['log']['#access'] = user_access('enter ' . $node->type . ' revision log entry') || user_access('enter all revision log entry');
// Add access to the 'Revision information' fieldset.
$form['revision_information']['revision']['#access'] = user_access('override ' . $node->type . ' revision option');
$form['revision_information']['revision']['#access'] = user_access('override ' . $node->type . ' revision option') || user_access('override all revision option');
$form['revision_information']['#access'] = element_get_visible_children($form['revision_information']);
// Add access to the 'Authoring information' fieldset.
$form['author']['name']['#access'] = user_access('override ' . $node->type . ' authored by option');
$form['author']['date']['#access'] = user_access('override ' . $node->type . ' authored on option');
if (key_exists('#access', $form['author'])) {
$form['author']['name']['#access'] = user_access('override ' . $node->type . ' authored by option') || user_access('override all authored by option');
$form['author']['date']['#access'] = user_access('override ' . $node->type . ' authored on option') || user_access('override all authored on option');
if (array_key_exists('#access', $form['author'])) {
$form['author']['#access'] |= element_get_visible_children($form['author']);
}
else {
$form['author']['#access'] = element_get_visible_children($form['author']);
}
// Add access to the 'Publishing options' fieldset.
$form['options']['status']['#access'] = user_access('override ' . $node->type . ' published option');
$form['options']['promote']['#access'] = user_access('override ' . $node->type . ' promote to front page option');
$form['options']['sticky']['#access'] = user_access('override ' . $node->type . ' sticky option');
if (key_exists('#access', $form['options'])) {
$form['options']['status']['#access'] = user_access(sprintf('override %s published option', $node->type));
$form['options']['promote']['#access'] = user_access(sprintf('override %s promote to front page option', $node->type));
$form['options']['sticky']['#access'] = user_access(sprintf('override %s sticky option', $node->type));
// If access is granted for promote or sticky, show (but disable) status.
// This keeps core's JS working, and correctly populates the vertical tab.
if ($form['options']['status']['#access'] == FALSE && ($form['options']['promote']['#access'] || $form['options']['sticky']['#access'])) {
$form['options']['status']['#access'] = TRUE;
$form['options']['status']['#disabled'] = TRUE;
}
$form['options']['status']['#access'] = user_access('override ' . $node->type . ' published option') || user_access('override all published option');
$form['options']['promote']['#access'] = user_access('override ' . $node->type . ' promote to front page option') || user_access('override all promote to front page option');
$form['options']['sticky']['#access'] = user_access('override ' . $node->type . ' sticky option') || user_access('override all sticky option');
if (array_key_exists('#access', $form['options'])) {
$form['options']['#access'] |= element_get_visible_children($form['options']);
}
else {
$form['options']['#access'] = element_get_visible_children($form['options']);
}
// @todo Remove when http://drupal.org/node/683630 is fixed.
if ($form['author']['name']['#access']) {
$form['#submit'][] = 'override_node_options_submit_node';
// Add access to the 'Comment settings' fieldset.
if (module_exists('comment') && isset($form['comment_settings'])) {
$form['comment_settings']['#access'] |= user_access('override ' . $node->type . ' comment setting option') || user_access('override all comment setting option');
}
if (!empty($form['#node_edit_form']) && !user_access('administer nodes')) {
$form['author']['#attached']['js'][1]['data']['anonymous'] = $form['author']['name']['#default_value'];
}
}
}
/**
* Perform additional node form submission processing normally skipped by core.
*
* @todo Remove when http://drupal.org/node/683630 is fixed.
*/
function override_node_options_submit_node($form, &$form_state) {
// Populate the "authored by" field.
if ($account = user_load_by_name($form_state['values']['name'])) {
$form_state['values']['uid'] = $account->uid;
}
else {
$form_state['values']['uid'] = 0;
}
}

View File

@@ -5,57 +5,86 @@
* Unit tests for the override_node_options module.
*/
/**
* Defines a base class for testing the Override Node Options module.
*/
class OverrideNodeOptionsTestCase extends DrupalWebTestCase {
protected $normal_user;
protected $admin_user;
/**
* A standard user with basic permissions.
*
* @var stdClass
*/
protected $normalUser;
/**
* A page node to test against.
*
* @var stdClass
*/
protected $node;
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'Override node options',
'description' => 'Functional tests for overridding options on node forms.',
'description' => 'Functional tests for overriding options on node forms.',
'group' => 'Override node options',
);
}
/**
* {@inheritdoc}
*/
public function setUp() {
parent::setUp('override_node_options');
$this->normal_user = $this->drupalCreateUser(array('create page content', 'edit any page content'));
$this->normalUser = $this->drupalCreateUser(array('create page content', 'edit any page content'));
$this->node = $this->drupalCreateNode();
}
/**
* Assert that fields in a node were updated to certail values.
* Assert that fields in a node were updated to certain values.
*
* @param $node
* @param \stdClass $node
* The node object to check (will be reloaded from the database).
* @param $fields
* @param array $fields
* An array of values to check equality, keyed by node object property.
*/
function assertNodeFieldsUpdated(stdClass $node, array $fields) {
private function assertNodeFieldsUpdated(stdClass $node, array $fields) {
// Re-load the node from the database to make sure we have the current
// values.
$node = node_load($node->nid, NULL, TRUE);
foreach ($fields as $field => $value) {
$this->assertEqual($node->$field, $value, t('Node @field was updated to !value, expected !expected.', array('@field' => $field, '!value' => var_export($node->$field, TRUE), '!expected' => var_export($value, TRUE))));
$this->assertEqual(
$node->$field,
$value,
t('Node @field was updated to !value, expected !expected.', array(
'@field' => $field,
'!value' => var_export($node->$field, TRUE),
'!expected' => var_export($value, TRUE),
))
);
}
}
/**
* Assert that the user cannot access fields on node add and edit forms.
*
* @param $node
* @param \stdClass $node
* The node object, will be used on the node edit form.
* @param $fields
* @param array $fields
* An array of form fields to check.
*/
function assertNodeFieldsNoAccess(stdClass $node, array $fields) {
$this->drupalGet('node/add/' . $node->type);
private function assertNodeFieldsNoAccess(stdClass $node, array $fields) {
$this->drupalGet("node/add/{$node->type}");
foreach ($fields as $field) {
$this->assertNoFieldByName($field);
}
$this->drupalGet('node/' . $this->node->nid . '/edit');
$this->drupalGet("node/{$this->node->nid}/edit");
foreach ($fields as $field) {
$this->assertNoFieldByName($field);
}
@@ -64,61 +93,135 @@ class OverrideNodeOptionsTestCase extends DrupalWebTestCase {
/**
* Test the 'Authoring information' fieldset.
*/
function testNodeOptions() {
$this->admin_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'override page published option', 'override page promote to front page option', 'override page sticky option'));
$this->drupalLogin($this->admin_user);
protected function testNodeOptions() {
$specific_user = $this->drupalCreateUser(array(
'create page content',
'edit any page content',
'override page published option',
'override page promote to front page option',
'override page sticky option',
'override page comment setting option',
));
$fields = array(
'status' => (bool) !$this->node->status,
'promote' => (bool) !$this->node->promote,
'sticky' => (bool) !$this->node->sticky,
);
$this->drupalPost('node/' . $this->node->nid . '/edit', $fields, t('Save'));
$this->assertNodeFieldsUpdated($this->node, $fields);
$general_user = $this->drupalCreateUser(array(
'create page content',
'edit any page content',
'override all published option',
'override all promote to front page option',
'override all sticky option',
'override all comment setting option',
));
$this->drupalLogin($this->normal_user);
foreach (array($specific_user, $general_user) as $account) {
$this->drupalLogin($account);
$fields = array(
'status' => (bool) !$this->node->status,
'promote' => (bool) !$this->node->promote,
'sticky' => (bool) !$this->node->sticky,
'comment' => COMMENT_NODE_OPEN,
);
$this->drupalPost("node/{$this->node->nid}/edit", $fields, t('Save'));
$this->assertNodeFieldsUpdated($this->node, $fields);
}
$this->drupalLogin($this->normalUser);
$this->assertNodeFieldsNoAccess($this->node, array_keys($fields));
}
/**
* Test the 'Revision information' fieldset.
*/
function testNodeRevisions() {
$this->admin_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'override page revision option'));
$this->drupalLogin($this->admin_user);
protected function testNodeRevisions() {
$specific_user = $this->drupalCreateUser(array(
'create page content',
'edit any page content',
'override page revision option',
));
$fields = array(
'revision' => TRUE,
);
$this->drupalPost('node/' . $this->node->nid . '/edit', $fields, t('Save'));
$this->assertNodeFieldsUpdated($this->node, array('vid' => $this->node->vid + 1));
$general_user = $this->drupalCreateUser(array(
'create page content',
'edit any page content',
'override all revision option',
));
$this->drupalLogin($this->normal_user);
foreach (array($specific_user, $general_user) as $account) {
$this->drupalLogin($account);
// Ensure that we have the latest node data.
$node = node_load($this->node->nid, NULL, TRUE);
$fields = array(
'revision' => TRUE,
);
$this->drupalPost("node/{$node->nid}/edit", $fields, t('Save'));
$this->assertNodeFieldsUpdated($node, array('vid' => $node->vid + 1));
}
$this->drupalLogin($this->normalUser);
$this->assertNodeFieldsNoAccess($this->node, array_keys($fields));
}
/**
* Test the 'Authoring information' fieldset.
*/
function testNodeAuthor() {
$this->admin_user = $this->drupalCreateUser(array('create page content', 'edit any page content', 'override page authored on option', 'override page authored by option'));
$this->drupalLogin($this->admin_user);
protected function testNodeAuthor() {
$specific_user = $this->drupalCreateUser(array(
'create page content',
'edit any page content',
'override page authored on option',
'override page authored by option',
));
$this->drupalPost('node/' . $this->node->nid . '/edit', array('name' => 'invalid-user'), t('Save'));
$this->assertText('The username invalid-user does not exist.');
$general_user = $this->drupalCreateUser(array(
'create page content',
'edit any page content',
'override all authored on option',
'override all authored by option',
));
$this->drupalPost('node/' . $this->node->nid . '/edit', array('date' => 'invalid-date'), t('Save'));
$this->assertText('You have to specify a valid date.');
foreach (array($specific_user, $general_user) as $account) {
$this->drupalLogin($account);
$time = time() + 500;
$fields = array(
'name' => '',
'date' => format_date($time, 'custom', 'Y-m-d H:i:s O'),
);
$this->drupalPost('node/' . $this->node->nid . '/edit', $fields, t('Save'));
$this->assertNodeFieldsUpdated($this->node, array('uid' => 0, 'created' => $time));
$this->drupalPost("node/{$this->node->nid}/edit", array('name' => 'invalid-user'), t('Save'));
$this->assertText('The username invalid-user does not exist.');
$this->drupalLogin($this->normal_user);
$this->drupalPost("node/{$this->node->nid}/edit", array('date' => 'invalid-date'), t('Save'));
$this->assertText('You have to specify a valid date.');
$time = time() + 500;
$fields = array(
'name' => '',
'date' => format_date($time, 'custom', 'Y-m-d H:i:s O'),
);
$this->drupalPost("node/{$this->node->nid}/edit", $fields, t('Save'));
$this->assertNodeFieldsUpdated($this->node, array('uid' => 0, 'created' => $time));
}
$this->drupalLogin($this->normalUser);
$this->assertNodeFieldsNoAccess($this->node, array_keys($fields));
}
/**
* Ensure that the node created date does not change when the node is edited.
*/
public function testNodeCreatedDateDoesNotChange() {
$this->drupalLogin(
$this->drupalCreateUser(array('edit any page content'))
);
$node = $this->drupalCreateNode();
// Update the node.
$this->drupalPost("node/{$node->nid}/edit", array(), t('Save'));
// Load a new instance of the node.
$node2 = node_load($node->nid);
// Ensure that the node was updated by comparing the changed dates, but the
// created dates still match.
$this->assertNotEqual($node->changed, $node2->changed, t('Changed values do not match.'));
$this->assertEqual($node->created, $node2->created, t('Created values do match.'));
}
}