I'm trying to create a hook for a role to be able to download all files but also enforce the download per file limits.
I have noticed that now the admin cannot download either now. The links do show as for other people they are hidden, but they show as plain text.

I'm hoping that the "check access" checkbox on the formatter would just open it up and allow anyone to download with the limits still enforcing.

Any suggestions?


bojanz’s picture

Right now the admin user (or user with the "administer licenses" permission) can always download, it's never a plaintext link.

The user can access any files that he has licenses for.
I am assuming you want a role to access files that are licensable, but for which the user has no license?
This is not currently possible. Even if we made it possible, you wouldn't be able to track the file downloads (and limit them), because
that requires a license.

So it seems a hook won't help you much.
What's your use case?

surfkid’s picture

I ended up creating a new formatter to control the download links on a different site.
On my install of commerce file though, administrator has that permission and it shows plain text for all files for the admin.
I won't really download from those links, but was just wondering why it was plain text though.

bojanz’s picture

As I said, it's not something I can reproduce, and it doesn't look possible from the code.
Every access / download check checks for user_access("administer licenses") and returns TRUE immediately if found.
Check if your admin user actually has that perm.

surfkid’s picture

Thanks bojanz for the quick reply.
I checked the permission and the admin has the 'administer licenses' and it still shows plain text when showing file under the "add to cart"
Is there anything else I should check?
When a user purchases, and acquires a license, the link works great.

bojanz’s picture

Ah, it's before license purchase.
As I said, a license is always needed for download.

I can add a hook for granting access before that, but the download limits will never work since they are keyed by license id.

surfkid’s picture

Status: Active » Closed (works as designed)

Oh ok. So it works as designed.
I ended up hooking the "download link" from file entity to use alongside commerce file for this site.
Thank you for the info.
Keep up the good work!

bojanz’s picture

Title: Admin cannot download in 2.x » Allow users to bypass license control
Category: support » feature
Status: Closed (works as designed) » Fixed

Actually, let's do this properly.
Added a permission that allows license control to be bypassed:

So just grant your role the "bypass license control" permission and you're good to go.

Status: Fixed » Closed (fixed)

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