diff --git a/contentbank/classes/output/viewcontent.php b/contentbank/classes/output/viewcontent.php
index b514c4da142..7813aafaf2c 100644
--- a/contentbank/classes/output/viewcontent.php
+++ b/contentbank/classes/output/viewcontent.php
@@ -14,16 +14,10 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see .
-/**
- * Class containing data for a content view.
- *
- * @package core_contentbank
- * @copyright 2020 Victor Deniz
- * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
- */
namespace core_contentbank\output;
+use context;
use core_contentbank\content;
use core_contentbank\contenttype;
use moodle_url;
@@ -180,8 +174,13 @@ class viewcontent implements renderable, templatable {
$data->editcontenturl = $editcontenturl->out(false);
}
- $closeurl = new moodle_url('/contentbank/index.php', ['contextid' => $this->content->get_contextid()]);
- $data->closeurl = $closeurl->out(false);
+ // Close/exit link for those users who can access that context.
+ $context = context::instance_by_id($this->content->get_contextid());
+ if (has_capability('moodle/contentbank:access', $context)) {
+ $closeurl = new moodle_url('/contentbank/index.php', ['contextid' => $context->id]);
+ $data->closeurl = $closeurl->out(false);
+ }
+
$data->actionmenu = $this->get_edit_actions_dropdown();
$data->heading = $this->content->get_name();
if ($this->content->get_visibility() == content::VISIBILITY_UNLISTED) {
diff --git a/contentbank/templates/viewcontent/toolbarview.mustache b/contentbank/templates/viewcontent/toolbarview.mustache
index 7dde8d58a82..02acfb0eaac 100644
--- a/contentbank/templates/viewcontent/toolbarview.mustache
+++ b/contentbank/templates/viewcontent/toolbarview.mustache
@@ -54,31 +54,28 @@ along with Moodle. If not, see .
}
}}
{{#heading}}