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);
}
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!");
}
}
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;
}
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);
}
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);
}
Aggregations