--- loncom/interface/lonmenu.pm 2023/10/06 02:04:47 1.540 +++ loncom/interface/lonmenu.pm 2023/11/03 01:12:15 1.541 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Routines to control the menu # -# $Id: lonmenu.pm,v 1.540 2023/10/06 02:04:47 raeburn Exp $ +# $Id: lonmenu.pm,v 1.541 2023/11/03 01:12:15 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -436,10 +436,10 @@ sub primary_menu { # #TODO this should probably be moved somewhere more central #since it can be used by different parts of the system -sub getauthor{ +sub getauthor { return unless $env{'request.role'}=~/^(ca|aa|au)/; #nothing to do if user isn't some kind of author - #co- or assistent author? + #co- or assistant author? my ($dom, $user) = ($env{'request.role'} =~ /^(?:ca|aa)\.\/($match_domain)\/($match_username)$/) ? ($1, $2) #domain, username of the parent author : @env{ ('request.role.domain', 'user.name') }; #own domain, username @@ -480,6 +480,15 @@ sub secondary_menu { my $canplc = &Apache::lonnet::allowed('plc', $crs_sec); my $author = &getauthor(); + my ($is_author,$is_coauthor); + if ($author) { + if ($env{'request.role'} =~ /^au\./) { + $is_author = 1; + } elsif ($env{'request.role'} =~ /^ca\./) { + $is_coauthor = 1; + } + } + my ($cdom,$cnum,$showsyllabus,$showfeeds,$showresv,$grouptools, $lti,$ltimapres,%ltiexc,%menuopts); $grouptools = 0; @@ -539,15 +548,25 @@ sub secondary_menu { $linkattr = 'aria-disabled="true"'; } - my ($canmodifycoauthor); + my ($canlistcoauthors,$canmodifycoauthor); if ($env{'request.role'} eq "au./$env{'user.domain'}/") { my $extent = "$env{'user.domain'}/$env{'user.name'}"; if ((&Apache::lonnet::allowed('cca',$extent)) || (&Apache::lonnet::allowed('caa',$extent))) { $canmodifycoauthor = 1; } + } elsif ($env{'request.role'} =~ m{^(aa|ca)\./($match_domain/$match_username)$}) { + my ($role,$extent) = ($1,$2); + if (&Apache::lonnet::allowed('vca',$extent)) { + if ($env{"environment.internal.manager./$extent"}) { + $canmodifycoauthor = 1; + } else { + $canlistcoauthors = 1; + } + } elsif (&Apache::lonnet::allowed('vaa',$extent)) { + $canlistcoauthors = 1; + } } - my ($roleswitcher_js,$roleswitcher_form); if ($links_target ne '') { $target = $links_target; @@ -570,8 +589,12 @@ sub secondary_menu { # evaluate conditions next if ref($menuitem) ne 'ARRAY'; next if (($crstype eq 'Placement') && ($$menuitem[3] ne 'Roles') && (!$env{'request.role.adv'})); - next if $$menuitem[4] ne 'always' - && ($$menuitem[4] ne 'author' && $$menuitem[4] ne 'cca') + next if $$menuitem[4] ne 'always' + && $$menuitem[4] ne 'coauthor' + && $$menuitem[4] ne 'author' + && $$menuitem[4] ne 'authorspace' + && $$menuitem[4] ne 'vca' + && $$menuitem[4] ne 'mca' && !$env{'request.course.id'}; next if $$menuitem[4] =~ /^crsedit/ && (!$canedit && !$canvieweditor); @@ -599,9 +622,17 @@ sub secondary_menu { && !$showfeeds; next if $$menuitem[4] eq 'plc' && !$canplc; - next if $$menuitem[4] eq 'author' + next if $$menuitem[4] eq 'authorspace' && !$author; - next if $$menuitem[4] eq 'cca' + next if $$menuitem[4] eq 'author' + && !$is_author; + next if $$menuitem[4] eq 'coauthor' + && !$is_coauthor; + next if $$menuitem[4] eq 'vca' + && (!$canlistcoauthors || $canmodifycoauthor); + next if $$menuitem[4] eq 'vaa' + && (!$canlistcoauthors || $canmodifycoauthor); + next if $$menuitem[4] eq 'mca' && !$canmodifycoauthor; next if $$menuitem[4] eq 'notltimapres' && $ltimapres; @@ -637,8 +668,8 @@ sub secondary_menu { next if ($item->[2] eq 'vcg' && !$canviewgrps); next if ($item->[2] eq 'crsedit' && !$canedit && !$canvieweditor); next if ($item->[2] eq 'params' && !$canmodpara && !$canviewpara); - next if ($item->[2] eq 'author' && !$author); - next if ($item->[2] eq 'cca' && !$canmodifycoauthor); + next if ($item->[2] eq 'author' && !$is_author); + next if ($item->[2] eq 'vca' && !$canlistcoauthors); next if ($item->[2] eq 'lti' && !$lti); if ($item->[2] =~ /^lti(portfolio|wishlist|blog)$/) { my $tool = $1; @@ -724,6 +755,20 @@ sub secondary_menu { } $menu =~ s/\[url\]/$escurl/g; $menu =~ s/\[symb\]/$escsymb/g; + } elsif (($menu =~ m{/adm/preferences\?}) && ($menu =~ /\[returnurl\]/)) { + my $returnurl = $ENV{'REQUEST_URI'}; + if ($ENV{'REQUEST_URI'} =~ m{/adm/preferences\?action=authorsettings\&returnurl=([^\&]+)$}) { + $returnurl = $1; + } + if (($returnurl =~ m{^/adm/createuser($|\?action=)}) || + ($returnurl =~ m{^/priv/$match_domain/$match_username}) || + ($returnurl =~ m{^/res(/?$|/$match_domain/$match_username)})) { + $returnurl =~ s{\?.*$}{}; + $returnurl = '&returnurl='.&HTML::Entities::encode($returnurl,'"<>&\''); + } else { + undef($returnurl); + } + $menu =~ s/\[returnurl\]/$returnurl/; } $menu =~ s/\[uname\]/$$author{user}/g; $menu =~ s/\[udom\]/$$author{dom}/g; @@ -1559,20 +1604,40 @@ sub prepare_functions { $editbutton = &get_editbutton($cfile,$home,$switchserver, $forceedit,$forceview,$forcereg); } - } elsif ((!$env{'request.course.id'}) && - ($env{'user.author'}) && ($env{'request.filename'}) && - ($env{'request.role'} !~/^(aa|ca|au)/)) { + } elsif (!$env{'request.course.id'}) { + if (($env{'user.author'}) && ($resurl eq '/adm/viewcoauthors')) { + if ($env{'request.role'} =~/^(ca|au)/) { + my ($audom,$auname); + if ($env{'request.role'} eq "au./$env{'user.domain'}/") { + ($audom,$auname) = ($env{'user.domain'},$env{'user.name'}); + } elsif ($env{'request.role'} =~ m{^ca\./($match_domain)/($match_username)}) { + ($audom,$auname) = ($1,$2); + } + if (($audom ne '') && ($auname ne '')) { + my $file=&Apache::lonnet::declutter($env{'request.filename'}); + ($cfile,$home,$switchserver,$forceedit,$forceview) = + &Apache::lonnet::can_edit_resource($file,$auname,$audom, + $resurl); + if ($cfile) { + $editbutton = &get_editbutton($resurl,'','',$forceedit, + $forceview); + } + } + } + } elsif (($env{'user.author'}) && ($env{'request.filename'}) && + ($env{'request.role'} !~/^(aa|ca|au)/)) { # # Currently do not have the role of author or co-author. # Do we have authoring privileges for the resource? # - my $file=&Apache::lonnet::declutter($env{'request.filename'}); - ($cfile,$home,$switchserver,$forceedit,$forceview) = - &Apache::lonnet::can_edit_resource($file,$cnum,$cdom, - &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group); - if (($cfile) && ($home ne '') && ($home ne 'no_host')) { - $editbutton = &get_editbutton($cfile,$home,$switchserver, - $forceedit,$forceview,$forcereg); + my $file=&Apache::lonnet::declutter($env{'request.filename'}); + ($cfile,$home,$switchserver,$forceedit,$forceview) = + &Apache::lonnet::can_edit_resource($file,$cnum,$cdom, + &Apache::lonnet::clutter($resurl),$env{'request.symb'},$group); + if (($cfile) && ($home ne '') && ($home ne 'no_host')) { + $editbutton = &get_editbutton($cfile,$home,$switchserver, + $forceedit,$forceview,$forcereg); + } } } elsif ($env{'request.course.id'}) { # @@ -1980,6 +2045,8 @@ sub rawconfig { } else { next; } + } elsif ($priv eq 'cca') { + next if ($rol eq 'cm'); } if ((($priv eq 'bre') && (&Apache::lonnet::allowed($priv,$prt) eq 'F')) || (($priv ne 'bre') && (&Apache::lonnet::allowed($priv,$prt)))) { @@ -2061,6 +2128,24 @@ sub rawconfig { } } } + } elsif ($pro eq 'coauthor') { + if ($env{'request.role'}=~ m{^(ca|aa)\./($match_domain)/($match_username)$}) { + my ($role,$audom,$auname) = ($1,$2,$3); + if ((($prt eq 'raa') && ($role eq 'aa')) || + (($prt eq 'rca') && ($role eq 'ca') && + (!$env{"environment.internal.manager./$audom/$auname"}))) { + $output.=&switch($auname,$audom, + $row,$col,$img,$top,$bot,$act,$desc,$cat); + } + } + } elsif ($pro eq 'coauthorenv_manager') { + if ($env{'request.role'}=~ m{^ca\./($match_domain)/($match_username)$}) { + my ($audom,$auname) = ($1,$2); + if ($env{"environment.internal.manager./$audom/$auname"}) { + $output.=&switch($auname,$audom, + $row,$col,$img,$top,$bot,$act,$desc,$cat); + } + } } elsif ($pro eq 'tools') { my @tools = ('aboutme','blog','portfolio'); if (grep(/^\Q$prt\E$/,@tools)) {