Search in sources :

Example 46 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class Action method createPleaseJoinCourseResponse.

protected ActionResult createPleaseJoinCourseResponse(String courseId) {
    String errorMessage = "You are not registered in the course " + SanitizationHelper.sanitizeForHtml(courseId);
    statusToUser.add(new StatusMessage(errorMessage, StatusMessageColor.DANGER));
    isError = true;
    statusToAdmin = Const.ACTION_RESULT_FAILURE + " : " + errorMessage;
    return createRedirectResult(Const.ActionURIs.STUDENT_HOME_PAGE);
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Example 47 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class Action method setStatusForException.

/**
 * Status messages to be shown to the admin will be set based
 * on the error message in the exception {@code e}.<br>
 * Status message to be shown to the user will be set as {@code statusMessageToUser}.<br>
 * {@code isError} is also set to true.
 */
protected void setStatusForException(Exception e, String statusMessageToUser) {
    isError = true;
    String statusMessageForHtml = statusMessageToUser.replace(System.lineSeparator(), Const.HTML_BR_TAG);
    statusToUser.add(new StatusMessage(statusMessageForHtml, StatusMessageColor.DANGER));
    String exceptionMessageForHtml = e.getMessage().replace(System.lineSeparator(), Const.HTML_BR_TAG);
    statusToAdmin = Const.ACTION_RESULT_FAILURE + " : " + exceptionMessageForHtml;
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Example 48 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class Action method setStatusForException.

/**
 * Status messages to be shown to the user and the admin will be set based
 * on the error message in the exception {@code e}.<br>
 * {@code isError} is also set to true.
 */
protected void setStatusForException(Exception e) {
    isError = true;
    String exceptionMessageForHtml = e.getMessage().replace(System.lineSeparator(), Const.HTML_BR_TAG);
    statusToUser.add(new StatusMessage(exceptionMessageForHtml, StatusMessageColor.DANGER));
    statusToAdmin = Const.ACTION_RESULT_FAILURE + " : " + exceptionMessageForHtml;
}
Also used : StatusMessage(teammates.common.util.StatusMessage)

Example 49 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class AdminAccountDeleteAction method execute.

@Override
protected ActionResult execute() {
    gateKeeper.verifyAdminPrivileges(account);
    String instructorId = getRequestParamValue(Const.ParamsNames.INSTRUCTOR_ID);
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    String account = getRequestParamValue("account");
    // TODO: We should extract these into separate actions e.g., AdminInstructorDowngradeAction
    if (courseId == null && account == null) {
        // delete instructor status
        logic.downgradeInstructorToStudentCascade(instructorId);
        statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_STATUS_DELETED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Instructor Status for <span class=\"bold\">" + instructorId + "</span> has been deleted.";
        return createRedirectResult(Const.ActionURIs.ADMIN_ACCOUNT_MANAGEMENT_PAGE);
    }
    if (courseId == null && account != null) {
        // delete entire account
        logic.deleteAccount(instructorId);
        statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_ACCOUNT_DELETED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Instructor Account for <span class=\"bold\">" + instructorId + "</span> has been deleted.";
        return createRedirectResult(Const.ActionURIs.ADMIN_ACCOUNT_MANAGEMENT_PAGE);
    }
    String studentId = getRequestParamValue(Const.ParamsNames.STUDENT_ID);
    if (courseId != null && studentId != null) {
        // remove student from course
        StudentAttributes student = logic.getStudentForGoogleId(courseId, studentId);
        logic.deleteStudent(courseId, student.email);
        statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_DELETED, StatusMessageColor.SUCCESS));
        statusToAdmin = "Instructor <span class=\"bold\">" + instructorId + "</span>'s student status in Course" + "<span class=\"bold\">[" + courseId + "]</span> has been deleted";
        return createRedirectResult(Const.ActionURIs.ADMIN_ACCOUNT_DETAILS_PAGE + "?instructorid=" + studentId);
    }
    // remove instructor from course
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, instructorId);
    logic.deleteInstructor(courseId, instructor.email);
    statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_REMOVED_FROM_COURSE, StatusMessageColor.SUCCESS));
    statusToAdmin = "Instructor <span class=\"bold\">" + instructorId + "</span> has been deleted from Course<span class=\"bold\">[" + courseId + "]</span>";
    return createRedirectResult(Const.ActionURIs.ADMIN_ACCOUNT_DETAILS_PAGE + "?instructorid=" + instructorId);
}
Also used : StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) StatusMessage(teammates.common.util.StatusMessage) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 50 with StatusMessage

use of teammates.common.util.StatusMessage in project teammates by TEAMMATES.

the class AdminActivityLogPageAction method generateStatusMessage.

private void generateStatusMessage(List<String> versionToQuery, AdminActivityLogPageData data, List<ActivityLogEntry> logs, String courseId) {
    StringBuilder status = new StringBuilder(500);
    status.append("Total Logs gone through in last search: " + totalLogsSearched + "<br>Total Relevant Logs found in last search: " + String.format("%s<br>", logs.size()));
    long earliestSearchTime = data.getFromDate();
    ActivityLogEntry earliestLogChecked = null;
    if (!logs.isEmpty()) {
        earliestLogChecked = logs.get(logs.size() - 1);
    }
    // if the search space is limited to a certain log
    if (logs.size() >= RELEVANT_LOGS_PER_PAGE && earliestLogChecked != null) {
        earliestSearchTime = earliestLogChecked.getLogTime();
    }
    ZoneId targetTimeZone = null;
    if (data.isPersonSpecified()) {
        String targetUserGoogleId = data.getPersonSpecified();
        targetTimeZone = getLocalTimeZoneForRequest(targetUserGoogleId, "");
        if (targetTimeZone == null && courseId != null && !courseId.isEmpty()) {
            // if the user is unregistered, try finding the timezone by course id passed from Search page
            targetTimeZone = getLocalTimeZoneForUnregisteredUserRequest(courseId);
        }
    } else {
        targetTimeZone = Const.SystemParams.ADMIN_TIME_ZONE_ID;
    }
    String timeInAdminTimeZone = TimeHelper.formatActivityLogTime(Instant.ofEpochMilli(earliestSearchTime), Const.SystemParams.ADMIN_TIME_ZONE_ID);
    String timeInUserTimeZone = TimeHelper.formatActivityLogTime(Instant.ofEpochMilli(earliestSearchTime), targetTimeZone);
    status.append("The earliest log entry checked on <b>" + timeInAdminTimeZone + "</b> in Admin Time Zone (" + Const.SystemParams.ADMIN_TIME_ZONE_ID.getId() + ") and ");
    if (targetTimeZone == null) {
        status.append(timeInUserTimeZone).append(".<br>");
    } else {
        status.append("on <b>" + timeInUserTimeZone + "</b> in Local Time Zone (" + targetTimeZone + ").<br>");
    }
    status.append("Logs are from following version(s): ");
    for (int i = 0; i < versionToQuery.size(); i++) {
        String version = versionToQuery.get(i).replace('-', '.');
        if (i < versionToQuery.size() - 1) {
            status.append(version).append(", ");
        } else {
            status.append(version).append("<br>");
        }
    }
    status.append("All available version(s): ");
    GaeVersionApi versionApi = new GaeVersionApi();
    List<Version> versionList = versionApi.getAvailableVersions();
    for (int i = 0; i < versionList.size(); i++) {
        String version = versionList.get(i).toString();
        if (i < versionList.size() - 1) {
            status.append(version).append(", ");
        } else {
            status.append(version).append("<br>");
        }
    }
    // the "Search More" button to continue searching from the previous fromDate
    status.append("<button class=\"btn-link\" id=\"button_older\" data-next-end-time-to-search=\"" + nextEndTimeToSearch + "\">Search More</button><input id=\"ifShowAll\" type=\"hidden\" value=\"" + data.getShouldShowAllLogs() + "\"/><input id=\"ifShowTestData\" type=\"hidden\" value=\"" + data.getShouldShowTestData() + "\"/>");
    String statusString = status.toString();
    data.setStatusForAjax(statusString);
    statusToUser.add(new StatusMessage(statusString, StatusMessageColor.INFO));
}
Also used : ActivityLogEntry(teammates.common.util.ActivityLogEntry) ZoneId(java.time.ZoneId) Version(teammates.common.util.Version) GaeVersionApi(teammates.common.util.GaeVersionApi) StatusMessage(teammates.common.util.StatusMessage)

Aggregations

StatusMessage (teammates.common.util.StatusMessage)81 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)34 InvalidParametersException (teammates.common.exception.InvalidParametersException)20 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)18 ArrayList (java.util.ArrayList)14 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)9 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)9 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)7 List (java.util.List)6 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)6 EntityAlreadyExistsException (teammates.common.exception.EntityAlreadyExistsException)6 HashMap (java.util.HashMap)4 StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)4 UnauthorizedAccessException (teammates.common.exception.UnauthorizedAccessException)3 PageData (teammates.ui.pagedata.PageData)3 BlobInfo (com.google.appengine.api.blobstore.BlobInfo)2 BlobKey (com.google.appengine.api.blobstore.BlobKey)2 BlobstoreFailureException (com.google.appengine.api.blobstore.BlobstoreFailureException)2 Text (com.google.appengine.api.datastore.Text)2 AppLogLine (com.google.appengine.api.log.AppLogLine)2