Search in sources :

Example 36 with FeedbackResponseCommentAttributes

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

the class InstructorFeedbackResponseCommentEditActionTest method testAccessControl.

@Override
@Test
protected void testAccessControl() throws Exception {
    final FeedbackQuestionsDb fqDb = new FeedbackQuestionsDb();
    final FeedbackResponsesDb frDb = new FeedbackResponsesDb();
    final FeedbackResponseCommentsDb frcDb = new FeedbackResponseCommentsDb();
    FeedbackSessionAttributes fs = typicalBundle.feedbackSessions.get("session1InCourse1");
    int questionNumber = 1;
    FeedbackQuestionAttributes feedbackQuestion = fqDb.getFeedbackQuestion("First feedback session", "idOfTypicalCourse1", questionNumber);
    String giverEmail = "student1InCourse1@gmail.tmt";
    String receiverEmail = "student1InCourse1@gmail.tmt";
    FeedbackResponseAttributes feedbackResponse = frDb.getFeedbackResponse(feedbackQuestion.getId(), giverEmail, receiverEmail);
    FeedbackResponseCommentAttributes feedbackResponseComment = typicalBundle.feedbackResponseComments.get("comment1FromT1C1ToR1Q1S1C1");
    feedbackResponseComment = frcDb.getFeedbackResponseComment(feedbackResponse.getId(), feedbackResponseComment.giverEmail, feedbackResponseComment.createdAt);
    String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, fs.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, fs.getFeedbackSessionName(), Const.ParamsNames.FEEDBACK_RESPONSE_ID, feedbackResponse.getId(), Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_ID, feedbackResponseComment.getId().toString(), Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT, "comment", Const.ParamsNames.FEEDBACK_RESULTS_SORTTYPE, "recipient" };
    // this person is not the giver. so not accessible
    verifyUnaccessibleWithoutModifySessionCommentInSectionsPrivilege(submissionParams);
    verifyOnlyInstructorsCanAccess(submissionParams);
}
Also used : FeedbackResponseCommentsDb(teammates.storage.api.FeedbackResponseCommentsDb) FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) FeedbackResponsesDb(teammates.storage.api.FeedbackResponsesDb) FeedbackQuestionsDb(teammates.storage.api.FeedbackQuestionsDb) Test(org.testng.annotations.Test)

Example 37 with FeedbackResponseCommentAttributes

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

the class BaseTestCaseWithDatastoreAccess method verifyEquals.

private void verifyEquals(EntityAttributes<?> expected, EntityAttributes<?> actual) {
    if (expected instanceof AccountAttributes) {
        AccountAttributes expectedAccount = ((AccountAttributes) expected).getCopy();
        AccountAttributes actualAccount = (AccountAttributes) actual;
        equalizeIrrelevantData(expectedAccount, actualAccount);
        assertEquals(JsonUtils.toJson(expectedAccount), JsonUtils.toJson(actualAccount));
    } else if (expected instanceof CourseAttributes) {
        CourseAttributes expectedCourse = (CourseAttributes) expected;
        CourseAttributes actualCourse = (CourseAttributes) actual;
        equalizeIrrelevantData(expectedCourse, actualCourse);
        assertEquals(JsonUtils.toJson(expectedCourse), JsonUtils.toJson(actualCourse));
    } else if (expected instanceof FeedbackQuestionAttributes) {
        FeedbackQuestionAttributes expectedFq = (FeedbackQuestionAttributes) expected;
        FeedbackQuestionAttributes actualFq = (FeedbackQuestionAttributes) actual;
        equalizeIrrelevantData(expectedFq, actualFq);
        assertEquals(JsonUtils.toJson(expectedFq), JsonUtils.toJson(actualFq));
    } else if (expected instanceof FeedbackResponseCommentAttributes) {
        FeedbackResponseCommentAttributes expectedFrc = (FeedbackResponseCommentAttributes) expected;
        FeedbackResponseCommentAttributes actualFrc = (FeedbackResponseCommentAttributes) actual;
        assertEquals(expectedFrc.courseId, actualFrc.courseId);
        assertEquals(expectedFrc.giverEmail, actualFrc.giverEmail);
        assertEquals(expectedFrc.feedbackSessionName, actualFrc.feedbackSessionName);
        assertEquals(expectedFrc.commentText, actualFrc.commentText);
    } else if (expected instanceof FeedbackResponseAttributes) {
        FeedbackResponseAttributes expectedFr = (FeedbackResponseAttributes) expected;
        FeedbackResponseAttributes actualFr = (FeedbackResponseAttributes) actual;
        equalizeIrrelevantData(expectedFr, actualFr);
        assertEquals(JsonUtils.toJson(expectedFr), JsonUtils.toJson(actualFr));
    } else if (expected instanceof FeedbackSessionAttributes) {
        FeedbackSessionAttributes expectedFs = ((FeedbackSessionAttributes) expected).getCopy();
        FeedbackSessionAttributes actualFs = (FeedbackSessionAttributes) actual;
        equalizeIrrelevantData(expectedFs, actualFs);
        assertEquals(JsonUtils.toJson(expectedFs), JsonUtils.toJson(actualFs));
    } else if (expected instanceof InstructorAttributes) {
        InstructorAttributes expectedInstructor = ((InstructorAttributes) expected).getCopy();
        InstructorAttributes actualInstructor = (InstructorAttributes) actual;
        equalizeIrrelevantData(expectedInstructor, actualInstructor);
        assertTrue(expectedInstructor.isEqualToAnotherInstructor(actualInstructor));
    } else if (expected instanceof StudentAttributes) {
        StudentAttributes expectedStudent = ((StudentAttributes) expected).getCopy();
        StudentAttributes actualStudent = (StudentAttributes) actual;
        equalizeIrrelevantData(expectedStudent, actualStudent);
        assertEquals(JsonUtils.toJson(expectedStudent), JsonUtils.toJson(actualStudent));
    } else {
        throw new RuntimeException("Unknown entity type!");
    }
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) AccountAttributes(teammates.common.datatransfer.attributes.AccountAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackQuestionAttributes(teammates.common.datatransfer.attributes.FeedbackQuestionAttributes) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) CourseAttributes(teammates.common.datatransfer.attributes.CourseAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 38 with FeedbackResponseCommentAttributes

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

the class AdminInstructorAccountAddAction method importDemoData.

/**
 * Imports Demo course to new instructor.
 * @param pageData data from AdminHomePageData
 * @return the ID of Demo course
 */
private String importDemoData(AdminHomePageData pageData) throws InvalidParametersException, EntityDoesNotExistException {
    String courseId = generateDemoCourseId(pageData.instructorEmail);
    String jsonString = Templates.populateTemplate(Templates.INSTRUCTOR_SAMPLE_DATA, // replace email
    "teammates.demo.instructor@demo.course", pageData.instructorEmail, // replace name
    "Demo_Instructor", pageData.instructorName, // replace course
    "demo.course", courseId);
    DataBundle data = JsonUtils.fromJson(jsonString, DataBundle.class);
    BackDoorLogic backDoorLogic = new BackDoorLogic();
    backDoorLogic.persistDataBundle(data);
    List<FeedbackResponseCommentAttributes> frComments = logic.getFeedbackResponseCommentForGiver(courseId, pageData.instructorEmail);
    List<StudentAttributes> students = logic.getStudentsForCourse(courseId);
    List<InstructorAttributes> instructors = logic.getInstructorsForCourse(courseId);
    logic.putFeedbackResponseCommentDocuments(frComments);
    logic.putStudentDocuments(students);
    logic.putInstructorDocuments(instructors);
    return courseId;
}
Also used : BackDoorLogic(teammates.logic.backdoor.BackDoorLogic) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) DataBundle(teammates.common.datatransfer.DataBundle) StudentAttributes(teammates.common.datatransfer.attributes.StudentAttributes) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes)

Example 39 with FeedbackResponseCommentAttributes

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

the class InstructorFeedbackResponseCommentAbstractAction method verifyAccessibleForInstructorToFeedbackResponseComment.

protected void verifyAccessibleForInstructorToFeedbackResponseComment(String feedbackResponseCommentId, InstructorAttributes instructor, FeedbackSessionAttributes session, FeedbackResponseAttributes response) {
    FeedbackResponseCommentAttributes frc = logic.getFeedbackResponseComment(Long.parseLong(feedbackResponseCommentId));
    if (frc == null) {
        return;
    }
    if (instructor != null && frc.giverEmail.equals(instructor.email)) {
        // giver, allowed by default
        return;
    }
    gateKeeper.verifyAccessible(instructor, session, false, response.giverSection, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS);
    gateKeeper.verifyAccessible(instructor, session, false, response.recipientSection, Const.ParamsNames.INSTRUCTOR_PERMISSION_MODIFY_SESSION_COMMENT_IN_SECTIONS);
}
Also used : FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)

Example 40 with FeedbackResponseCommentAttributes

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

the class InstructorFeedbackResponseCommentAddAction method execute.

@Override
protected ActionResult execute() throws EntityDoesNotExistException {
    String courseId = getRequestParamValue(Const.ParamsNames.COURSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COURSE_ID, courseId);
    String feedbackSessionName = getRequestParamValue(Const.ParamsNames.FEEDBACK_SESSION_NAME);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionName);
    String feedbackQuestionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_QUESTION_ID, feedbackQuestionId);
    String feedbackResponseId = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_ID, feedbackResponseId);
    String commentId = getRequestParamValue(Const.ParamsNames.COMMENT_ID);
    Assumption.assertPostParamNotNull(Const.ParamsNames.COMMENT_ID, commentId);
    InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
    FeedbackSessionAttributes session = logic.getFeedbackSession(feedbackSessionName, courseId);
    FeedbackResponseAttributes response = logic.getFeedbackResponse(feedbackResponseId);
    Assumption.assertNotNull(response);
    boolean isCreatorOnly = true;
    gateKeeper.verifyAccessible(instructor, session, !isCreatorOnly, response.giverSection, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS);
    gateKeeper.verifyAccessible(instructor, session, !isCreatorOnly, response.recipientSection, Const.ParamsNames.INSTRUCTOR_PERMISSION_SUBMIT_SESSION_IN_SECTIONS);
    InstructorFeedbackResponseCommentAjaxPageData data = new InstructorFeedbackResponseCommentAjaxPageData(account, sessionToken);
    String giverEmail = response.giver;
    String recipientEmail = response.recipient;
    FeedbackSessionResultsBundle bundle = logic.getFeedbackSessionResultsForInstructor(feedbackSessionName, courseId, instructor.email);
    String giverName = bundle.getGiverNameForResponse(response);
    String giverTeamName = bundle.getTeamNameForEmail(giverEmail);
    data.giverName = bundle.appendTeamNameToName(giverName, giverTeamName);
    String recipientName = bundle.getRecipientNameForResponse(response);
    String recipientTeamName = bundle.getTeamNameForEmail(recipientEmail);
    data.recipientName = bundle.appendTeamNameToName(recipientName, recipientTeamName);
    // Set up comment text
    String commentText = getRequestParamValue(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT);
    Assumption.assertPostParamNotNull(Const.ParamsNames.FEEDBACK_RESPONSE_COMMENT_TEXT, commentText);
    if (commentText.trim().isEmpty()) {
        data.errorMessage = Const.StatusMessages.FEEDBACK_RESPONSE_COMMENT_EMPTY;
        data.isError = true;
        return createAjaxResult(data);
    }
    FeedbackResponseCommentAttributes feedbackResponseComment = FeedbackResponseCommentAttributes.builder(courseId, feedbackSessionName, instructor.email, new Text(commentText)).withFeedbackQuestionId(feedbackQuestionId).withFeedbackResponseId(feedbackResponseId).withCreatedAt(Instant.now()).withGiverSection(response.giverSection).withReceiverSection(response.recipientSection).build();
    // Set up visibility settings
    String showCommentTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWCOMMENTSTO);
    String showGiverNameTo = getRequestParamValue(Const.ParamsNames.RESPONSE_COMMENTS_SHOWGIVERTO);
    feedbackResponseComment.showCommentTo = new ArrayList<>();
    if (showCommentTo != null && !showCommentTo.isEmpty()) {
        String[] showCommentToArray = showCommentTo.split(",");
        for (String viewer : showCommentToArray) {
            feedbackResponseComment.showCommentTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
        }
    }
    feedbackResponseComment.showGiverNameTo = new ArrayList<>();
    if (showGiverNameTo != null && !showGiverNameTo.isEmpty()) {
        String[] showGiverNameToArray = showGiverNameTo.split(",");
        for (String viewer : showGiverNameToArray) {
            feedbackResponseComment.showGiverNameTo.add(FeedbackParticipantType.valueOf(viewer.trim()));
        }
    }
    FeedbackResponseCommentAttributes createdComment = null;
    try {
        createdComment = logic.createFeedbackResponseComment(feedbackResponseComment);
        logic.putDocument(createdComment);
    } catch (InvalidParametersException e) {
        setStatusForException(e);
        data.errorMessage = e.getMessage();
        data.isError = true;
    }
    if (!data.isError) {
        statusToAdmin += "InstructorFeedbackResponseCommentAddAction:<br>" + "Adding comment to response: " + feedbackResponseComment.feedbackResponseId + "<br>" + "in course/feedback session: " + feedbackResponseComment.courseId + "/" + feedbackResponseComment.feedbackSessionName + "<br>" + "by: " + feedbackResponseComment.giverEmail + " at " + feedbackResponseComment.createdAt + "<br>" + "comment text: " + feedbackResponseComment.commentText.getValue();
    }
    if (createdComment == null) {
        data.showCommentToString = "";
        data.showGiverNameToString = "";
    } else {
        data.showCommentToString = StringHelper.toString(createdComment.showCommentTo, ",");
        data.showGiverNameToString = StringHelper.toString(createdComment.showGiverNameTo, ",");
    }
    data.comment = createdComment;
    data.commentId = commentId;
    data.instructorEmailNameTable = bundle.instructorEmailNameTable;
    data.question = logic.getFeedbackQuestion(feedbackQuestionId);
    data.sessionTimeZone = session.getTimeZone();
    return createShowPageResult(Const.ViewURIs.INSTRUCTOR_FEEDBACK_RESPONSE_COMMENTS_ADD, data);
}
Also used : FeedbackSessionAttributes(teammates.common.datatransfer.attributes.FeedbackSessionAttributes) FeedbackResponseAttributes(teammates.common.datatransfer.attributes.FeedbackResponseAttributes) FeedbackResponseCommentAttributes(teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes) Text(com.google.appengine.api.datastore.Text) InvalidParametersException(teammates.common.exception.InvalidParametersException) InstructorFeedbackResponseCommentAjaxPageData(teammates.ui.pagedata.InstructorFeedbackResponseCommentAjaxPageData) InstructorAttributes(teammates.common.datatransfer.attributes.InstructorAttributes) FeedbackSessionResultsBundle(teammates.common.datatransfer.FeedbackSessionResultsBundle)

Aggregations

FeedbackResponseCommentAttributes (teammates.common.datatransfer.attributes.FeedbackResponseCommentAttributes)46 FeedbackResponseAttributes (teammates.common.datatransfer.attributes.FeedbackResponseAttributes)15 Test (org.testng.annotations.Test)13 Text (com.google.appengine.api.datastore.Text)12 ArrayList (java.util.ArrayList)12 FeedbackQuestionAttributes (teammates.common.datatransfer.attributes.FeedbackQuestionAttributes)9 FeedbackSessionAttributes (teammates.common.datatransfer.attributes.FeedbackSessionAttributes)9 InstructorAttributes (teammates.common.datatransfer.attributes.InstructorAttributes)9 StudentAttributes (teammates.common.datatransfer.attributes.StudentAttributes)6 FeedbackResponseCommentsDb (teammates.storage.api.FeedbackResponseCommentsDb)6 FeedbackQuestionsDb (teammates.storage.api.FeedbackQuestionsDb)5 FeedbackResponsesDb (teammates.storage.api.FeedbackResponsesDb)5 InstructorFeedbackResponseCommentAjaxPageData (teammates.ui.pagedata.InstructorFeedbackResponseCommentAjaxPageData)4 FeedbackResponseCommentRow (teammates.ui.template.FeedbackResponseCommentRow)4 InvalidParametersException (teammates.common.exception.InvalidParametersException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 FeedbackResponseCommentSearchResultBundle (teammates.common.datatransfer.FeedbackResponseCommentSearchResultBundle)2 FeedbackSessionResultsBundle (teammates.common.datatransfer.FeedbackSessionResultsBundle)2