1

I have a group of users that I need to be able to set the audience of story nodes to any of the Organic Groups within our systems. Is there a way to do this without giving them the "administer nodes" permission.

I am currently assuming this isn't possible with my current set-up but was hoping there is a module out there that would allow it.

If there isn't a module where would I begin to look at creating a module that created this permission? What Drupal API hooks would I begin with?

1

I created a patch to the Organic Groups module to add the "administer audience" permission. The patch can be found here, http://drupal.org/node/1211974

Here's the patch inline,

diff --git og.module og.module
index 38cc452..0206115 100644
--- og.module
+++ og.module
@@ -558,7 +558,7 @@
  * Implementation of hook_perm().
  */
 function og_perm() {
-  return array('administer organic groups');
+  return array('administer organic groups', 'administer audience');
 }

 /**
@@ -1833,7 +1833,7 @@
   }

   $node = $form['#node'];
-  $required = variable_get('og_audience_required', 0) && !user_access('administer nodes');
+  $required = variable_get('og_audience_required', 0) && !user_access('administer nodes') && !user_access('administer audience');
   $is_optgroup = FALSE;

   // Determine the list of groups that are shown.
@@ -1843,7 +1843,7 @@
   foreach ($subs as $key => $val) {
     $options[$key] = $val['title'];
   }
-  if (user_access('administer nodes')) {
+  if (user_access('administer nodes') || user_access('administer audience')) {
     // Node admins see all of groups.
     $all = og_all_groups_options();
     $other = array_diff_assoc($all, $options);
@@ -1900,7 +1900,7 @@
   elseif (!empty($gids)) {
    // populate field from the querystring if sent
    $groups = $gids;
-   if (!user_access('administer nodes') && $simple) {
+   if ((!user_access('administer nodes') && !user_access('administer audience')) && $simple) {
      // filter out any groups where author is not a member. we cannot rely on fapi to do this when in simple mode.
      $groups = array_intersect($gids, array_keys($options));
    }
@@ -1949,7 +1949,7 @@
     // show multi-select. if less than 20 choices, use checkboxes.
     $type = $cnt >= 20 || $is_optgroup ? 'select' : 'checkboxes';
     $max_groups = variable_get('og_max_groups_'.$node->type,'');
-    $description_max_groups = ($max_groups && !user_access('administer nodes')) ? format_plural($max_groups," Limited to !max_groups choice."," Limited to !max_groups choices.", array('!max_groups' => $max_groups)):'';
+    $description_max_groups = ($max_groups && !user_access('administer nodes') && !user_access('administer audience')) ? format_plural($max_groups," Limited to !max_groups choice."," Limited to !max_groups choices.", array('!max_groups' => $max_groups)):'';
     $form['og_nodeapi']['visible']['og_groups'] = array(
       '#type' => $type,
       '#title' => t('Audience'),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.