use of teammates.ui.pagedata.AdminHomePageData in project teammates by TEAMMATES.
the class AdminHomePageActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
______TS("Normal case: starting with a blank adminHome page");
final String adminUserId = "admin.user";
gaeSimulation.loginAsAdmin(adminUserId);
final AdminHomePageAction a = getAction();
final ShowPageResult result = getShowPageResult(a);
assertEquals(Const.ViewURIs.ADMIN_HOME, result.destination);
final AdminHomePageData startingPageData = (AdminHomePageData) result.data;
assertEquals("", startingPageData.instructorEmail);
assertEquals("", startingPageData.instructorInstitution);
assertEquals("", startingPageData.instructorName);
assertEquals("", result.getStatusMessage());
}
use of teammates.ui.pagedata.AdminHomePageData in project teammates by TEAMMATES.
the class AdminInstructorAccountAddActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
final String name = "JamesBond";
final String email = "jamesbond89@gmail.tmt";
final String institute = "TEAMMATES Test Institute 1";
final String adminUserId = "admin.user";
______TS("Not enough parameters");
gaeSimulation.loginAsAdmin(adminUserId);
verifyAssumptionFailure();
verifyAssumptionFailure(Const.ParamsNames.INSTRUCTOR_NAME, name);
verifyAssumptionFailure(Const.ParamsNames.INSTRUCTOR_NAME, name, Const.ParamsNames.INSTRUCTOR_EMAIL, email);
verifyAssumptionFailure(Const.ParamsNames.INSTRUCTOR_NAME, name, Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute);
verifyAssumptionFailure(Const.ParamsNames.INSTRUCTOR_EMAIL, email, Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute);
______TS("Normal case: not importing demo couse, extra spaces around values");
final String nameWithSpaces = " " + name + " ";
final String emailWithSpaces = " " + email + " ";
final String instituteWithSpaces = " " + institute + " ";
AdminInstructorAccountAddAction a = getAction(Const.ParamsNames.INSTRUCTOR_NAME, nameWithSpaces, Const.ParamsNames.INSTRUCTOR_EMAIL, emailWithSpaces, Const.ParamsNames.INSTRUCTOR_INSTITUTION, instituteWithSpaces);
AjaxResult r = getAjaxResult(a);
assertTrue(r.getStatusMessage().contains("Instructor " + name + " has been successfully created"));
verifyNumberOfEmailsSent(a, 1);
EmailWrapper emailSent = a.getEmailSender().getEmailsSent().get(0);
assertEquals(String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), name), emailSent.getSubject());
assertEquals(email, emailSent.getRecipient());
______TS("Error: invalid parameter");
final String invalidName = "James%20Bond99";
a = getAction(Const.ParamsNames.INSTRUCTOR_NAME, invalidName, Const.ParamsNames.INSTRUCTOR_EMAIL, email, Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute);
String expectedError = "\"" + invalidName + "\" is not acceptable to TEAMMATES as a/an person name because " + "it contains invalid characters. A/An person name must start with an " + "alphanumeric character, and cannot contain any vertical bar (|) or percent sign (%).";
AjaxResult rInvalidParam = getAjaxResult(a);
assertEquals(expectedError, rInvalidParam.getStatusMessage());
AdminHomePageData pageData = (AdminHomePageData) rInvalidParam.data;
assertEquals(email, pageData.instructorEmail);
assertEquals(institute, pageData.instructorInstitution);
assertEquals(invalidName, pageData.instructorName);
verifyNoEmailsSent(a);
______TS("Normal case: importing demo couse");
a = getAction(Const.ParamsNames.INSTRUCTOR_NAME, name, Const.ParamsNames.INSTRUCTOR_EMAIL, email, Const.ParamsNames.INSTRUCTOR_INSTITUTION, institute);
r = getAjaxResult(a);
assertTrue(r.getStatusMessage().contains("Instructor " + name + " has been successfully created"));
verifyNumberOfEmailsSent(a, 1);
emailSent = a.getEmailSender().getEmailsSent().get(0);
assertEquals(String.format(EmailType.NEW_INSTRUCTOR_ACCOUNT.getSubject(), name), emailSent.getSubject());
assertEquals(email, emailSent.getRecipient());
new Logic().deleteCourse(getDemoCourseIdRoot(email));
}
use of teammates.ui.pagedata.AdminHomePageData in project teammates by TEAMMATES.
the class AdminInstructorAccountAddAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
AdminHomePageData data = new AdminHomePageData(account, sessionToken);
data.instructorName = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_NAME).trim();
data.instructorEmail = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_EMAIL).trim();
data.instructorInstitution = getNonNullRequestParamValue(Const.ParamsNames.INSTRUCTOR_INSTITUTION).trim();
data.isInstructorAddingResultForAjax = true;
data.statusForAjax = "";
data.instructorName = data.instructorName.trim();
data.instructorEmail = data.instructorEmail.trim();
data.instructorInstitution = data.instructorInstitution.trim();
try {
logic.verifyInputForAdminHomePage(data.instructorName, data.instructorInstitution, data.instructorEmail);
} catch (InvalidParametersException e) {
data.statusForAjax = e.getMessage().replace(System.lineSeparator(), Const.HTML_BR_TAG);
data.isInstructorAddingResultForAjax = false;
statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.DANGER));
return createAjaxResult(data);
}
String courseId = null;
try {
courseId = importDemoData(data);
} catch (Exception e) {
String retryUrl = Const.ActionURIs.ADMIN_INSTRUCTORACCOUNT_ADD;
retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_NAME, data.instructorName);
retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_EMAIL, data.instructorEmail);
retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.INSTRUCTOR_INSTITUTION, data.instructorInstitution);
retryUrl = Url.addParamToUrl(retryUrl, Const.ParamsNames.SESSION_TOKEN, data.getSessionToken());
StringBuilder errorMessage = new StringBuilder(100);
String retryLink = "<a href=" + retryUrl + ">Exception in Importing Data, Retry</a>";
errorMessage.append(retryLink);
statusToUser.add(new StatusMessage(errorMessage.toString(), StatusMessageColor.DANGER));
String message = "<span class=\"text-danger\">Servlet Action failure in AdminInstructorAccountAddAction" + "<br>" + e.getClass() + ": " + TeammatesException.toStringWithStackTrace(e) + "<br></span>";
errorMessage.append("<br>").append(message);
statusToUser.add(new StatusMessage("<br>" + message, StatusMessageColor.DANGER));
statusToAdmin = message;
data.isInstructorAddingResultForAjax = false;
data.statusForAjax = errorMessage.toString();
return createAjaxResult(data);
}
List<InstructorAttributes> instructorList = logic.getInstructorsForCourse(courseId);
String joinLink = Config.getAppUrl(Const.ActionURIs.INSTRUCTOR_COURSE_JOIN).withRegistrationKey(StringHelper.encrypt(instructorList.get(0).key)).withInstructorInstitution(data.instructorInstitution).toAbsoluteString();
EmailWrapper email = new EmailGenerator().generateNewInstructorAccountJoinEmail(instructorList.get(0).email, data.instructorName, joinLink);
try {
emailSender.sendEmail(email);
} catch (EmailSendingException e) {
log.severe("Instructor welcome email failed to send: " + TeammatesException.toStringWithStackTrace(e));
}
data.statusForAjax = "Instructor " + SanitizationHelper.sanitizeForHtml(data.instructorName) + " has been successfully created " + "<a href=" + joinLink + ">" + Const.JOIN_LINK + "</a>";
statusToUser.add(new StatusMessage(data.statusForAjax, StatusMessageColor.SUCCESS));
statusToAdmin = "A New Instructor <span class=\"bold\">" + SanitizationHelper.sanitizeForHtmlTag(data.instructorName) + "</span> has been created.<br>" + "<span class=\"bold\">Id: </span>" + "ID will be assigned when the verification link was clicked and confirmed" + "<br>" + "<span class=\"bold\">Email: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorEmail) + "<span class=\"bold\">Institution: </span>" + SanitizationHelper.sanitizeForHtmlTag(data.instructorInstitution);
return createAjaxResult(data);
}
use of teammates.ui.pagedata.AdminHomePageData in project teammates by TEAMMATES.
the class AdminHomePageDataTest method createData.
private void createData() {
AccountAttributes admin = dataBundle.accounts.get("instructor1OfCourse1");
pageData = new AdminHomePageData(admin, dummySessionToken);
}
use of teammates.ui.pagedata.AdminHomePageData in project teammates by TEAMMATES.
the class AdminHomePageAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
AdminHomePageData data = new AdminHomePageData(account, sessionToken);
data.instructorName = "";
data.instructorEmail = "";
data.instructorInstitution = "";
statusToAdmin = "Admin Home Page Load";
return createShowPageResult(Const.ViewURIs.ADMIN_HOME, data);
}
Aggregations