use of teammates.ui.pagedata.AdminEmailComposePageData in project teammates by TEAMMATES.
the class AdminEmailGroupReceiverListUploadAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
data = new AdminEmailComposePageData(account, sessionToken);
BlobInfo blobInfo = extractGroupReceiverListFileKey();
if (blobInfo == null) {
data.isFileUploaded = false;
data.fileSrcUrl = null;
log.info("Group Receiver List Upload Failed");
statusToAdmin = "Group Receiver List Upload Failed";
data.ajaxStatus = "Group receiver list upload failed. Please try again.";
return createAjaxResult(data);
}
try {
List<List<String>> groupReceiverList = GoogleCloudStorageHelper.getGroupReceiverList(blobInfo.getBlobKey());
// log all email addresses retrieved from the txt file
int i = 0;
for (List<String> list : groupReceiverList) {
for (String str : list) {
log.info(str + " - " + i + " \n");
i++;
}
}
} catch (IOException e) {
data.isFileUploaded = false;
data.fileSrcUrl = null;
log.info("Group Receiver List Upload Failed: uploaded file is corrupted");
statusToAdmin = "Group Receiver List Upload Failed: uploaded file is corrupted";
data.ajaxStatus = "Group receiver list upload failed: uploaded file is corrupted. " + "Please make sure the txt file contains only email addresses " + "separated by comma";
deleteGroupReceiverListFile(blobInfo.getBlobKey());
return createAjaxResult(data);
}
BlobKey blobKey = blobInfo.getBlobKey();
data.groupReceiverListFileKey = blobKey.getKeyString();
data.isFileUploaded = true;
statusToAdmin = "New Group Receiver List Uploaded";
data.ajaxStatus = "Group receiver list successfully uploaded to Google Cloud Storage";
return createAjaxResult(data);
}
use of teammates.ui.pagedata.AdminEmailComposePageData in project teammates by TEAMMATES.
the class AdminEmailImageUploadAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
FileUploadPageData uploadPageData = prepareData();
AdminEmailComposePageData data = new AdminEmailComposePageData(account, sessionToken);
data.isFileUploaded = uploadPageData.isFileUploaded;
data.fileSrcUrl = uploadPageData.fileSrcUrl;
data.ajaxStatus = uploadPageData.ajaxStatus;
return createAjaxResult(data);
}
use of teammates.ui.pagedata.AdminEmailComposePageData in project teammates by TEAMMATES.
the class AdminEmailComposePageAction method execute.
@Override
protected ActionResult execute() {
gateKeeper.verifyAdminPrivileges(account);
AdminEmailComposePageData data = new AdminEmailComposePageData(account, sessionToken);
String idOfEmailToEdit = getRequestParamValue(Const.ParamsNames.ADMIN_EMAIL_ID);
boolean isEmailEdit = idOfEmailToEdit != null;
if (isEmailEdit) {
data.emailToEdit = logic.getAdminEmailById(idOfEmailToEdit);
statusToAdmin = data.emailToEdit == null ? "adminEmailComposePage Page Load : " + Const.StatusMessages.EMAIL_NOT_FOUND : "adminEmailComposePage Page Load : Edit Email " + "[" + SanitizationHelper.sanitizeForHtml(data.emailToEdit.getSubject()) + "]";
if (data.emailToEdit == null) {
isError = true;
statusToUser.add(new StatusMessage(Const.StatusMessages.EMAIL_NOT_FOUND, StatusMessageColor.WARNING));
}
return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
statusToAdmin = "adminEmailComposePage Page Load";
data.init();
return createShowPageResult(Const.ViewURIs.ADMIN_EMAIL, data);
}
use of teammates.ui.pagedata.AdminEmailComposePageData in project teammates by TEAMMATES.
the class AdminEmailComposePageActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
final String adminUserId = "admin.user";
gaeSimulation.loginAsAdmin(adminUserId);
______TS("compose new email : typical values given : success");
AdminEmailComposePageAction action = getAction();
ShowPageResult pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
String normalLogSegment = "adminEmailComposePage Page Load";
AssertHelper.assertContains(normalLogSegment, action.getLogMessage());
assertEquals("", pageResult.getStatusMessage());
AdminEmailComposePageData data = (AdminEmailComposePageData) pageResult.data;
assertNull(data.emailToEdit);
______TS("edit existing email : typical values given : success");
// retrieve email id from logic
AdminEmailAttributes emailData = dataBundle.adminEmails.get("adminEmail1");
AdminEmailAttributes email = adminEmailsLogic.getAdminEmailBySubject(emailData.subject);
action = getAction(Const.ParamsNames.ADMIN_EMAIL_ID, email.emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, "admin.user"), pageResult.getDestinationWithParams());
String expectedLogSegment = normalLogSegment + " : Edit Email [Admin Email 1 <b>bold tags</b>]";
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
assertEquals("", pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertNotNull(data.emailToEdit);
______TS("edit existing email : email does not exist : failure");
String emailId = "nonexistingEmailId";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, "admin.user"), pageResult.getDestinationWithParams());
expectedLogSegment = normalLogSegment + " : " + Const.StatusMessages.EMAIL_NOT_FOUND;
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
assertEquals(Const.StatusMessages.EMAIL_NOT_FOUND, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertNull(data.emailToEdit);
}
use of teammates.ui.pagedata.AdminEmailComposePageData in project teammates by TEAMMATES.
the class AdminEmailComposeSaveActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() throws Exception {
final String adminUserId = "admin.user";
gaeSimulation.loginAsAdmin(adminUserId);
______TS("save new email : typical values given : success");
String subject = "New Email Subject";
String content = "<p>Email Content</p>";
String receiver = "test@example.tmt";
AdminEmailComposeSaveAction action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver);
ShowPageResult pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
String expectedLogSegment = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>Subject: New Email Subject";
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
assertEquals(Const.StatusMessages.EMAIL_DRAFT_SAVED, pageResult.getStatusMessage());
AdminEmailComposePageData data = (AdminEmailComposePageData) pageResult.data;
assertNull(data.emailToEdit);
AdminEmailAttributes savedEmail = adminEmailsLogic.getAdminEmailBySubject(subject);
assertNotNull("Email should be saved and should exists.", savedEmail);
assertEquals(SanitizationHelper.sanitizeForRichText(content), savedEmail.getContentValue());
assertEquals(receiver, String.join(", ", savedEmail.getAddressReceiver().toArray(new String[0])));
______TS("save new email : invalid subject : failure");
content = "<p>Email Content</p>";
subject = "!Not starting with alphanumeric";
receiver = "test@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, adminUserId), pageResult.getDestinationWithParams());
expectedLogSegment = Const.ACTION_RESULT_FAILURE;
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
String expectedStatus = "\"!Not starting with alphanumeric\" is not acceptable to TEAMMATES as a/an email subject";
AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertEquals(subject, data.emailToEdit.subject);
______TS("save new email : invalid content : failure");
content = "";
subject = "valid subject";
receiver = "test@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, adminUserId), pageResult.getDestinationWithParams());
expectedLogSegment = Const.ACTION_RESULT_FAILURE;
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
expectedStatus = "email content should not be empty.";
AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertEquals(subject, data.emailToEdit.subject);
______TS("save existing email : typical values given : success");
AdminEmailAttributes emailData = dataBundle.adminEmails.get("adminEmail1");
AdminEmailAttributes email = adminEmailsLogic.getAdminEmailBySubject(emailData.getSubject());
String emailId = email.emailId;
content = "valid content";
subject = "valid existing email subject";
receiver = "test@example.tmt, test2@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
expectedLogSegment = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>" + "Subject: valid existing email subject";
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
assertEquals(Const.StatusMessages.EMAIL_DRAFT_SAVED, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertNull(data.emailToEdit);
savedEmail = adminEmailsLogic.getAdminEmailBySubject(subject);
assertNotNull("Email should be saved and should exists.", savedEmail);
assertEquals(SanitizationHelper.sanitizeForRichText(content), savedEmail.getContentValue());
assertEquals(receiver, String.join(", ", savedEmail.getAddressReceiver().toArray(new String[0])));
______TS("save existing email : values require sanitization : success");
emailId = email.emailId;
content = "<p onclick=\"alert('hello');\">contents</p> </div> unclosed tags <script>alert(\"hello\");</script>";
subject = "valid existing email subject <b>To check sanitization</b>";
receiver = "test@example.tmt, test2@example.tmt, test3@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
expectedLogSegment = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>" + "Subject: valid existing email subject <b>To check sanitization</b>";
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
assertEquals(Const.StatusMessages.EMAIL_DRAFT_SAVED, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertNull(data.emailToEdit);
savedEmail = adminEmailsLogic.getAdminEmailBySubject(subject);
assertNotNull("Email should be saved and should exists.", savedEmail);
assertEquals(SanitizationHelper.sanitizeForRichText(content), savedEmail.getContentValue());
assertEquals(receiver, String.join(", ", savedEmail.getAddressReceiver().toArray(new String[0])));
______TS("save existing email : invalid subject : failure");
content = "valid content";
subject = " ";
receiver = "test@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, adminUserId), pageResult.getDestinationWithParams());
expectedLogSegment = Const.ACTION_RESULT_FAILURE;
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
expectedStatus = "The provided email subject is not acceptable to TEAMMATES as it contains only whitespace" + " or contains extra spaces at the beginning or at the end of the text.";
AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertEquals(subject, data.emailToEdit.subject);
assertEquals(email.emailId, data.emailToEdit.emailId);
______TS("save existing email : invalid content : failure");
content = "";
subject = "valid subject";
receiver = "test@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, adminUserId), pageResult.getDestinationWithParams());
expectedLogSegment = Const.ACTION_RESULT_FAILURE;
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
expectedStatus = "email content should not be empty.";
AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertEquals(subject, data.emailToEdit.subject);
assertEquals(email.emailId, data.emailToEdit.emailId);
______TS("save non-existing email : typical values given : success");
emailId = "nonExisitingId";
content = "valid content";
subject = "valid non-existing email subject <b>To check sanitization</b>";
receiver = "test@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, false, adminUserId), pageResult.getDestinationWithParams());
expectedLogSegment = Const.StatusMessages.EMAIL_DRAFT_SAVED + ": <br>" + "Subject: valid non-existing email subject <b>To check sanitization</b>";
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
assertEquals(Const.StatusMessages.EMAIL_DRAFT_SAVED, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertNull(data.emailToEdit);
savedEmail = adminEmailsLogic.getAdminEmailBySubject(subject);
assertNotNull("Email should be saved and should exists.", savedEmail);
assertEquals(SanitizationHelper.sanitizeForRichText(content), savedEmail.getContentValue());
assertEquals(receiver, String.join(", ", savedEmail.getAddressReceiver().toArray(new String[0])));
______TS("save non-existing email : invalid subject : failure");
emailId = "nonExisitingId";
content = "valid content";
subject = "";
receiver = "test@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, "admin.user"), pageResult.getDestinationWithParams());
expectedLogSegment = Const.ACTION_RESULT_FAILURE;
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
expectedStatus = "The field 'email subject' is empty.";
AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertEquals(subject, data.emailToEdit.subject);
______TS("save non-existing email : invalid content : failure");
emailId = "nonExisitingId";
content = "";
subject = "valid subject";
receiver = "test@example.tmt";
action = getAction(Const.ParamsNames.ADMIN_EMAIL_CONTENT, content, Const.ParamsNames.ADMIN_EMAIL_SUBJECT, subject, Const.ParamsNames.ADMIN_EMAIL_ADDRESS_RECEIVERS, receiver, Const.ParamsNames.ADMIN_EMAIL_ID, emailId);
pageResult = getShowPageResult(action);
assertEquals(getPageResultDestination(Const.ViewURIs.ADMIN_EMAIL, true, "admin.user"), pageResult.getDestinationWithParams());
expectedLogSegment = Const.ACTION_RESULT_FAILURE;
AssertHelper.assertContains(expectedLogSegment, action.getLogMessage());
expectedStatus = "email content should not be empty.";
AssertHelper.assertContains(expectedStatus, pageResult.getStatusMessage());
data = (AdminEmailComposePageData) pageResult.data;
assertEquals(subject, data.emailToEdit.subject);
}
Aggregations