From 8492c28d617272151885d1c7d9754d92196aef36 Mon Sep 17 00:00:00 2001
From: Frode Petterson <frode.andre.petterson@gmail.com>
Date: Mon, 18 Jul 2016 10:50:46 +0200
Subject: [PATCH] Remove download button when no permission

---
 view.php | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/view.php b/view.php
index 651cffd..cbc9a46 100644
--- a/view.php
+++ b/view.php
@@ -82,10 +82,15 @@ $export = '';
 if (!isset($CFG->mod_hvp_export) || $CFG->mod_hvp_export === true) {
     // Find course context.
     $context = \context_course::instance($course->id);
-    $hvppath = "{$CFG->httpswwwroot}/pluginfile.php/{$context->id}/mod_hvp";
-
-    $exportfilename = ($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p';
-    $export = "{$hvppath}/exports/{$exportfilename}";
+    if (has_capability('mod/hvp:getexport', $context)) {
+      $hvppath = "{$CFG->httpswwwroot}/pluginfile.php/{$context->id}/mod_hvp";
+      $exportfilename = ($content['slug'] ? $content['slug'] . '-' : '') . $content['id'] . '.h5p';
+      $export = "{$hvppath}/exports/{$exportfilename}";
+    }
+}
+if (empty($export)) {
+  // Remove Download button when there's no export URL
+  $content['disable'] |= \H5PCore::DISABLE_DOWNLOAD;
 }
 
 // Add JavaScript settings for this content.
-- 
GitLab