Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-34945-23' of git://github.com/FMCorz/moodle into MO…

…ODLE_23_STABLE
  • Loading branch information...
commit ce077202d081ffae2d7e9d43dd55d84d513919cc 2 parents d98c8fc + 7c4fc5b
@stronk7 stronk7 authored
Showing with 16 additions and 6 deletions.
  1. +6 −0 repository/lib.php
  2. +10 −6 repository/manage_instances.php
View
6 repository/lib.php
@@ -1515,6 +1515,12 @@ public static function display_instances_list($context, $typename = null) {
$types = repository::get_editable_types($context);
foreach ($types as $type) {
if (!empty($type) && $type->get_visible()) {
+ // If the user does not have the permission to view the repository, it won't be displayed in
+ // the list of instances. Hiding the link to create new instances will prevent the
+ // user from creating them without being able to find them afterwards, which looks like a bug.
+ if (!has_capability('repository/'.$type->get_typename().':view', $context)) {
+ continue;
+ }
$instanceoptionnames = repository::static_function($type->get_typename(), 'get_instance_option_names');
if (!empty($instanceoptionnames)) {
$baseurl->param('new', $type->get_typename());
View
16 repository/manage_instances.php
@@ -106,12 +106,16 @@
$type = repository::get_type_by_id($instance->options['typeid']);
}
-if (isset($type) && !$type->get_visible()) {
- print_error('typenotvisible', 'repository', $baseurl);
-}
-
-if (isset($type) && !$type->get_contextvisibility($context)) {
- print_error('usercontextrepositorydisabled', 'repository', $baseurl);
+if (isset($type)) {
+ if (!$type->get_visible()) {
+ print_error('typenotvisible', 'repository', $baseurl);
+ }
+ // Prevents the user from creating/editing an instance if the repository is not visible in
+ // this context OR if the user does not have the capability to view this repository in this context.
+ $canviewrepository = has_capability('repository/'.$type->get_typename().':view', $context);
+ if (!$type->get_contextvisibility($context) || !$canviewrepository) {
+ print_error('usercontextrepositorydisabled', 'repository', $baseurl);
+ }
}
/// Create navigation links
Please sign in to comment.
Something went wrong with that request. Please try again.