updated Fast permission admin module to last dev
This commit is contained in:
@@ -1,5 +1,26 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Main module file for FPA.
|
||||
*/
|
||||
|
||||
define('FPA_ATTR_PERMISSION', 'fpa-permission');
|
||||
define('FPA_ATTR_MODULE', 'fpa-module');
|
||||
define('FPA_ATTR_ROLE', 'fpa-role');
|
||||
|
||||
define('FPA_ATTR_CHECKED', 'fpa-checked');
|
||||
define('FPA_ATTR_NOT_CHECKED', 'fpa-not-checked');
|
||||
|
||||
define('FPA_ATTR_SYSTEM_NAME', 'fpa-system-name');
|
||||
|
||||
// Replacement for improper use of hook_hook_info().
|
||||
require_once dirname(__FILE__) . '/fpa.theme.inc';
|
||||
require_once dirname(__FILE__) . '/fpa.form_alter.inc';
|
||||
|
||||
/**
|
||||
* Implements hook_menu().
|
||||
*/
|
||||
function fpa_menu() {
|
||||
$items = array();
|
||||
|
||||
@@ -7,63 +28,82 @@ function fpa_menu() {
|
||||
'title' => 'Permissions',
|
||||
'page callback' => '_fpa_ctools',
|
||||
'page arguments' => array(1),
|
||||
'access callback' => TRUE,
|
||||
'access arguments' => array('administer permissions'),
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements hook_admin_paths().
|
||||
*/
|
||||
function fpa_admin_paths() {
|
||||
return array(
|
||||
'fpa_modal/*/permissions' => FALSE,
|
||||
'fpa_modal/*/permissions' => TRUE,
|
||||
);
|
||||
}
|
||||
|
||||
function fpa_js_load($arg) {
|
||||
if (module_exists('ctools')) {
|
||||
return ctools_js_load($arg);
|
||||
/**
|
||||
* Implements hook_help().
|
||||
*/
|
||||
function fpa_help($path, $arg) {
|
||||
if ($path == 'admin/people/permissions') {
|
||||
|
||||
$output = '';
|
||||
|
||||
$output .= '<p>' . t('Permissions and Module names will match on the readable or system name. The system name is provided as a togglable column.') . '</p>';
|
||||
|
||||
$output .= '<p>' . t('Enter in the format of "permission@module", e.g. "admin@system" will show only permissions with the text "admin" in modules with the text "system".') . '</p>';
|
||||
|
||||
return $output;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loader function to wrap ctools loader function.
|
||||
*/
|
||||
function fpa_js_load($arg) {
|
||||
$return_code = 0;
|
||||
|
||||
if (module_exists('ctools')) {
|
||||
$return_code = ctools_js_load($arg);
|
||||
}
|
||||
|
||||
return $return_code;
|
||||
}
|
||||
|
||||
function fpa_l($permission = '', $text = NULL, $options = array()) {
|
||||
|
||||
// available modal modules in order of priority
|
||||
// Available modal module system names in order of priority.
|
||||
$supported_modules = array(
|
||||
//'dialog', // dialog api is buggy
|
||||
'ctools',
|
||||
'modalframe',
|
||||
);
|
||||
|
||||
if (is_null($text)) {
|
||||
$text = t('Manage Permissions');
|
||||
}
|
||||
|
||||
// gets the most prefered modal method from the available methods
|
||||
// Find the most preferred modal method from the available methods.
|
||||
$modules = array_intersect($supported_modules, array_keys(module_list()));
|
||||
$method = array_shift($modules);
|
||||
|
||||
$path = 'fpa_modal/nojs/permissions';
|
||||
|
||||
$query = array(
|
||||
'fpa_perm' => $permission,
|
||||
'fpa_method' => $method,
|
||||
);
|
||||
|
||||
$attributes = array();
|
||||
$query = array('fpa_perm' => $permission, 'fpa_method' => $method);
|
||||
|
||||
switch ($method) {
|
||||
case 'dialog':
|
||||
dialog_add_js();
|
||||
$attributes['class'] = 'ctools-use-dialog';
|
||||
break;
|
||||
case 'ctools':
|
||||
ctools_include('ajax');
|
||||
ctools_include('modal');
|
||||
ctools_modal_add_js();
|
||||
$attributes['class'] = 'ctools-use-modal';
|
||||
break;
|
||||
case 'modalframe':
|
||||
modalframe_parent_js();
|
||||
drupal_add_js(drupal_get_path('module', 'fpa') . '/js/fpa.js');
|
||||
$attributes['class'] = 'fpa_modalframe';
|
||||
break;
|
||||
default:
|
||||
$path = 'admin/people/permissions';
|
||||
$attributes['target'] = '_blank';
|
||||
@@ -76,7 +116,7 @@ function fpa_l($permission = '', $text = NULL, $options = array()) {
|
||||
return l($text, $path, $options);
|
||||
}
|
||||
|
||||
function fpa_fieldset($permission, &$parent_item, $group = array()) {
|
||||
function fpa_fieldset($filter_string, &$parent_item, $group = array()) {
|
||||
|
||||
$parent_item['fpa_fieldset'] = array(
|
||||
'#type' => 'fieldset',
|
||||
@@ -90,39 +130,23 @@ function fpa_fieldset($permission, &$parent_item, $group = array()) {
|
||||
|
||||
$parent_item['fpa_fieldset']['fpa'] = array(
|
||||
'#type' => 'markup',
|
||||
'#markup' => fpa_l($permission),
|
||||
'#markup' => fpa_l($filter_string),
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
function fpa_form_node_type_form_alter(&$form, &$form_state) {
|
||||
if (!empty($form['type']['#default_value']) && user_access('administer permissions')) {
|
||||
fpa_fieldset($form['#node_type']->type . ':', $form, array('#group' => 'additional_settings'));
|
||||
}
|
||||
}
|
||||
|
||||
function fpa_form_user_admin_permissions_alter(&$form, &$form_state) {
|
||||
if (isset($_GET['fpa_method']) && $_GET['fpa_method'] == 'modalframe') {
|
||||
modalframe_child_js();
|
||||
$form['#submit'][] = '_fpa_modalframe_submit';
|
||||
}
|
||||
$fpa_module_path = drupal_get_path('module', 'fpa');
|
||||
drupal_add_css($fpa_module_path .'/css/fpa.css');
|
||||
drupal_add_js($fpa_module_path .'/js/fpa.js');
|
||||
drupal_add_js(array('fpa' => array('perm' => isset($_GET['fpa_perm']) && $_GET['fpa_perm'] ? check_plain($_GET['fpa_perm']) : '')), array('type' => 'setting'));
|
||||
}
|
||||
|
||||
function _fpa_modalframe_submit() {
|
||||
modalframe_close_dialog();
|
||||
}
|
||||
|
||||
/**
|
||||
* Page callback for CTools modal path.
|
||||
*/
|
||||
function _fpa_ctools($js = NULL) {
|
||||
// Need to include the file that contains the permissions form.
|
||||
module_load_include('inc', 'user', 'user.admin');
|
||||
|
||||
$form_id = 'user_admin_permissions';
|
||||
|
||||
// Fall back if $js is not set.
|
||||
if (!$js) {
|
||||
return drupal_get_form('user_admin_permissions');
|
||||
return drupal_get_form($form_id);
|
||||
}
|
||||
|
||||
ctools_include('modal');
|
||||
@@ -133,11 +157,8 @@ function _fpa_ctools($js = NULL) {
|
||||
);
|
||||
|
||||
switch ($_GET['fpa_method']) {
|
||||
case 'dialog':
|
||||
$output = dialog_get_form('user_admin_permissions', $form_state);
|
||||
break;
|
||||
case 'ctools':
|
||||
$output = ctools_modal_form_wrapper('user_admin_permissions', $form_state);
|
||||
$output = ctools_modal_form_wrapper($form_id, $form_state);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -149,3 +170,37 @@ function _fpa_ctools($js = NULL) {
|
||||
echo ajax_render($output);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int Approximate number of bytes of ram required to render the permissions form.
|
||||
*/
|
||||
function _fpa_memory_required() {
|
||||
|
||||
$permissions_count = count(module_invoke_all('permission'));
|
||||
|
||||
$user_roles_count = count(user_roles());
|
||||
|
||||
|
||||
$page_ram_required = (9 * 1024 * 1024);
|
||||
|
||||
|
||||
// Takes ~26kb per row without any checkboxes.
|
||||
$permission_row_overhead = 27261.028783658;
|
||||
|
||||
$permissions_ram_required = $permissions_count * $permission_row_overhead;
|
||||
|
||||
|
||||
// Determined by checking peak ram on permissions page, over several different number of visible roles.
|
||||
$bytes_per_checkbox = 18924.508820799;
|
||||
|
||||
$checkboxes_ram_required = $permissions_count * $user_roles_count * $bytes_per_checkbox;
|
||||
|
||||
|
||||
return (int) ($page_ram_required + $permissions_ram_required + $checkboxes_ram_required);
|
||||
}
|
||||
|
||||
function _fpa_reset_filter_defaults() {
|
||||
setcookie("fpa_module_match", "", time() - 3600, '/');
|
||||
setcookie("fpa_filter", "", time() - 3600, '/');
|
||||
setcookie("fpa_roles", "", time() - 3600, '/');
|
||||
}
|
||||
|
Reference in New Issue
Block a user