--- loncom/auth/lonroles.pm 2021/01/04 12:53:37 1.269.2.37.2.2
+++ loncom/auth/lonroles.pm 2025/02/23 05:16:01 1.376
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.269.2.37.2.2 2021/01/04 12:53:37 raeburn Exp $
+# $Id: lonroles.pm,v 1.376 2025/02/23 05:16:01 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -140,10 +140,82 @@ use Apache::lonnavdisplay();
use Apache::loncoursequeueadmin;
use Apache::longroup;
use Apache::lonrss;
+use Apache::lonplacementtest;
use GDBM_File;
use LONCAPA qw(:DEFAULT :match);
use HTML::Entities;
-
+
+my $registered_cleanup;
+my $rosterupdates;
+
+sub start_loading_course {
+ my ($r,$title,$only_body) = @_;
+ &Apache::loncommon::content_type($r,'text/html');
+ &Apache::loncommon::no_cache($r);
+ $r->send_http_header;
+ if ($only_body) {
+ $r->print(&Apache::loncommon::start_page($title,undef,{'only_body' => 1,
+ 'add_progressbar' => 1}));
+ } else {
+ my $swinfo=&Apache::lonmenu::rawconfig();
+ # Breadcrumbs
+ my $brcrum = [{'href' => '',
+ 'text' => $title},];
+ my $start_page = &Apache::loncommon::start_page($title,undef,
+ {'bread_crumbs' => $brcrum,
+ 'bread_crumbs_nomenu' => 1,
+ 'links_disabled' => 1});
+ $r->print(< $msg $msg '.&mt('The following problems occurred:').
- ' $lt{'tfp'}
+
'.
- $error.
- '
'.&mt('Continue').''
- );
- $r->print(&Apache::loncommon::end_page());
+ my $end_page = &Apache::loncommon::end_page();
+ $dest = &HTML::Entities::encode($dest,'"<>&');
+ $r->print(<
+$error
+
$lt{'con'}
+$end_page
+END
+ return;
}
sub handler {
@@ -227,6 +292,129 @@ sub handler {
$update = $then;
}
+ my ($norolelist,$blocked_by_ip,$blocked_type,$clientip);
+ $clientip = &Apache::lonnet::get_requestor_ip($r);
+ if (($env{'request.course.id'}) && ($env{'request.deeplink.login'})) {
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
+ my $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
+ if ($deeplink_symb) {
+ my ($menucoll,$deeplinkmenu,$menuref) = &Apache::loncommon::menucoll_in_effect();
+ if (ref($menuref) eq 'HASH') {
+ unless (($menuref->{'role'}) || ($env{'request.role.adv'})) {
+ foreach my $envkey (keys(%env)) {
+ next unless ($envkey =~ /^form\./);
+ if ($envkey =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
+ unless (($1 eq $cdom) && ($2 eq $cnum)) {
+ delete($env{$envkey});
+ }
+ }
+ }
+ if ($env{'form.selectrole'}) {
+ if ($env{'form.switchrole'} =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
+ unless (($1 eq $cdom) && ($2 eq $cnum)) {
+ delete($env{'form.selectrole'});
+ delete($env{'form.switchrole'});
+ }
+ } elsif ($env{'form.newrole'} =~ m{\./($match_domain)/($match_courseid)(?:/(\w+)|$)}) {
+ unless (($1 eq $cdom) && ($2 eq $cnum)) {
+ delete($env{'form.selectrole'});
+ delete($env{'form.newrole'});
+ }
+ }
+ }
+ $norolelist = 1;
+ }
+ }
+ }
+ }
+
+ if ($env{'form.selectrole'}) {
+ my ($role,$cdom,$cnum,$rest);
+ if ($env{'form.switchrole'} =~ m{^(co|cc|in|ta|ep|ad|st|cr).*?\./($match_domain)/($match_courseid)(/(\w+)|$)}) {
+ ($role,$cdom,$cnum,$rest) = ($1,$2,$3,$4);
+ } elsif ($env{'form.newrole'} =~ m{^(co|cc|in|ta|ep|ad|st|cr).*?\./($match_domain)/($match_courseid)(/(\w+)|$)}) {
+ ($role,$cdom,$cnum,$rest) = ($1,$2,$3,$4);
+ }
+ if ($cdom ne '') {
+ my ($has_evb,$check_ipaccess,$showrole);
+ $showrole = 1;
+ my $checkrole = "cm./$cdom/$cnum";
+ if ($rest ne '') {
+ $checkrole .= "/$rest";
+ }
+ if ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
+ ($role ne 'st')) {
+ $has_evb = 1;
+ }
+ unless ($has_evb) {
+ my @machinedoms = &Apache::lonnet::current_machine_domains();
+ my $udom = $env{'user.domain'};
+ if ($udom eq $cdom) {
+ $check_ipaccess = 1;
+ } elsif (($udom ne '') && (grep(/^\Q$udom\E$/,@machinedoms))) {
+ $check_ipaccess = 1;
+ } else {
+ my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
+ my $internet_names = &Apache::lonnet::get_internet_names($lonhost);
+ my $cprim = &Apache::lonnet::domain($cdom,'primary');
+ my $cintdom = &Apache::lonnet::internet_dom($cprim);
+ if (($cintdom ne '') && (ref($internet_names) eq 'ARRAY')) {
+ if (grep(/^\Q$cintdom\E$/,@{$internet_names})) {
+ $check_ipaccess = 1;
+ }
+ }
+ }
+ if ($check_ipaccess) {
+ my ($ipaccessref,$cached)=&Apache::lonnet::is_cached_new('ipaccess',$cdom);
+ unless (defined($cached)) {
+ my %domconfig =
+ &Apache::lonnet::get_dom('configuration',['ipaccess'],$cdom);
+ $ipaccessref = &Apache::lonnet::do_cache_new('ipaccess',$cdom,$domconfig{'ipaccess'},1800);
+ }
+ if (ref($ipaccessref) eq 'HASH') {
+ foreach my $id (keys(%{$ipaccessref})) {
+ if (ref($ipaccessref->{$id}) eq 'HASH') {
+ my $range = $ipaccessref->{$id}->{'ip'};
+ if ($range) {
+ my $type = 'exclude';
+ if (&Apache::lonnet::ip_match($clientip,$range)) {
+ $type = 'include';
+ }
+ if (ref($ipaccessref->{$id}->{'courses'}) eq 'HASH') {
+ if ($ipaccessref->{$id}->{'courses'}{$cdom.'_'.$cnum}) {
+ if ($type eq 'include') {
+ $showrole = 1;
+ last;
+ } else {
+ $showrole = 0;
+ }
+ } else {
+ if ($type eq 'include') {
+ $showrole = 0;
+ } else {
+ $showrole = 1;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ unless ($showrole) {
+ $blocked_by_ip = 1;
+ $blocked_type = &Apache::loncommon::course_type($cdom.'_'.$cnum);
+ delete($env{'form.selectrole'});
+ delete($env{'form.newrole'});
+ }
+ }
+ }
+
+ $registered_cleanup=0;
+ @{$rosterupdates}=();
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
# -------------------------------------------------- Check if setting hot list
@@ -258,15 +446,27 @@ sub handler {
$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 = ();
- my ($numdc,$numhelpdesk,$numadhoc) =
+ my %helpdeskroles = ();
+ my ($numdc,$numhelpdesk,$numadhoc) =
&check_for_adhoc(\%dcroles,\%helpdeskroles,$update,$then);
my $loncaparev = $r->dir_config('lonVersion');
# ================================================================== Roles Init
if ($env{'form.selectrole'}) {
+ if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq '')) {
+ if ($env{'form.ltitarget'} eq 'iframe') {
+ &Apache::lonnet::appenv({'request.lti.target' => 'iframe'});
+ delete($env{'form.ltitarget'});
+ }
+ }
my $locknum=&Apache::lonnet::get_locks();
if ($locknum) { return 409; }
@@ -307,6 +507,7 @@ sub handler {
"request.course.sec" => '',
"request.course.tied" => '',
"request.course.timechecked" => '',
+ "request.course.suppupdated" => '',
"request.role" => 'cm',
"request.role.adv" => $env{'user.adv'},
"request.role.domain" => $env{'user.domain'}});
@@ -319,7 +520,7 @@ sub handler {
if ($custom_adhoc) {
my ($possroles,$description) = &Apache::lonnet::get_my_adhocroles($cdom.'_'.$cnum,1);
if (ref($possroles) eq 'ARRAY') {
- if (grep(/^\Q$rolename\E$/,@{$possroles})) {
+ if (grep(/^\Q$rolename\E$/,@{$possroles})) {
if (&Apache::lonnet::check_adhoc_privs($cdom,$cnum,$update,$refresh,$now,
"cr/$cdom/$cdom".'-domainconfig/'.$rolename,undef,$sec)) {
&Apache::lonnet::appenv({"environment.internal.$cdom.$cnum.cr/$cdom/$cdom".'-domainconfig/'."$rolename.adhoc" => time});
@@ -331,8 +532,8 @@ sub handler {
# Check if user is a DC trying to enter a course or author space and needs privs to be created
# Check if user is a DH or DA trying to enter a course and needs privs to be created
foreach my $envkey (keys(%env)) {
- if ($numdc) {
# Is this an ad-hoc Coordinator role?
+ if ($numdc) {
if (my ($ccrole,$domain,$coursenum) =
($envkey =~ m-^form\.(cc|co)\./($match_domain)/($match_courseid)$-)) {
if ($dcroles{$domain}) {
@@ -423,10 +624,9 @@ sub handler {
}
last;
}
- }
+ }
}
}
-
foreach $envkey (keys(%env)) {
next if ($envkey!~/^user\.role\./);
my ($where,$trolecode,$role,$tstatus,$tend,$tstart);
@@ -484,17 +684,24 @@ sub handler {
$env{'environment.key.'.$cdom.'_'.$cnum},
$authdom,$authnum)) {
# there is no valid key
+ my $swinfo=&Apache::lonmenu::rawconfig();
+ my $crumbtext = 'User Roles';
+ my $show_course=&Apache::loncommon::show_course();
+ if ($show_course) {
+ $crumbtext = 'Courses';
+ }
if ($env{'form.newkey'}) {
# student attempts to register a new key
&Apache::loncommon::content_type($r,'text/html');
&Apache::loncommon::no_cache($r);
$r->send_http_header;
- my $swinfo=&Apache::lonmenu::rawconfig();
+ my $pagetitle = 'Verifying Access Key to Unlock this Course';
+ my $brcrum =[{href=>"/adm/roles",text=>$crumbtext},
+ {href=>"/adm/roles",text=>'Verify Access Key'}];
my $start_page=&Apache::loncommon::start_page
- ('Verifying Access Key to Unlock this Course');
+ ($pagetitle, undef,{bread_crumbs=>$brcrum,});
my $end_page=&Apache::loncommon::end_page();
- my $buttontext=&mt('Enter Course');
- my $message=&mt('Successfully registered key');
+ my ($buttontext,$message,$inputitem,$accessheader);
my $ip = &Apache::lonnet::get_requestor_ip();
my $assignresult=
&Apache::lonnet::assign_access_key(
@@ -505,41 +712,63 @@ sub handler {
$env{'user.name'},
&mt('Assigned from [_1] at [_2] for [_3]'
,$ip
- ,&Apache::lonlocal::locallocaltime()
+ ,&Apache::lonlocal::locallocaltime($now)
,$trolecode)
);
- unless ($assignresult eq 'ok') {
- $assignresult=~s/^error\:\s*//;
- $message=&mt($assignresult).
- '
'.
- &mt('Logout').'';
- $buttontext=&mt('Re-Enter Key');
- }
- $r->print(<
'.
+ &mt('Result').': '.&mt($assignresult);
+ my $labeltext = &mt('Enter access key');
+ $inputitem = '';
+ }
+ $r->print(<<"ENDREGKEY");
$start_page
-
'.&mt('If you were expecting to see an active role listed for a particular course, that course may not have been created yet.').'
'); @@ -1572,7 +2095,7 @@ sub findcourse_advice { $r->print(''.&mt('You may also have been assigned to a course in the time since you last logged-in, or checked for changes.').
'
'.
&mt('If that is the case you can use the "Check for changes" link in the gray Functions bar to update the list of your available course roles.').'