[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm /interface loncoursequeueadmin.pm lonrequestcourse.pm

raeburn raeburn at source.lon-capa.org
Wed Aug 15 10:37:23 EDT 2012


raeburn		Wed Aug 15 14:37:23 2012 EDT

  Modified files:              
    /loncom/interface	loncoursequeueadmin.pm lonrequestcourse.pm 
    /loncom/auth	lonroles.pm 
  Log:
  - Requests author roles by users who do not have them.
    - Move code from lonroles.pm to new routines in loncoursequeueadmin.pm
      is_active_author(), author_prompt(), reqauthor_check(), process_reqauthor()
      to facilitate re-use.
    - At conclusion of course/community request process, offer option to
      request an author role to users without one, who have to rights to
      request one.
  
  
-------------- next part --------------
Index: loncom/interface/loncoursequeueadmin.pm
diff -u loncom/interface/loncoursequeueadmin.pm:1.30 loncom/interface/loncoursequeueadmin.pm:1.31
--- loncom/interface/loncoursequeueadmin.pm:1.30	Tue Aug 14 15:45:06 2012
+++ loncom/interface/loncoursequeueadmin.pm	Wed Aug 15 14:37:13 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Utilities to administer domain course requests and course self-enroll requests
 #
-# $Id: loncoursequeueadmin.pm,v 1.30 2012/08/14 15:45:06 raeburn Exp $
+# $Id: loncoursequeueadmin.pm,v 1.31 2012/08/15 14:37:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -70,6 +70,14 @@
 
 =item process_official_reqs()
 
+=item is_active_author()
+
+=item author_prompt()
+
+=item reqauthor_check()
+
+=item process_reqauthor()
+
 =back
 
 =cut
@@ -101,7 +109,7 @@
     } elsif ($context eq 'domainmanagers') {
         $rawsubj = 'Course/Community requests reviewed';
         push(@rawmsg,{
-                      mt  => 'Course/Community creation requests in the following domain: [_1] have been reviewed.',
+                      mt  => 'Course/Community creation requests in the following domain: "[_1]" have been reviewed.',
                       args => ["\n$contextdesc"],
                      });
         if (ref($textstr) eq 'ARRAY') {
@@ -110,7 +118,7 @@
     } elsif ($context eq 'authormanagers') {
         $rawsubj = 'Authoring space requests reviewed';
         push(@rawmsg,{
-                      mt  => 'Authoring requests in the following domain: [_1] have been reviewed.',
+                      mt  => 'Authoring requests in the following domain: "[_1]" have been reviewed.',
                       args => ["\n$contextdesc"],
                      });
         if (ref($textstr) eq 'ARRAY') {
@@ -170,14 +178,14 @@
                      },
                      {
                       mt =>'[_1]As Domain Coordinator, use: [_2]Main Menu -> Course and community creation -> Approve or reject requests[_3]to display a list of pending requests, which you can either approve or reject.',
-                      args => ["\n","\n\n  ","\n\n"],
+                      args => ["\n","\n\n","\n\n"],
                      });
     } elsif ($context eq 'selfenrollreq') {
         $rawsubj = 'Self-enrollment request';
         if ($crstype eq 'community') {
-            $msgtxt = 'Enrollment in the following community: [_1] was requested by [_2] on [_3].'
+            $msgtxt = 'Enrollment in the following community: [_1]was requested by [_2] on [_3].'
         } else {
-            $msgtxt = 'Enrollment in the following course: [_1] was requested by [_2] on [_3].'
+            $msgtxt = 'Enrollment in the following course: [_1]was requested by [_2] on [_3].'
         }
         push(@rawmsg,{
                       mt  => $msgtxt,
@@ -196,7 +204,7 @@
                      });
     } elsif ($context eq 'authorreq') {
         $rawsubj = 'Authoring space request to review';
-        $msgtxt = 'Assignment of an author role in the [_1] domain[_2] was requested by [_3] on [_4].';
+        $msgtxt = 'Assignment of an author role in the [_1] domain[_2]was requested by [_3] on [_4].';
         push(@rawmsg,{
                       mt  => $msgtxt,
                       args => [$contextdesc,"\n",$textstr,$timestamp],
@@ -1783,4 +1791,142 @@
     return $output;
 }
 
+sub is_active_author {
+    if ($env{'user.role.au./'.$env{'user.domain'}.'/'} =~ /^(\d*)\.(\d*)$/) {
+        if ((!$1 || $1 < time) &&
+            (!$2 || $2 > time)) {
+            return 1;
+        }
+    }
+}
+
+sub author_prompt {
+    my ($is_active_author,$offer_author);
+    if ($env{'environment.canrequest.author'}) {
+        unless (&is_active_author()) {
+            if ($env{'environment.canrequest.author'}) {
+                unless (&reqauthor_check() =~ /^approval:\d+$/) {
+                    $offer_author = 1;
+                }
+            }
+        }
+    }
+    return $offer_author;
+}
+
+sub reqauthor_check {
+    my $queued = $env{'environment.requestauthorqueued'};
+    my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
+                                         $env{'user.domain'},$env{'user.name'});
+    my $reqstatus = $reqauthor{'author_status'};
+    if (($reqstatus eq '' && $queued ne '') ||
+        ($env{'environment.requestauthorqueued'} !~ /^\Q$reqstatus\E/)) {
+        if (ref($reqauthor{'author'}) eq 'HASH') {
+            $queued = $reqstatus.':'.$reqauthor{'author'}{'timestamp'};
+        } else {
+            undef($queued);
+        }
+        &Apache::lonnet::appenv({'environment.requestauthorqueued' => $queued});
+    }
+    return $queued;
+}
+
+sub process_reqauthor {
+    my ($dispositionref,$updateref) = @_;
+    if (&is_active_author()) {
+        return '<span class="LC_warning">'.
+                &mt('An authoring space has already been assigned to you.').'<br />'.
+                &mt('Please select the Author role from your [_1]roles page[_2].','<a href="/adm/roles">',
+                '</a>').'</span>';
+    }
+    unless ($env{'environment.canrequest.author'}) {
+        return '<span class="LC_warning">'.
+                &mt('You do not currently have rights to request an authoring space.').'<br />'.
+                &mt('Please contact the [_1]helpdesk[_2].','<a href="/adm/helpdesk">',
+                '</a>').'</span>';
+    }
+    my $queued = &reqauthor_check();
+    if ($queued =~ /^approval:(\d+)$/) {
+        my $timestamp = $1;
+        return '<span class="LC_info">'.
+               &mt('A request for authoring space submitted on [_1] is awaiting approval',
+               &Apache::lonlocal::locallocaltime($timestamp)).
+               '</span>';
+    } elsif ($queued =~ /^approved:(\d+)$/) {
+        my $timestamp = $1;   
+        my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
+                                                      ['active'],['au'],[$env{'user.domain'}]);
+        if (keys(%roleshash) > 0) {
+            return '<span class="LC_info">'.
+                   &mt('A request for authoring space submitted on [_1] has been approved.',
+                   &Apache::lonlocal::locallocaltime($timestamp)).
+                   '</span>';
+        }
+    }
+    my ($output, at inststatuses,%domconfig);
+    %domconfig = &Apache::lonnet::get_dom('configuration',['requestauthor'],
+                                          $env{'user.domain'});
+    my $val = &get_processtype('requestauthor',$env{'user.name'},$env{'user.domain'},
+                               $env{'user.adv'},$env{'user.domain'},undef,
+                               \@inststatuses,\%domconfig);
+    my $now = time;
+    if ($val eq 'automatic') {
+        my $start = $now-1;
+        if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
+                                        'au',undef,$start,undef,undef,'requestauthor') eq 'ok') {
+            $output = '<span class="LC_info">'.
+                      &mt('Access to authoring space has been activated').'</span><br />';
+                      &Apache::lonroles::update_session_roles();
+            &Apache::lonnet::appenv({'user.update.time'  => $now});
+            if (ref($updateref)) {
+                $$updateref = $now;
+            }
+            if (ref($dispositionref)) {
+                $$dispositionref = 'created';
+            }
+        } else {
+            $output = '<span class="LC_info">'.
+                      &mt('An error occurred while activating your access to authoring space');
+        }
+    } elsif ($val eq 'approval') {
+        my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
+        if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
+                                 $env{'user.domain'},$domconfiguser) eq 'ok') {
+            my %userrequest = (
+                author => {
+                            timestamp   => $now,
+                            status      => $val,
+                          },
+                author_status => $val,
+            );
+            my $req_notifylist;
+            if (ref($domconfig{'requestauthor'}) eq 'HASH') {
+                if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
+                    my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
+                    if ($req_notifylist) {
+                        my $fullname = &Apache::loncommon::plainname($env{'user.name'},
+                                                                     $env{'user.domain'});
+                        my $sender = $env{'user.name'}.':'.$env{'user.domain'};
+                        my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
+                        &send_selfserve_notification($req_notifylist,
+                                                     "$fullname ($env{'user.name'}:$env{'user.domain'})",
+                                                     undef,$domdesc,$now,'authorreq',$sender);
+                    }
+                }
+            }
+            my $userresult =
+                &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
+            $output = '<span class="LC_info">'.
+                      &mt('Your request for authoring space has been submitted for approval.').
+                      '</span>';
+            &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
+        } else {
+            $output = '<span class="LC_info">'.
+                      &mt('An error occurred saving your request for authoring space.').
+                      '</span>';
+        }
+    }
+    return $output;
+}
+
 1;
Index: loncom/interface/lonrequestcourse.pm
diff -u loncom/interface/lonrequestcourse.pm:1.64 loncom/interface/lonrequestcourse.pm:1.65
--- loncom/interface/lonrequestcourse.pm:1.64	Tue Aug 14 15:45:06 2012
+++ loncom/interface/lonrequestcourse.pm	Wed Aug 15 14:37:13 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Request a course
 #
-# $Id: lonrequestcourse.pm,v 1.64 2012/08/14 15:45:06 raeburn Exp $
+# $Id: lonrequestcourse.pm,v 1.65 2012/08/15 14:37:13 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -147,6 +147,12 @@
         }
     }
 
+    if (($action eq 'new') && (&Apache::loncoursequeueadmin::author_prompt())) {
+        if (ref($states{$action}) eq 'ARRAY') {
+            push(@{$states{$action}},'reqauthor');
+        }
+    }
+
     foreach my $key (keys(%states)) {
         if (ref($states{$key}) eq 'ARRAY') {
             unshift (@{$states{$key}},'crstype');
@@ -162,6 +168,7 @@
                  personnel     => 'Personnel',
                  review        => 'Review',
                  process       => 'Result',
+                 reqauthor     => 'Authoring Space Result',
                  pick_request  => 'Display Summary',
                  details       => 'Request Details',
                  cancel        => 'Cancel Request',
@@ -439,7 +446,7 @@
                     $crumb = &Apache::lonhtmlcommon::breadcrumbs('Course/Community Requests','Course_Requests');
                     last;
                 } else {
-                    if (($$state eq 'process') || ($$state eq 'removal')) {
+                    if (($$state eq 'process') || ($$state eq 'removal') || ($$state eq 'reqauthor')) {
                         &Apache::lonhtmlcommon::add_breadcrumb(
                             { href => '/adm/requestcourse',
                               text => "$trail->{$states->{$action}[$i]}",
@@ -1444,13 +1451,71 @@
                                                            \@code_order);
         $r->print($result);
         if (($storeresult eq 'ok') || ($storeresult eq 'created')) {
-            $r->print('<p>');
             if ($storeresult eq 'ok') {
-                $r->print('<a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
-                          &mt('Modify this request').'</a>'.(' 'x4));
+                $r->print('<p><a href="/adm/requestcourse?action=view&state=details&showdom='.$dom.'&cnum='. $env{'form.cnum'}.'">'.
+                          &mt('Modify this request').'</a>'.(' 'x4).
+                          '<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
+            }
+            if (&Apache::loncoursequeueadmin::author_prompt()) {
+                $r->print('<h3>'.&mt('Access to authoring space').'</h3>'.
+                          '<p>'.
+                          &mt('Although assessment items can be created directly inside a course, such items only use part of the assessment capabilities of LON-CAPA.').
+                          '<br />'.
+                          &mt('By contrast, items created in authoring space, then imported into a course, can use all of the features of the assessment engine.').'</p>'.
+                          '<p>'.&mt('Request authoring space access now?').
+                          '<span class="LC_nobreak"> '.
+                          '<label><input type="radio" name="requestauthor" value="1" />'.&mt('Yes').'</label>'.
+                          (' 'x2).
+                          '<label><input type="radio" name="requestauthor" value="0" checked="checked"/>'.&mt('No').'</label>'.
+                          '</span></p>'.
+                          '<input type="submit" name="newauthor" value="'.&mt('Submit authoring request').'" />'.
+                          '<input type="hidden" name="state" value="reqauthor" />'.
+                          '<input type="hidden" name="action" value="'.$env{'form.action'}.'" />'.
+                          '<input type="hidden" name="cnum" value="'.$env{'form.cnum'}.'" />'.
+                          '<input type="hidden" name="showdom" value="'.$env{'form.showdom'}.'" />'.
+                          '<input type="hidden" name="crstype" value="'.$env{'form.crstype'}.'" />'.
+                          '<input type="hidden" name="disposition" value="'.$storeresult.'" />'.
+                          '<br />');
+            } elsif ($storeresult eq 'created') {
+                $r->print('<p><a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
+            }
+        }
+    } elsif ($state eq 'reqauthor') {
+        my ($result, at links); 
+        if ($env{'form.requestauthor'}) {
+            $r->print(&Apache::loncoursequeueadmin::process_reqauthor(\$result));
+            if ($result eq 'created') {
+                my $role = 'au';
+                my $spec = "$role./$env{'form.showdom'}/";
+                push(@links,&mt('Enter your authoring space with role: [_1]',
+                                '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.
+                                &Apache::lonnet::plaintext($role).'</a>'));
             }
-            $r->print('<a href="/adm/requestcourse">'.&mt('Make another request').'</a></p>');
-            return;
+        }
+        if (($env{'form.disposition'} eq 'created') &&
+            ($env{'form.cnum'} =~ /^$match_courseid$/) &&
+            ($env{'form.showdom'} =~ /^$match_domain$/)) {
+            my ($spec,$area,$role,$type);
+            my $role = 'cc';
+            my $spec = "$role./$env{'form.showdom'}/$env{'form.cnum'}";
+            my $type = 'Course';
+            if ($env{'form.crstype'} eq 'community') {
+                $type = 'Community';
+            }
+            my $showrole = &Apache::lonnet::plaintext($role,$type);
+            unshift(@links,&mt('Enter new course with role: [_1]',
+                               '<a href="/adm/roles?selectrole=1&'.$spec.'=1">'.$showrole.'</a>'));
+        }
+        if (@links > 1) {
+            $r->print(&mt('New roles will be listed on your [_1]Roles[_2] page.',
+                          '<a href="/adm/roles">','</a>').'&nbsp'.&mt('Choose a role:').
+                       '<ul>');
+            foreach my $link (@links) {
+                $r->print('<li>'.$link.'</li>');
+            }
+            $r->print('</ul>');
+        } elsif (@links == 1) {
+            $r->print('<p>'.$links[0].'</p>');
         }
     }
     my @excluded = &get_excluded_elements($dom,$states,$action,$state);
@@ -1480,15 +1545,18 @@
                 $count ++;
             }
             $env{'form.persontotal'} = $count;
-             
         }
     }
     if ($state eq 'enrollment') {
         push(@excluded,('sectotal','crosslisttotal'));
     }
-    $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
-    &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
-                        $navtxt{'next'},$state);
+    if (($state eq 'process') || ($state eq 'reqauthor')) {
+        $r->print('</form>');
+    } else {
+        $r->print(&Apache::lonhtmlcommon::echo_form_input(\@excluded).'</form>');
+        &display_navbuttons($r,$dom,$formname,$prev,$navtxt{'prev'},$next,
+                            $navtxt{'next'},$state);
+    }
     return;
 }
 
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.271 loncom/auth/lonroles.pm:1.272
--- loncom/auth/lonroles.pm:1.271	Tue Aug 14 17:35:04 2012
+++ loncom/auth/lonroles.pm	Wed Aug 15 14:37:23 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.271 2012/08/14 17:35:04 raeburn Exp $
+# $Id: lonroles.pm,v 1.272 2012/08/15 14:37:23 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -225,96 +225,13 @@
         $updateresult .= &update_session_roles();
         &Apache::lonnet::appenv({'user.update.time'  => $now});
         $update = $now;
-        &reqauthor_check();
+        &Apache::loncoursequeueadmin::reqauthor_check();
     }
 
 # -------------------------------------------------- Check for author requests
-
     my $reqauthor;
     if ($env{'form.requestauthor'}) {
-        if ($env{'environment.canrequest.author'}) {
-            unless (&is_active_author()) {
-                my $queued = &reqauthor_check();
-                my $skipreq;
-                if ($queued =~ /^approval:\d+$/) {
-                    my ($status,$timestamp) = split(/:/,$env{'environment.requestauthorqueued'});
-                    if ($status eq 'approval') {
-                        $reqauthor = '<span class="LC_info">'.
-                                     &mt('A request for authoring space submitted on [_1] is awaiting approval',
-                                         &Apache::lonlocal::locallocaltime($timestamp)).
-                                     '</span>';
-                    }
-                    $skipreq = 1;
-                } elsif ($queued =~ /^approved:\d+$/) {
-                    my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles',
-                                                                  ['active'],['au'],[$env{'user.domain'}]);
-                    if (keys(%roleshash) > 0) {
-                        $skipreq = 1; 
-                    }
-                }
-                unless ($skipreq) {
-                    my (@inststatuses,%domconfig);
-                    %domconfig =
-                        &Apache::lonnet::get_dom('configuration',
-                                                 ['requestauthor'],$env{'user.domain'});
-                    my $val = &Apache::loncoursequeueadmin::get_processtype('requestauthor',$env{'user.name'},
-                                                                            $env{'user.domain'},$env{'user.adv'},
-                                                                            $env{'user.domain'},undef,
-                                                                            \@inststatuses,\%domconfig);
-                    if ($val eq 'automatic') {
-                        my $start = $now-1;
-                        if (&Apache::lonnet::assignrole($env{'user.domain'},$env{'user.name'},'/'.$env{'user.domain'}.'/',
-                                                        'au',undef,$start,undef,undef,'requestauthor') eq 'ok') {
-                            $reqauthor = '<span class="LC_info">'.
-                                         &mt('Access to authoring space has been activated').'</span><br />';
-                                         &update_session_roles();
-                            &Apache::lonnet::appenv({'user.update.time'  => $now});
-                            $update = $now;
-                        } else {
-                            $reqauthor = '<span class="LC_info">'.
-                                         &mt('An error occurred while activating your access to authoring space');   
-                        }
-                    } elsif ($val eq 'approval') {
-                        my $domconfiguser = &Apache::lonnet::get_domainconfiguser($env{'user.domain'});
-                        if (&Apache::lonnet::put('requestauthorqueue',{ $env{'user.name'}.'_'.$val => $now },
-                                                 $env{'user.domain'},$domconfiguser) eq 'ok') {
-                            my %userrequest = (
-                                author => {
-                                          timestamp   => $now,
-                                          status      => $val,
-                                        },
-                                author_status => $val,
-                            );
-                            my $req_notifylist;
-                            if (ref($domconfig{'requestauthor'}) eq 'HASH') {
-                                if (ref($domconfig{'requestauthor'}{'notify'}) eq 'HASH') {
-                                    my $req_notifylist = $domconfig{'requestauthor'}{'notify'}{'approval'};
-                                    if ($req_notifylist) {
-                                        my $fullname = &Apache::loncommon::plainname($env{'user.name'},
-                                                                                     $env{'user.domain'});
-                                        my $sender = $env{'user.name'}.':'.$env{'user.domain'};
-                                        my $domdesc = &Apache::lonnet::domain($env{'user.domain'},'description');
-                                        &Apache::loncoursequeueadmin::send_selfserve_notification($req_notifylist,
-                                            "$fullname ($env{'user.name'}:$env{'user.domain'})",undef,$domdesc,
-                                            $now,'authorreq',$sender);
-                                    }
-                                }
-                            }
-                            my $userresult =
-                                &Apache::lonnet::put('requestauthor',\%userrequest,$env{'user.domain'},$env{'user.name'});
-                            $reqauthor = '<span class="LC_info">'.
-                                         &mt('Your request for authoring space has been submitted for approval.').
-                                         '</span>';
-                            &Apache::lonnet::appenv({'environment.requestauthorqueued' => $val.':'.$now});
-                        } else {
-                            $reqauthor = '<span class="LC_info">'.
-                                         &mt('An error occurred saving your request for authoring space.').
-                                         '</span>';
-                        }
-                    }
-                }
-            }
-        }
+       $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
     }
 
     my $envkey;


More information about the LON-CAPA-cvs mailing list