diff --git a/taxonomy_access_fix.install b/taxonomy_access_fix.install new file mode 100644 index 0000000..5a9d6c8 --- /dev/null +++ b/taxonomy_access_fix.install @@ -0,0 +1,41 @@ +fields('rp') + ->condition('module', 'taxonomy_access_fix', '=') + ->execute(); + while ($permission = $query->fetchObject()) { + $permissions[] = $permission; + $vocabulary_ids[] = (int) substr($permission->permission, strlen('add terms in '), strlen($permission->permission)); + } + + if (!empty($permissions)) { + $vocabularies = taxonomy_vocabulary_load_multiple($vocabulary_ids); + if (empty($vocabularies)) { + return; + } + + foreach ($permissions as $k => $permission) { + $vocabulary = $vocabularies[$vocabulary_ids[$k]]; + db_update('role_permission') + ->fields(array( + 'permission' => 'add terms in ' . $vocabulary->machine_name, + )) + ->condition('rid', $permission->rid, '=') + ->condition('permission', $permission->permission, '=') + ->condition('module', 'taxonomy_access_fix', '=') + ->execute(); + } + } +} diff --git a/taxonomy_access_fix.module b/taxonomy_access_fix.module index 36acf93..cc90d79 100644 --- a/taxonomy_access_fix.module +++ b/taxonomy_access_fix.module @@ -56,7 +56,7 @@ function taxonomy_access_fix_permission() { $permissions = array(); foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) { - $permissions['add terms in ' . $vid] = array( + $permissions['add terms in ' . $vocabulary->machine_name] = array( 'title' => t('Add terms in %vocabulary', array('%vocabulary' => $vocabulary->name)), ); } @@ -111,23 +111,21 @@ function taxonomy_access_fix_access($op, $vocabulary = NULL) { case 'index': // Only if they have >= 1 vocabulary access. foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) { - if (user_access('edit terms in ' . $vid) || user_access('delete terms in ' . $vid) || user_access('add terms in ' . $vid)) { + if (user_access('edit terms in ' . $vocabulary->machine_name) || user_access('delete terms in ' . $vocabulary->machine_name) || user_access('add terms in ' . $vocabulary->machine_name)) { return TRUE; } } break; case 'list terms': if ($vocabulary) { - $vid = $vocabulary->vid; - if (user_access('edit terms in ' . $vid) || user_access('delete terms in ' . $vid) || user_access('add terms in ' . $vid)) { + if (user_access('edit terms in ' . $vocabulary->machine_name) || user_access('delete terms in ' . $vocabulary->machine_name) || user_access('add terms in ' . $vocabulary->machine_name)) { return TRUE; } } break; case 'add terms': if ($vocabulary) { - $vid = $vocabulary->vid; - if (user_access('add terms in ' . $vid)) { + if (user_access('add terms in ' . $vocabulary->machine_name)) { return TRUE; } }