]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8522 fixed role reset warnings + only one legacy cap type allowed now in each...
authorskodak <skodak>
Tue, 6 Mar 2007 19:19:19 +0000 (19:19 +0000)
committerskodak <skodak>
Tue, 6 Mar 2007 19:19:19 +0000 (19:19 +0000)
admin/roles/manage.php
lang/en_utf8/role.php
lib/accesslib.php

index 960df0bae9423209fd3ddb9e5f7758fa4c4dd27b..e7db01baa9aacd817f9e5d158d72729d8a2b2b97 100755 (executable)
                 $a->id = $roleid;
                 $a->name = $roles[$roleid]->name;
                 $a->shortname = $roles[$roleid]->shortname;
-                notice_yesno(get_string('resetrolesure', 'role', $a), 'manage.php', 'manage.php', $optionsyes, $optionsno, 'post', 'get');
+                $a->legacytype = get_legacy_type($roleid);
+                if (empty($a->legacytype)) {
+                    $warning = get_string('resetrolesurenolegacy', 'role', $a);
+                } else {
+                    $warning = get_string('resetrolesure', 'role', $a);
+                }
+                notice_yesno($warning, 'manage.php', 'manage.php', $optionsyes, $optionsno, 'post', 'get');
                 admin_externalpage_print_footer($adminroot);
                 die;
             }
index 110419ba366517e6f781e48631f97f42131da836..b220b6f660aee2ecd6f75c44a396bd96d0015db2 100644 (file)
@@ -80,7 +80,8 @@ $string['question:export'] = 'Export questions';
 $string['question:import'] = 'Import questions';
 $string['question:manage'] = 'Manage questions';
 $string['question:managecategory'] = 'Manage question category';
-$string['resetrolesure'] = 'Are you sure that you want to reset role \"$a->name ($a->shortname)\" to defaults?<p></p>The defaults are taken from the selected legacy capability.';
+$string['resetrolesure'] = 'Are you sure that you want to reset role \"$a->name ($a->shortname)\" to defaults?<p></p>The defaults are taken from the selected legacy capability ($a->legacytype).';
+$string['resetrolesurenolegacy'] = 'Are you sure that you want to removed all permissions defined in this role \"$a->name ($a->shortname)\"?';
 $string['risks'] = 'Risks';
 $string['role:assign'] = 'Assign roles to users';
 $string['role:manage'] = 'Create and manage roles';
index 8668589471be7f523eba528e70e8a5581698e946..5632324670a7f2fe6a62c44daf8a7f28c19677f9 100755 (executable)
@@ -1565,6 +1565,26 @@ function get_legacy_roles() {
     );
 }
 
+function get_legacy_type($roleid) {
+    $sitecontext = get_context_instance(CONTEXT_SYSTEM);
+    $legacyroles = get_legacy_roles();
+
+    $result = '';
+    foreach($legacyroles as $ltype=>$lcap) {
+        $localoverride = get_local_override($roleid, $sitecontext->id, $lcap);
+        if (!empty($localoverride->permission) and $localoverride->permission == CAP_ALLOW) {
+            //choose first selected legacy capability - reset the rest
+            if (empty($result)) {
+                $result = $ltype;
+            } else {
+                delete_records('role_capabilities', 'roleid', $roleid, 'contextid', $sitecontext->id, 'capability', $lcap);
+            } 
+        }
+    }
+
+    return $result;
+}
+
 /**
  * Assign the defaults found in this capabality definition to roles that have
  * the corresponding legacy capabilities assigned to them.