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

raeburn raeburn at source.lon-capa.org
Wed Jan 10 15:07:38 EST 2024


raeburn		Wed Jan 10 20:07:38 2024 EDT

  Modified files:              
    /loncom/interface	loncommon.pm londocs.pm 
    /loncom/publisher	lonpubdir.pm 
  Log:
  - Code used to create default.rights file for course authoring space
    moved from londocs.pm to loncommon.pm to facilitate reuse.
  - Course Editor > Content Utilities > Enter Course Authoring Space
    will create required directories and default.rights file if absent.
  
  
-------------- next part --------------
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1425 loncom/interface/loncommon.pm:1.1426
--- loncom/interface/loncommon.pm:1.1425	Sun Dec 31 23:03:40 2023
+++ loncom/interface/loncommon.pm	Wed Jan 10 20:07:37 2024
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1425 2023/12/31 23:03:40 raeburn Exp $
+# $Id: loncommon.pm,v 1.1426 2024/01/10 20:07:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2437,6 +2437,66 @@
 END
 }
 
+sub crsauthor_rights {
+    my ($rightsfile,$path,$docroot,$cnum,$cdom) = @_;
+    my $sourcerights = "$path/$rightsfile";
+    my $now = time;
+    if (!-e $sourcerights) {
+        my $cid = $cdom.'_'.$cnum;
+        if (!-e "$docroot/priv/$cdom") {
+            mkdir("$docroot/priv/$cdom",0755);
+        }
+        if (!-e "$docroot/priv/$cdom/$cnum") {
+            mkdir("$docroot/priv/$cdom/$cnum",0755);
+        }
+        if (open(my $fh,">$sourcerights")) {
+            print $fh <<END;
+<accessrule effect="deny" realm="" type="course" role="" />
+<accessrule effect="allow" realm="$cid" type="course" role="" />
+END
+            close($fh);
+        }
+    }
+    if (!-e "$sourcerights.meta") {
+        if (open(my $fh,">$sourcerights.meta")) {
+            my $author=$env{'environment.firstname'}.' '.
+                       $env{'environment.middlename'}.' '.
+                       $env{'environment.lastname'}.' '.
+                       $env{'environment.generation'};
+            $author =~ s/\s+$//;
+            print $fh <<"END";
+
+<abstract></abstract>
+<author>$author</author>
+<authorspace>$cnum:$cdom</authorspace>
+<copyright>private</copyright>
+<creationdate>$now</creationdate>
+<customdistributionfile></customdistributionfile>
+<dependencies></dependencies>
+<domain>$cdom</domain>
+<highestgradelevel>0</highestgradelevel>
+<keywords></keywords>
+<language>notset </language>
+<lastrevisiondate>$now</lastrevisiondate>
+<lowestgradelevel>0</lowestgradelevel>
+<mime>rights</mime>
+<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
+<notes></notes>
+<obsolete></obsolete>
+<obsoletereplacement></obsoletereplacement>
+<owner>$cnum:$cdom</owner>
+<rule>deny:::course,allow:$cid::course</rule>
+<sourceavail></sourceavail>
+<standards></standards>
+<subject></subject>
+<title>Course Authoring Rights</title>
+END
+            close($fh);
+        }
+    }
+    return;
+}
+
 =pod
 
 =item * &iframe_wrapper_headjs()
Index: loncom/interface/londocs.pm
diff -u loncom/interface/londocs.pm:1.708 loncom/interface/londocs.pm:1.709
--- loncom/interface/londocs.pm:1.708	Mon Jan  8 18:17:50 2024
+++ loncom/interface/londocs.pm	Wed Jan 10 20:07:37 2024
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Documents
 #
-# $Id: londocs.pm,v 1.708 2024/01/08 18:17:50 raeburn Exp $
+# $Id: londocs.pm,v 1.709 2024/01/10 20:07:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -102,6 +102,7 @@
     my %outhash=();
     my $home=0;
     my $other=0;
+    my @ids=&Apache::lonnet::current_machine_ids();
     foreach my $key (keys(%env)) {
 	if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
 	    my $role=$1;
@@ -118,7 +119,6 @@
 	    }
 	    my $allowed=0;
 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
-	    my @ids=&Apache::lonnet::current_machine_ids();
 	    foreach my $id (@ids) {
                 if ($id eq $myhome) {
                     $allowed=1;
@@ -263,8 +263,8 @@
                          add_entries => {'onload' => "hide_searching();"},
                      };
     }
-    $r->print(&Apache::loncommon::start_page('Copy '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
-              &Apache::lonhtmlcommon::breadcrumbs('Copy '.$crstype.' Content to Authoring Space')."\n");
+    $r->print(&Apache::loncommon::start_page('Copy uploaded content to Authoring Space',$js,$starthash)."\n".
+              &Apache::lonhtmlcommon::breadcrumbs('Copy uploaded content to Authoring Space')."\n");
     $r->print(&startContentScreen('tools'));
     my ($home,$other,%outhash)=&authorhosts();
     unless ($home) {
@@ -5965,7 +5965,7 @@
       &init_breadcrumbs('versions','Check/Set Resource Versions','Docs_Check_Resource_Versions');
       &checkversions($r,$canedit);
   } elsif ($canedit && $env{'form.dumpcourse'}) {
-      &init_breadcrumbs('dumpcourse','Copy '.&Apache::loncommon::course_type().' Content to Authoring Space');
+      &init_breadcrumbs('dumpcourse','Copy uploaded content to Authoring Space');
       &dumpcourse($r);
   } elsif ($canedit && $env{'form.exportcourse'}) {
       &init_breadcrumbs('exportcourse','IMS Export');
@@ -9407,7 +9407,7 @@
     );
     my %html_js_lt = &Apache::lonlocal::texthash(
         swit => 'Switch server?',
-        duco => 'Copying Content to Authoring Space',
+        duco => 'Copying uploaded content to Authoring Space',
         yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
         chos => 'Choose server',
     );
@@ -9548,55 +9548,8 @@
                         if ($redirect) {
                             my $rightsfile = 'default.rights';
                             my $sourcerights = "$path/$rightsfile";
+                            &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$coursenum,$coursedom);
                             my $targetrights = $docroot."/res/$coursedom/$coursenum/$rightsfile";
-                            my $now = time;
-                            if (!-e $sourcerights) {
-                                my $cid = $coursedom.'_'.$coursenum;
-                                if (open(my $fh,">$sourcerights")) {
-                                    print $fh <<END;
-<accessrule effect="deny" realm="" type="course" role="" />
-<accessrule effect="allow" realm="$cid" type="course" role="" />
-END
-                                    close($fh);
-                                }
-                            }
-                            if (!-e "$sourcerights.meta") {
-                                if (open(my $fh,">$sourcerights.meta")) {
-                                    my $author=$env{'environment.firstname'}.' '.
-                                               $env{'environment.middlename'}.' '.
-                                               $env{'environment.lastname'}.' '.
-                                               $env{'environment.generation'};
-                                    $author =~ s/\s+$//;
-                                    print $fh <<"END";
-
-<abstract></abstract>
-<author>$author</author>
-<authorspace>$coursenum:$coursedom</authorspace>
-<copyright>private</copyright>
-<creationdate>$now</creationdate>
-<customdistributionfile></customdistributionfile>
-<dependencies></dependencies>
-<domain>$coursedom</domain>
-<highestgradelevel>0</highestgradelevel>
-<keywords></keywords>
-<language>notset </language>
-<lastrevisiondate>$now</lastrevisiondate>
-<lowestgradelevel>0</lowestgradelevel>
-<mime>rights</mime>
-<modifyinguser>$env{'user.name'}:$env{'user.domain'}</modifyinguser>
-<notes></notes>
-<obsolete></obsolete>
-<obsoletereplacement></obsoletereplacement>
-<owner>$coursenum:$coursedom</owner>
-<rule>deny:::course,allow:$cid::course</rule>
-<sourceavail></sourceavail>
-<standards></standards>
-<subject></subject>
-<title>Course Authoring Rights</title>
-END
-                                    close($fh);
-                                }
-                            }
                             if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
                                 if (!-e "$docroot/res/$coursedom") {
                                     mkdir("$docroot/res/$coursedom",0755);
Index: loncom/publisher/lonpubdir.pm
diff -u loncom/publisher/lonpubdir.pm:1.182 loncom/publisher/lonpubdir.pm:1.183
--- loncom/publisher/lonpubdir.pm:1.182	Tue Nov 28 22:28:05 2023
+++ loncom/publisher/lonpubdir.pm	Wed Jan 10 20:07:37 2024
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Authoring Space Directory Lister
 #
-# $Id: lonpubdir.pm,v 1.182 2023/11/28 22:28:05 raeburn Exp $
+# $Id: lonpubdir.pm,v 1.183 2024/01/10 20:07:37 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -36,6 +36,7 @@
 use Apache::loncommon();
 use Apache::lonhtmlcommon();
 use Apache::londiff();
+use Apache::lonpublisher();
 use Apache::lonlocal;
 use Apache::lonmsg;
 use Apache::lonmenu;
@@ -86,14 +87,15 @@
     my $linkdir='/priv'.$thisdisfn;      # Full URL name of constr space.
 
     my $cstr = 'author';
-    my ($crsauthor,$crstype);
+    my ($crsauthor,$crstype,$crstoplevel,$cdom,$cnum);
     if ($env{'request.course.id'}) {
-        my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
-        my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+        $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+        $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
         if ($thisdisfn =~ m{^/\Q$cdom/$cnum\E}) {
             $crsauthor = 1;
             $cstr = 'course';
             $crstype = &Apache::loncommon::course_type();
+            $crstoplevel = "$docroot/priv/$cdom/$cnum";
         }
     }
 
@@ -108,23 +110,47 @@
 
     &startpage($r, $uname, $udom, $thisdisfn, $current_disk_usage, $disk_quota, $crsauthor);
 
+    my @files;
     if (!-d $fn) {
-        if (-e $fn) {
-            $r->print('<p class="LC_info">'.&mt('Requested item is a file not a directory.').'</p>');
+        if (($crsauthor) && ($fn eq $crstoplevel)) {
+            my $path = "$docroot/priv/$cdom/$cnum";
+            my $rightsfile = 'default.rights';
+            my $sourcerights = "$path/$rightsfile";
+            &Apache::loncommon::crsauthor_rights($rightsfile,$path,$docroot,$cnum,$cdom);
+            my $targetrights = $docroot."/res/$cdom/$cnum/$rightsfile";
+            if ((-e $sourcerights) && (-e "$sourcerights.meta")) {
+                if (!-e "$docroot/res/$cdom") {
+                    mkdir("$docroot/res/$cdom",0755);
+                }
+                if (!-e "$docroot/res/$cdom/$cnum") {
+                    mkdir("$docroot/res/$cdom/$cnum",0755);
+                }
+                if ((-e "$docroot/res/$cdom/$cnum") && (!-e $targetrights)) {
+                    my $nokeyref = &Apache::lonpublisher::getnokey($r->dir_config('lonIncludes'));
+                    my $output = &Apache::lonpublisher::batchpublish($r,$sourcerights,$targetrights,$nokeyref,1);
+                }
+            } else {
+                $r->print('<p class="LC_info">'.&mt('The requested subdirectory does not exist.').'</p>');
+                return OK;
+            }
         } else {
-            $r->print('<p class="LC_info">'.&mt('The requested subdirectory does not exist.').'</p>');
+            if (-e $fn) {
+                $r->print('<p class="LC_info">'.&mt('Requested item is a file not a directory.').'</p>');
+            } else {
+                $r->print('<p class="LC_info">'.&mt('The requested subdirectory does not exist.').'</p>');
+            }
+            $r->print(&Apache::loncommon::end_page());
+            return OK;
         }
-        $r->print(&Apache::loncommon::end_page());
-        return OK;
-    }
-    my @files;
-    if (opendir(DIR,$fn)) {
-        @files = grep(!/^\.+$/,readdir(DIR));
-        closedir(DIR);
     } else {
-        $r->print('<p class="LC_error">'.&mt('Could not open directory.').'</p>');
-        $r->print(&Apache::loncommon::end_page());
-        return OK;
+        if (opendir(DIR,$fn)) {
+            @files = grep(!/^\.+$/,readdir(DIR));
+            closedir(DIR);
+        } else {
+            $r->print('<p class="LC_error">'.&mt('Could not open directory.').'</p>');
+            $r->print(&Apache::loncommon::end_page());
+            return OK;
+        }
     }
 
     # Put out actions for directory, browse/upload + new file page.


More information about the LON-CAPA-cvs mailing list