Search in sources :

Example 41 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class StudentProfileEditSaveActionTest method testActionWithInvalidParameters.

private void testActionWithInvalidParameters(AccountAttributes student) throws Exception {
    gaeSimulation.loginAsStudent(student.googleId);
    ______TS("Failure case: invalid parameters");
    String[] submissionParams = createInvalidParamsForProfile();
    StudentProfileAttributes expectedProfile = getProfileAttributesFrom(student.googleId, submissionParams);
    expectedProfile.googleId = student.googleId;
    StudentProfileEditSaveAction action = getAction(submissionParams);
    RedirectResult result = getRedirectResult(action);
    assertTrue(result.isError);
    AssertHelper.assertContains(getPageResultDestination(Const.ActionURIs.STUDENT_PROFILE_PAGE, true, student.googleId), result.getDestinationWithParams());
    List<String> expectedErrorMessages = new ArrayList<>();
    expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.INVALID_NAME_ERROR_MESSAGE, submissionParams[1], FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.REASON_START_WITH_NON_ALPHANUMERIC_CHAR, FieldValidator.PERSON_NAME_MAX_LENGTH));
    expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, submissionParams[3], FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH));
    AssertHelper.assertContains(expectedErrorMessages, result.getStatusMessage());
    String expectedLogMessage = "TEAMMATESLOG|||studentProfileEditSave|||studentProfileEditSave" + "|||true|||Student|||" + student.name + "|||" + student.googleId + "|||" + student.email + "|||" + Const.ACTION_RESULT_FAILURE + " : " + result.getStatusMessage() + "|||/page/studentProfileEditSave";
    AssertHelper.assertContainsRegex(expectedLogMessage, action.getLogMessage());
    ______TS("Failure case: invalid parameters with attempted script injection");
    submissionParams = createInvalidParamsForProfileWithScriptInjection();
    expectedProfile = getProfileAttributesFrom(student.googleId, submissionParams);
    expectedProfile.googleId = student.googleId;
    action = getAction(submissionParams);
    result = getRedirectResult(action);
    assertTrue(result.isError);
    AssertHelper.assertContains(Const.ActionURIs.STUDENT_PROFILE_PAGE + "?error=true&user=" + student.googleId, result.getDestinationWithParams());
    expectedErrorMessages = new ArrayList<>();
    expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.INVALID_NAME_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[1]), FieldValidator.PERSON_NAME_FIELD_NAME, FieldValidator.REASON_CONTAINS_INVALID_CHAR, FieldValidator.PERSON_NAME_MAX_LENGTH));
    expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.EMAIL_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[3]), FieldValidator.EMAIL_FIELD_NAME, FieldValidator.REASON_INCORRECT_FORMAT, FieldValidator.EMAIL_MAX_LENGTH));
    expectedErrorMessages.add(getPopulatedErrorMessage(FieldValidator.INVALID_NAME_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[5]), FieldValidator.INSTITUTE_NAME_FIELD_NAME, FieldValidator.REASON_START_WITH_NON_ALPHANUMERIC_CHAR, FieldValidator.INSTITUTE_NAME_MAX_LENGTH));
    expectedErrorMessages.add(String.format(FieldValidator.NATIONALITY_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[7])));
    expectedErrorMessages.add(String.format(FieldValidator.GENDER_ERROR_MESSAGE, SanitizationHelper.sanitizeForHtml(submissionParams[9])));
    AssertHelper.assertContains(expectedErrorMessages, result.getStatusMessage());
    expectedLogMessage = "TEAMMATESLOG|||studentProfileEditSave|||studentProfileEditSave" + "|||true|||Student|||" + student.name + "|||" + student.googleId + "|||" + student.email + "|||" + Const.ACTION_RESULT_FAILURE + " : " + result.getStatusMessage() + "|||/page/studentProfileEditSave";
    AssertHelper.assertContainsRegex(expectedLogMessage, action.getLogMessage());
}
Also used : RedirectResult(teammates.ui.controller.RedirectResult) ArrayList(java.util.ArrayList) StudentProfileEditSaveAction(teammates.ui.controller.StudentProfileEditSaveAction) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 42 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class Logic method createAccount.

/**
 * Creates a new Account based on given values. If a profile is not given,
 * a default empty profile is created for the user<br>
 * Preconditions: <br>
 * * All parameters are non-null.
 */
public void createAccount(String googleId, String name, boolean isInstructor, String email, String institute, StudentProfileAttributes studentProfileParam) throws InvalidParametersException {
    Assumption.assertNotNull(googleId);
    Assumption.assertNotNull(name);
    Assumption.assertNotNull(isInstructor);
    Assumption.assertNotNull(email);
    Assumption.assertNotNull(institute);
    StudentProfileAttributes studentProfile = studentProfileParam;
    if (studentProfile == null) {
        studentProfile = StudentProfileAttributes.builder(googleId).build();
    }
    AccountAttributes accountToAdd = AccountAttributes.builder().withGoogleId(googleId).withName(name).withEmail(email).withInstitute(institute).withIsInstructor(isInstructor).withStudentProfileAttributes(studentProfile).build();
    accountsLogic.createAccount(accountToAdd);
}
Also used : AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 43 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class ProfilesDb method hasNoNewChangesToProfile.

private boolean hasNoNewChangesToProfile(StudentProfileAttributes newSpa, StudentProfile profileToUpdate) {
    StudentProfileAttributes newSpaCopy = newSpa.getCopy();
    StudentProfileAttributes existingProfile = StudentProfileAttributes.valueOf(profileToUpdate);
    newSpaCopy.modifiedDate = existingProfile.modifiedDate;
    return existingProfile.toString().equals(newSpaCopy.toString());
}
Also used : StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Example 44 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class InstructorStudentRecordsPageAction method execute.

@Override
public ActionResult execute() {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    gateKeeper.verifyAccessible(instructor, logic.getCourse(courseId));
    String studentEmail = getRequestParamValue(Const.ParamsNames.STUDENT_EMAIL);
    Assumption.assertPostParamNotNull(Const.ParamsNames.STUDENT_EMAIL, studentEmail);
    StudentAttributes student = logic.getStudentForEmail(courseId, studentEmail);
    if (student == null) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_NOT_FOUND_FOR_RECORDS, StatusMessageColor.DANGER));
        isError = true;
        return createRedirectResult(Const.ActionURIs.INSTRUCTOR_HOME_PAGE);
    }
    List<FeedbackSessionAttributes> sessions = logic.getFeedbackSessionsListForInstructor(account.googleId, false);
    filterFeedbackSessions(courseId, sessions, instructor, student);
    sessions.sort(FeedbackSessionAttributes.DESCENDING_ORDER);
    StudentProfileAttributes studentProfile = null;
    boolean isInstructorAllowedToViewStudent = instructor.isAllowedForPrivilege(student.section, Const.ParamsNames.INSTRUCTOR_PERMISSION_VIEW_STUDENT_IN_SECTIONS);
    boolean isStudentWithProfile = !student.googleId.isEmpty();
    if (isInstructorAllowedToViewStudent && isStudentWithProfile) {
        studentProfile = logic.getStudentProfile(student.googleId);
        Assumption.assertNotNull(studentProfile);
    } else {
        if (student.googleId.isEmpty()) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_NOT_JOINED_YET_FOR_RECORDS, StatusMessageColor.WARNING));
        } else if (!isInstructorAllowedToViewStudent) {
            statusToUser.add(new StatusMessage(Const.StatusMessages.STUDENT_PROFILE_UNACCESSIBLE_TO_INSTRUCTOR, StatusMessageColor.WARNING));
        }
    }
    if (sessions.isEmpty()) {
        statusToUser.add(new StatusMessage(Const.StatusMessages.INSTRUCTOR_NO_STUDENT_RECORDS, StatusMessageColor.WARNING));
    }
    List<String> sessionNames = new ArrayList<>();
    for (FeedbackSessionAttributes fsa : sessions) {
        sessionNames.add(fsa.getFeedbackSessionName());
    }
    InstructorStudentRecordsPageData data = new InstructorStudentRecordsPageData(account, student, sessionToken, courseId, studentProfile, sessionNames);
    statusToAdmin = "instructorStudentRecords Page Load<br>" + "Viewing <span class=\"bold\">" + studentEmail + "'s</span> records " + "for Course <span class=\"bold\">[" + courseId + "]</span><br>" + "Number of sessions: " + sessions.size() + "<br>" + "Student Profile: " + (studentProfile == null ? "No Profile" : SanitizationHelper.sanitizeForHtmlTag(studentProfile.toString()));
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_STUDENT_RECORDS, data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) ArrayList(java.util.ArrayList) InstructorStudentRecordsPageData(teammates.ui.pagedata.InstructorStudentRecordsPageData) StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) StatusMessage(teammates.common.util.StatusMessage)

Example 45 with StudentProfileAttributes

use of teammates.common.datatransfer.attributes.StudentProfileAttributes in project teammates by TEAMMATES.

the class StudentProfileEditSaveAction method extractProfileData.

private StudentProfileAttributes extractProfileData() {
    StudentProfileAttributes editedProfile = StudentProfileAttributes.builder(account.googleId).build();
    editedProfile.shortName = getRequestParamValue(Const.ParamsNames.STUDENT_SHORT_NAME);
    editedProfile.email = getRequestParamValue(Const.ParamsNames.STUDENT_PROFILE_EMAIL);
    editedProfile.institute = getRequestParamValue(Const.ParamsNames.STUDENT_PROFILE_INSTITUTION);
    editedProfile.nationality = getRequestParamValue(Const.ParamsNames.STUDENT_NATIONALITY);
    if ("".equals(editedProfile.nationality)) {
        editedProfile.nationality = getRequestParamValue("existingNationality");
    }
    editedProfile.gender = getRequestParamValue(Const.ParamsNames.STUDENT_GENDER);
    editedProfile.moreInfo = getRequestParamValue(Const.ParamsNames.STUDENT_PROFILE_MOREINFO);
    editedProfile.pictureKey = "";
    preprocessParameters(editedProfile);
    validatePostParameters(editedProfile);
    return editedProfile;
}
Also used : StudentProfileAttributes(teammates.common.datatransfer.attributes.StudentProfileAttributes)

Aggregations

StudentProfileAttributes (teammates.common.datatransfer.attributes.StudentProfileAttributes)45 Test (org.testng.annotations.Test)15 AccountAttributes (teammates.common.datatransfer.attributes.AccountAttributes)11 EntityDoesNotExistException (teammates.common.exception.EntityDoesNotExistException)7 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 BlobKey (com.google.appengine.api.blobstore.BlobKey)5 CourseAttributes (teammates.common.datatransfer.attributes.CourseAttributes)5 RedirectResult (teammates.ui.controller.RedirectResult)5 ArrayList (java.util.ArrayList)4 InvalidParametersException (teammates.common.exception.InvalidParametersException)4 StatusMessage (teammates.common.util.StatusMessage)4 StudentProfile (teammates.storage.entity.StudentProfile)4 StudentProfileEditSaveAction (teammates.ui.controller.StudentProfileEditSaveAction)4 CourseDetailsBundle (teammates.common.datatransfer.CourseDetailsBundle)3 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)3 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)3 Text (com.google.appengine.api.datastore.Text)2 ShowPageResult (teammates.ui.controller.ShowPageResult)2 InstructorStudentRecordsPageData (teammates.ui.pagedata.InstructorStudentRecordsPageData)2 Key (com.googlecode.objectify.Key)1