[LON-CAPA-cvs] cvs: loncom /auth roles.tab rolesplain.tab /interface loncommon.pm loncreateuser.pm portfolio.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Tue, 21 Nov 2006 21:38:47 -0000


This is a MIME encoded message

--raeburn1164145127
Content-Type: text/plain

raeburn		Tue Nov 21 16:38:47 2006 EDT

  Modified files:              
    /loncom/auth	roles.tab rolesplain.tab 
    /loncom/interface	loncreateuser.pm portfolio.pm loncommon.pm 
  Log:
  Users with "mpq" privilege for a domain can set and modify the portfolio quota for a user in the domain.
  
  When a user uploads a file to his/her portfolio, the user's portfolio quota is retrieved, if one has not been set, the default for the domain is used, if no default has been set, the original static value of 20 Mb for backwards compatibility.
  
  In the future we might want to consider different defaults for different types of user in a single domain.
  
  
--raeburn1164145127
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20061121163847.txt"

Index: loncom/auth/roles.tab
diff -u loncom/auth/roles.tab:1.49 loncom/auth/roles.tab:1.50
--- loncom/auth/roles.tab:1.49	Tue May  9 15:04:40 2006
+++ loncom/auth/roles.tab	Tue Nov 21 16:38:44 2006
@@ -1,6 +1,6 @@
 su:s csu&U:sma:mau:cdc&U:dro:psa:adv
 dc:s bre:sma:adv:mcr:srm
-dc:d cli&UIK:cau&UIK:cca&UIK:caa&UIK:cdg&UIK:mau:ccc&U:cin&UIK:cta&UIK:cep&UIK:ccr&UIK:cst&UIK:cad&UIK:csc&UIK:dro:mky:psa:usc
+dc:d cli&UIK:cau&UIK:cca&UIK:caa&UIK:cdg&UIK:mau:ccc&U:cin&UIK:cta&UIK:cep&UIK:ccr&UIK:cst&UIK:cad&UIK:csc&UIK:dro:mky:psa:usc:mpq
 cc:s bre:sma:mcr:vsa:adv:vcl
 cc:c cin&IK:cta&IK:cep&IK:ccr&IK:cst&IK:are:cre:ere:vgr:gan:srm:opa:mgr:mqg:mgq:rin:pch:plc:mdc:usc:vsa:vcl:mdg:vcg:pav:pfo:whn
 in:s sma:vgr:adv:vcl
Index: loncom/auth/rolesplain.tab
diff -u loncom/auth/rolesplain.tab:1.26 loncom/auth/rolesplain.tab:1.27
--- loncom/auth/rolesplain.tab:1.26	Mon Jul 17 11:17:20 2006
+++ loncom/auth/rolesplain.tab	Tue Nov 21 16:38:44 2006
@@ -45,6 +45,7 @@
 mky:Manage access keys
 mcr:Create a Course Custom Role:Create a Group Custom Role
 mau:Modify authentication mechanism and data for a user
+mpq:Modify disk space allocated to portfolio files for a user
 bre:Browse resources
 are:Assemble resources
 cre:Copy resources
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.133 loncom/interface/loncreateuser.pm:1.134
--- loncom/interface/loncreateuser.pm:1.133	Tue Nov 21 16:03:06 2006
+++ loncom/interface/loncreateuser.pm	Tue Nov 21 16:38:44 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.133 2006/11/21 21:03:06 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.134 2006/11/21 21:38:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -116,6 +116,20 @@
     return 1;
 }
 
+# ====================================================
+
+sub portfolio_quota {
+    my ($ccuname,$ccdomain) = @_;
+    my %lt = &Apache::lonlocal::texthash(
+                   'disk' => "Disk space allocated to user's portfolio files",
+    );
+    my $output = '<h3>'.$lt{'disk'}.'</h3>'.
+                 '<input type="text" name="portfolioquota" size ="5" value="'.
+                 &Apache::loncommon::get_user_quota($ccuname,$ccdomain).
+                 '" />&nbsp;Mb';
+    return $output;
+}
+
 # =================================================================== Phase one
 
 sub print_username_entry_form {
@@ -501,6 +515,11 @@
                     'hs'   => "Home Server",
                     'lg'   => "Login Data"
 				       );
+        my $portfolioform;
+        if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
+            # Current user has quota modification privileges
+            $portfolioform = &portfolio_quota($ccuname,$ccdomain);
+        }
 	my $genhelp=&Apache::loncommon::help_open_topic('Generation');
         &initialize_authen_forms();
 	$r->print(<<ENDNEWUSER);
@@ -533,6 +552,8 @@
 <p>$authformint </p>
 <p>$authformfsys</p>
 <p>$authformloc </p>
+<hr />
+$portfolioform
 ENDNEWUSER
     } else { # user already exists
 	my %lt=&Apache::lonlocal::texthash(
@@ -552,8 +573,8 @@
 ENDCHANGEUSER
         # Get the users information
         my %userenv = &Apache::lonnet::get('environment',
-                          ['firstname','middlename','lastname','generation'],
-                          $ccdomain,$ccuname);
+                          ['firstname','middlename','lastname','generation',
+                           'portfolioquota'],$ccdomain,$ccuname);
         my %rolesdump=&Apache::lonnet::dump('roles',$ccdomain,$ccuname);
         $r->print(<<END);
 <hr />
@@ -875,6 +896,10 @@
 ENDNOPRIV
                 } 
             }
+            if (&Apache::lonnet::allowed('mpq',$env{'request.role.domain'})) {
+                # Current user has quota modification privileges
+                $r->print(&portfolio_quota($ccuname,$ccdomain));
+            }
         }  ## End of "check for bad authentication type" logic
     } ## End of new user/old user logic
     $r->print('<hr /><h3>'.&mt('Add Roles').'</h3>');
@@ -1122,8 +1147,8 @@
     if (! $env{'form.makeuser'} ) {
         # Check for need to change
         my %userenv = &Apache::lonnet::get
-            ('environment',['firstname','middlename','lastname','generation'],
-             $env{'form.ccdomain'},$env{'form.ccuname'});
+            ('environment',['firstname','middlename','lastname','generation',
+             'portfolioquota'],$env{'form.ccdomain'},$env{'form.ccuname'});
         my ($tmp) = keys(%userenv);
         if ($tmp =~ /^(con_lost|error)/i) { 
             %userenv = ();
@@ -1133,13 +1158,31 @@
             # Strip leading and trailing whitespace
             $env{'form.c'.$_} =~ s/(\s+$|^\s+)//g; 
         }
+        my ($quotachanged,$namechanged,$oldportfolioquota);
+        my %changeHash;
+        if (exists($userenv{'portfolioquota'})) {
+            $oldportfolioquota = $userenv{'portfolioquota'};
+            if (exists($env{'form.portfolioquota'})) {
+                if ($env{'form.portfolioquota'} ne $userenv{'portfolioquota'}) {
+                    if (&Apache::lonnet::allowed('mpq',$env{'form.ccdomain'})) {
+                        # Current user has quota modification privileges
+                        $quotachanged = 1;
+                        $changeHash{'portfolioquota'} = $env{'form.portfolioquota'};
+                    }
+                }
+            }
+        } else {
+            $oldportfolioquota = &default_quota($env{'form.ccdomain'});
+        }
         if (&Apache::lonnet::allowed('mau',$env{'form.ccdomain'}) && 
             ($env{'form.cfirstname'}  ne $userenv{'firstname'}  ||
              $env{'form.cmiddlename'} ne $userenv{'middlename'} ||
              $env{'form.clastname'}   ne $userenv{'lastname'}   ||
              $env{'form.cgeneration'} ne $userenv{'generation'} )) {
+            $namechanged = 1;
+        }
+        if ($namechanged) {
             # Make the change
-            my %changeHash;
             $changeHash{'firstname'}  = $env{'form.cfirstname'};
             $changeHash{'middlename'} = $env{'form.cmiddlename'};
             $changeHash{'lastname'}   = $env{'form.clastname'};
@@ -1155,6 +1198,7 @@
                              'mddl' => "middle",
                              'lst'  => "last",
 			     'gen'  => "generation",
+                             'disk' => "disk space allocated to portfolio files",
                              'prvs' => "Previous",
                              'chto' => "Changed To"
 						   );
@@ -1165,17 +1209,21 @@
     <th>$lt{'frst'}</th>
     <th>$lt{'mddl'}</th>
     <th>$lt{'lst'}</th>
-    <th>$lt{'gen'}</th></tr>
+    <th>$lt{'gen'}</th>
+    <th>$lt{'disk'}<th></tr>
 <tr><td>$lt{'prvs'}</td>
     <td>$userenv{'firstname'}  </td>
     <td>$userenv{'middlename'} </td>
     <td>$userenv{'lastname'}   </td>
-    <td>$userenv{'generation'} </td></tr>
+    <td>$userenv{'generation'} </td>
+    <td>$oldportfolioquota</td>
+</tr>
 <tr><td>$lt{'chto'}</td>
     <td>$env{'form.cfirstname'}  </td>
     <td>$env{'form.cmiddlename'} </td>
     <td>$env{'form.clastname'}   </td>
-    <td>$env{'form.cgeneration'} </td></tr>
+    <td>$env{'form.cgeneration'} </td>
+    <td>$env{'form.portfolioquota'} Mb</td></tr>
 </table>
 END
             } else { # error occurred
@@ -1184,18 +1232,30 @@
                       $env{'form.ccdomain'}."</h2>");
             }
         }  else { # End of if ($env ... ) logic
+            my $putresult;
+            if ($quotachanged) {
+                $putresult = &Apache::lonnet::put
+                                 ('environment',\%changeHash,
+                                  $env{'form.ccdomain'},$env{'form.ccuname'});
+            }
             # They did not want to change the users name but we can
             # still tell them what the name is
 	    my %lt=&Apache::lonlocal::texthash(
                            'usr'  => "User",                    
                            'id'   => "in domain",
-                           'gen'  => "Generation"
+                           'gen'  => "Generation",
+                           'disk' => "Disk space allocated to user's portfolio files",
 					       );
-                $r->print(<<"END");
+            $r->print(<<"END");
 <h2>$lt{'usr'} "$env{'form.ccuname'}" $lt{'id'} "$env{'form.ccdomain'}"</h2>
 <h4>$userenv{'firstname'} $userenv{'middlename'} $userenv{'lastname'} </h4>
 <h4>$lt{'gen'}: $userenv{'generation'}</h4>
 END
+            if ($putresult eq 'ok') {
+                if ($oldportfolioquota ne $env{'form.portfolioquota'}) {
+                    $r->print('<h4>'.$lt{'disk'}.': '.$env{'form.portfolioquota'}.' Mb</h4>');
+                }
+            }
         }
     }
     ##
Index: loncom/interface/portfolio.pm
diff -u loncom/interface/portfolio.pm:1.172 loncom/interface/portfolio.pm:1.173
--- loncom/interface/portfolio.pm:1.172	Thu Nov  9 17:33:32 2006
+++ loncom/interface/portfolio.pm	Tue Nov 21 16:38:44 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # portfolio browser
 #
-# $Id: portfolio.pm,v 1.172 2006/11/09 22:33:32 raeburn Exp $
+# $Id: portfolio.pm,v 1.173 2006/11/21 21:38:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1748,7 +1748,7 @@
     my ($r,$url,$group)=@_;
     my $fname=$env{'form.uploaddoc.filename'};
     my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
-    my $disk_quota = 20000; # expressed in k
+    my $disk_quota;
     if (defined($group)) {
         my $grp_quota = &get_group_quota($group); # quota expressed in k 
         if ($grp_quota ne '') {
@@ -1756,6 +1756,10 @@
         } else {
             $disk_quota = 0;
         }
+    } else {
+        $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
+                                    $env{'user.domain'}); #expressed in Mb
+        $disk_quota = 1000 * $disk_quota; # convert from Mb to kb
     }
     $fname=&Apache::lonnet::clean_filename($fname);
 
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.471 loncom/interface/loncommon.pm:1.472
--- loncom/interface/loncommon.pm:1.471	Mon Nov 20 16:00:47 2006
+++ loncom/interface/loncommon.pm	Tue Nov 21 16:38:44 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.471 2006/11/20 21:00:47 banghart Exp $
+# $Id: loncommon.pm,v 1.472 2006/11/21 21:38:44 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4612,6 +4612,96 @@
     return;
 }
 
+###############################################
+
+=pod
+
+=item * &get_user_quota()
+
+Retrieves quota assigned for storage of portfolio files for a user  
+
+Incoming parameters:
+1. user's username
+2. user's domain
+
+Returns:
+1. Disk quota (in Mb) assigned to student. 
+
+If a value has been stored in the user's environment, 
+it will return that, otherwise it returns the default
+for users in the domain.
+
+=cut
+
+###############################################
+
+
+sub get_user_quota {
+    my ($uname,$udom) = @_;
+    my $quota;
+    if (!defined($udom)) {
+        $udom = $env{'user.domain'};
+    }
+    if (!defined($uname)) {
+        $uname = $env{'user.name'};
+    }
+    if (($udom eq '' || $uname eq '') ||
+        ($udom eq 'public') && ($uname eq 'public')) {
+        $quota = 0;
+    } else {
+        if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
+            $quota = $env{'environment.portfolioquota'};
+        } else {
+            my %userenv = &Apache::lonnet::dump('environment',$udom,$uname);
+            my ($tmp) = keys(%userenv);
+            if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
+                $quota = $userenv{'portfolioquota'};
+            } else {
+                undef(%userenv);
+            }
+        }
+        if ($quota eq '') {
+            $quota = &default_quota($udom);
+        }
+    }
+    return $quota;
+}
+
+###############################################
+
+=pod
+
+=item * &default_quota()
+
+Retrieves default quota assigned for storage of user portfolio files
+
+Incoming parameters:
+1. domain
+
+Returns:
+1. Default disk quota (in Mb) for user portfolios in the domain.
+
+If a value has been stored in the domain's configuration db,
+it will return that, otherwise it returns 20 (for backwards 
+compatibility with domains which have not set up a configuration
+db file; the original statically defined portfolio quota was 20 Mb). 
+
+=cut
+
+###############################################
+
+
+sub default_quota {
+    my ($udom) = @_;
+    my %defaults = &Apache::lonnet::get_dom('configuration',
+                                            ['portfolioquota'],$udom);
+    if ($defaults{'portfolioquota'} ne '') {
+        return $defaults{'portfolioquota'};
+    } else {
+        return '20';
+    }
+}
+
 sub get_secgrprole_info {
     my ($cdom,$cnum,$needroles,$type)  = @_;
     my %sections_count = &get_sections($cdom,$cnum);

--raeburn1164145127--