I have a site that I sell files with the commerce file module and everything works great, users can purchase their files and then download them like module is supposed to work. Once I enable Domain Access module and it rebuilds the content permissions my users can no longer download their files. Everyone including the admin looses rights to download their files. Not sure if I should place this as a bug report here or on the domain access module. Any help would be appreciated.

Comments

hmartens’s picture

I've got the same problem but not from Domain Access module...All my clients' previous purchases says "Active" but when they try to download it it says "403 Error - Access Denied". All I can think of that has changed from a month ago is that I updated Commerce module...but did run update.php...

Maybe it wasn't Domain Access that messed up your licenses?

d3vo’s picture

I'm pretty sure it has to do with domain access module. With my issue. As soon as I disable the module it rebuilds the access permissions and users can begin to download their files again. I haven't had time to look into this more but I plan to this week. I think I need to probably move this issue into the domain access module issues also.
As far as your issue then have you installed any modules that might have messes with the content access?
Regards

recrit’s picture

@d3vo
Domain Access module ...

  1. Creates node access controls, so ensure that the file is not also on a node somewhere.
  2. Rewrites the path and forces redirects in various places:
    • To isolate the issue from licenses, edit a product with user 1 and see if you can download the file from the link displayed in the Commerce File field. IF this fails, then the issue could be with Domain Access and Drupal's private file system in general.
timothywisdom’s picture

We are running a site that uses Domain Access and Commerce File.

I have logged in as User 1 and attempted to download a file from the link displayed in a product's edit screen. Access was denied.

recrit’s picture

thanks timothywisdom. Could you test on a regular file field setup with the private file system.. possibly on a test content type? Trying to isolate if it's the access protection on Commerce files or if its just the private file system + Domain Access

timothywisdom’s picture

I made a content type with two fields:

File
and
Commerce File

The File Field was set to use the Private File system. Both fields are set to display the file when viewing the node.

I made a node of that content type and uploaded the same text file to both fields.

When viewing the node as User 1, I can access the File field's file but NOT the Commerce File field's file.
When editing the node as User 1, I can access the File field's file but NOT the Commerce File field's file.

Does that test satisfy your isolation test?

recrit’s picture

@ timothywisdom
Thanks for your testing. That's exactly what I wanted so that I can focus the troubleshooting.

recrit’s picture

Status: Active » Needs review

I have committed an update that will always allowed admins of Commerce File to access the files - http://drupalcode.org/project/commerce_file.git/commit/91d6e03

Please test and report back.

d3vo’s picture

I will test this out. But it sounds like you have only allowed admin rights correct so it will probably still not work for my users?

recrit’s picture

@d3vo: correct, the commit in #8 only addresses admins

johnlutz’s picture

Hi recrit. Working on same site as timothywisdom. I can confirm that your commit lets admins download the files. However, the main issue we are still having is that it is not letting the owners of the file license download the file.

I tried to troubleshoot a bit and found the _commerce_file_license_query function where it queries the db to check for the license. The final query there is not coming back with any results of licenses that are associated with that user and fid. But, if I create a query_alter function to spit out the final sql query so I can test in phpmyadmin, this sql code produces a result in phpmyadmin.

So, wondering if something within domain or somewhere else is altering this query along the way or something. Why would this EntityFieldQuery produce no result, but the underlying sql that it creates does? Does this help at all in the diagnosis?

recrit’s picture

Can you let me know which dev version you are testing?
I recently revamped the hook_field_access() after the commit in #8 so updating to the latest would remove that from issue.
Domain Access could still be alter the query somewhere but I am still trying to track that down.

johnlutz’s picture

I downloaded it at about 10pm wednesday. I will download latest right now and test. Could this have somthing to do with a caching issue?

recrit’s picture

the dev tar on the project page usually rebuilds at midnight EST or something like that. It's updated now though, so download dev there.

recrit’s picture

update: since the commerce file formatters handle the viewing the file as a link or not, I have opted to removed the entire hook_field_access() per http://drupalcode.org/project/commerce_file.git/commit/14b612c

johnlutz’s picture

well, this last change of yours to remove that function has done something because now we can download files by the user with the license. However, it seems sporadic as to when they do and don't. Have tried separate users on same files to see if I could see something product specific and thought I could see a pattern with 3 files downloading with same 3 users and another one not downloading with same users. Saw one difference was that the owner domain was different but all were pushed to all affiliates. So, changed the one to the same domain owner as the other 3 and still couldn't download that file. Then I downloaded it again and it worked. Then again and it didn't. And again and it didn't. I am just confused at what modules are controlling what now. Any insight?

recrit’s picture

I believe I tracked this down ... crossing the fingers. The problem stems from the entity field query when a node access module is present on the site (ie Domain Access, Content Access, etc). The issue http://drupal.org/node/1302228 has a fix at http://drupal.org/node/1597378 for Drupal 7.15 (not released yet). Therefore, I have implemented the work around described in http://drupal.org/node/997394#comment-5096664

You can download the snapshot at http://drupalcode.org/project/commerce_file.git/commit/fdab094

johnlutz’s picture

I think you have done it recrit! Kudos!! It seems to be working perfectly now on the testing we have done so far. We will see how things go and report back.

Small side question. We have updated this module to the dev version to try to get this particular problem solved and assumed there might be other changes in there we needed for it to work. Do you think for this particular problem we really need the dev version though? Could we just patch these small changes you made to the efq stuff to the stable beta3 release and be ok or do you have an idea of when you all will make a new release? Or maybe we should just stick to the dev version? Just not sure what other changes are in there that we might need to keep a close eye on.

Thanks for the quick work on this!!

recrit’s picture

Status: Needs review » Fixed

I've been working towards a new beta release which could be as soon as today. A lot has gone in to let admins to always be able to download and improvements in hook_file_download. There are updates in the dev version so you'd have to run update.php also.

If you wanted to put a hot fix in place on your older version, you just need to add the following at the bottom of the efq function before it performs the execute():

$query->addMetaData('account', user_load(1));
spanac’s picture

Why person that bought file cant download it (after this change: http://drupal.org/node/1239258, in beta 1 everything was OK with that). When using latest beta 3, on clean Drupal install, commerce file displays "Access Denied" to user after he/she tries to download purchased file.

How to grant user right to download file?

recrit’s picture

beta3 is not supported anymore and all the fixes discuss in this issue are in the latest dev version. If you still have a problem after using the latest dev, then open up an new issue.

Status: Fixed » Closed (fixed)

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