]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-8523 Show default capabilities in role definition; added CSS popup_form spacing
authorskodak <skodak>
Sat, 3 Mar 2007 21:07:07 +0000 (21:07 +0000)
committerskodak <skodak>
Sat, 3 Mar 2007 21:07:07 +0000 (21:07 +0000)
admin/roles/manage.html
admin/roles/manage.php
lib/accesslib.php
theme/standard/styles_color.css
theme/standard/styles_layout.css

index 7a21c673961f1e4988b1a9709b7e9496b89a6983..ac9f8a374bef2db9d78aac4f2702067a768d24ac 100755 (executable)
     } 
 ?>
 <form id="rolesform" action="manage.php" method="post">
+<fieldset class="invisiblefieldset">
 <input type="hidden" name="roleid" value="<?php p($roleid) ?>" />
 <input type="hidden" name="sesskey" value="<?php p(sesskey()) ?>" />
 <input type="hidden" name="action" value="<?php if ($action != 'view') { echo p($action); } ?>" />
-
+</fieldset>
 <table cellpadding="9" cellspacing="0" align="center">
 <tr valign="top">
-    <td align="right"><?php print_string('name') ?>:</td>
+    <td align="right"><label for="name"><?php print_string('name') ?></label></td>
     <td><?php
     if ($action == 'view') {
         p($role->name);
     } else {
-        echo '<input type="text" name="name" maxlength="254" size="50" value="'.s($role->name).'" />';
+        echo '<input type="text" id="name" name="name" maxlength="254" size="50" value="'.s($role->name).'" />';
         if (isset($errors["name"])) formerr($errors["name"]);
     } ?></td>
 </tr>
 <tr valign="top">
-    <td align="right"><?php print_string('shortname') ?>:</td>
+    <td align="right"><label for="shortname"><?php print_string('shortname') ?></label></td>
     <td><?php
     if ($action == 'view') {
         p($role->shortname);
     } else {
-        echo '<input type="text" name="shortname" maxlength="20" size="15" value="'.s($role->shortname).'" />';
+        echo '<input type="text" id="shortname" name="shortname" maxlength="20" size="15" value="'.s($role->shortname).'" />';
         if (isset($errors["shortname"])) formerr($errors["shortname"]);
     } ?></td>
 </tr>
 <tr valign="top">
-    <td align="right"><?php print_string('description') ?>:</td>
+    <td align="right"><label for="edit-description"><?php print_string('description') ?></label></td>
     <td><?php
     if ($action == 'view') {
         p($role->description);
@@ -87,6 +88,27 @@ $component = '';
 $strrisks = s(get_string('risks', 'role'));
 $strcapabilities = s(get_string('capabilities', 'role'));
 
+// prepare legacy defaults
+$legacyroles = get_legacy_roles();
+
+$defaultcaps = false;
+foreach($legacyroles as $ltype=>$lcap) {
+    if (empty($errors)) {
+       // check the capability override for this cap, this role in this context
+        $localoverride = get_local_override($roleid, $sitecontext->id, $lcap);
+    } else {
+        $localoverride->permission = $role->{$lcap};
+    }
+    if (!empty($localoverride->permission) and $localoverride->permission == CAP_ALLOW) {
+        if ($defaultcaps !== false) {
+            //oh, several legacy caps selected!
+            $defaultcaps = false;
+            break;
+        }
+        $defaultcaps = get_default_capabilities($ltype);
+    }
+}
+
 foreach ($capabilities as $capability) {
     // prints a breaker if component or name or context level
     if ($capability->component != $component or $capability->contextlevel != $contextlevel) {
@@ -100,7 +122,6 @@ foreach ($capabilities as $capability) {
 
     if (empty($errors)) {
        // check the capability override for this cap, this role in this context
-        $sitecontext = get_context_instance(CONTEXT_SYSTEM, SITEID);
         $localoverride = get_local_override($roleid, $sitecontext->id, $capability->name);
     } else {
         $localoverride = new object();
@@ -142,14 +163,28 @@ foreach ($capabilities as $capability) {
     }
     $riskinfo .= '</td>';
 
+    if ($defaultcaps === false) {
+        $capclass = '';
+    } else {
+        $capclass = 'capdefault';
+    }
+    $isinherit  = (!isset($defaultcaps[$capability->name]) or $defaultcaps[$capability->name] == CAP_INHERIT) ? $capclass : '';
+    $isallow    = (isset($defaultcaps[$capability->name]) and $defaultcaps[$capability->name] == CAP_ALLOW) ? $capclass : '';
+    $isprevent  = (isset($defaultcaps[$capability->name]) and $defaultcaps[$capability->name] == CAP_PREVENT) ? $capclass : '';
+    $isprohibit = (isset($defaultcaps[$capability->name]) and $defaultcaps[$capability->name] == CAP_PROHIBIT) ? $capclass : '';
+       
     ?>
 
         <tr class="rolecap <?php echo $rowclasses; ?>">
         <td class="name"><span class="cap-desc"><a target="docspopup" href="<?php echo $CFG->docroot.'/'.$lang.'/'.$strcapabilities.'/'.$capability->name ?>"><?php echo get_capability_string($capability->name); ?></a><span class="cap-name"><?php echo $capability->name ?></span></span></td>
-        <td class="inherit"><input type="radio" title="<?php p($strinherit); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_INHERIT ?>" <?php if (!isset($localoverride->permission) || $localoverride->permission==CAP_INHERIT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
-        <td class="allow"><input type="radio" title="<?php p($strallow); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_ALLOW ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_ALLOW){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
-        <td class="prevent" ><input type="radio" title="<?php p($strprevent); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_PREVENT ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_PREVENT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
-        <td class="prohibit" ><input type="radio" title="<?php p($strprohibit); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_PROHIBIT ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_PROHIBIT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
+        <td class="inherit <?php echo $isinherit ?>">
+          <input type="radio" title="<?php p($strinherit); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_INHERIT ?>" <?php if (!isset($localoverride->permission) || $localoverride->permission==CAP_INHERIT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
+        <td class="allow <?php echo $isallow ?>">
+          <input type="radio" title="<?php p($strallow); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_ALLOW ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_ALLOW){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
+        <td class="prevent <?php echo $isprevent ?>" >
+          <input type="radio" title="<?php p($strprevent); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_PREVENT ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_PREVENT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
+        <td class="prohibit <?php echo $isprohibit ?>" >
+          <input type="radio" title="<?php p($strprohibit); ?>" name="<?php echo $capability->name; ?>" value="<?php echo CAP_PROHIBIT ?>" <?php if (isset($localoverride->permission) && $localoverride->permission==CAP_PROHIBIT){ echo 'checked="checked"'; }?> <?php echo $disabled; ?>/></td>
 
         <?php echo $riskinfo; ?>
 
index 87745efdc4054d3548bab2b527a16aa6f8becb50..ec9ad157ef527c036509322d59a88096ef0d11d5 100755 (executable)
         echo '<div class="selector">';
         if ($action == 'view') {
             popup_form('manage.php?action=view&amp;roleid=', $roleoptions, 'switchrole', $roleid, '', '', '', 
-                       false, 'self', get_string('selectrole', 'role').': ');
+                       false, 'self', get_string('selectrole', 'role'));
 
             $options = array();
             $options['roleid'] = $roleid;
index e6b425d788313ecb262498ed8c76b063c0aac5fc..960b2df47b31e0940d4b53e1da75371e73a2b749 100755 (executable)
@@ -1550,6 +1550,21 @@ function moodle_install_roles() {
 
 }
 
+/**
+ * Returns array of all legacy roles.
+ */
+function get_legacy_roles() {
+    return array(
+        'guest'          => 'moodle/legacy:guest',
+        'user'           => 'moodle/legacy:user',
+        'student'        => 'moodle/legacy:student',
+        'teacher'        => 'moodle/legacy:teacher',
+        'editingteacher' => 'moodle/legacy:editingteacher',
+        'coursecreator'  => 'moodle/legacy:coursecreator',
+        'admin'          => 'moodle/legacy:admin'
+    );
+}
+
 /**
  * Assign the defaults found in this capabality definition to roles that have
  * the corresponding legacy capabilities assigned to them.
@@ -1564,19 +1579,17 @@ function moodle_install_roles() {
  */
 function assign_legacy_capabilities($capability, $legacyperms) {
 
+    $legacyroles = get_legacy_roles();
+
     foreach ($legacyperms as $type => $perm) {
 
         $systemcontext = get_context_instance(CONTEXT_SYSTEM);
 
-        // The legacy capabilities are:
-        //   'moodle/legacy:guest'
-        //   'moodle/legacy:student'
-        //   'moodle/legacy:teacher'
-        //   'moodle/legacy:editingteacher'
-        //   'moodle/legacy:coursecreator'
-        //   'moodle/legacy:admin'
+        if (!array_key_exists($type, $legacyroles)) {
+            error('Incorrect legacy role definition for type: '.$type);
+        }
 
-        if ($roles = get_roles_with_capability('moodle/legacy:'.$type, CAP_ALLOW)) {
+        if ($roles = get_roles_with_capability($legacyroles[$type], CAP_ALLOW)) {
             foreach ($roles as $role) {
                 // Assign a site level capability.
                 if (!assign_capability($capability, $perm, $role->id, $systemcontext->id)) {
@@ -2362,6 +2375,38 @@ function get_cached_capabilities($component='moodle') {
     return $storedcaps;
 }
 
+/**
+ * Returns default capabilities for given legacy role type.
+ *
+ * @param string legacy role name
+ * @return array
+ */
+function get_default_capabilities($legacyrole) {
+    if (!$allcaps = get_records('capabilities')) {
+        error('Error: no capabilitites defined!');
+    }
+    $alldefs = array();
+    $defaults = array();
+    $components = array();
+    foreach ($allcaps as $cap) {
+        if (!array_search($cap->component, $components)) {
+            $components[] = $cap->component;
+            $alldefs = array_merge($alldefs, load_capability_def($cap->component));
+        }
+    }
+    foreach($alldefs as $name=>$def) {
+        if (isset($def['legacy'][$legacyrole])) {
+            $defaults[$name] = $def['legacy'][$legacyrole];
+        }
+    }
+
+    //some exceptions
+    $defaults['moodle/legacy:'.$legacyrole] = CAP_ALLOW;
+    if ($legacyrole == 'admin') {
+        $defaults['moodle/site:doanything'] = CAP_ALLOW;
+    }
+    return $defaults;
+}
 
 /**
  * Updates the capabilities table with the component capability definitions.
index 686a36dc93cc3d5763b5ca9c72babee2d0efeec0..cace117ca0c9ee7ef0f8ac761a7222b5cd9ce82d 100644 (file)
@@ -981,6 +981,11 @@ body#mod-quiz-report table#attempts .r1 {
   border: 1px solid #cecece;
 }
 
+#admin-roles-manage .capdefault {
+  background-color:#dddddd;
+  border: 1px solid #cecece;
+}
+
 #admin-roles-manage .rolecap,
 #admin-roles-override .rolecap {
   border:none;
index 51402871e037150272b7387a0e5702c8b16787d3..122b0aeaaaa6065c5cff22abb53c3d08562cc7cf 100644 (file)
@@ -340,6 +340,10 @@ form.popupform {
   display: inline;
 }
 
+form.popupform label {
+  margin-right: 0.5em;
+}
+
 .arrow_button {
   margin-top:3em;
 }