Per as the title, when no one is logged in a "Administer My Categories" link still shows up in the Navigation menu. If its just a problem with my configuration let me know.

Thanks for the module by the way, it works really well and was exactly what I was looking for.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jaredwiltshire’s picture

OK, the problem stems from this piece of code in hook_menu(). I think there is a difference between Drupal 5 and Drupal 6 as to when hook_menu() is called. Drupal 5 used to call it on every page view but Drupal 6 only calls it when the module first gets enabled, the delegated roles are updated etc.

    // User admin callback.
  $any = count(_taxonomy_delegate_my_vocabularies());
  if ($any) {
    $items['category_admin'] = array(
      'title' => '@name',
      'title arguments' => array('@name' => variable_get('taxonomy_delegate_menu', t('Administer My Categories'))),
      'page callback' => 'taxonomy_delegate_mycategories',
      'access arguments' => array('access content'),
      );
  }

This also means that unless the person who is delegating the roles is actually a member of a role the role wont actually be able to administer the taxonomy per as the way this module is supposed to work.

I think what this module needs for the Drupal 6 version is to remove the Delegation tab/hook and simply define a permision for each vocabulary.
'access arguments' => array('access content') would be changed to 'access arguments' => $array_of_all_vocab_permissions.
The Permissions page can then be used to assign certain roles to certain vocabularies. This will obviously require a fairly substantial rewrite.

jaredwiltshire’s picture

Priority: Normal » Critical

Seeing as the module doesnt work as designed, I'll change this to critical

jaredwiltshire’s picture

Status: Active » Closed (duplicate)

This is the same issue as http://drupal.org/node/286359

NancyDru’s picture

Status: Closed (duplicate) » Active
NikLP’s picture

Looking into this, but it's low priority at the moment. Need this in the not-too-distant tho.

NancyDru’s picture

Assigned: Unassigned » NancyDru
Status: Active » Fixed

Jared you were on the right track. A sudden inspiration told me to just create a new access callback function. It seems to have done the job.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

gintass’s picture

It seems to me that this is still a problem - anonymous users still can see "Administer My Categories" link.

gaellafond’s picture

Status: Closed (fixed) » Active

The bug seem to be back...

The element "Administer My Categories" is visible for everyone who can see the "Content Administration" Block menu.

NOTE: In my case, it's called "Administer Topics". An other programmer from my team has changed the menu item title. Just to be sure that we are talking about the same thing, it lead to the page "/category_admin".

On my installation, anonymous users can not see the "Content Administration" menu, but they can access the page it they type the address in the browser address bar. It doesn't seems to be a security issue since the page contains no items; only the title and the table header.

EDIT:
I found a workaround that slow down the system, but maybe it can help to find a solution:
When I modify the function "taxonomy_delegate_init()" in the file "taxonomy_delegate.module" like this:

<?php
function taxonomy_delegate_init() {
  include_once(drupal_get_path('module', 'taxonomy') .'/taxonomy.admin.inc');
  menu_rebuild(); // Testing only!! This is seriously Overkill!!
}
?>

The menu is destroyed and regenerated on every page request. This is seriously overkill and it add about 2 seconds to load every single page, but, at lease, it give the expected behaviour. I think that's mean that the output of the delegate module is cached, for some reason, including the menu.

EDIT:
The blocks have a caching system. The "Administer My Categories" item is in a Menu. The menu module specify to not cache Menus when they are use as a Block. I look on the DB and add some debugging on the page and the Menus cache are really set as "BLOCK_NO_CACHE" and they seems to be used that way.
All the caching system are disabled on "Administer > Site configuration > Performance". I'm now looking for another caching system...

Any ideas?

gaellafond’s picture

Status: Active » Needs review

According to this article:
http://dgtlmoon.com/dynamic_hookmenu_results_in_drupal_was_5_not_in_6
the menus used to be dynamic but they are now static.

Actually, it's seems to be semi-dynamic. The menu items are generated only once, but the menu display the items according to the rights from the permissions page (Administer > User management > Permissions). Since this menu item rely on permissions from the taxonomy_delegate module and not the permission page, the item is display according to the right of the user that generated it.
i.e. always display (if the first user to request the menu as the rights to see it) or never display (if the first user to request the menu as the rights to see it).
Adding a special permission for this module on the permission page would sort of duplicate the permissions settings, which will allow to introduce inconsistency between both systems, which is not a good idea.

The best and simple workaround I can find for now, without modifying the sources, is to create a special menu containing only this item and allow only some groups to see this block (the menus are automatically listed as blocks).

How to do this:

1. Create a new menu.
  Administer > Site building > Menus > Add menu
    Menu name: [menu-category-admin]
    Title: [Categories Administration]

2. Add the "Administer My Categories" item to the menu.
  Administer > Site building > Menus > Categories Administration > Add item
    Path: [category_admin]
    Menu link title: [Administer My Categories]
    [X] Enabled
    Parent item: [Categories Administration]

3. Disable the "Administer My Categories" from the previous semi-dynamic menu (it's called "Content Administration" in my system).
  Administer > Site building > Menus > Content Administration
    Uncheck the "Enabled" checkbox for "Administer My Categories"

4. Set the permission for the new Menu.
  Administer > Site building > Blocks > List
    Find "Categories Administration" and click on "configure"
    Under "CSS class(es)", add the same classes as "Content Administration" menu
    Under "Show block for specific roles", check the box of the groups that are allow to administer their categories

5. Display the new Menu on the Web Site.
  Administer > Site building > Blocks > List
    Drag the "Categories Administration" block just after "Content Administration" (or whatever it's called on your system)

It's not perfect since the user that are not allow to see the menu are still able to access the "Administer My Categories" page by typing the address, but the page is empty and, at lease, they can not see any link that lead to this page.

Another workaround
According to this article http://drupal.org/node/307510 this workaround is ugly. They propose to use the hook_load() function, but I didn't manage to make to get it called by the system.

The "ugly" solution that do exactly what we want to do:
Modify the "www/sites/all/modules/taxonomy_delegate/taxonomy_delegate.module" file as follow:
1. Add a check_count() function
2. Set the access callback to call this function. Put the name of the function as a String and not the function itself! Otherwise, the function will be execute at the creation and the result will be use as a callback. By setting the function name, the callback will call the function each time the item is requested by the menu.

<?php
function check_count() {
  $any = count(_taxonomy_delegate_my_vocabularies());
  if ($any) {
    return TRUE;
  }
  return FALSE;
}

/**
 * Implementation of hook_menu().
 */
function taxonomy_delegate_menu() {
  global $user;
  $items = array();

  [...]

  // User admin callback.
  $items['category_admin'] = array(
    'title' => '@name',
    'title arguments' => array('@name' => variable_get('taxonomy_delegate_menu', t('Administer My Categories'))),
    'page callback' => 'taxonomy_delegate_mycategories',
    'access callback'   => 'check_count',
    'access arguments' => array('access content'),
  );

  [...]

  return $items;
}
?>

See patch in my next post.

NOTE: There is the pretty solution with hook_load(), that do NOT work. Please, tell me what I'm doing wrong if you manage to make it work.

<?php
/**
 * Implementation of hook_load().
 * I also tried with taxonomy_delegate_node_load with no success
 */
function taxonomy_delegate_load($arg) {
  $items = array();

  $any = count(_taxonomy_delegate_my_vocabularies());
  if ($any) {
    // User admin callback.
    $items['category_admin'] = array(
      'title' => '@name',
      'title arguments' => array('@name' => variable_get('taxonomy_delegate_menu', t('Administer My Categories'))),
      'page callback' => 'taxonomy_delegate_mycategories',
      'access callback'   => 'check_count',
      'access arguments' => array('access content'),
    );
  }
  return $items;
}
?>
gaellafond’s picture

Patch for the "Ugly" workaround. Do not apply this patch if you don't experiment this Bug.
NOTE: Don't forget to clear the menu cache after applying the patch.

NancyDru’s picture

Status: Needs review » Closed (duplicate)

I believe #867614: hook_menu is incorrect. fixes this.