[support] Issues with access arguments

Davide Mirtillo davide at ser-tec.org
Fri Apr 29 09:15:24 UTC 2011


Hello, i'm trying to develop a module similar to private_download, but
with multiple directories:

http://drupal.org/project/private_download

The module has been written based on this post:

http://www.drupalcoder.com/blog/mixing-private-and-public-downloads-in-drupal-6

I managed to create the hook_menu implementation, but i am running into
issues with the access callback function.

My drupal install seems to completely skip the access argument check and
i can't figure out why, since the same access arguments variable present
in the hook_menu implementation in the original module is working
flawlessly.

I'd really like some ideas on why the files are downloadable by everyone
and the permission check does not have any effect.

This is the code of my custom module:

/**
 * Implementation of hook_perm().
 */

function custom_private_download_perm() {
  return array('access role A files', 'access role B files');
}

/**
 * Implementation of hook_menu().
 */

function custom_private_download_name_menu() {
  $items = array();
	
  $items['system/files/kb/role/a/%'] = array(
    'access arguments' => array('access role A files'),
    'type' =>  MENU_CALLBACK,
    'page callback' => 'file_download',
    'page arguments' => array('kb/role/a'),
  );

  $items['system/files/kb/role/b/%'] = array(
    'access arguments' => array('access role B files'),
    'type' =>  MENU_CALLBACK,
    'page callback' => 'file_download',
    'page arguments' => array('kb/role/b'),
  );
  return $items;
}

/**
 * Implementation of hook_file_download().
 */

function custom_private_download_file_download($filepath) {
  // define default file header attributes
  $header = array(
    'Content-Type: '. file_get_mimetype($filepath),
    'Content-Length: '. filesize(file_create_path($filepath)),
    'Content-Disposition: attachment; filename="'.
mime_header_encode(basename($filepath)) .'"'
  );
  // additional user-defined file header attributes (if any)
  return array_merge($header, explode("\n",
variable_get('private_download_header', "Content-Transfer-Encoding:
binary\nCache-Control: max-age=60, must-revalidate")));
}


More information about the support mailing list