Skip to content

Commit 2386975

Browse files
committed
Add override node options for editors to publish.
1 parent 897ad74 commit 2386975

9 files changed

+905
-0
lines changed

www/modules/contrib/override_node_options/LICENSE.txt

Lines changed: 340 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Override Node Options
2+
======================
3+
4+
Allows granular permissions for most administrative tasks on the node form.
5+
6+
The Override Node Options module allows granular permissions for most
7+
administrative tasks on the node form. Permissions for each task within the
8+
Authoring information, Publishing options, Comment settings, and URL Path field sets on the node
9+
form.
10+
11+
12+
Installation
13+
------------
14+
15+
- Install this module using the official Backdrop CMS instructions at
16+
https://backdropcms.org/guide/modules
17+
18+
- (Optional) Visit the configuration page under Administration >
19+
Configuration > Content authoring > Override Node Options
20+
(admin/config/content/override-node-options) and choose your permission
21+
granularity.
22+
23+
- Visit the permissions page under Administration > Configuration > User
24+
Accounts > Permissions (admin/config/people/permissions) and set the
25+
appropriate grants for your site.
26+
27+
28+
License
29+
-------
30+
31+
This project is GPL v2 software. See the LICENSE.txt file in this directory for
32+
complete text.
33+
34+
35+
Current Maintainers
36+
-------------------
37+
38+
- Jen Lampton (https://github.com/jenlampton)
39+
- Seeking additional maintainers
40+
41+
42+
Credits
43+
-------
44+
45+
- Originally written for Drupal by Oliver Davies
46+
(https://www.drupal.org/u/opdavies).
47+
- Ported to Backdrop CMS by Jen Lampton (https://www.drupal.org/u/jenlampton).
48+
- Port to Backdrop sponsored by [America's Best Bootfiters](http://www.bootfitters.com).
49+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"_config_name": "override_node_options.settings",
3+
"_module": "override_node_options",
4+
"permissions": {
5+
"general": "general",
6+
"specific": 0
7+
}
8+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
<?php
2+
/**
3+
* @file
4+
* Administrative form code for Override Node Options.
5+
*/
6+
7+
/**
8+
* Settings form.
9+
*/
10+
function override_node_options_settings_form($form, &$form_values) {
11+
$show_perms = config_get('override_node_options.settings', 'permissions');
12+
13+
$form = array();
14+
$form['permissions'] = array(
15+
'#type' => 'checkboxes',
16+
'#title' => t('Provide the following permissions:'),
17+
'#options' => array(
18+
'general' => t('General: one permission for all content types'),
19+
'specific' => t('Specific: individual permissions - one for each content type'),
20+
),
21+
'#default_value' => $show_perms,
22+
);
23+
$form['actions'] = array('#type' => 'actions');
24+
$form['actions']['submit'] = array(
25+
'#type' => 'submit',
26+
'#value' => t('Save configuration'),
27+
);
28+
$form['#submit'][] = 'override_node_options_settings_form_submit';
29+
30+
return $form;
31+
}
32+
33+
/**
34+
* Submit handler for settings form.
35+
*/
36+
function override_node_options_settings_form_submit(&$form, &$form_state) {
37+
// Get old perms to compare.
38+
$old_perms = config_get('override_node_options.settings', 'permissions');
39+
$new_perms = $form_state['values']['permissions'];
40+
41+
// Save the setting.
42+
config_set('override_node_options.settings', 'permissions', $new_perms);
43+
44+
// Clean up saved permissions.
45+
$role_names = user_roles();
46+
$revoke = array();
47+
$alert = FALSE;
48+
49+
// If they had specific before and don't now.
50+
if (!in_array('specific', $new_perms, TRUE) && in_array('specific', $old_perms, TRUE)) {
51+
$alert = TRUE;
52+
$permissions = array();
53+
foreach (node_permissions_get_configured_types() as $type) {
54+
$permissions += override_node_options_list_permissions($type);
55+
}
56+
57+
foreach ($permissions as $permission => $description) {
58+
$revoke[$permission] = FALSE;
59+
}
60+
61+
// Be sure to clear the cache.
62+
cache_clear_all();
63+
}
64+
65+
// If they had general before and don't now.
66+
if (!in_array('general', $new_perms, TRUE) && in_array('general', $old_perms, TRUE)) {
67+
$alert = TRUE;
68+
$revoke = array(
69+
'override all published option' => FALSE,
70+
'override all promote to front page option' => FALSE,
71+
'override all sticky option' => FALSE,
72+
'override all revision option' => FALSE,
73+
'enter all revision log entry' => FALSE,
74+
'override all authored on option' => FALSE,
75+
'override all authored by option' => FALSE,
76+
);
77+
if (module_exists('comment')) {
78+
$revoke['override all comment setting option'] = FALSE;
79+
}
80+
}
81+
82+
// Any specific grants not used anymore need to be deleted.
83+
if (!empty($revoke)) {
84+
foreach ($role_names as $rid => $name) {
85+
user_role_change_permissions($rid, $revoke);
86+
}
87+
}
88+
89+
// Set a helpful message.
90+
$message = 'Configuration saved.';
91+
$arguments = array();
92+
$status = 'status';
93+
94+
if ($alert) {
95+
if (user_access('administer permissions')) {
96+
$arguments = array('!permissions' => l(t('the permissions page'), 'admin/config/people/permissions', array('fragment' => 'module-override_node_options')));
97+
$message .= t(' Please visit !permissions and double check access.');
98+
$status = 'warning';
99+
}
100+
else {
101+
$message .= t(' Please visit the permissions page and double check access.');
102+
}
103+
}
104+
105+
backdrop_set_message(t($message, $arguments), $status);
106+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
type = module
2+
name = Override node options
3+
description = Allow non-admins to override the default options for nodes.
4+
backdrop = 1.x
5+
6+
configure = admin/config/content/override-node-options
7+
8+
; Added by Backdrop CMS packaging script on 2022-09-23
9+
project = override_node_options
10+
version = 1.x-1.13.2
11+
timestamp = 1663981637
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* @file
4+
* Install, update and uninstall functions for the override_node_options module.
5+
*/
6+
7+
/**
8+
* Implements hook_install().
9+
*/
10+
function override_node_options_install() {
11+
db_update('system')->fields(array(
12+
'weight' => 1
13+
))
14+
->condition('name', 'override_node_options', '=')
15+
->execute();
16+
}
17+
18+
/**
19+
* Implements hook_update_last_removed().
20+
*/
21+
function override_node_options_update_last_removed() {
22+
// We've removed the 1.x-1.x version of mymodule, including database updates.
23+
// For the 1.x-2.x version of the module, the next update function would be
24+
// mymodule_update_1200().
25+
return 7114;
26+
}
27+
28+
/**
29+
* Converts Drupal 7 variables to config.
30+
*/
31+
function override_node_options_update_1000(&$sandbox){
32+
$defaults = array('general', 'specific');
33+
34+
$config = config('override_node_options.settings');
35+
$config->set('permissions', update_variable_get('override_node_options_permissions', $defaults));
36+
$config->save();
37+
38+
update_variable_del('override_node_options_permissions');
39+
}

0 commit comments

Comments
 (0)