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

raeburn lon-capa-cvs@mail.lon-capa.org
Thu, 09 Feb 2006 22:11:54 -0000


raeburn		Thu Feb  9 17:11:54 2006 EDT

  Modified files:              
    /loncom/interface	lonfeedback.pm lonparmset.pm 
  Log:
  Bug 4651.  Specify which roles can edit their own discussion posts.
  
  
Index: loncom/interface/lonfeedback.pm
diff -u loncom/interface/lonfeedback.pm:1.179 loncom/interface/lonfeedback.pm:1.180
--- loncom/interface/lonfeedback.pm:1.179	Thu Feb  9 15:30:47 2006
+++ loncom/interface/lonfeedback.pm	Thu Feb  9 17:11:54 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Feedback
 #
-# $Id: lonfeedback.pm,v 1.179 2006/02/09 20:30:47 raeburn Exp $
+# $Id: lonfeedback.pm,v 1.180 2006/02/09 22:11:54 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -906,7 +906,7 @@
                             } else {
                                 @{$$namesort{$lastname}{$firstname}} = ("$idx");
                             }
-                            if ($env{'course.'.$env{'request.course.id'}.'.allow_discussion_post_editing'} =~ m/yes/i) {
+                            if (&editing_allowed()) {
                                 if (($env{'user.domain'} eq $contrib{$idx.':senderdomain'}) && ($env{'user.name'} eq $contrib{$idx.':sendername'})) {
                                     $sender.=' <a href="/adm/feedback?editdisc='.
                                          $escsymb.':::'.$idx;
@@ -2992,7 +2992,15 @@
 
   &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
          ['hide','unhide','deldisc','postdata','preview','replydisc','editdisc','cmd','symb','onlyunread','allposts','onlyunmark','previous','markread','markonread','markondisp','toggoff','toggon','modifydisp','changes','navtime','navmaps','navurl','sortposts','applysort','rolefilter','statusfilter','sectionpick','posterlist','userpick','attach','origpage','currnewattach','deloldattach','keepold','allversions','export']);
-
+  if ($env{'form.editdisc'}) {
+      if (!(&editing_allowed())) {
+          my $symb=(split(/\:\:\:/,$env{'form.editdisc'}))[0];
+          my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb);
+          my $feedurl=&Apache::lonnet::clutter($url);
+          &redirect_back($r,$feedurl,&mt('Editing not permitted').'<br />',                     '0','0','','',$env{'form.previous'},'','','',);
+          return OK;
+      }
+  } 
   if ($env{'form.discsymb'}) {
       my ($symb,$feedurl) = &get_feedurl_and_clean_symb($env{'form.discsymb'});
       my $readkey = $symb.'_read';
@@ -3187,6 +3195,18 @@
       my ($symb,$idx)=split(/\:\:\:/,$entry);
       ($symb,my $feedurl)=&get_feedurl_and_clean_symb($symb);
 
+      my $crs='/'.$env{'request.course.id'};
+      if ($env{'request.course.sec'}) {
+          $crs.='_'.$env{'request.course.sec'};
+      }
+      $crs=~s/\_/\//g;
+      my $seeid=&Apache::lonnet::allowed('rin',$crs);
+
+      if ($env{'form.hide'} && !$seeid && !(&editing_allowed())) {
+          &redirect_back($r,$feedurl,&mt('Deletion not permitted').'<br />',                 '0','0','','',$env{'form.previous'},'','','',);
+          return OK;
+      }
+
       my %contrib=&Apache::lonnet::restore($symb,$env{'request.course.id'},
                           $env{'course.'.$env{'request.course.id'}.'.domain'},
 		          $env{'course.'.$env{'request.course.id'}.'.num'});
@@ -3194,13 +3214,6 @@
       my $currenthidden=$contrib{'hidden'};
       my $currentstudenthidden=$contrib{'studenthidden'};
 
-      my $crs='/'.$env{'request.course.id'};
-      if ($env{'request.course.sec'}) {
-	  $crs.='_'.$env{'request.course.sec'};
-      }
-      $crs=~s/\_/\//g;
-      my $seeid=&Apache::lonnet::allowed('rin',$crs);
-
       if ($env{'form.hide'}) {
 	  $currenthidden.='.'.$idx.'.';
 	  unless ($seeid) {
@@ -3477,5 +3490,39 @@
     my $feedurl = &get_feedurl($symb);
     return ($symb,$feedurl);
 }
+
+sub editing_allowed {
+    my $can_edit = 0;
+    my $cid = $env{'request.course.id'};
+    my $role = (split(/\./,$env{'request.role'}))[0];
+    my $section = $env{'request.course.sec'};
+    my $allow_editing_config = $env{'course.'.$env{'request.course.id'}.
+                               '.allow_discussion_post_editing'};
+    if ($allow_editing_config =~ m/^\s*yes\s*$/i) {
+        $can_edit = 1;
+    } else {
+        my @editor_roles = split(/,/,$allow_editing_config);
+        if (@editor_roles > 0) {
+            foreach my $editor (@editor_roles) {
+                my ($editor_role,$editor_sec) = split(/:/,$editor);
+                if ($editor_role eq $role) {
+                    if (defined($editor_sec)) {
+                        if (defined($section)) {
+                            if ($editor_sec eq $section) {
+                                $can_edit = 1;
+                                last;
+                            }
+                        }
+                    } else {
+                        $can_edit = 1;
+                        last;
+                    }
+                }
+            }
+        }
+    }
+    return $can_edit;
+}
+
 1;
 __END__
Index: loncom/interface/lonparmset.pm
diff -u loncom/interface/lonparmset.pm:1.275 loncom/interface/lonparmset.pm:1.276
--- loncom/interface/lonparmset.pm:1.275	Tue Jan 10 00:27:57 2006
+++ loncom/interface/lonparmset.pm	Thu Feb  9 17:11:54 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set parameters for assessments
 #
-# $Id: lonparmset.pm,v 1.275 2006/01/10 05:27:57 raeburn Exp $
+# $Id: lonparmset.pm,v 1.276 2006/02/09 22:11:54 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2138,8 +2138,11 @@
 	         => '<b>'.&mt('Allow limited HTML in discussion posts').'</b><br />'.
 	            '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
              'allow_discussion_post_editing'
-                 => '<b>'.&mt('Allow users to edit/delete their own discussion posts').'</b><br />'.
-                    '('.&mt('Set value to "[_1]" to allow',"<tt>yes</tt>").')',
+                 => '<b>'.&mt('Allow users with specified roles to edit/delete their own discussion posts').'</b><br />"<tt>st</tt>": '.
+                                  &mt('student').', "<tt>ta</tt>": '.
+                                  'TA, "<tt>in</tt>": '.
+                                  &mt('instructor').';&nbsp;(<tt>'.&mt('role:section,role:section,..., e.g., st:001,st:002,in,cc would permit students in sections 001 and 002 and instructors in any section, and course coordinators to edit their own posts.').'</tt>)<br />'.
+                    '('.&mt('or set value to "[_1]" to allow all roles',"<tt>yes</tt>").')',
 	     'rndseed'
 	         => '<b>'.&mt('Randomization algorithm used').'</b> <br />'.
                     '<font color="red">'.&mt('Modifying this will make problems').' '.