summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBojan Zivanovic2013-08-15 16:23:17 (GMT)
committer Bojan Zivanovic2013-08-15 16:33:28 (GMT)
commit221357c313ecff6bd585172ac5d816cdcc29bf0f (patch)
tree81ca90f740d1a1edf27c8551e993401fb550e2aa
parent2447a4bd3767420e2d371473796583befce47d74 (diff)
Issue #2051711: Allow users to bypass license control.
-rw-r--r--commerce_file.module49
1 files changed, 40 insertions, 9 deletions
diff --git a/commerce_file.module b/commerce_file.module
index eb7748e..463027e 100644
--- a/commerce_file.module
+++ b/commerce_file.module
@@ -138,6 +138,36 @@ function commerce_file_file_download_headers_alter(array &$headers, $file) {
}
/**
+ * Implements hook_permission().
+ */
+function commerce_file_permission() {
+ return array(
+ 'bypass license control' => array(
+ 'title' => t('Bypass license control'),
+ 'description' => t('Download files without having a license.'),
+ 'restrict access' => TRUE,
+ ),
+ );
+}
+
+/**
+ * Checks whether the provided user is allowed to bypass license control.
+ *
+ * This allows the user to download a file without having a license.
+ * Since there's no license, download limits can't be checked and respected.
+ *
+ * @param $account
+ * The account to check for. If not given, the current user is used instead.
+ *
+ * @return
+ * TRUE if the account is allowed to bypass license control, FALSE
+ * otherwise.
+ */
+function commerce_file_bypass_license_control($account = NULL) {
+ return user_access('bypass license control', $account) || user_access('administer licenses', $account);
+}
+
+/**
* Implements hook_file_entity_access().
*/
function commerce_file_file_entity_access($op, $file, $account) {
@@ -175,7 +205,7 @@ function commerce_file_file_download($uri) {
}
// If the file is licensable, don't allow it to be downloaded this way.
- if (commerce_file_is_licensable($file)) {
+ if (commerce_file_is_licensable($file) && !commerce_file_bypass_license_control()) {
return -1;
}
}
@@ -211,8 +241,8 @@ function commerce_file_access($op, $file, $account = NULL) {
if (!empty($_SESSION['commerce_license_uid']) && empty($account->uid)) {
$account = user_load($_SESSION['commerce_license_uid']);
}
- // No need to check access for admin.
- if (user_access('administer licenses', $account)) {
+ // No need to check access.
+ if (commerce_file_bypass_license_control($account)) {
return TRUE;
}
// This file is not licensable.
@@ -385,8 +415,8 @@ function commerce_file_can_download($license, $file, $account = NULL) {
if (!empty($_SESSION['commerce_license_uid']) && empty($account->uid)) {
$account = user_load($_SESSION['commerce_license_uid']);
}
- // The admin can always download.
- if (user_access('administer licenses', $account)) {
+ // No need to check access.
+ if (commerce_file_bypass_license_control($account)) {
return TRUE;
}
// This is not this user's license, and he has no admin rights.
@@ -700,8 +730,7 @@ function commerce_file_field_formatter_view($entity_type, $entity, $field, $inst
$license = commerce_file_get_product_license($entity);
$access = TRUE;
if (!empty($settings['check_access'])) {
- // The user must either have admin privileges, or have a license.
- $access = (user_access('administer licenses') || $license);
+ $access = ($license || commerce_file_bypass_license_control());
}
foreach ($items as $delta => $item) {
@@ -745,8 +774,10 @@ function theme_commerce_file_download_link($variables) {
$icon = $variables['icon'] . ' ';
}
- $can_download = FALSE;
- if (!empty($variables['license'])) {
+ if (empty($variables['license'])) {
+ $can_download = commerce_file_bypass_license_control();
+ }
+ else {
// The file that this theme function receives is just the filefield item
// array converted to an object (yay, D7!). The limit download check needs
// the actual file entity.