[LON-CAPA-cvs] cvs: loncom /interface londocs.pm

raeburn raeburn at source.lon-capa.org
Sat Nov 26 10:39:52 EST 2016


raeburn		Sat Nov 26 15:39:52 2016 EDT

  Modified files:              
    /loncom/interface	londocs.pm 
  Log:
  - Support case where custom role can access Course Editor, but adv priv  
    not set at system level for current role.
  
    - Both hiddenresource and encryturl parameters set at map level apply 
    (recursively) to display of folder listing in Course Editor. 
  
    - If hiddenresource parameter set at general (in Course) or at enclosing
    map or folder for resource in top level of course, Course Editor shows
    "Main Content Hidden" for Main Content Editor.
  
  
-------------- next part --------------
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.614 loncom/interface/londocs.pm:1.615
--- loncom/interface/londocs.pm:1.614	Sat Nov 26 01:28:14 2016
+++ loncom/interface/londocs.pm	Sat Nov 26 15:39:52 2016
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.614 2016/11/26 01:28:14 raeburn Exp $
+# $Id: londocs.pm,v 1.615 2016/11/26 15:39:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2970,7 +2970,8 @@
 
 sub editor {
     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
-        $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,$canedit)=@_;
+        $supplementalflag,$orderhash,$iconpath,$pathitem,$ltitoolsref,
+        $canedit,$navmapref,$hiddentop)=@_;
     my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
     if ($allowed) {
         (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
@@ -2993,9 +2994,21 @@
         $randompick = -1;
     }
 
-    my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
-				    $folder.'.'.$container);
-    return $errtext if ($fatal);
+    my ($errtext,$fatal);
+    if (($folder eq '') && (!$supplementalflag)) {
+        if (@LONCAPA::map::order) {
+            undef(@LONCAPA::map::order);
+            undef(@LONCAPA::map::resources);
+            undef(@LONCAPA::map::resparms);
+            undef(@LONCAPA::map::zombies);
+        }
+        $folder = 'default';
+        $container = 'sequence'; 
+    } else {
+        ($errtext,$fatal) = &mapread($coursenum,$coursedom,
+				     $folder.'.'.$container);
+        return $errtext if ($fatal);
+    }
 
     if ($#LONCAPA::map::order<1) {
 	my $idx=&LONCAPA::map::getresidx();
@@ -3287,7 +3300,7 @@
         $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
                               $coursenum,$coursedom,$crstype,
                               $pathitem,$supplementalflag,$container,
-                              \%filters,\%curr_groups,$ltitoolsref,$canedit,$isencrypted);
+                              \%filters,\%curr_groups,$ltitoolsref,$canedit,$isencrypted,$navmapref);
         $idx++;
         $shown++;
     }
@@ -3369,9 +3382,15 @@
             if (!$allowed) {
                 $to_show .= $toolslink;
             }
+            my $noresmsg;
+            if ($allowed && $hiddentop && !$supplementalflag) {
+                $noresmsg = &mt('Main Content Hidden'); 
+            } else {
+                $noresmsg = &mt('Currently empty');
+            }
             $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
                        .'<div class="LC_info" id="contentlist">'
-                       .&mt('Currently empty')
+                       .$noresmsg
                        .'</div>'
                        .&Apache::loncommon::end_scrollbox();
         }
@@ -3662,7 +3681,7 @@
 sub entryline {
     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
         $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups,
-        $ltitoolsref,$canedit,$isencrypted)=@_;
+        $ltitoolsref,$canedit,$isencrypted,$navmapref)=@_;
     my ($foldertitle,$renametitle,$oldtitle);
     if (&is_supplemental_title($title)) {
 	($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
@@ -3888,6 +3907,7 @@
     my $isfolder;
     my $ispage;
     my $containerarg;
+    my $folderurl;
     if ($uploaded) {
         if (($extension eq 'sequence') || ($extension eq 'page')) {
             $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
@@ -3899,6 +3919,7 @@
                 $icon=$iconpath.'page.gif';
                 $ispage=1;
             }
+            $folderurl = &Apache::lonnet::declutter($url);
             if ($allowed) {
                 $url='/adm/coursedocs?';
             } else {
@@ -3944,15 +3965,31 @@
                     }
                 }
                 $url.=(($url=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
-            } elsif ((!$env{'request.role.adv'}) &&
-                     (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
-                      $isencrypted)) {
-                my $shownsymb = &Apache::lonenc::encrypted($symb);
-                my $shownurl = &Apache::lonenc::encrypted($url);
-                if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
-                    $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
-                    if ($env{'request.enc'} ne '') {
-                        delete($env{'request.enc'});
+            } elsif (!$env{'request.role.adv'}) {
+                my $checkencrypt;
+                if (((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) ||
+                      $isencrypted || (&Apache::lonnet::EXT('resource.0.encrypturl',$symb) =~ /^yes$/i)) {
+                    $checkencrypt = 1;
+                } else {
+                    unless (ref($$navmapref)) {
+                        $$navmapref = Apache::lonnavmaps::navmap->new();
+                    }
+                    if (ref($$navmapref)) {
+                        if (lc($$navmapref->get_mapparam($symb,undef,"0.encrypturl")) eq 'yes') {
+                            $checkencrypt = 1;       
+                        }
+                    }
+                }
+                if ($checkencrypt) {
+                    my $shownsymb = &Apache::lonenc::encrypted($symb);
+                    my $shownurl = &Apache::lonenc::encrypted($url);
+                    if (&Apache::lonnet::symbverify($shownsymb,$shownurl)) {
+                        $url = $shownurl.(($shownurl=~/\?/)?'&':'?').'symb='.&HTML::Entities::encode($shownsymb,'"<>&');
+                        if ($env{'request.enc'} ne '') {
+                            delete($env{'request.enc'});
+                        }
+                    } else {
+                        $url='';
                     }
                 } else {
                     $url='';
@@ -3969,7 +4006,7 @@
             }
         }
     }
-    my ($rand_pick_text,$rand_order_text);
+    my ($rand_pick_text,$rand_order_text,$hiddenfolder);
     if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
 	my $foldername=&escape($foldertitle);
 	my $folderpath=$env{'form.folderpath'};
@@ -3990,11 +4027,24 @@
                                                .':'.((&LONCAPA::map::getparameter($orderidx,
                                               'parameter_randomorder'))[0]=~/^yes$/i)
                                                .':'.$ispage;
-            if ($env{'request.role.adv'} ||
-                (&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]!~/^yes$/i) {
+            if (!$env{'request.role.adv'}) {
+                if (lc((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]) eq 'yes') {
+                    $url = '';
+                    $hiddenfolder = 1;
+                } else {
+                    unless (ref($$navmapref)) {
+                        $$navmapref = Apache::lonnavmaps::navmap->new();
+                    }
+                    if (ref($$navmapref)) {
+                        if (lc($$navmapref->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
+                            $url = '';
+                            $hiddenfolder = 1;
+                        }
+                    }
+                }
+            }
+            unless ($url eq '') {
                 $url.='folderpath='.&escape($folderpath);
-            } else {
-                $url = '';
             }
             my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
                                                         'parameter_randompick'))[0];
@@ -4117,6 +4167,8 @@
        $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes'.
                                              (($anchor ne '')?$anchor:''),
                                              $title,600,500);
+    } elsif ($hiddenfolder) {
+       $line.=$title.' <span class="LC_warning LC_docs_reinit_warn">'.&mt('(Hidden)').'</span>';
     } else {
        $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
     }
@@ -5056,6 +5108,8 @@
     my $containertag;
     my $pathitem;
     my %ltitools;
+    my $navmap;
+    my $hiddentop; 
 
 # Do we directly jump somewhere?
 
@@ -5095,7 +5149,14 @@
     if ((!$env{'form.folderpath'}) && $allowed) {
         &Apache::loncommon::restore_course_settings($stored_folderpath,
                                           {'folderpath' => 'scalar'});
-        unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
+
+        if (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
+            if ($supplementalflag) {
+                undef($env{'form.folderpath'}) if ($1 eq 'default'); 
+            } else {
+                undef($env{'form.folderpath'}) if ($1 eq 'supplemental');
+            }
+        } else {
             undef($env{'form.folderpath'});
         }
     }
@@ -5112,6 +5173,31 @@
                                   .'&'.
                                   $env{'form.folderpath'};
     }
+# If allowed and user's role is not advanced check folderpath is not hidden  
+    if (($allowed) && (!$env{'request.role.adv'}) && 
+        ($env{'form.folderpath'} ne '') && (!$supplementalflag)) {
+        my $folderurl;
+        my @pathitems = split(/\&/,$env{'form.folderpath'});
+        my $container = $pathitems[-2];
+        if ($container ne '') {
+            $folderurl = "uploaded/$coursedom/$coursenum/$container";
+            if ((split(/\:/,$pathitems[-1]))[4]) {
+                $folderurl .= '.page';
+            } else {
+                $folderurl .= '.sequence';
+            }
+            $navmap = Apache::lonnavmaps::navmap->new();
+            if (ref($navmap)) {
+                if (lc($navmap->get_mapparam(undef,$folderurl,"0.hiddenresource")) eq 'yes') {
+                    undef($env{'form.folderpath'});
+                }
+            }
+        } else {
+            undef($env{'form.folderpath'});    
+        }
+    }
+
+
 # If after all of this, we still don't have any paths, make them
     unless ($env{'form.folderpath'}) {
        if ($supplementalflag) {
@@ -5119,12 +5205,29 @@
        } else {
           $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
                                   ':::::');
+          if (($allowed) && (!$env{'request.role.adv'})) {
+# If allowed and user's role is not advanced check entire course is not hidden
+              unless (ref($navmap)) {
+                  $navmap = Apache::lonnavmaps::navmap->new();
+              }
+              if (ref($navmap)) {
+                  if (lc($navmap->get_mapparam(undef,"uploaded/$coursedom/$coursenum/default.sequence",
+                                               "0.hiddenresource")) eq 'yes') {
+                      undef($env{'form.folderpath'});
+                      $hiddentop = 1;
+                      if ($env{'form.folder'}) {
+                          undef($env{'form.folder'});
+                      }
+                  }
+              }
+          }
        }
     }
 
+
 # Store this
     unless ($toolsflag) {
-        if ($allowed) {
+        if (($allowed) && ($env{'form.folderpath'} ne '')) {
             &Apache::loncommon::store_course_settings($stored_folderpath,
                                                       {'folderpath' => 'scalar'});
         }
@@ -5562,9 +5665,11 @@
         if ($folder eq '') {
             $folder='default';
         }
-	my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
-        if ($output) {
-            $r->print($output);
+        if ($canedit) {
+	    my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
+            if ($output) {
+                $r->print($output);
+            }
         }
 	$r->print(<<HIDDENFORM);
 	<form name="renameform" method="post" action="/adm/coursedocs">
@@ -5601,7 +5706,7 @@
 
     if ($allowed) {
        my $folder=$env{'form.folder'};
-       if ($folder eq '' || $supplementalflag) {
+       if ((($folder eq '') && (!$hiddentop)) || ($supplementalflag)) {
            $folder='default';
 	   $savefolderpath = $env{'form.folderpath'};
 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
@@ -6065,7 +6170,8 @@
  $hadchanges=0;
        unless (($supplementalflag || $toolsflag)) {
           my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
-                              $supplementalflag,\%orderhash,$iconpath,$pathitem,\%ltitools,$canedit);
+                              $supplementalflag,\%orderhash,$iconpath,$pathitem,
+                              \%ltitools,$canedit,\$navmap,$hiddentop);
           if ($error) {
              $r->print('<p><span class="LC_error">'.$error.'</span></p>');
           }
@@ -6212,7 +6318,8 @@
                 );
         if ($supplementalflag) {
            my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
-                               $supplementalflag,\%suporderhash,$iconpath,$pathitem,\%ltitools,$canedit);
+                               $supplementalflag,\%suporderhash,$iconpath,$pathitem,
+                               \%ltitools,$canedit,\$navmap);
            if ($error) {
               $r->print('<p><span class="LC_error">'.$error.'</span></p>');
            } else {
@@ -6232,7 +6339,7 @@
         }
     } elsif ($supplementalflag) {
         my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
-                            $supplementalflag,'',$iconpath,$pathitem,$canedit);
+                            $supplementalflag,'',$iconpath,$pathitem);
         if ($error) {
             $r->print('<p><span class="LC_error">'.$error.'</span></p>');
         }


More information about the LON-CAPA-cvs mailing list