[LON-CAPA-cvs] cvs: loncom /auth lonroles.pm /interface domainprefs.pm loncommon.pm loncoursequeueadmin.pm loncreateuser.pm longroup.pm lonuserutils.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Tue Jun 20 10:04:03 EDT 2023


raeburn		Tue Jun 20 14:04:03 2023 EDT

  Modified files:              
    /loncom/interface	domainprefs.pm loncommon.pm 
                     	loncoursequeueadmin.pm loncreateuser.pm 
                     	longroup.pm lonuserutils.pm 
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/auth	lonroles.pm 
  Log:
  - Support case where assignment of roles in a different domain is queued
    pending acceptance of the role by the role recipient. 
    - A user can also choose to decline the role.
    - Domain configuration can be set for domain roles, co-author roles,
      course roles and community roles. 
  
  
-------------- next part --------------
Index: loncom/interface/domainprefs.pm
diff -u loncom/interface/domainprefs.pm:1.426 loncom/interface/domainprefs.pm:1.427
--- loncom/interface/domainprefs.pm:1.426	Sat Jun  3 19:26:31 2023
+++ loncom/interface/domainprefs.pm	Tue Jun 20 14:03:52 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Handler to set domain-wide configuration settings
 #
-# $Id: domainprefs.pm,v 1.426 2023/06/03 19:26:31 raeburn Exp $
+# $Id: domainprefs.pm,v 1.427 2023/06/20 14:03:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -568,7 +568,7 @@
                   modify => \&modify_selfenrollment,
                  },
         'privacy' => 
-                 {text   => 'Availability of User Information',
+                 {text   => 'Role assignments and user privacy',
                   help   => 'Domain_Configuration_User_Privacy',
                   header => [{col1 => 'Role assigned in different domain',
                               col2 => 'Approval options'},
@@ -882,7 +882,7 @@
     } elsif ($action eq 'lti') {
         $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
     } elsif ($action eq 'privacy') {
-        $output = &modify_privacy($dom,%domconfig);
+        $output = &modify_privacy($dom,$lastactref,%domconfig);
     } elsif ($action eq 'passwords') {
         $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
     } elsif ($action eq 'wafproxy') {
@@ -17096,7 +17096,7 @@
 }
 
 sub modify_privacy {
-    my ($dom,%domconfig) = @_;
+    my ($dom,$lastactref,%domconfig) = @_;
     my ($resulttext,%current,%changes);
     if (ref($domconfig{'privacy'}) eq 'HASH') {
         %current = %{$domconfig{'privacy'}};
@@ -17332,6 +17332,28 @@
                 }
             }
             $resulttext .= '</ul>';
+            if ($changes{'approval'}) {
+                my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
+                delete($domdefaults{'userapprovals'});
+                if (ref($privacyhash{'approval'}) eq 'HASH') {
+                    foreach my $domtype ('instdom','extdom') {
+                        if (ref($privacyhash{'approval'}{$domtype}) eq 'HASH') {
+                            foreach my $roletype ('domain','author','course','community') {
+                                if ($privacyhash{'approval'}{$domtype}{$roletype} eq 'user') {
+                                    $domdefaults{'userapprovals'} = 1;
+                                    last;
+                                }
+                            }
+                        }
+                        last if ($domdefaults{'userapprovals'});               
+                    }
+                }
+                my $cachetime = 24*60*60;
+                &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
+                if (ref($lastactref) eq 'HASH') {
+                    $lastactref->{'domdefaults'} = 1;
+                }
+            }
         } else {
             $resulttext = &mt('No changes made to user information settings');
         }
Index: loncom/interface/loncommon.pm
diff -u loncom/interface/loncommon.pm:1.1407 loncom/interface/loncommon.pm:1.1408
--- loncom/interface/loncommon.pm:1.1407	Sun Jun 11 20:45:35 2023
+++ loncom/interface/loncommon.pm	Tue Jun 20 14:03:52 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # a pile of common routines
 #
-# $Id: loncommon.pm,v 1.1407 2023/06/11 20:45:35 raeburn Exp $
+# $Id: loncommon.pm,v 1.1408 2023/06/20 14:03:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -10500,6 +10500,16 @@
 
 ###############################################
 sub show_course {
+    my ($udom,$uname) = @_;
+    if (($udom ne '') && ($uname ne '')) {
+        if (($udom ne $env{'user.domain'}) || ($uname ne $env{'user.name'})) {
+            if (&Apache::lonnet::is_advanced($udom,$uname)) {
+                return 0;
+            } else {
+                return 1;
+            }
+        }
+    }
     my $course = !$env{'user.adv'};
     if (!$env{'user.adv'}) {
         foreach my $env (keys(%env)) {
@@ -16531,9 +16541,10 @@
 
 
 sub commit_customrole {
-    my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
+    my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context,$othdomby,$requester) = @_;
     my $result = &Apache::lonnet::assigncustomrole(
-                     $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context);
+                     $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,
+                     $context,$othdomby,$requester);
     my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
                          ($start?', '.&mt('starting').' '.localtime($start):'').
                          ($end?', ending '.localtime($end):'').': <b>'.$result.'</b><br />';
@@ -16545,7 +16556,8 @@
 }
 
 sub commit_standardrole {
-    my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
+    my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits,
+        $othdomby,$requester) = @_;
     my ($output,$logmsg,$linefeed,$result);
     if ($context eq 'auto') {
         $linefeed = "\n";
@@ -16554,7 +16566,8 @@
     }  
     if ($three eq 'st') {
         $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
-                                      $one,$two,$sec,$context,$credits);
+                                      $one,$two,$sec,$context,$credits,$othdomby,
+                                      $requester);
         if (($result =~ /^error/) || ($result eq 'not_in_class') || 
             ($result eq 'unknown_course') || ($result eq 'refused')) {
             $output = $logmsg.' '.&mt('Error: ').$result."\n"; 
@@ -16574,7 +16587,8 @@
         $output = &mt('Assigning').' '.$three.' in '.$url.
                ($start?', '.&mt('starting').' '.localtime($start):'').
                ($end?', '.&mt('ending').' '.localtime($end):'').': ';
-        $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
+        $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,
+                                              '','',$context,$othdomby,$requester);
         if ($context eq 'auto') {
             $output .= $result.$linefeed;
         } else {
@@ -16590,7 +16604,7 @@
 
 sub commit_studentrole {
     my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
-        $credits) = @_;
+        $credits,$othdomby,$requester) = @_;
     my ($result,$linefeed,$oldsecurl,$newsecurl);
     if ($context eq 'auto') {
         $linefeed = "\n";
@@ -16614,8 +16628,9 @@
                 }
                 $oldsecurl = $uurl;
                 $expire_role_result = 
-                    &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','','',$context);
-                if ($env{'request.course.sec'} ne '') { 
+                    &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,
+                                                '','','',$context,$othdomby,$requester);
+                if ($env{'request.course.sec'} ne '') {
                     if ($expire_role_result eq 'refused') {
                         my @roles = ('st');
                         my @statuses = ('previous');
@@ -16641,7 +16656,8 @@
                 &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
                                                            undef,undef,undef,$sec,
                                                            $end,$start,'','',$cid,
-                                                           '',$context,$credits);
+                                                           '',$context,$credits,'',
+                                                           $othdomby,$requester);
             if ($modify_section_result =~ /^ok/) {
                 if ($secchange == 1) {
                     if ($sec eq '') {
Index: loncom/interface/loncoursequeueadmin.pm
diff -u loncom/interface/loncoursequeueadmin.pm:1.66 loncom/interface/loncoursequeueadmin.pm:1.67
--- loncom/interface/loncoursequeueadmin.pm:1.66	Wed Mar 29 16:01:13 2023
+++ loncom/interface/loncoursequeueadmin.pm	Tue Jun 20 14:03:52 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Utilities to administer domain course requests and course self-enroll requests
 #
-# $Id: loncoursequeueadmin.pm,v 1.66 2023/03/29 16:01:13 raeburn Exp $
+# $Id: loncoursequeueadmin.pm,v 1.67 2023/06/20 14:03:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -271,16 +271,18 @@
         }
     } elsif ($context eq 'othdomroleuser') {
         my $linktext = 'Roles';
-        if (&Apache::loncommon::show_course()) {
-            $linktext = 'Courses';
+        if ($notifylist =~ /^($match_username):($match_domain)$/) {
+            if (&Apache::loncommon::show_course($2,$1)) {
+                $linktext = 'Courses';
+            }
         }
         $rawsubj = 'Role Assignment Approval';
         push(@rawmsg,{
-                      mt  => 'A domain different to your own LON-CAPA domain ([_1]) wants to assign you a role in their domain.',
+                      mt  => 'A domain different to your own LON-CAPA domain [_1]wants to assign you a role in their domain.',
                       args => ["\n$contextdesc\n"],
                      },
                      {
-                      mt =>"[_1]Click $linktext at top right, then click 'Manage Role Requests' in the gray Functions bar ".
+                      mt =>"[_1]Click $linktext at top right, then click 'Show pending' in the gray Functions bar ".
                            "to display a list of pending role assignments in other domain(s), which you can either accept or reject.",
                       args => ["\n\n"],
                      });
@@ -295,13 +297,24 @@
  -> Queued Role Assignments (this domain) [_3]to display a list of pending requests, which you can either approve or reject.',
                       args => ["\n","\n\n  ","\n\n"],
                      });
-    } elsif ($context eq 'othdombydc') {
+    } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
         $rawsubj = 'Status of Role Assignment Requests';
-        push(@rawmsg,{
-                      mt =>'A Domain Coordinator in a domain different to your own LON-CAPA domain '.
-                           'has taken action on queued role assignment(s) in this domain for user(s) from that other domain ([_1])',
-                      args => ["\n$contextdesc\n"],
-                      });
+        if ($context eq 'othdombydc') {
+            push(@rawmsg,{
+                          mt =>'A Domain Coordinator in a domain different to your own LON-CAPA domain '.
+                               'has taken action on queued role assignment(s) in this domain for user(s) from that other domain [_1]',
+                          args => ["\n$contextdesc\n"],
+                          });
+        } elsif ($context eq 'othdombyuser') {
+            push(@rawmsg,{
+                          mt => "Action has been taken by a user to whom you had assigned role(s) ".
+                                "which had been queued, pending acceptance of the role(s).",
+                          args => [],
+                         });
+        }
+        if (ref($textstr) eq 'ARRAY') {
+            push(@rawmsg,@{$textstr});
+        }
     }
     my @to_notify = split(/,/,$notifylist);
     my $numsent = 0;
@@ -340,7 +353,11 @@
     $message = '';
     foreach my $item (@rawmsg) {
         if (ref($item) eq 'HASH') {
-            $message .= &mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
+            if (ref($item->{args}) eq 'ARRAY') {
+                $message .= &mt_user($sender_lh,$item->{mt},@{$item->{args}})."\n";
+            } else {
+                $message .= &mt_user($sender_lh,$item->{mt})."\n";
+            }
         }
     }
     &Apache::lonmsg::process_sent_mail($subject,'',$numsent,$stamp,$uname,$udom,$msgcount,$cid,$$,$message,
@@ -390,13 +407,6 @@
             if ($rejectedlist) {
                 $message .= "\n\n".&mt_user($sender_lh,'Rejected LON-CAPA account requests:')."\n".$rejectedlist;
             }
-        } elsif ($context eq 'othdombydc') {
-            if ($approvedlist) {
-                $message .= "\n\n".&mt_user($sender_lh,'Approved LON-CAPA role assignments:')."\n".$approvedlist;
-            }
-            if ($rejectedlist) {
-                $message .= "\n\n".&mt_user($sender_lh,'Rejected LON-CAPA role assignments:')."\n".$rejectedlist;
-            }
         }
         $status .= &Apache::lonmsg::user_normal_msg($ccname,$ccdom,$subject,$message,undef,undef,undef,1,
                                                     \%sentmessage,undef,undef,undef,1,$recipid).',';
@@ -446,12 +456,13 @@
             %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
         }
     } elsif ($context eq 'othdomaction') {
-        $formaction = '/adm/createuser';
         $namespace = 'nohist_queuedrolereqs';
         if ($secondary eq 'domain') {
+            $formaction = '/adm/createuser';
             my $confname = &Apache::lonnet::get_domainconfiguser($dom);
             %requesthash = &Apache::lonnet::dump($namespace,$dom,$confname);
         } else {
+            $formaction = '/adm/roles';
             %requesthash = &Apache::lonnet::dump($namespace,$dom,$cnum);
         }
         $nextelement = '<input type="hidden" name="state" value="done" />';
@@ -550,9 +561,7 @@
                 $output .= '<h3>'.&mt('Community role assignments for users from another domain which were/are queued for approval').'</h3>';
             }
         } elsif ($context eq 'othdomaction') {
-            if ($secondary eq 'user') {
-                $output .= '<h3>'.&mt('Role assignments for you in other domains, queued pending your acceptance of the role.').'</h3>';
-            } elsif ($secondary eq 'domain') {
+            unless ($secondary eq 'user') {
                 $output .= '<h3>'.&mt('Role assignments in other domains, queued pending domain coordinator approval in this domain.').'</h3>';
             }
         } else {
@@ -563,6 +572,9 @@
         } else {
             $output .= &build_queue_display($dom,$context,\%queue_by_date,$secondary).
                        '<input type="hidden" name="queue" value="approval" />';
+            if ($secondary eq 'user') {
+                $output .= "\n".'<input type="hidden" name="approvals" value="show" />'."\n";
+            }
         }
         if ($context eq 'pending') {
             $output .= '<br /><input type="submit" name="validationcheck" value="'.
@@ -574,7 +586,11 @@
         }
         $output .= '</form>';
     } else {
-        $output .= '<div class="LC_info">';
+        if (($context eq 'othdomaction') && ($secondary eq 'user')) { 
+            $output .= '<span class="LC_info">';
+        } else {
+            $output .= '<div class="LC_info">';
+        }
         if ($context eq 'course') {
             $output .= &mt('There are currently no enrollment requests awaiting approval.');
         } elsif (($context eq 'pending') || ($context eq 'displaypending')) {
@@ -595,14 +611,18 @@
             }
         } elsif ($context eq 'othdomaction') {
             if ($secondary eq 'user') {
-                $output .= &mt('There are currently no pending role assignments for you in other domains, queued pending your acceptance of the role.');
+                $output .= &mt('No role assignments for you in other domains currently awaiting your acceptance');
             } elsif ($secondary eq 'domain') {
-                $output .= &mt('There are currently no pending role assignments in other domains, queued pending domain coordinator approval in this domain.');
+                $output .= &mt('No role assignments in other domains currently awaiting domain coordinator approval');
             }
         } else {
             $output .= &mt('There are currently no course or community requests awaiting approval.');
         }
-        $output .= '</div>';
+        if (($context eq 'othdomaction') && ($secondary eq 'user')) {
+            $output .= '</span>';
+        } else {
+            $output .= '</div>';
+        }
     }
     return $output;
 }
@@ -713,13 +733,15 @@
                     }
                     if (($role eq 'ca') || ($role eq 'aa')) {
                         my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
-                        $location = &mt('Author').': '.&Apache::loncommon::plainname($auname,$audom);
+                        $location = &mt('Domain').': '.&Apache::lonnet::domain($audom,'description').'<br />'.
+                                    &mt('Author').': '.&Apache::loncommon::plainname($auname,$audom);
                     } elsif ($role eq 'co') {
                         my ($cdom,$cnum)  = ($extent =~ m{^/($match_domain)/($match_courseid)});
                         if (&Apache::lonnet::is_course($cdom,$cnum)) {
                             my %info = &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
                             $crstype = $info{'type'};
-                            $location = &mt('Community').': '.$info{'description'};
+                            $location = &mt('Domain').': '.&Apache::lonnet::domain($cdom,'description').'<br />'.
+                                        &mt('Community').': '.$info{'description'};
                             $showrole = &Apache::lonnet::plaintext($role,'Community');
                         }
                     } elsif ($role =~ m{^cr/}) {
@@ -728,7 +750,8 @@
                         if (&Apache::lonnet::is_course($cdom,$cnum)) {
                             my %info = &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
                             $crstype = $info{'type'};
-                            $location = &mt($crstype).': '.$info{'description'};
+                            $location = &mt('Domain').': '.&Apache::lonnet::domain($cdom,'description').'<br />'. 
+                                        &mt($crstype).': '.$info{'description'};
                             if ($csec ne '') {
                                 $location .= '<br />'.&mt('Section').': '.$csec;
                             }
@@ -741,13 +764,14 @@
                                     if (&Apache::lonnet::is_course($cdom,$cnum)) {
                                         my %info = &Apache::lonnet::coursedescription("$cdom/$cnum",{'one_time' => 1});
                                         $crstype = $info{'type'};
-                                        $location = &mt($crstype).': '.$info{'description'};
+                                        $location = &mt('Domain').': '.&Apache::lonnet::domain($cdom,'description').'<br />'.
+                                                    &mt($crstype).': '.$info{'description'};
                                         if ($csec ne '') {
                                             $location .= '<br />'.&mt('Section').': '.$csec;
                                         }
                                     }
                                 } else {
-                                    my ($domain)  = ($extent =~ m{^/($match_domain)/});
+                                    my ($domain)  = ($extent =~ m{^/($match_domain)/$});
                                     $location = &mt('Domain').': '.&Apache::lonnet::domain($domain,'description');
                                 }
                                 last;
@@ -1251,8 +1275,8 @@
         if ($context eq 'othdombydc') {
             $confname = &Apache::lonnet::get_domainconfiguser($cdom);
             %requesthash = &Apache::lonnet::dump($namespace,$cdom,$confname);
-        } else {
-            %requesthash = &Apache::lonnet::dump($namespace,$cdom,$cnum);
+        } elsif ($context eq 'othdombyuser') {
+            %requesthash = &Apache::lonnet::dump($namespace);
         }
         $domdesc = &Apache::lonnet::domain($cdom);
         $dbname = 'nohist_othdomqueued';
@@ -1481,126 +1505,139 @@
             }
             push(@toremove, at invalidusers);
         } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
+            my ($num,$extent,$role,$uname,$udom,$key,$logmsg,$result);
             if ($context eq 'othdombydc') {
-                my ($num,$extent,$role,$uname,$udom) = split(/:/,$item);
-                my ($logmsg,$result);
+                ($num,$extent,$role,$uname,$udom) = split(/:/,$item);
                 if ($udom eq $cdom) {
-                    my $key = 'pending:'.$uname.':'.$extent.':'.$role;
-                    if (exists($requesthash{$key})) {
-                        if (ref($requesthash{$key}) eq 'HASH') {
-                            my $requester = $requesthash{$key}->{'requester'};
-                            my ($requname,$requdom) = split(/:/,$requester);
-                            my $start = $requesthash{$key}->{'start'};
-                            my $end = $requesthash{$key}->{'end'};
-                            my $credits = $requesthash{$key}->{'credits'};
-                            my $reqcontext = $requesthash{$key}->{'context'};
-                            if ((&Apache::lonnet::homeserver($uname,$udom) ne 'no_host') &&
-                                (&Apache::lonnet::homeserver($requname,$requdom) ne 'no_host')) {
-                                if (($role eq 'ca') || ($role eq 'aa')) {
-                                    my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
-                                    if (&Apache::lonnet::homeserver($auname,$audom) ne 'no_host') {
-                                        if ($requester eq $auname.':'.$audom) {
-                                            unless ($gotroles{$requester}) {
-                                                &requester_roles($auname,$audom,\%requesteractive);
-                                                $gotroles{$requester} = 1;
-                                            }
-                                            if (ref($requesteractive{$requester}) eq 'HASH') {
-                                                if ($requesteractive{$requester}{':'.$audom.':au'}) {
-                                                    $result = &Apache::lonnet::assignrole($udom,$uname,$extent,$role,
-                                                                                          $end,$start,'','',$reqcontext);
-                                                }
-                                            }
+                    $key = 'pending:'.$uname.':'.$extent.':'.$role;
+                }
+            } elsif ($context eq 'othdombyuser') {
+                ($num,$extent,$role) = split(/:/,$item);
+                $key = 'pending:'.$extent.':'.$role;
+                $uname = $env{'user.name'};
+                $udom = $env{'user.domain'};
+            }
+            if (($key) && (exists($requesthash{$key}))) {
+                if (ref($requesthash{$key}) eq 'HASH') {
+                    my $requester = $requesthash{$key}->{'requester'};
+                    my ($requname,$requdom) = split(/:/,$requester);
+                    my $start = $requesthash{$key}->{'start'};
+                    my $end = $requesthash{$key}->{'end'};
+                    my $credits = $requesthash{$key}->{'credits'};
+                    my $reqcontext = $requesthash{$key}->{'context'};
+                    if ((($context eq 'othdombydc') &&
+                        (&Apache::lonnet::homeserver($uname,$udom) ne 'no_host')) ||
+                        ($context eq 'othdombyuser')) {
+                        if (&Apache::lonnet::homeserver($requname,$requdom) ne 'no_host') {
+                            if (($role eq 'ca') || ($role eq 'aa')) {
+                                my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
+                                if (&Apache::lonnet::homeserver($auname,$audom) ne 'no_host') {
+                                    if ($requester eq $auname.':'.$audom) {
+                                        unless ($gotroles{$requester}) {
+                                            &requester_roles($auname,$audom,\%requesteractive);
+                                            $gotroles{$requester} = 1;
                                         }
-                                    }
-                                } elsif (($role eq 'co') || ($role eq 'cc')) {
-                                    my ($crsdom,$crsnum)  = ($extent =~ m{^/($match_domain)/($match_courseid)});
-                                    if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
-                                        my %info = &Apache::lonnet::coursedescription("$crsdom/$crsnum",{'one_time' => 1});
-                                        if ((($role eq 'co') && ($info{'type'} eq 'Community')) ||
-                                           (($role eq 'cc') && ($info{'type'} ne 'Community'))) {
-                                            if ($info{'internal.courseowner'} eq $requester) {
-                                                unless ($gotroles{$requester}) {
-                                                    &requester_roles($requname,$requdom,\%requesteractive);
-                                                    $gotroles{$requester} = 1;
-                                                }
-                                                if (ref($requesteractive{$requester}) eq 'HASH') {
-                                                    if ($requesteractive{$requester}{"$crsnum:$crsdom:$role"}) {
-                                                        ($logmsg,$result) =
-                                                            &Apache::loncommon::commit_standardrole($udom,$uname,$extent,$role,$start,
-                                                                                                    $end,$crsdom,$crsnum,'',
-                                                                                                    $reqcontext);
-                                                    }
-                                                }
+                                        if (ref($requesteractive{$requester}) eq 'HASH') {
+                                            if ($requesteractive{$requester}{':'.$audom.':au'}) {
+                                                $result = &Apache::lonnet::assignrole($udom,$uname,$extent,$role,
+                                                                                      $end,$start,'','',$reqcontext,
+                                                                                      $context,$requester);
                                             }
                                         }
                                     }
-                                } elsif ($role =~ m{^(cr)/($match_domain)/($match_username)/(\w+)$}) {
-                                    my ($mrole,$crudom,$cruname,$rolename) = ($1,$2,$3,$4);
-                                    my ($crsdom,$crsnum,$csec) =
-                                        ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$});
-                                    if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
-                                        my ($rdummy,$roledef) =
-                                            &Apache::lonnet::get('roles',["rolesdef_$rolename"],$crudom,$cruname);
-                                        if (($rdummy ne 'con_lost') && ($roledef ne '')) {
+                                }
+                            } elsif (($role eq 'co') || ($role eq 'cc')) {
+                                my ($crsdom,$crsnum)  = ($extent =~ m{^/($match_domain)/($match_courseid)});
+                                if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
+                                    my %info = &Apache::lonnet::coursedescription("$crsdom/$crsnum",{'one_time' => 1});
+                                    if ((($role eq 'co') && ($info{'type'} eq 'Community')) ||
+                                        (($role eq 'cc') && ($info{'type'} ne 'Community'))) {
+                                        if ($info{'internal.courseowner'} eq $requester) {
                                             unless ($gotroles{$requester}) {
                                                 &requester_roles($requname,$requdom,\%requesteractive);
                                                 $gotroles{$requester} = 1;
                                             }
                                             if (ref($requesteractive{$requester}) eq 'HASH') {
-                                                if (&requester_has_perm($crsdom,$crsnum,$mrole,$requesteractive{$requester})) {
+                                                if ($requesteractive{$requester}{"$crsnum:$crsdom:$role"}) {
                                                     ($logmsg,$result) =
-                                                        &Apache::loncommon::commit_customrole($udom,$uname,$extent,$crudom,$cruname,
-                                                                                              $rolename,$start,$end,$reqcontext);
+                                                        &Apache::loncommon::commit_standardrole($udom,$uname,$extent,$role,$start,
+                                                                                                $end,$crsdom,$crsnum,'',
+                                                                                                $reqcontext,'',$context,
+                                                                                                $requester);
                                                 }
                                             }
                                         }
                                     }
-                                } else {
-                                    my $process;
-                                    foreach my $type ('course','domain') {
-                                        if (grep(/^\Q$role\E$/,@{$roles_by_context{$type}})) {
-                                            if ($type eq 'course') {
-                                                my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$});
-                                                if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
-                                                    my $typeok;
-                                                    if ($role eq 'cc') {
-                                                        my %info = &Apache::lonnet::coursedescription("$crsdom/$crsnum",{'one_time' => 1});
-                                                        if ($info{'type'} eq 'Course') {
-                                                            $typeok = 1;
-                                                        }
-                                                    } else {
+                                }
+                            } elsif ($role =~ m{^(cr)/($match_domain)/($match_username)/(\w+)$}) {
+                                my ($mrole,$crudom,$cruname,$rolename) = ($1,$2,$3,$4);
+                                my ($crsdom,$crsnum,$csec) =
+                                    ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$});
+                                if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
+                                    my ($rdummy,$roledef) =
+                                        &Apache::lonnet::get('roles',["rolesdef_$rolename"],$crudom,$cruname);
+                                    if (($rdummy ne 'con_lost') && ($roledef ne '')) {
+                                        unless ($gotroles{$requester}) {
+                                            &requester_roles($requname,$requdom,\%requesteractive);
+                                            $gotroles{$requester} = 1;
+                                        }
+                                        if (ref($requesteractive{$requester}) eq 'HASH') {
+                                            if (&requester_has_perm($crsdom,$crsnum,$mrole,$requesteractive{$requester})) {
+                                                ($logmsg,$result) =
+                                                    &Apache::loncommon::commit_customrole($udom,$uname,$extent,$crudom,$cruname,
+                                                                                          $rolename,$start,$end,$reqcontext,
+                                                                                          $context,$requester);
+                                            }
+                                        }
+                                    }
+                                }
+                            } else {
+                                my $process;
+                                foreach my $type ('course','domain') {
+                                    if (grep(/^\Q$role\E$/,@{$roles_by_context{$type}})) {
+                                        if ($type eq 'course') {
+                                            my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$});
+                                            if (&Apache::lonnet::is_course($crsdom,$crsnum)) {
+                                                my $typeok;
+                                                if ($role eq 'cc') {
+                                                    my %info = &Apache::lonnet::coursedescription("$crsdom/$crsnum",{'one_time' => 1});
+                                                    if ($info{'type'} eq 'Course') {
                                                         $typeok = 1;
                                                     }
-                                                    if ($typeok) {
-                                                        unless ($gotroles{$requester}) {
-                                                            &requester_roles($requname,$requdom,\%requesteractive);
-                                                            $gotroles{$requester} = 1;
-                                                        }
-                                                        if (ref($requesteractive{$requester}) eq 'HASH') {
-                                                            if (&requester_has_perm($crsdom,$crsnum,$role,$requesteractive{$requester})) {
-                                                                ($logmsg,$result) =
-                                                                    &Apache::loncommon::commit_standardrole($udom,$uname,$extent,$role,$start,
-                                                                                                            $end,$crsdom,$crsnum,$csec,
-                                                                                                            $reqcontext,$credits);
-                                                            }
-                                                        }
-                                                    }
+                                                } else {
+                                                    $typeok = 1;
                                                 }
-                                            } else {
-                                                my ($domain) = ($extent =~ m{^/($match_domain)/});
-                                                if (&Apache::lonnet::domain($domain) ne '') {
+                                                if ($typeok) {
                                                     unless ($gotroles{$requester}) {
                                                         &requester_roles($requname,$requdom,\%requesteractive);
                                                         $gotroles{$requester} = 1;
                                                     }
-                                                    if (&requester_has_perm($domain,'',$role,$requesteractive{$requester})) {
-                                                        $result = &Apache::lonnet::assignrole($udom,$uname,$extent,$role,
-                                                                                              $end,$start,'','',$reqcontext);
+                                                    if (ref($requesteractive{$requester}) eq 'HASH') {
+                                                        if (&requester_has_perm($crsdom,$crsnum,$role,$requesteractive{$requester})) {
+                                                            ($logmsg,$result) =
+                                                                &Apache::loncommon::commit_standardrole($udom,$uname,$extent,$role,$start,
+                                                                                                        $end,$crsdom,$crsnum,$csec,
+                                                                                                        $reqcontext,$credits,$context,
+                                                                                                        $requester);
+                                                        }
                                                     }
                                                 }
                                             }
-                                            last;
+                                        } else {
+                                            my ($domain) = ($extent =~ m{^/($match_domain)/});
+                                            if (&Apache::lonnet::domain($domain) ne '') {
+                                                unless ($gotroles{$requester}) {
+                                                    &requester_roles($requname,$requdom,\%requesteractive);
+                                                    $gotroles{$requester} = 1;
+                                                }
+                                                if (&requester_has_perm($domain,'',$role,$requesteractive{$requester})) {
+                                                    $result = &Apache::lonnet::assignrole($udom,$uname,$extent,$role,
+                                                                                          $end,$start,'','',$reqcontext,
+                                                                                          $context,$requester);
+                                                }
+                                            }
                                         }
+                                        last;
                                     }
                                 }
                             }
@@ -1621,26 +1658,23 @@
                                     $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'approved'},$crsdom,$crsnum);
                                 }
                                 if ($statusres eq 'ok') {
-                                    my $newkey = 'approved:'.$uname.':'.$extent.':'.$role;
+                                    my $newkey;
+                                    if ($context eq 'othdombydc') {
+                                        $newkey = 'approved:'.$uname.':'.$extent.':'.$role;
+                                    } elsif ($context eq 'othdombyuser') {
+                                        $newkey = 'approved:'.$extent.':'.$role;
+                                    }
                                     $requesthash{$newkey} = $requesthash{$key};
                                     delete($requesthash{$key});
                                     push(@toremove,$key);
                                     push(@completed,$item);
                                 }
+                            } else {
+                                push(@warn_approves,$key);
                             }
                         }
                     }
                 }
-            } else {
-                my ($num,$extent,$role) = split(/:/,$item);
-                if (exists($requesthash{$extent.':'.$role})) {
-                    if (ref($requesthash{$extent.':'.$role}) eq 'HASH') {
-#FIXME
-#check if extent is valid
-#check if role is valid
-#check requester privs
-                    }
-                }
             }
         } else {
             my ($num,$cnum) = split(':',$item);
@@ -1842,36 +1876,45 @@
                     push(@warn_rejects,$uname);
                 }
             } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
+                my ($extent,$role,$uname,$udom,$oldkey,$newkey);
+                my $dbname = 'nohist_othdomqueued';
                 if ($context eq 'othdombydc') {
-                    my ($extent,$role,$uname,$udom) = split(/:/,$item);
-                    my $oldkey = 'pending:'.$uname.':'.$extent.':'.$role;
-                    my $newkey = 'rejected:'.$uname.':'.$extent.':'.$role;
-                    my $dbname = 'nohist_othdomqueued';
-                    if (exists($requesthash{$oldkey})) {
-                        if (ref($requesthash{$oldkey}) eq 'HASH') {
+                    ($extent,$role,$uname,$udom) = split(/:/,$item);
+                    $oldkey = 'pending:'.$uname.':'.$extent.':'.$role;
+                    $newkey = 'rejected:'.$uname.':'.$extent.':'.$role;
+                } elsif ($context eq 'othdombyuser') {
+                    ($extent,$role) = split(/:/,$item);
+                    $oldkey = 'pending:'.$extent.':'.$role;
+                    $newkey = 'rejected:'.$extent.':'.$role;
+                    $uname = $env{'user.name'};
+                    $udom = $env{'user.domain'};
+                }
+                if (exists($requesthash{$oldkey})) {
+                    if (ref($requesthash{$oldkey}) eq 'HASH') {
+                        my $statusres;
+                        my $id = $uname.':'.$udom.':'.$role;
+                        if (($role eq 'ca') || ($role eq 'aa')) {
+                            my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
+                            $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$audom,$auname);
+                        } elsif ($extent =~ m{^/($match_domain)/\Q$role\E$}) {
+                            my $domain = $1;
+                            my $configuser = &Apache::lonnet::get_domainconfiguser($domain);
+                            $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$domain,$configuser);
+                        } else {
+                            my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/([^/]+))$});
+                            $id .= ':'.$csec;
+                            $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$crsdom,$crsnum);
+                        }
+                        if ($statusres eq 'ok') {
                             $requesthash{$newkey} = $requesthash{$oldkey};
                             delete($requesthash{$oldkey});
                             push(@toremove,$oldkey);
                             $requesthash{$newkey}->{'timestamp'} = $now;
                             $requesthash{$newkey}->{'adjudicator'} = $env{'user.name'}.':'.$env{'user.domain'};
-                            my $statusres;
-                            my $id = $uname.':'.$udom.':'.$role;
-                            if (($role eq 'ca') || ($role eq 'aa')) {
-                                my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
-                                $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$audom,$auname);
-                            } elsif ($extent =~ m{^/($match_domain)/$}) {
-                                my $domain = $1;
-                                my $configuser = &Apache::lonnet::get_domainconfiguser($domain);
-                                $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$domain,$configuser);
-                            } else {
-                                my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/([^/]+))$});
-                                $id .= ':'.$csec;
-                                $statusres = &Apache::lonnet::put($dbname,{'status&'.$id => 'rejected'},$crsdom,$crsnum);
-                            }
-                            if ($statusres eq 'ok') {
-                                $requestedby{$item} = $requesthash{$newkey}->{'requester'};
-                                push(@rejectedreqs,$item);
-                            }
+                            $requestedby{$item} = $requesthash{$newkey}->{'requester'};
+                            push(@rejectedreqs,$item);
+                        } else {
+                            push(@warn_rejects,$oldkey);
                         }
                     }
                 }
@@ -1961,12 +2004,19 @@
                 }
             }
         }
-        unless ($context eq 'othdombydc') {
+        unless (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
             @toremove = map {$_.'_approval'} (@toremove);
         }
-        my $delresult = &Apache::lonnet::del_dom($namespace,\@toremove,$cdom);
-        if (($delresult ne 'ok') && ($context eq 'othdombydc')) {
-            push(@warn_dels, at toremove);
+        if (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
+            my $delresult;
+            if ($context eq 'othdombyuser') {
+                $delresult = &Apache::lonnet::del($namespace,\@toremove,$env{'user.domain'},$env{'user.name'});
+            } else {
+                $delresult = &Apache::lonnet::del_dom($namespace,\@toremove,$cdom);
+            }
+            unless ($delresult eq 'ok') {
+                push(@warn_dels, at toremove);
+            }
         }
     }
     if (@changes) {
@@ -1976,7 +2026,9 @@
         } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
             if ($context eq 'othdombydc') {
                 $delresult = &Apache::lonnet::put($namespace,\%requesthash,$cdom,$confname);
-            }
+            } elsif ($context eq 'othdombyuser') {
+                $delresult = &Apache::lonnet::put($namespace,\%requesthash,$env{'user.domain'},$env{'user.name'});
+            } 
         } else {
             $delresult = &Apache::lonnet::del_dom($namespace,\@changes,$cdom);
         }
@@ -2066,32 +2118,61 @@
                                                  $approvedlist,$rejectedlist);
                 }
             } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
-                $chgmsg = "'Action was taken on the following role requests by [_1].',$namelink";
+                my @chgmsgs = ({ mt => 'Action was taken by [_1].',
+                                 args => [$namelink] });
                 my (%approvals_by_requester,%rejections_by_requester,%for_requester);
                 my $sender = $env{'user.name'}.':'.$env{'user.domain'};
                 if (@completed) {
-                    $output .= '<p>'.&mt('The following roles in other domain(s) were assigned for user(s) in this domain:').'<ul>'.
-                               &get_othdombydc_results('approved',\@completed,\%approvals_by_requester,\%requestedby,\%for_requester).
+                    my $msg;
+                    if ($context eq 'othdombydc') {
+                        $msg = &mt('The following roles in other domain(s) were assigned for user(s) in this domain:');
+                    } elsif ($context eq 'othdombyuser') {
+                        $msg = &mt('The following roles in other domain(s) were assigned:');
+                    }
+                    $output .= '<p>'.$msg.'<ul>'.
+                               &get_othdomby_results($context,'approved',\@completed,\%approvals_by_requester,\%requestedby,\%for_requester).
                                '</ul></p>';
                 }
                 if (@rejectedreqs) {
-                    $output .= '<p>'.&mt('The following role assignments in other domain(s) for user(s) in this domain were rejected:').'<ul>'.
-                               &get_othdombydc_results('rejected',\@rejectedreqs,\%rejections_by_requester,\%requestedby,\%for_requester).
+                    my $msg;
+                    if ($context eq 'othdombydc') {
+                        $msg = &mt('The following role assignments in other domain(s) for user(s) in this domain were rejected:');
+                    } elsif ($context eq 'othdombyuser') {
+                        $msg = &mt('The following role assignments in other domain(s) were rejected:');
+                    }
+                    $output .= '<p>'.$msg.'<ul>'.
+                               &get_othdomby_results($context,'rejected',\@rejectedreqs,\%rejections_by_requester,\%requestedby,\%for_requester).
                                '</ul></p>';
                 }
                 foreach my $key (sort(keys(%for_requester))) {
                     if (ref($approvals_by_requester{$key}) eq 'ARRAY') {
                         if (@{$approvals_by_requester{$key}} > 0) {
-                            $approvedlist = join("\n\n",@{$approvals_by_requester{$key}});
+                            if ($context eq 'othdombydc') {
+                                push(@chgmsgs,{ mt => '[_1]The following roles in other domain(s) were assigned:',
+                                                args => ["\n"]});
+                            } elsif ($context eq 'othdombyuser') {
+                                push(@chgmsgs,{ mt => '[_1]The following roles in other domain(s) were accepted:',
+                                                args => ["\n"]});
+                            }
+                            push(@chgmsgs,@{$approvals_by_requester{$key}});
+                            $approvedlist = $key;
                         }
                     }
                     if (ref($rejections_by_requester{$key}) eq 'ARRAY') {
                         if (@{$rejections_by_requester{$key}} > 0) {
-                            $rejectedlist = join("\n\n",@{$rejections_by_requester{$key}});
+                            if ($context eq 'othdombydc') {
+                                push(@chgmsgs,{ mt => '[_1]The following roles in other domain(s) were rejected:',
+                                                args => ["\n"]});
+                            } elsif ($context eq 'othdombyuser') {
+                                push(@chgmsgs,{ mt => '[_1]The following roles in other domain(s) were declined:',
+                                                args => ["\n"]});
+                            }
+                            push(@chgmsgs,@{$rejections_by_requester{$key}});
+                            $rejectedlist = $key;
                         }
                     }
                     if (($approvedlist ne '') || ($rejectedlist ne '')) {
-                        &send_selfserve_notification($key,$chgmsg,'',$domdesc,$now,
+                        &send_selfserve_notification($key,\@chgmsgs,'',$domdesc,$now,
                                                      $context,$sender,$approvedlist,
                                                      $rejectedlist);
                     }
@@ -2138,7 +2219,8 @@
                 }
             }
         } else {
-            if (($context eq 'requestauthor') || ($context eq 'requestusername') || ($context eq 'othdombydc')) {
+            if (($context eq 'requestauthor') || ($context eq 'requestusername') || 
+                ($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
                 push(@warn_dels, at changes);
             }
         }
@@ -2314,8 +2396,21 @@
                 $output .= '<li>'.$uname.'</li>';
             }
             $output .= '</ul></p>';
-        } elsif ($context eq 'othdombydc') {
-
+        } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
+            my $msg;
+            if ($context eq 'othdombydc') {
+                $msg = &mt("For the following assignments of roles in other domain(s) for users from this domain, an error occurred when updating status in the pending queue");  
+            } elsif ($context eq 'othdombyuser') {
+                $msg = &mt("For the following assignments of roles in other domain(s), an error occurred when updating status in the pending queue");
+            }
+            $output .= '<p>'.$msg.'<ul>';
+            if (@warn_approves) {
+                $output .= &get_othdomby_results($context,'dequeue_error',\@warn_approves);
+            }
+            if (@warn_rejects) {
+                $output .= &get_othdomby_results($context,'dequeue_error',\@warn_rejects);
+            }
+            $output .= '</ul></p>';
         } else {
             $output .= '<p>'.&mt("For the following course/community requests an error occurred when updating the requestor's own requests record:").'<ul>';
             foreach my $cnum (@warn_approves, at warn_rejects) {
@@ -2346,10 +2441,15 @@
                 $output .= '<li>'.&unescape($escuname).'</li>';
             }
             $output .= '</ul></p>';
-        } elsif ($context eq 'othdombydc') {
-            $output .= '<p>'.
-                       &mt("For the following queued role assignments an error occurred when removing the item from the queue:").
-                       '<ul>'.&get_othdombydc_results('dequeue_error',\@warn_dels).'</ul>'.
+        } elsif (($context eq 'othdombydc') || ($context eq 'othdombyuser')) {
+            my $msg; 
+            if ($context eq 'othdombydc') {
+                $msg = &mt("For the following queued role assignments an error occurred when removing the item from the queue:");    
+            } elsif ($context eq 'othdombyuser') {
+                $msg = &mt("For the following role assignments pending approval an error occurred when removing the item from the queue:");
+            }
+            $output .= '<p>'.$msg.
+                       '<ul>'.&get_othdomby_results($context,'dequeue_error',\@warn_dels).'</ul>'.
                        '</p>';
         } else {
             $output .= '<p>'.&mt("For the following course/community requests an error occurred when removing requests from the pending queue:").'<ul>';
@@ -2368,8 +2468,8 @@
     return $output;
 }
 
-sub get_othdombydc_results {
-    my ($action,$items,$results,$requestedby,$for_requester) = @_;
+sub get_othdomby_results {
+    my ($context,$action,$items,$results,$requestedby,$for_requester) = @_;
     return unless (ref($items) eq 'ARRAY');
     unless ($action eq 'dequeue_error') {
         return unless ((ref($results) eq 'HASH') && (ref($requestedby) eq 'HASH') &&
@@ -2379,44 +2479,111 @@
     foreach my $item (@{$items}) {
         my ($extent,$role,$uname,$udom);
         if ($action eq 'approved') {
-            (my $num,$extent,$role,$uname,$udom) = split(/:/,$item);
+            if ($context eq 'othdombydc') {
+                (my $num,$extent,$role,$uname,$udom) = split(/:/,$item);
+            } elsif ($context eq 'othdombyuser') {
+                (my $num,$extent,$role) = split(/:/,$item);
+            }
         } elsif ($action eq 'rejected') {
-            ($extent,$role,$uname,$udom) = split(/:/,$item);
+            if ($context eq 'othdombydc') {
+                ($extent,$role,$uname,$udom) = split(/:/,$item);
+            } elsif ($context eq 'othdombyuser') {
+                ($extent,$role) = split(/:/,$item);
+            }
         } elsif ($action eq 'dequeue_error') {
-            (my $oldstatus,$uname,$extent,$role) = split(/:/,$item);
-            $udom = $env{'request.role.domain'};
+            if ($context eq 'othdombydc') {
+                if ($item =~ /^\d+:/) {
+                   (my $num,$extent,$role,$uname,$udom) = split(/:/,$item);
+                } elsif ($item =~ /^pending:/) {
+                    (my $oldstatus,$uname,$extent,$role) = split(/:/,$item);
+                    $udom = $env{'request.role.domain'};
+                } else {
+                    ($extent,$role,$uname,$udom) = split(/:/,$item);
+                }
+            } elsif ($context eq 'othdombyuser') {
+                if ($item =~ /^\d+:/) {
+                    (my $num,$extent,$role) = split(/:/,$item);
+                } elsif ($item =~ /^pending:/) {
+                    (my $oldstatus,$extent,$role) = split(/:/,$item);
+                } else {
+                    ($extent,$role) = split(/:/,$item);
+                }
+            }
+        }
+        if ($context eq 'othdombyuser') {
+            $uname = $env{'user.name'};
+            $udom = $env{'user.domain'};
+        }
+        my (@text, at msgs);
+        if ($context eq 'othdombydc') {
+            push(@text,&mt('User: [_1]',$uname));
+            push(@msgs,{ mt => '[_1]User: [_2]',
+                         args => ["\n",$uname]});
         }
-        my @text = (&mt('User: [_1]',$uname));
         if (($role eq 'ca') || ($role eq 'aa')) {
             my $plainrole = &Apache::lonnet::plaintext($role);
             my ($audom,$auname) = ($extent =~ m{^/($match_domain)/($match_username)$});
             my $title = &Apache::loncommon::plainname($auname,$audom);
+            my $domdesc = &Apache::lonnet::domain($audom);
             push(@text,(&mt('Role: [_1]',$plainrole),
-                        &mt('Domain: [_1]',&Apache::lonnet::domain($audom)),
+                        &mt('Domain: [_1]',$domdesc),
                         &mt('Authoring Space belonging to: [_1]',$title)));
+            push(@msgs,{ mt => 'Role: [_1]',
+                         args => [$plainrole],
+                       },
+                       { mt => 'Domain: [_1]',
+                         args => [$domdesc],
+                       },
+                       { mt => 'Authoring Space belonging to: [_1]',
+                         args => ["$title\n"],
+                       });
         } elsif ($extent =~ m{^/($match_domain)/$}) {
             my $domain = $1;
+            my $domdesc = &Apache::lonnet::domain($domain);
             my $plainrole = &Apache::lonnet::plaintext($role);
-            if (&Apache::lonnet::domain($domain) ne '') {
+            if ($domdesc ne '') {
                 push(@text,(&mt('Role: [_1]',$plainrole),
-                            &mt('Domain: [_1]',&Apache::lonnet::domain($domain))));
+                            &mt('Domain: [_1]',$domdesc)));
+                push(@msgs,{ mt => 'Role: [_1]',
+                             args => [$plainrole],
+                           },
+                           { mt => 'Domain: [_1]',
+                             args => ["$domdesc\n"],
+                           });
             }
         } else {
             my ($crsdom,$crsnum,$csec) = ($extent =~ m{^/($match_domain)/($match_courseid)(?:|/([^/]+)$)});
             if (($crsdom ne '') && ($crsnum ne '')) {
                 my %info = &Apache::lonnet::coursedescription("$crsdom/$crsnum");
                 my $plainrole = &Apache::lonnet::plaintext($role,$info{'type'});
+                my $domdesc = &Apache::lonnet::domain($crsdom);
                 push(@text,(&mt('Role: [_1]',$plainrole),
-                            &mt('Domain: [_1]',&Apache::lonnet::domain($crsdom)),
+                            &mt('Domain: [_1]',$domdesc),
                             &mt("$info{'type'}: [_1]",$info{'description'})));
+                push(@msgs,{ mt => 'Role: [_1]',
+                             args => [$plainrole],
+                           },
+                           { mt => 'Domain: [_1]',
+                             args => [$domdesc],
+                           });
                 if ($csec ne '') {
                     push(@text,&mt('Section: [_1]',$csec));
+                    push(@msgs,{ mt => "$info{'type'}: [_1]",
+                                 args => [$info{'description'}],
+                               },
+                               { mt => 'Section: [_1]',
+                                 args => ["$info{'description'}\n"],
+                               });
+                } else {
+                    push(@msgs,{ mt => "$info{'type'}: [_1]",
+                                 args => ["$info{'description'}\n"],
+                               });
                 }
             }
         }
         $output .= '<li><ul><li>'.join('</li><li>', at text).'</li></ul></li>';
         unless ($action eq 'dequeue_error') {
-            push(@{$results->{$requestedby->{$item}}},join("\n", at text));
+            push(@{$results->{$requestedby->{$item}}}, at msgs);
             $for_requester->{$requestedby->{$item}} = 1;
         }
     }
Index: loncom/interface/loncreateuser.pm
diff -u loncom/interface/loncreateuser.pm:1.467 loncom/interface/loncreateuser.pm:1.468
--- loncom/interface/loncreateuser.pm:1.467	Wed Mar 29 16:01:13 2023
+++ loncom/interface/loncreateuser.pm	Tue Jun 20 14:03:52 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Create a user
 #
-# $Id: loncreateuser.pm,v 1.467 2023/03/29 16:01:13 raeburn Exp $
+# $Id: loncreateuser.pm,v 1.468 2023/06/20 14:03:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4246,7 +4246,6 @@
 			      0 );
 		my $url='/'.$one.'/'.$two;
                 my $id = $url.'_'.$three;
-                my $type = 'three';
                 # split multiple sections
                 my %sections = ();
                 my $num_sections = &build_roles($env{'form.sec_'.$one.'_'.$two.'_'.$three},\%sections,$three);
@@ -4330,6 +4329,7 @@
                 my $two = $2;
 		my $url='/'.$one.'/';
                 my $id = $url.'_'.$two;
+                my ($cdom,$cnum) = split(/\//,$one);
                 # split multiple sections
                 my %sections = ();
                 my ($restricted,$numchanges);
@@ -4337,7 +4337,7 @@
                 if ($num_sections == 0) {
                     unless ($udom eq $one) {
                         $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
-                                          $uname,$two,$start,$end,$one,$two,'','',\%process_by,
+                                          $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
                                           \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                           \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
                         next if ($restricted);
@@ -4353,7 +4353,7 @@
                             unless ($udom eq $one) {
                                 undef($restricted);
                                 $restricted = &Apache::lonuserutils::restricted_dom($context,$secid,$udom,
-                                                  $uname,$two,$start,$end,$one,$two,$sec,'',\%process_by,
+                                                  $uname,$two,$start,$end,$cdom,$cnum,$sec,'',\%process_by,
                                                   \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                                   \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
                                 next if ($restricted);
@@ -4368,7 +4368,7 @@
                         unless ($udom eq $one) {
                             undef($restricted);
                             $restricted = &Apache::lonuserutils::restricted_dom($context,$id,$udom,
-                                              $uname,$two,$start,$end,$one,$two,'','',\%process_by,
+                                              $uname,$two,$start,$end,$cdom,$cnum,'','',\%process_by,
                                               \%instdoms,\%got_role_approvals,\%got_instdoms,\%reject,
                                               \%pending,\%notifydc,\%status,\%unauthorized,\%currqueued);
                             next if ($restricted);
@@ -7070,12 +7070,13 @@
                      chgcontext         => 'any',
                      rolelog_start_date => $defstart,
                      rolelog_end_date   => $now,
+                     approvals          => 'any',
                    );
     my $more_records = 0;
 
     # set current
     my %curr;
-    foreach my $item ('show','page','role','chgcontext') {
+    foreach my $item ('show','page','role','chgcontext','approvals') {
         $curr{$item} = $env{'form.'.$item};
     }
     my ($startdate,$enddate) = 
@@ -7149,6 +7150,11 @@
         if (($context eq 'course') && ($viewablesec ne '')) {
             next if ($roleslog{$id}{'logentry'}{'section'} ne $viewablesec);
         }
+        if ($curr{'approvals'} eq 'none') {
+            next if ($roleslog{$id}{'logentry'}{'approval'});
+        } elsif ($curr{'approvals'} ne 'any') { 
+            next if ($roleslog{$id}{'logentry'}{'approval'} ne $curr{'approvals'});
+        }
         $count ++;
         next if ($count < $minshown);
         unless ($showntableheader) {
@@ -7195,11 +7201,30 @@
         if ($chgcontext ne '' && $lt{$chgcontext} ne '') {
             $chgcontext = $lt{$chgcontext};
         }
+        my ($showreqby,%reqby);
+        if (($roleslog{$id}{'logentry'}{'approval'}) &&
+            ($roleslog{$id}{'logentry'}{'requester'})) {
+            if ($reqby{$roleslog{$id}{'logentry'}{'requester'}} eq '') {
+                my ($requname,$requdom) = split(/:/,$roleslog{$id}{'logentry'}{'requester'});
+                $reqby{$roleslog{$id}{'logentry'}{'requester'}} =
+                    &Apache::loncommon::plainname($requname,$requdom);
+            }
+            $showreqby = &mt('Requester').': <span class="LC_nobreak">'.$reqby{$roleslog{$id}{'logentry'}{'requester'}}.'</span><br />';
+            if ($roleslog{$id}{'logentry'}{'approval'} eq 'domain') {
+                $showreqby .= &mt('Adjudicator').': <span class="LC_nobreak">'.
+                              $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.
+                              '</span>';
+            } else {
+                $showreqby .= '<span class="LC_nobreak">'.&mt('User approved').'</span>';
+            }
+        } else {
+            $showreqby = $whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}};
+        }
         $r->print(
             &Apache::loncommon::start_data_table_row()
            .'<td>'.$count.'</td>'
            .'<td>'.&Apache::lonlocal::locallocaltime($roleslog{$id}{'exe_time'}).'</td>'
-           .'<td>'.$whodunit{$roleslog{$id}{'exe_uname'}.':'.$roleslog{$id}{'exe_udom'}}.'</td>'
+           .'<td>'.$showreqby.'</td>'
            .'<td>'.$changed{$roleslog{$id}{'uname'}.':'.$roleslog{$id}{'udom'}}.'</td>'
            .'<td>'.&Apache::lonnet::plaintext($roleslog{$id}{'logentry'}{'role'},$crstype).'</td>');
         if ($context eq 'course') { 
@@ -7688,7 +7713,7 @@
                &mt('Context:').'</b><br /><select name="chgcontext">';
     my @posscontexts;
     if ($context eq 'course') {
-        @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype');
+        @posscontexts = ('any','automated','updatenow','createcourse','course','domain','selfenroll','requestcourses','chgtype','ltienroll');
     } elsif ($context eq 'domain') {
         @posscontexts = ('any','domain','requestauthor','domconfig','server');
     } else {
@@ -7706,8 +7731,20 @@
         }
         $output .= '<option value="'.$chgtype.'"'.$selstr.'>'.$lt{$chgtype}.'</option>'."\n";
     }
-    $output .= '</select></td>'
-              .'</tr></table>';
+    my @possapprovals = ('any','none','domain','user');
+    my %apptxt = &approval_types();
+    $output .= '</select></td>'.
+               '<td>  </td>'.
+               '<td valign="top"><b>'.
+               &mt('Approvals:').'</b><br /><select name="approvals">';
+    foreach my $approval (@possapprovals) {
+        my $selstr = '';
+        if ($curr->{'approvals'} eq $approval) {
+            $selstr = ' selected="selected"';
+        }    
+        $output .= '<option value="'.$approval.'"'.$selstr.'>'.$apptxt{$approval}.'</option>';
+    }
+    $output .= '</select></td></tr></table>';
 
     # Update Display button
     $output .= '<p>'
@@ -7744,6 +7781,7 @@
                                              domain       => 'User Management in domain',
                                              selfenroll   => 'Self-enrolled',
                                              requestcourses => 'Course Request',
+                                             ltienroll    => 'Enrollment via LTI',
                                          );
         if ($crstype eq 'Community') {
             $lt{'createcourse'} = &mt('Community Creation');
@@ -7768,6 +7806,15 @@
     return %lt;
 }
 
+sub approval_types {
+    return &Apache::lonlocal::texthash (
+                                          any => 'Any',
+                                          none => 'No approval needed',
+                                          user => 'Role recipient approval',
+                                          domain => 'Domain coordinator approval',
+                                       );
+}
+
 sub print_helpdeskaccess_display {
     my ($r,$permission,$brcrum) = @_;
     my $formname = 'helpdeskaccess';
Index: loncom/interface/longroup.pm
diff -u loncom/interface/longroup.pm:1.31 loncom/interface/longroup.pm:1.32
--- loncom/interface/longroup.pm:1.31	Fri Mar 11 22:11:22 2016
+++ loncom/interface/longroup.pm	Tue Jun 20 14:03:52 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # accessor routines used to provide information about course groups 
 #
-# $Id: longroup.pm,v 1.31 2016/03/11 22:11:22 musolffc Exp $
+# $Id: longroup.pm,v 1.32 2023/06/20 14:03:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -237,7 +237,8 @@
 =cut
 
 sub group_changes {
-    my ($udom,$uname,$url,$role,$origend,$origstart,$selfenroll,$context) = @_;
+    my ($udom,$uname,$url,$role,$origend,$origstart,$selfenroll,$context,
+        $othdomby,$requester) = @_;
     my $now = time;
     my $chgtype;
     if ($origend > 0 && $origend <= $now) {
@@ -343,7 +344,8 @@
                                                   $add,$uname.':'.$udom,
                                                   $settings{$add}{'enddate'},
                                                   $settings{$add}{'startdate'},
-                                                  $group_privs,$selfenroll,$context) eq 'ok') {
+                                                  $group_privs,$selfenroll,$context,
+                                                  $othdomby,$requester) eq 'ok') {
                             my %usersettings;
                             $usersettings{$add.':'.$uname.':'.$udom} =
                                                                $addgroup{$add};
@@ -413,7 +415,8 @@
                                                          $uname.':'.$udom,$now,
                                                          $dropstart{$drop},
                                                          $currpriv{$drop},
-                                                         $selfenroll,$context) 
+                                                         $selfenroll,$context,
+                                                         $othdomby,$requester) 
                                                                      eq 'ok') {
                                 my %usersettings;
                                 $usersettings{$drop.':'.$uname.':'.$udom} =
Index: loncom/interface/lonuserutils.pm
diff -u loncom/interface/lonuserutils.pm:1.213 loncom/interface/lonuserutils.pm:1.214
--- loncom/interface/lonuserutils.pm:1.213	Thu Dec  1 01:28:26 2022
+++ loncom/interface/lonuserutils.pm	Tue Jun 20 14:03:52 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Utility functions for managing LON-CAPA user accounts
 #
-# $Id: lonuserutils.pm,v 1.213 2022/12/01 01:28:26 raeburn Exp $
+# $Id: lonuserutils.pm,v 1.214 2023/06/20 14:03:52 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -616,7 +616,7 @@
         $output .= '</ul></p>';
         if (keys(%touser)) {
             foreach my $key (keys(%touser)) {
-                my ($uname,$udom) = split(/:/,$touser{$key});
+                my ($uname,$udom) = split(/:/,$key);
                 if (&Apache::lonnet::put('nohist_queuedrolereqs',$touser{$key},$udom,$uname) eq 'ok') {
                     my $owndomdesc = &Apache::lonnet::domain($udom);
                     &Apache::loncoursequeueadmin::send_selfserve_notification($uname.':'.$udom,
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1511 loncom/lonnet/perl/lonnet.pm:1.1512
--- loncom/lonnet/perl/lonnet.pm:1.1511	Fri Jun  2 01:20:29 2023
+++ loncom/lonnet/perl/lonnet.pm	Tue Jun 20 14:03:57 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1511 2023/06/02 01:20:29 raeburn Exp $
+# $Id: lonnet.pm,v 1.1512 2023/06/20 14:03:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2757,7 +2757,7 @@
                                   'coursecategories','ssl','autoenroll',
                                   'trust','helpsettings','wafproxy',
                                   'ltisec','toolsec','domexttool',
-                                  'exttool'],$domain);
+                                  'exttool','privacy'],$domain);
     my @coursetypes = ('official','unofficial','community','textbook','placement');
     if (ref($domconfig{'defaults'}) eq 'HASH') {
         $domdefaults{'lang_def'} = $domconfig{'defaults'}{'lang_def'}; 
@@ -2968,6 +2968,21 @@
             }
         }
     }
+    if (ref($domconfig{'privacy'}) eq 'HASH') {
+        if (ref($domconfig{'privacy'}{'approval'}) eq 'HASH') {
+            foreach my $domtype ('instdom','extdom') {
+                if (ref($domconfig{'privacy'}{'approval'}{$domtype}) eq 'HASH') {
+                    foreach my $roletype ('domain','author','course','community') {
+                        if ($domconfig{'privacy'}{'approval'}{$domtype}{$roletype} eq 'user') {
+                            $domdefaults{'userapprovals'} = 1;
+                            last;
+                        }
+                    }
+                }
+                last if ($domdefaults{'userapprovals'});
+            }
+        }
+    }
     &do_cache_new('domdefaults',$domain,\%domdefaults,$cachetime);
     return %domdefaults;
 }
@@ -5424,7 +5439,8 @@
 }
 
 sub courserolelog {
-    my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,$selfenroll,$context)=@_;
+    my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,$selfenroll,
+        $context,$othdomby,$requester)=@_;
     if ($area =~ m-^/($match_domain)/($match_courseid)/?([^/]*)-) {
         my $cdom = $1;
         my $cnum = $2;
@@ -5437,6 +5453,16 @@
                            selfenroll => $selfenroll,
                            context    => $context,
                         );
+        if ($othdomby) {
+            if ($othdomby eq 'othdombydc') {
+                $storehash{'approval'} = 'domain';
+            } elsif ($othdomby eq 'othdombyuser') {
+                $storehash{'approval'} = 'user'; 
+            }
+            if ($requester ne '') {
+                $storehash{'requester'} = $requester;
+            }
+        }
         if ($trole eq 'gr') {
             $namespace = 'groupslog';
             $storehash{'group'} = $sec;
@@ -5453,7 +5479,8 @@
 }
 
 sub domainrolelog {
-    my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,$context)=@_;
+    my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,
+        $context,$othdomby,$requester)=@_;
     if ($area =~ m{^/($match_domain)/$}) {
         my $cdom = $1;
         my $domconfiguser = &get_domainconfiguser($cdom);
@@ -5464,6 +5491,16 @@
                            end     => $tend,
                            context => $context,
                         );
+        if ($othdomby) {
+            if ($othdomby eq 'othdombydc') {
+                $storehash{'approval'} = 'domain';
+            } elsif ($othdomby eq 'othdombyuser') {
+                $storehash{'approval'} = 'user';
+            }
+            if ($requester ne '') {
+                $storehash{'requester'} = $requester;
+            }
+        }
         &write_log('domain',$namespace,\%storehash,$delflag,$username,
                    $domain,$domconfiguser,$cdom);
     }
@@ -5472,7 +5509,8 @@
 }
 
 sub coauthorrolelog {
-    my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,$context)=@_;
+    my ($trole,$username,$domain,$area,$tstart,$tend,$delflag,
+        $context,$othdomby,$requester)=@_;
     if ($area =~ m{^/($match_domain)/($match_username)$}) {
         my $audom = $1;
         my $auname = $2;
@@ -5483,6 +5521,16 @@
                            end     => $tend,
                            context => $context,
                         );
+        if ($othdomby) {
+            if ($othdomby eq 'othdombydc') {
+                $storehash{'approval'} = 'domain';
+            } elsif ($othdomby eq 'othdombyuser') {
+                $storehash{'approval'} = 'user';
+            }
+            if ($requester ne '') {
+                $storehash{'requester'} = $requester;
+            }
+        }
         &write_log('author',$namespace,\%storehash,$delflag,$username,
                    $domain,$auname,$audom);
     }
@@ -8249,7 +8297,8 @@
 }
 
 sub is_advanced_user {
-    my ($udom,$uname) = @_;
+    my ($udom,$uname,$nocache) = @_;
+    my ($is_adv,$is_author,$use_cache,$hashid);
     if ($udom ne '' && $uname ne '') {
         if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'})) {
             if (wantarray) {
@@ -8257,11 +8306,21 @@
             } else {
                 return $env{'user.adv'};
             }
+        } elsif (!$nocache) {
+            $use_cache = 1;
+            $hashid = "$udom:$uname";  
+            my ($info,$cached)=&is_cached_new('isadvau',$hashid);
+            if ($cached) {
+                ($is_adv,$is_author) = split(/:/,$info);
+                if (wantarray) {
+                    return ($is_adv,$is_author);
+                }
+                return $is_adv; 
+            }
         }
     }
     my %roleshash = &get_my_roles($uname,$udom,'userroles',undef,undef,undef,1);
     my %allroles;
-    my ($is_adv,$is_author);
     foreach my $role (keys(%roleshash)) {
         my ($trest,$tdomain,$trole,$sec) = split(/:/,$role);
         my $area = '/'.$tdomain.'/'.$trest;
@@ -8292,6 +8351,10 @@
             }
         }
     }
+    if ($use_cache) {
+        my $cachetime = 600;
+        &do_cache_new('isadvau',$hashid,$is_adv.':'.$is_author,$cachetime);
+    }
     if (wantarray) {
         return ($is_adv,$is_author);
     }
@@ -10339,11 +10402,13 @@
 }
 
 sub modify_group_roles {
-    my ($cdom,$cnum,$group_id,$user,$end,$start,$userprivs,$selfenroll,$context) = @_;
+    my ($cdom,$cnum,$group_id,$user,$end,$start,$userprivs,$selfenroll,$context,
+        $othdomby,$requester) = @_;
     my $url = '/'.$cdom.'/'.$cnum.'/'.$group_id;
     my $role = 'gr/'.&escape($userprivs);
     my ($uname,$udom) = split(/:/,$user);
-    my $result = &assignrole($udom,$uname,$url,$role,$end,$start,'',$selfenroll,$context);
+    my $result = &assignrole($udom,$uname,$url,$role,$end,$start,'',$selfenroll,$context,
+                             $othdomby,$requester);
     if ($result eq 'ok') {
         &devalidate_getgroups_cache($udom,$uname,$cdom,$cnum);
     }
@@ -10471,43 +10536,66 @@
 
 sub assignrole {
     my ($udom,$uname,$url,$role,$end,$start,$deleteflag,$selfenroll,
-        $context)=@_;
+        $context,$othdomby,$requester,$reqsec,$reqrole)=@_;
     my $mrole;
     if ($role =~ /^cr\//) {
         my $cwosec=$url;
         $cwosec=~s/^\/($match_domain)\/($match_courseid)\/.*/$1\/$2/;
         if ((!&allowed('ccr',$cwosec)) && (!&allowed('ccr',$udom))) {
-           my $refused = 1;
-           if ($context eq 'requestcourses') {
-               if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
-                   if ($role =~ m{^cr/($match_domain)/($match_username)/([^/]+)$}) {
-                       if (($1 eq $env{'user.domain'}) && ($2 eq $env{'user.name'})) {
-                           my ($cdom,$cnum) = ($cwosec =~ m{^/?($match_domain)/($match_courseid)$});
-                           my %crsenv = &userenvironment($cdom,$cnum,('internal.courseowner'));
-                           if ($crsenv{'internal.courseowner'} eq
-                               $env{'user.name'}.':'.$env{'user.domain'}) {
-                               $refused = '';
-                           }
-                       }
-                   }
-               }
-           }
-           if ($refused) {
-               &logthis('Refused custom assignrole: '.
-                        $udom.' '.$uname.' '.$url.' '.$role.' '.$end.' '.$start.
-                        ' by '.$env{'user.name'}.' at '.$env{'user.domain'});
-               return 'refused';
-           }
+            my $refused = 1;
+            if ($context eq 'requestcourses') {
+                if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '')) {
+                    if ($role =~ m{^cr/($match_domain)/($match_username)/([^/]+)$}) {
+                        if (($1 eq $env{'user.domain'}) && ($2 eq $env{'user.name'})) {
+                            my ($cdom,$cnum) = ($cwosec =~ m{^/?($match_domain)/($match_courseid)$});
+                            my %crsenv = &userenvironment($cdom,$cnum,('internal.courseowner'));
+                            if ($crsenv{'internal.courseowner'} eq
+                                $env{'user.name'}.':'.$env{'user.domain'}) {
+                                $refused = '';
+                            }
+                        }
+                    }
+                }
+            } elsif (($context eq 'course') && ($othdomby eq 'othdombyuser')) {
+                my ($cdom,$cnum) = ($cwosec =~ m{^/?($match_domain)/($match_courseid)$});
+                my ($sec) = ($url =~ m{^/\Q$cwosec\E/(.*)$});
+                my $key = "$uname:$udom:$role:$sec";
+                my %queuedrolereq = &Apache::lonnet::get('nohist_othdomqueued',[$key],$cdom,$cnum);
+                if ((exists($queuedrolereq{$key})) && (ref($queuedrolereq{$key}) eq 'HASH')) {
+                    if (($queuedrolereq{$key}{'adj'} eq 'user') && ($queuedrolereq{$key}{'requester'} eq $requester)) {
+                        $refused = '';
+                    }
+                }
+            }
+            if ($refused) {
+                &logthis('Refused custom assignrole: '.
+                         $udom.' '.$uname.' '.$url.' '.$role.' '.$end.' '.$start.
+                         ' by '.$env{'user.name'}.' at '.$env{'user.domain'});
+                return 'refused';
+            }
         }
         $mrole='cr';
     } elsif ($role =~ /^gr\//) {
         my $cwogrp=$url;
         $cwogrp=~s{^/($match_domain)/($match_courseid)/.*}{$1/$2};
-        unless (&allowed('mdg',$cwogrp)) {
-            &logthis('Refused group assignrole: '.
-              $udom.' '.$uname.' '.$url.' '.$role.' '.$end.' '.$start.' by '.
-                    $env{'user.name'}.' at '.$env{'user.domain'});
-            return 'refused';
+        if (!&allowed('mdg',$cwogrp)) {
+            my $refused = 1;
+            if (($refused) && ($othdomby eq 'othdombyuser') && ($requester ne '') && ($reqrole ne '')) {
+                my ($cdom,$cnum) = ($cwogrp =~ m{^/?($match_domain)/($match_courseid)$});
+                my $key = "$uname:$udom:$reqrole:$reqsec";
+                my %queuedrolereq = &Apache::lonnet::get('nohist_othdomqueued',[$key],$cdom,$cnum);
+                if ((exists($queuedrolereq{$key})) && (ref($queuedrolereq{$key}) eq 'HASH')) {
+                    if (($queuedrolereq{$key}{'adj'} eq 'user') && ($queuedrolereq{$key}{'requester'} eq $requester)) {
+                        $refused = '';
+                    }
+                }
+            }
+            if ($refused) {
+                &logthis('Refused group assignrole: '.
+                         $udom.' '.$uname.' '.$url.' '.$role.' '.$end.' '.$start.' by '.
+                         $env{'user.name'}.' at '.$env{'user.domain'});
+                return 'refused';
+            }
         }
         $mrole='gr';
     } else {
@@ -10524,7 +10612,8 @@
             }
             if ($refused) {
                 my ($cdom,$cnum) = ($cwosec =~ m{^/?($match_domain)/($match_courseid)$});
-                if (!$selfenroll && (($context eq 'course') || ($context eq 'ltienroll' && $env{'request.lti.login'}))) {
+                if (!$selfenroll && ($othdomby ne 'othdombyuser') &&
+                   (($context eq 'course') || ($context eq 'ltienroll' && $env{'request.lti.login'}))) {
                     my %crsenv;
                     if ($role eq 'cc' || $role eq 'co') {
                         %crsenv = &userenvironment($cdom,$cnum,('internal.courseowner'));
@@ -10550,6 +10639,49 @@
                     } elsif (($context eq 'ltienroll') && ($env{'request.lti.login'})) {
                         $refused = '';
                     }
+                } elsif ($othdomby eq 'othdombyuser') {
+                    my ($key,%queuedrolereq);
+                    if ($context eq 'course') {
+                        my ($sec) = ($url =~ m{^/\Q$cwosec\E/(.*)$});
+                        $key = "$uname:$udom:$role:$sec";
+                        %queuedrolereq = &Apache::lonnet::get('nohist_othdomqueued',[$key],$cdom,$cnum);
+                        if ((exists($queuedrolereq{$key})) && (ref($queuedrolereq{$key}) eq 'HASH')) {
+                            if (($queuedrolereq{$key}{'adj'} eq 'user') && ($queuedrolereq{$key}{'requester'} eq $requester)) {
+                                if ((($role eq 'cc') && ($cnum !~ /^$match_community$/)) || 
+                                    (($role eq 'co') && ($cnum =~ /^$match_community$/))) {
+                                    my %crsenv = &userenvironment($cdom,$cnum,('internal.courseowner'));
+                                    if ($crsenv{'internal.courseowner'} eq $requester) {
+                                        $refused = '';
+                                    }
+                                } elsif ($role =~ /^(?:in|ta|ep|st)$/) {
+                                    $refused = '';
+                                }
+                            }
+                        }
+                    } elsif (($context eq 'author') && ($role =~ /^ca|aa$/)) {
+                        my $key = "$uname:$udom:$role"; 
+                        my ($audom,$auname) = ($url =~ m{^/($match_domain)/($match_username)$});
+                        if (($audom ne '') && ($auname ne '')) {
+                            my %queuedrolereq = &Apache::lonnet::get('nohist_othdomqueued',[$key],$audom,$auname);
+                            if ((exists($queuedrolereq{$key})) && (ref($queuedrolereq{$key}) eq 'HASH')) {
+                                if (($queuedrolereq{$key}{'adj'} eq 'user') && ($queuedrolereq{$key}{'requester'} eq $requester)) {
+                                    $refused = '';
+                                }
+                            }
+                        }
+                    } elsif (($context eq 'domain') && ($role ne 'dc') && ($role ne 'su')) {
+                        my $key = "$uname:$udom:$role";
+                        my ($roledom) = ($url =~ m{^/($match_domain)/\Q$role\E$});
+                        if ($roledom ne '') {
+                            my $confname = $roledom.'-domainconfig';
+                            my %queuedrolereq = &Apache::lonnet::get('nohist_othdomqueued',[$key],$roledom,$confname);
+                            if ((exists($queuedrolereq{$key})) && (ref($queuedrolereq{$key}) eq 'HASH')) {
+                                if (($queuedrolereq{$key}{'adj'} eq 'user') && ($queuedrolereq{$key}{'requester'} eq $requester)) {
+                                    $refused = '';
+                                }
+                            }
+                        }
+                    }
                 } elsif ($context eq 'requestcourses') {
                     my @possroles = ('st','ta','ep','in','cc','co');
                     if ((grep(/^\Q$role\E$/, at possroles)) && ($env{'user.name'} ne '' && $env{'user.domain'} ne '')) {
@@ -10662,15 +10794,15 @@
                                                  $origstart,$selfenroll,$context);
             }
             &courserolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,
-                           $selfenroll,$context);
+                           $selfenroll,$context,$othdomby,$requester);
         } elsif (($role eq 'li') || ($role eq 'dg') || ($role eq 'sc') ||
                  ($role eq 'au') || ($role eq 'dc') || ($role eq 'dh') ||
                  ($role eq 'da')) {
             &domainrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,
-                           $context);
+                           $context,$othdomby,$requester);
         } elsif (($role eq 'ca') || ($role eq 'aa')) {
             &coauthorrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag,
-                             $context); 
+                             $context,$othdomby,$requester); 
         }
         if ($role eq 'cc') {
             &autoupdate_coowners($url,$end,$start,$uname,$udom);
@@ -11022,7 +11154,7 @@
 
 sub modify_student_enrollment {
     my ($udom,$uname,$uid,$first,$middle,$last,$gene,$usec,$end,$start,$type,
-        $locktype,$cid,$selfenroll,$context,$credits,$instsec) = @_;
+        $locktype,$cid,$selfenroll,$context,$credits,$instsec,$othdomby,$requester) = @_;
     my ($cdom,$cnum,$chome);
     if (!$cid) {
 	unless ($cid=$env{'request.course.id'}) {
@@ -11083,7 +11215,7 @@
 	$uurl.='/'.$usec;
     }
     my $result = &assignrole($udom,$uname,$uurl,'st',$end,$start,undef,
-                             $selfenroll,$context);
+                             $selfenroll,$context,$othdomby,$requester);
     if ($result ne 'ok') {
         if ($old_entry{$user} ne '') {
             $reply = &cput('classlist',\%old_entry,$cdom,$cnum);
@@ -11359,9 +11491,11 @@
 # ---------------------------------------------------------- Assign Custom Role
 
 sub assigncustomrole {
-    my ($udom,$uname,$url,$rdom,$rnam,$rolename,$end,$start,$deleteflag,$selfenroll,$context)=@_;
+    my ($udom,$uname,$url,$rdom,$rnam,$rolename,$end,$start,$deleteflag,
+        $selfenroll,$context,$othdomby,$requester)=@_;
     return &assignrole($udom,$uname,$url,'cr/'.$rdom.'/'.$rnam.'/'.$rolename,
-                       $end,$start,$deleteflag,$selfenroll,$context);
+                       $end,$start,$deleteflag,$selfenroll,$context,$othdomby,
+                       $requester);
 }
 
 # ----------------------------------------------------------------- Revoke Role
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.369 loncom/auth/lonroles.pm:1.370
--- loncom/auth/lonroles.pm:1.369	Sat Oct 29 18:13:29 2022
+++ loncom/auth/lonroles.pm	Tue Jun 20 14:04:02 2023
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # User Roles Screen
 #
-# $Id: lonroles.pm,v 1.369 2022/10/29 18:13:29 raeburn Exp $
+# $Id: lonroles.pm,v 1.370 2023/06/20 14:04:02 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -444,6 +444,12 @@
        $reqauthor = &Apache::loncoursequeueadmin::process_reqauthor(\$update);
     }
 
+# ------------------------------------------------- Check for approval results
+    my $approvalresult;
+    if (($env{'form.approvals'} eq 'show') && ($env{'form.state'} eq 'done')) {
+        $approvalresult = &Apache::loncoursequeueadmin::update_request_queue('othdombyuser',  
+                                                                             $env{'user.domain'});
+    }
     my $envkey;
     my %dcroles = ();
     my %helpdeskroles = ();
@@ -1233,7 +1239,7 @@
     } else {
         my $crumbsright;
         unless (($norolelist) && ((split(/:/,$env{'user.error.msg'}))[2])) {
-            $funcs = &get_roles_functions($showcount,$cattype);
+            $funcs = &get_roles_functions($showcount,$cattype,$domdefs{'userapprovals'});
             if ($env{'browser.mobile'}) {
                 $crumbsright = $funcs;
                 undef($funcs);
@@ -1271,7 +1277,11 @@
 }
 
 function rolesView (caller) {
-    if ((caller == 'showall') || (caller == 'noshowall')) {
+    if (caller == 'approvals') {
+        document.rolechoice.approvals.value = 'show';
+    } else if (caller == 'noapprovals') {
+        document.rolechoice.approvals.value = 'hide';
+    } else if ((caller == 'showall') || (caller == 'noshowall')) {
         document.rolechoice.display.value = caller;
     } else {
         if ((caller == 'doupdate') || (caller == 'requestauthor') ||
@@ -1367,22 +1377,31 @@
             }
             if ($hotlist) {
                 $showresult .= $hotlist;
-            } 
+            }
             $showresult .= '</div>';
             $r->print($showresult);
         } elsif ($env{'form.state'} eq 'queued') {
             $r->print(&get_queued());
+        } elsif ($env{'form.approvals'} eq 'show') {
+            if ($env{'form.state'} eq 'done') {
+                $r->print($approvalresult).'<br />';
+            }
+            $r->print('<div class="LC_left_float"><fieldset><legend>'.&mt('Role assignments queued pending your acceptance').'</legend>'.
+                     &get_approvals().
+                     '</fieldset></div><br clear="all" />');
         }
         if (($ENV{'REDIRECT_QUERY_STRING'}) && ($fn)) {
     	    $fn.='?'.$ENV{'REDIRECT_QUERY_STRING'};
         }
         my $display = ($env{'form.display'} =~ /^(showall)$/);
+        my $approvals = ($env{'form.approvals'} =~ /^(show)$/);
         $r->print('<form method="post" name="rolechoice" action="'.(($fn)?$fn:$r->uri).'">');
         $r->print('<input type="hidden" name="orgurl" value="'.$fn.'" />');
         $r->print('<input type="hidden" name="selectrole" value="1" />');
         $r->print('<input type="hidden" name="newrole" value="" />');
         $r->print('<input type="hidden" name="display" value="'.$display.'" />');
         $r->print('<input type="hidden" name="state" value="" />');
+        $r->print('<input type="hidden" name="approvals" value="'.$approvals.'" />');
         if ($blocked_by_ip) {
             my $blocked_role = 'student';
             if ($blocked_type eq 'Community') {
@@ -3366,7 +3385,7 @@
 }
 
 sub get_roles_functions {
-    my ($rolescount,$cattype) = @_;
+    my ($rolescount,$cattype,$userapprovals) = @_;
     my @links;
     push(@links,["javascript:rolesView('doupdate');",'start-here-22x22',&mt('Check for changes')]);
     if ($env{'environment.canrequest.author'}) {
@@ -3395,6 +3414,13 @@
     unless ($cattype eq 'none') {
         push(@links,['/adm/coursecatalog','ccat-22x22',&mt('Course catalog')]);
     }
+    if ($userapprovals) {
+        if ($env{'form.approvals'} eq 'show') {
+            push(@links,["javascript:rolesView('noapprovals');",'list-add-22x22',&mt('Hide pending')]);
+        } else {
+            push(@links,["javascript:rolesView('approvals');",'list-add-22x22',&mt('Show pending')]);
+        }
+    }
     my $funcs;
     if ($env{'browser.mobile'}) {
         my @functions;
@@ -3498,15 +3524,23 @@
     unless ($output) {
         if ($env{'environment.canrequest.author'} || $env{'environment.canrequest.official'} ||
             $env{'environment.canrequest.unofficial'} || $env{'environment.canrequest.community'}) {
-            $output = &mt('No requests for courses, communities or authoring currently queued');
+            $output = '<span class="LC_info">'.
+                      &mt('No requests for courses, communities or authoring currently queued').
+                      '</span>';
         } else {
-            $output = &mt('No enrollment requests currently queued awaiting approval');
+            $output = '<span class="LC_info">'.
+                      &mt('No enrollment requests currently queued awaiting approval').
+                      '</span>';
         }
     }
     return '<div class="LC_left_float"><fieldset><legend>'.&mt('Queued requests').'</legend>'.
            $output.'</fieldset></div><br clear="all" />';
 }
 
+sub get_approvals {
+    return &Apache::loncoursequeueadmin::display_queued_requests('othdomaction',$env{'user.domain'},'','user');
+}
+
 sub process_lti {
     my ($r,$cdom,$cnum) = @_;
     my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');


More information about the LON-CAPA-cvs mailing list