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

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 04 Jan 2007 16:54:07 -0000


raeburn		Thu Jan  4 11:54:07 2007 EDT

  Modified files:              
    /loncom/interface	lonmsgdisplay.pm 
  Log:
  If currently viewing a message in the context of a role in the course, check if rsource referred to by message should be encrypted using lonnet::EXT().
  
  Both symb and url are encrypted in display of links, unless viewer has $env{'request.role.adv'}.
  
  Only do check of browse access to the unencrypted baseurl, if not in course context, to determine whether to display "Refers to" link.  (Addresses case where a resource encrypted in one course, is used unencrypted in another).
  
  
Index: loncom/interface/lonmsgdisplay.pm
diff -u loncom/interface/lonmsgdisplay.pm:1.61 loncom/interface/lonmsgdisplay.pm:1.62
--- loncom/interface/lonmsgdisplay.pm:1.61	Wed Jan  3 21:02:36 2007
+++ loncom/interface/lonmsgdisplay.pm	Thu Jan  4 11:54:07 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Routines for messaging display
 #
-# $Id: lonmsgdisplay.pm,v 1.61 2007/01/04 02:02:36 raeburn Exp $
+# $Id: lonmsgdisplay.pm,v 1.62 2007/01/04 16:54:07 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2030,6 +2030,7 @@
     if (defined($content{'baseurl'})) {
         $baseurl = &Apache::lonenc::check_encrypt($content{'baseurl'});
     }
+    print STDERR "baseurl is $content{'baseurl'}, title is $content{'resource_title'}, symb is $content{'symb'}, course is $content{'courseid'}\n";  
     $r->print('<br /><b>'.&mt('Subject').':</b> '.$content{'subject'}.
 	      ($folder ne 'sent'?'<br /><b>'.&mt('From').':</b> '.
 	      &Apache::loncommon::aboutmewrapper(
@@ -2045,25 +2046,36 @@
         if (defined($content{'courseid'}) && defined($env{'request.course.id'})) {
             if ($content{'courseid'} eq $env{'request.course.id'}) {
                 my $symblink;
+                my $showsymb = &Apache::lonenc::check_decrypt($symb);
+                my $showurl = &Apache::lonenc::check_decrypt($baseurl);
+                my $encrypturl = &Apache::lonnet::EXT('resource.0.encrypturl',
+                              $showsymb,$env{'user.domain'},$env{'user.name'});
                 if ($symb) {
-                    &Apache::lonenc::check_decrypt(\$symb);
-                    $symblink = '?symb='.$symb;
+                    if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
+                        $showsymb = &Apache::lonenc::check_encrypt($symb);
+                    }
+                    $symblink = '?symb='.$showsymb;
+                }
+                if ($encrypturl =~ /^yes$/i && !$env{'request.role.adv'}) {
+                    $showurl = $baseurl;
                 }
-                &Apache::lonenc::check_decrypt(\$baseurl);
-                $r->print('<br /><b>'.&mt('Refers to').':</b> <a href="'.$baseurl.$symblink.'">'.$restitle.'</a>');
+                $r->print('<br /><b>'.&mt('Refers to').':</b> <a href="'.$showurl.$symblink.'">'.$restitle.'</a>');
                 $refers_to = 1;
             }
         }
         if (!$refers_to) {
             if ($baseurl =~ m-^/enc/-) {
                 if (defined($content{'courseid'})) {
-                    my $unencurl = 
-                       &Apache::lonenc::unencrypted($baseurl,
-                                                    $content{'courseid'}); 
-                    if (defined($unencurl)) {
-                        if (&Apache::lonnet::allowed('bre',$unencurl)) {
-                            $r->print('<br /><b>'.&mt('Refers to').
-                                      ':</b> <a href="'.$unencurl.'">'.$restitle.'</a>');
+                    if (!$env{'request.course.id'}) {
+                        my $unencurl =
+                           &Apache::lonenc::unencrypted($baseurl,
+                                                        $content{'courseid'});
+                        if ($unencurl ne '') {
+                            if (&Apache::lonnet::allowed('bre',$unencurl)) {
+                                $r->print('<br /><b>'.&mt('Refers to').
+                                          ':</b> <a href="'.$unencurl.'">'.
+                                          $restitle.'</a>');
+                            }
                         }
                     }
                 }