Commit 24623313 authored by dragonwize's avatar dragonwize
Browse files

Fixed #363829 by dragonwize: Validation error for roles with admin filter perm

parent 548e29e9
......@@ -640,15 +640,7 @@ function better_formats_get_formats_per_role($default_title = 'Site') {
$roles = user_roles();
// get roles that have administer filters permission
$sql = "SELECT rid
FROM {permission}
WHERE perm LIKE '%administer filters%'
ORDER BY rid";
$result = db_query($sql);
$admin_roles = array();
while ($row = db_fetch_object($result)) {
$admin_roles[] = $row->rid;
}
$admin_roles = better_formats_get_filter_admin_roles();
$site_default_format = filter_resolve_format(FILTER_FORMAT_DEFAULT);
......@@ -725,4 +717,26 @@ function better_formats_get_role_default_fields($mode, $node_type = '') {
}
return $form;
}
/**
* Gets a list of roles that have the admin filter perm
*
* @return array
* An numeric indexed key of role IDs
*/
function better_formats_get_filter_admin_roles() {
static $roles;
if ( ! $roles) {
$sql = "SELECT rid
FROM {permission}
WHERE perm LIKE '%administer filters%'
ORDER BY rid";
$result = db_query($sql);
$roles = array();
while ($row = db_fetch_object($result)) {
$roles[] = $row->rid;
}
}
return $roles;
}
\ No newline at end of file
......@@ -44,10 +44,16 @@ function better_formats_defaults_admin_form_validate($form, &$form_state) {
foreach ($formats as $fid => $format) {
$roles[$fid] = explode(',', $format->roles);
}
// get roles that have administer filters permission
$admin_roles = better_formats_get_filter_admin_roles();
foreach ($form_state['values'] as $key => $values) {
if (strpos($key, 'node-') === 0 || strpos($key, 'comment-') === 0) {
list($type, $rid) = explode('-', $key);
if (in_array($rid, $admin_roles)) {
// role has the admin filters perm so it can use all formats
continue;
}
$fid = $values['format'];
if ($fid != 0 && ! in_array($rid, $roles[$fid])) {
form_set_error($key, t('Role does not have access to selected format.'));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment