Drupal 6: Notifications and content type access interaction

The notifications module lets users subscribe to content types that they don’t have view access to.

Users that subscribe to such content types will not actually receive the notifications because at the time of assembling the notification message, the permissions on each specific node are tested.

This can be reproduced with the content access module, by granting view access rights for some content types and not others to a certain role and going to the user’s account page: /user/[uid]/notifications/nodetype.

There doesn’t seem to be any hook to override this and using the form alter hook seems too involved.

My work around is to add a hook call in notifications_content_page_nodetype()


 * User subscriptions to content types
function notifications_content_page_nodetype($account = NULL) {
  global $user;
  if (!isset($account)) {
    $account = $user;
  // List of all subscribed node types
  $subscriptions = notifications_get_subscriptions(array('type' => 'nodetype', 'uid' => $account->uid), array('type' => NULL), TRUE, 'value');
  $output = '';
  $types = notifications_content_types('name');
  if ($types) {
    // call all modules hook_notify_content_types_alter(&$types, &$user)
    $data = &$types;
    $data['__drupal_alter_by_ref'] = array(&$account);
    drupal_alter('notify_content_types', $data);
  if (!$types) {
    $output .= t('There are no active content types.');    
  else {
    $defaults = array('type' => 'nodetype', 'event_type' => 'node');
    $options = array('title' => t('Type'));
    $output .= drupal_get_form('notifications_user_form', $account, 'nodetype', $subscriptions, $types, $defaults, $options);
  return $output;

And then implement the hook in my module:

 * implementation of hook_notify_content_types_alter
 * remove from $content_types the types that the current user
 * has no view access to accrding to content_access module. 
 * @param $content_types - array(content_type => content_type_name)
 * @param $user - the user to test access for
 * @see notifications_content_page_nodetype()
function mymodule_notify_content_types_alter(&$content_types, &$user) {
  if (function_exists('content_access_get_settings')) {
    $urids = array_keys($user->roles);
    $filtered = array();
    foreach ($content_types as $ct => $name) {
      $rids = content_access_get_settings('view', $ct);
      if (count(array_intersect($urids, $rids))) {
        $filtered[$ct] = $name;
    $content_types = $filtered;
  else {
    watchdog('notify_content_types', 'Can\'t filter content types because content_access_get_settings() does not exist.');

This being Drupal, there’s probably a module somewhere that does this already and that I missed.

Relevant versions:

Drupal 6.15
Notifications 6.x-2.2
Content Access	6.x-1.2
This entry was posted in Drupal and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *