SEBSERV-564 fixed for Moodle
This commit is contained in:
parent
c3a03719c9
commit
413fb96240
5 changed files with 88 additions and 48 deletions
|
@ -105,7 +105,7 @@ public abstract class MoodleUtils {
|
|||
return shortName.equals(Constants.EMPTY_NOTE) ? null : unmaskShortName(shortName);
|
||||
}
|
||||
|
||||
public static final String getIdnumber(final String internalQuizId) {
|
||||
public static String getIdnumber(final String internalQuizId) {
|
||||
if (StringUtils.isBlank(internalQuizId)) {
|
||||
return null;
|
||||
}
|
||||
|
@ -118,6 +118,67 @@ public abstract class MoodleUtils {
|
|||
return idNumber.equals(Constants.EMPTY_NOTE) ? null : idNumber;
|
||||
}
|
||||
|
||||
public static String getDisplayName(
|
||||
final String firstname,
|
||||
final String lastname,
|
||||
final String fullname,
|
||||
final String sessionId) {
|
||||
|
||||
if (StringUtils.isNotBlank(firstname) && StringUtils.isNotBlank(lastname)) {
|
||||
return lastname + Constants.SPACE + firstname;
|
||||
} else if (StringUtils.isNotBlank(lastname) && StringUtils.isNotBlank(fullname)) {
|
||||
return lastname + Constants.SPACE + fullname;
|
||||
} else if (StringUtils.isNotBlank(fullname)) {
|
||||
return fullname;
|
||||
} else {
|
||||
return sessionId;
|
||||
}
|
||||
}
|
||||
|
||||
public static Map<String, String> getMoodleAccountDetails(final MoodleUserDetails[] userDetails) {
|
||||
final Map<String, String> additionalAttributes = new HashMap<>();
|
||||
if (userDetails[0].firstname != null) {
|
||||
additionalAttributes.put("firstname", userDetails[0].firstname);
|
||||
}
|
||||
if (userDetails[0].lastname != null) {
|
||||
additionalAttributes.put("lastname", userDetails[0].lastname);
|
||||
}
|
||||
if (userDetails[0].firstaccess != null) {
|
||||
additionalAttributes.put("firstaccess", String.valueOf(userDetails[0].firstaccess));
|
||||
}
|
||||
if (userDetails[0].lastaccess != null) {
|
||||
additionalAttributes.put("lastaccess", String.valueOf(userDetails[0].lastaccess));
|
||||
}
|
||||
if (userDetails[0].auth != null) {
|
||||
additionalAttributes.put("auth", userDetails[0].auth);
|
||||
}
|
||||
if (userDetails[0].suspended != null) {
|
||||
additionalAttributes.put("suspended", String.valueOf(userDetails[0].suspended));
|
||||
}
|
||||
if (userDetails[0].confirmed != null) {
|
||||
additionalAttributes.put("confirmed", String.valueOf(userDetails[0].confirmed));
|
||||
}
|
||||
if (userDetails[0].lang != null) {
|
||||
additionalAttributes.put("lang", userDetails[0].lang);
|
||||
}
|
||||
if (userDetails[0].theme != null) {
|
||||
additionalAttributes.put("theme", userDetails[0].theme);
|
||||
}
|
||||
if (userDetails[0].timezone != null) {
|
||||
additionalAttributes.put("timezone", userDetails[0].timezone);
|
||||
}
|
||||
if (userDetails[0].description != null) {
|
||||
additionalAttributes.put("description", userDetails[0].description);
|
||||
}
|
||||
if (userDetails[0].mailformat != null) {
|
||||
additionalAttributes.put("mailformat", String.valueOf(userDetails[0].mailformat));
|
||||
}
|
||||
if (userDetails[0].descriptionformat != null) {
|
||||
additionalAttributes.put("descriptionformat", String.valueOf(userDetails[0].descriptionformat));
|
||||
}
|
||||
return additionalAttributes;
|
||||
}
|
||||
|
||||
public static void logMoodleWarning(
|
||||
final Collection<Warning> warnings,
|
||||
final String lmsSetupName,
|
||||
|
|
|
@ -403,24 +403,14 @@ public class MoodleCourseAccess implements CourseAccessAPI {
|
|||
throw new RuntimeException("No user details on Moodle API request");
|
||||
}
|
||||
|
||||
final Map<String, String> additionalAttributes = new HashMap<>();
|
||||
additionalAttributes.put("firstname", userDetails[0].firstname);
|
||||
additionalAttributes.put("lastname", userDetails[0].lastname);
|
||||
additionalAttributes.put("department", userDetails[0].department);
|
||||
additionalAttributes.put("firstaccess", String.valueOf(userDetails[0].firstaccess));
|
||||
additionalAttributes.put("lastaccess", String.valueOf(userDetails[0].lastaccess));
|
||||
additionalAttributes.put("auth", userDetails[0].auth);
|
||||
additionalAttributes.put("suspended", String.valueOf(userDetails[0].suspended));
|
||||
additionalAttributes.put("confirmed", String.valueOf(userDetails[0].confirmed));
|
||||
additionalAttributes.put("lang", userDetails[0].lang);
|
||||
additionalAttributes.put("theme", userDetails[0].theme);
|
||||
additionalAttributes.put("timezone", userDetails[0].timezone);
|
||||
additionalAttributes.put("description", userDetails[0].description);
|
||||
additionalAttributes.put("mailformat", String.valueOf(userDetails[0].mailformat));
|
||||
additionalAttributes.put("descriptionformat", String.valueOf(userDetails[0].descriptionformat));
|
||||
final Map<String, String> additionalAttributes = MoodleUtils.getMoodleAccountDetails(userDetails);
|
||||
return new ExamineeAccountDetails(
|
||||
userDetails[0].id,
|
||||
userDetails[0].lastname + " " + userDetails[0].firstname,
|
||||
MoodleUtils.getDisplayName(
|
||||
userDetails[0].firstname,
|
||||
userDetails[0].lastname,
|
||||
userDetails[0].fullname,
|
||||
examineeSessionId),
|
||||
userDetails[0].username,
|
||||
userDetails[0].email,
|
||||
additionalAttributes);
|
||||
|
|
|
@ -339,24 +339,14 @@ public class MoodlePluginCourseAccess extends AbstractCachedCourseAccess impleme
|
|||
throw new RuntimeException("No user details on Moodle API request");
|
||||
}
|
||||
|
||||
final Map<String, String> additionalAttributes = new HashMap<>();
|
||||
additionalAttributes.put("firstname", userDetails[0].firstname);
|
||||
additionalAttributes.put("lastname", userDetails[0].lastname);
|
||||
additionalAttributes.put("department", userDetails[0].department);
|
||||
additionalAttributes.put("firstaccess", String.valueOf(userDetails[0].firstaccess));
|
||||
additionalAttributes.put("lastaccess", String.valueOf(userDetails[0].lastaccess));
|
||||
additionalAttributes.put("auth", userDetails[0].auth);
|
||||
additionalAttributes.put("suspended", String.valueOf(userDetails[0].suspended));
|
||||
additionalAttributes.put("confirmed", String.valueOf(userDetails[0].confirmed));
|
||||
additionalAttributes.put("lang", userDetails[0].lang);
|
||||
additionalAttributes.put("theme", userDetails[0].theme);
|
||||
additionalAttributes.put("timezone", userDetails[0].timezone);
|
||||
additionalAttributes.put("description", userDetails[0].description);
|
||||
additionalAttributes.put("mailformat", String.valueOf(userDetails[0].mailformat));
|
||||
additionalAttributes.put("descriptionformat", String.valueOf(userDetails[0].descriptionformat));
|
||||
final Map<String, String> additionalAttributes = MoodleUtils.getMoodleAccountDetails(userDetails);
|
||||
return new ExamineeAccountDetails(
|
||||
userDetails[0].id,
|
||||
userDetails[0].lastname + " " + userDetails[0].firstname,
|
||||
MoodleUtils.getDisplayName(
|
||||
userDetails[0].firstname,
|
||||
userDetails[0].lastname,
|
||||
userDetails[0].fullname,
|
||||
examineeSessionId),
|
||||
userDetails[0].username,
|
||||
userDetails[0].email,
|
||||
additionalAttributes);
|
||||
|
|
|
@ -103,19 +103,18 @@ public class MoodleCourseAccessTest {
|
|||
assertEquals("user1 seb", userDetails.name);
|
||||
assertEquals("demo1@safeexambrowser.org", userDetails.email);
|
||||
assertEquals(
|
||||
"{auth=manual, "
|
||||
+ "confirmed=true, "
|
||||
+ "department=, "
|
||||
+ "description=, "
|
||||
+ "descriptionformat=1, "
|
||||
+ "firstaccess=1523400731, "
|
||||
+ "firstname=seb, "
|
||||
+ "lang=en, "
|
||||
+ "lastaccess=1596457337, "
|
||||
+ "lastname=user1, "
|
||||
+ "mailformat=1, "
|
||||
+ "suspended=false, "
|
||||
+ "theme=, timezone=99}",
|
||||
"{auth=manual, " +
|
||||
"confirmed=true, " +
|
||||
"description=, " +
|
||||
"descriptionformat=1, " +
|
||||
"firstaccess=1523400731, " +
|
||||
"firstname=seb, " +
|
||||
"lang=en, " +
|
||||
"lastaccess=1596457337, " +
|
||||
"lastname=user1, " +
|
||||
"mailformat=1, " +
|
||||
"suspended=false, " +
|
||||
"theme=, timezone=99}",
|
||||
new TreeMap<>(userDetails.additionalAttributes).toString());
|
||||
}
|
||||
|
||||
|
|
|
@ -252,8 +252,8 @@ public class MoodlePluginCourseAccessTest {
|
|||
assertFalse(userDetailsResult.hasError());
|
||||
final ExamineeAccountDetails examineeAccountDetails = userDetailsResult.get();
|
||||
assertEquals(
|
||||
"ExamineeAccountDetails [id=2, name=user test, username=testuser, email=text@user.mail, "
|
||||
+ "additionalAttributes={mailformat=null, firstname=test, auth=null, timezone=null, description=null, firstaccess=null, confirmed=null, suspended=null, lastname=user, lastaccess=null, theme=null, descriptionformat=null, department=null, lang=null}]",
|
||||
"ExamineeAccountDetails [id=2, name=user test, username=testuser, email=text@user.mail, " +
|
||||
"additionalAttributes={firstname=test, lastname=user}]",
|
||||
examineeAccountDetails.toString());
|
||||
|
||||
assertEquals(
|
||||
|
|
Loading…
Reference in a new issue