A client is trying to download files she purchased a month ago. She's downloaded them before but for some reason it now returns "403 Error - Access Denied" when she tries to download them. She purchased new files the this week and she can download them with now problems.

The Files says it is active and the download limit and all other settings are set to Unlimited. I attached a screenshot of the file it doesn't want to allow to download.

Please help.

Comments

recrit’s picture

It's hard to tell what's going on from only knowing that they are getting denied.

Can you provide some more information using the devel/php window?
The following will provide more information about a troubled license in question.

$license_id = 33; //  get from edit link of the license
$account_uid = 1; // uid of user attempting to download

$account = user_load($account_uid);
$license = commerce_file_license_load($license_id);

dpm($license->expiration, 'expiration');
dpm($license->get_limits(), 'limits');
dpm($license->can_download($account) ? 'TRUE' : 'FALSE', 'Can Download? ');
dpm($license->is_unlimited() ? 'TRUE' : 'FALSE', 'all limits unlimited?');
hmartens’s picture

Hi recrit

Thanks for your help. How do I go about using the devel/php window? I've installed devel but that's all I know how to :)

Sorry

recrit’s picture

you just need to visit the path "devel/php", paste the code into the textarea, and change the ids to your license in question

hmartens’s picture

StatusFileSize
new41.32 KB

Hi recrit

Thank you thank you thank you for helping me! Ok I filled in the details and it confirms that there shouldn't be anything wrong yet this user cannot download the file...I've logged in as them and also couldn't download it. They could download it before, but not anymore. There's a couple of users in the last month that has complained about similar problems.

Attached is a screenshot of the php result

hmartens’s picture

All I can remember doing on the website besides the normal module updates is that I installed Commerce Multicurrency on May 25...and then that same day I disabled it because the Paypal module seem to not support the South African currency...

I've been trying to think what else could have changed but can't think of anything. The site has been running stable for such a long time I didn't need to tweak or fix anything. And I can't just add another license file for the user because it Commerce File doesn't except filetypes other than "mp4, m4v, flv, wmv, mp3, wav, jpg, jpeg, png, pdf, doc, docx, ppt, pptx, xls, xlsx" . So I don't even have a work-around until the problem can be solved.

Recrit, I can give you access to the website if that would help although you probably have too much work "to do my work for me" :)

bah humbug!

hmartens’s picture

StatusFileSize
new70.74 KB

Now I'm getting an error...

This morning when I'm trying to run this same code again to test a license I get the error as attached.
"Notice: Trying to get property of non-object in eval() (line 7 of /home/embrojpq/public_html/sites/all/modules/devel/devel.module(1285) : eval()'d code)."

Is this a devel error or a license error?

Nevermind..think that error was just a flux...but I still need to fix this licensing problem...

Thank you for your help :) Really appreciate it!

recrit’s picture

@hmartens:
Check if you have any other contrib modules implementing hook_file_download, hook_file_download_access, or hook_file_download_access_alter. Commerce File controls access to the file with hook_file_download, but any other module can implement the hooks to deny access.

hmartens’s picture

Thank you @recrit. Is there any easy way to find that out (like a command that I can run) or do I have to go through each module and see its properties? Is there a way to reset commerce to have dominion again in my shop? I can't think of anything that I have installed recently though...

Thank you so much for your help!

recrit’s picture

you can search on the command line from your web root for each of the hooks:

grep -rn _file_download sites/all/modules

* Note change the directory if your modules are not in sites/all/modules

benjarlett’s picture

I think I'm having the same issue.. if I'm understanding it correctly...

when I do that search I get the following

sites/all/modules/commerce/modules/product/commerce_product.module:171: * Implements hook_file_download_access().
sites/all/modules/commerce/modules/product/commerce_product.module:190:function commerce_product_file_download_access($field, $entity_type, $entity) {
sites/all/modules/commerce_file/commerce_file.module:611: * Implements hook_file_download().
sites/all/modules/commerce_file/commerce_file.module:613:function commerce_file_file_download($uri) {
sites/all/modules/commerce_file/commerce_file.module:778: // - allow display, hook_file_download() will allow download if they have access
sites/all/modules/ctools/ctools.module:475: * Implementation of hook_file_download()
sites/all/modules/ctools/ctools.module:480:function ctools_file_download($filepath) {
Binary file sites/all/modules/ctools-7.x-1.0-rc1.tar matches
sites/all/modules/entity/entity.module:963: * Implements hook_file_download_access() for entity types provided by the CRUD API.
sites/all/modules/entity/entity.module:965:function entity_file_download_access($field, $entity_type, $entity) {
Binary file sites/all/modules/entity-7-1.x-1.0-rc1.tar matches
sites/all/modules/file_force/file_force.module:28: * Implements hook_file_download().
sites/all/modules/file_force/file_force.module:32:function file_force_file_download($uri) {
sites/all/modules/media/media.module:564: * Implements hook_file_download_access().
sites/all/modules/media/media.module:566:function media_file_download_access($field, $entity_type, $entity) {
Binary file sites/all/modules/media-7.x-1.0-rc3.tar matches
Binary file sites/all/modules/media-7.x-2.0-unstable3.tar matches

Note: the module file_force isn't active.

I'm liking commerce alot...but I do need purchasing downloads to work... help much appreciated.

hmartens’s picture

@recrit
I don't have direct access to the server as it's sitting with a service provider...so I can't run these commands.

If another module is interfering with the licenses, will it make certain licenses work and certain not to work or will it make all licenses to not work? I'm having problems where certain licenses, especially the from 2 months ago and older not to be accessable even though the that php script you gave me says it should be active.

Thank you for all your help!

hmartens’s picture

Morning @recrit

I asked the service provider to run the command for me. This is the results:
===
# grep -rn _file_download sites/all/modules
sites/all/modules/imce/imce.module:93: * Implements hook_file_download().
sites/all/modules/imce/imce.module:96:function imce_file_download($uri) {
sites/all/modules/entity/entity.module:963: * Implements hook_file_download_access() for entity types provided by the CRUD API.
sites/all/modules/entity/entity.module:965:function entity_file_download_access($field, $entity_type, $entity) {
sites/all/modules/commerce_file/commerce_file.module:583: * Implements hook_file_download().
sites/all/modules/commerce_file/commerce_file.module:585:function commerce_file_file_download($uri) {
sites/all/modules/commerce_file/commerce_file.module:750: // - allow display, hook_file_download() will allow download if they have access
sites/all/modules/ctools/ctools.module:475: * Implementation of hook_file_download()
sites/all/modules/ctools/ctools.module:480:function ctools_file_download($filepath) {
sites/all/modules/commerce/modules/product/commerce_product.module:171: * Implements hook_file_download_access().
sites/all/modules/commerce/modules/product/commerce_product.module:190:function commerce_product_file_download_access($field, $entity_type, $entity) {
====

Can you see anything here that is alarming and could cause certain licenses to not to work?

Thank you for your help.

recrit’s picture

Version: 7.x-1.0-beta3 » 7.x-1.x-dev
Status: Active » Needs review

I've committed a fix for EntityFieldQuery being altered for user permissions - http://drupalcode.org/project/commerce_file.git/commit/685fb23, @see http://drupal.org/node/1597378

The latest dev does have some updates, so you will need to run update.php

recrit’s picture

Status: Needs review » Fixed

@hmartens:
The commits in the latest dev have fixed file download issues for others. If the dev version does not work, then re-open.

hmartens’s picture

Thank you so very much Recrit for all your hard work! I definitely owe you coffee or lunch at a future Drupalcon ;) What is your twitter handle?

I will test this out shortly...

Status: Fixed » Closed (fixed)

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