From 7aceb41c13bf6ecca59da57b1b497d2f452bf963 Mon Sep 17 00:00:00 2001 From: Nathan Wallach Date: Tue, 27 Oct 2020 12:41:49 +0200 Subject: [PATCH 1/2] Add a fallback setting for $LTI_webwork_permissionLevel as student level, so if the test defined( $ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}} ) fails - the account will not get created with an undefined permission level, which prevents logins from working. The most likely cause of such problems are missing LMS roles which are not defined in %LMSrolesToWeBWorKroles (which is usually defined in conf/authen_LTI.conf). --- lib/WeBWorK/Authen/LTIAdvanced.pm | 11 +++++++---- lib/WeBWorK/Authen/LTIBasic.pm | 12 ++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/WeBWorK/Authen/LTIAdvanced.pm b/lib/WeBWorK/Authen/LTIAdvanced.pm index 03258355bb..5171ec45c6 100644 --- a/lib/WeBWorK/Authen/LTIAdvanced.pm +++ b/lib/WeBWorK/Authen/LTIAdvanced.pm @@ -501,13 +501,16 @@ sub create_user { } my $nr = scalar(@LTIroles); + + my $LTI_webwork_permissionLevel; if (! defined($ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}})) { croak("Cannot find a WeBWorK role that corresponds to the LMS role of " - . $LTIroles[0] ."."); + . $LTIroles[0] ." so will create a student level account."); + $LTI_webwork_permissionLevel = $ce->{userRoles}->{student}; + } else { + $LTI_webwork_permissionLevel = $ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}}; } - - my $LTI_webwork_permissionLevel - = $ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}}; + if ($nr > 1) { for (my $j =1; $j < $nr; $j++) { my $wwRole = $ce->{LMSrolesToWeBWorKroles}->{$LTIroles[$j]}; diff --git a/lib/WeBWorK/Authen/LTIBasic.pm b/lib/WeBWorK/Authen/LTIBasic.pm index 5c680e8b1f..d995f56d6f 100644 --- a/lib/WeBWorK/Authen/LTIBasic.pm +++ b/lib/WeBWorK/Authen/LTIBasic.pm @@ -517,12 +517,16 @@ sub authenticate } my $nr = scalar(@LTIroles); - if (! defined($ce -> {userRoles} -> {$ce -> {LMSrolesToWeBWorKroles} -> {$LTIroles[0]}})) { + + my $LTI_webwork_permissionLevel; + if (! defined($ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}})) { croak("Cannot find a WeBWorK role that corresponds to the LMS role of " - . $LTIroles[0] ."."); + . $LTIroles[0] ." so will create a student level account."); + $LTI_webwork_permissionLevel = $ce->{userRoles}->{student}; + } else { + $LTI_webwork_permissionLevel = $ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}}; } - my $LTI_webwork_permissionLevel - = $ce -> {userRoles} -> {$ce -> {LMSrolesToWeBWorKroles} -> {$LTIroles[0]}}; + if ($nr > 1) { for (my $j =1; $j < $nr; $j++) { my $wwRole = $ce -> {LMSrolesToWeBWorKroles} -> {$LTIroles[$j]}; From add3b17df6f6bdd78e499fc0d8c8c7542dc4ecf3 Mon Sep 17 00:00:00 2001 From: Nathan Wallach Date: Tue, 27 Oct 2020 13:53:10 +0200 Subject: [PATCH 2/2] Additional fix, so the second hash table lookup will not be tried if the first one would fail. --- lib/WeBWorK/Authen/LTIAdvanced.pm | 5 +++-- lib/WeBWorK/Authen/LTIBasic.pm | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/WeBWorK/Authen/LTIAdvanced.pm b/lib/WeBWorK/Authen/LTIAdvanced.pm index 5171ec45c6..6757904bc1 100644 --- a/lib/WeBWorK/Authen/LTIAdvanced.pm +++ b/lib/WeBWorK/Authen/LTIAdvanced.pm @@ -503,8 +503,9 @@ sub create_user { my $nr = scalar(@LTIroles); my $LTI_webwork_permissionLevel; - if (! defined($ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}})) { - croak("Cannot find a WeBWorK role that corresponds to the LMS role of " + if ( ! defined( $ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]} ) || + ! defined( $ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}} ) ) { + warn("Cannot find a WeBWorK role that corresponds to the LMS role of " . $LTIroles[0] ." so will create a student level account."); $LTI_webwork_permissionLevel = $ce->{userRoles}->{student}; } else { diff --git a/lib/WeBWorK/Authen/LTIBasic.pm b/lib/WeBWorK/Authen/LTIBasic.pm index d995f56d6f..4d867a1caf 100644 --- a/lib/WeBWorK/Authen/LTIBasic.pm +++ b/lib/WeBWorK/Authen/LTIBasic.pm @@ -519,8 +519,9 @@ sub authenticate my $nr = scalar(@LTIroles); my $LTI_webwork_permissionLevel; - if (! defined($ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}})) { - croak("Cannot find a WeBWorK role that corresponds to the LMS role of " + if ( ! defined( $ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]} ) || + ! defined( $ce->{userRoles}->{$ce->{LMSrolesToWeBWorKroles}->{$LTIroles[0]}} ) ) { + warn("Cannot find a WeBWorK role that corresponds to the LMS role of " . $LTIroles[0] ." so will create a student level account."); $LTI_webwork_permissionLevel = $ce->{userRoles}->{student}; } else {