use of teammates.common.exception.UnauthorizedAccessException in project teammates by TEAMMATES.
the class InstructorFeedbackQuestionCopyPageActionTest method testExecuteAndPostProcess.
@Override
@Test
public void testExecuteAndPostProcess() {
InstructorAttributes instructor1OfCourse1 = typicalBundle.instructors.get("instructor1OfCourse1");
gaeSimulation.loginAsInstructor(instructor1OfCourse1.googleId);
______TS("typical success case");
FeedbackSessionAttributes feedbackSessionAttributes = typicalBundle.feedbackSessions.get("session1InCourse1");
String[] submissionParams = new String[] { Const.ParamsNames.COURSE_ID, feedbackSessionAttributes.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionAttributes.getFeedbackSessionName() };
InstructorFeedbackQuestionCopyPageAction action = getAction(submissionParams);
ShowPageResult result = getShowPageResult(action);
String expectedString = getPageResultDestination(Const.ViewURIs.INSTRUCTOR_FEEDBACK_QUESTION_COPY_MODAL, false, instructor1OfCourse1.googleId);
assertEquals(expectedString, result.getDestinationWithParams());
assertTrue(result.getStatusMessage().isEmpty());
______TS("failure: non-existent feedback session");
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, feedbackSessionAttributes.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, "Non-existent Session Name" };
action = getAction(submissionParams);
try {
result = getShowPageResult(action);
signalFailureToDetectException();
} catch (UnauthorizedAccessException uae) {
assertEquals("Trying to access system using a non-existent feedback session entity", uae.getMessage());
}
______TS("failure: unsufficient permissions");
gaeSimulation.loginAsInstructor(typicalBundle.accounts.get("helperOfCourse1").googleId);
submissionParams = new String[] { Const.ParamsNames.COURSE_ID, feedbackSessionAttributes.getCourseId(), Const.ParamsNames.FEEDBACK_SESSION_NAME, feedbackSessionAttributes.getFeedbackSessionName() };
action = getAction(submissionParams);
try {
result = getShowPageResult(action);
signalFailureToDetectException();
} catch (UnauthorizedAccessException uae) {
assertEquals("Feedback session [First feedback session] is not accessible " + "to instructor [helper@course1.tmt] for privilege [canmodifysession]", uae.getMessage());
}
}
use of teammates.common.exception.UnauthorizedAccessException in project teammates by TEAMMATES.
the class BaseActionTest method verifyRedirectToLoginOrUnauthorisedException.
private void verifyRedirectToLoginOrUnauthorisedException(String... params) {
try {
Action c = gaeSimulation.getActionObject(getActionUri(), params);
assertFalse(c.isValidUser());
} catch (UnauthorizedAccessException ue) {
ignoreExpectedException();
}
}
use of teammates.common.exception.UnauthorizedAccessException in project teammates by TEAMMATES.
the class BaseActionTest method verifyCannotMasquerade.
/**
* Verifies that the {@link Action} matching the {@code params} is not
* accessible to the logged in user masquerading as another user.
*/
protected void verifyCannotMasquerade(String... params) {
try {
Action c = gaeSimulation.getActionObject(getActionUri(), params);
c.executeAndPostProcess();
signalFailureToDetectException();
} catch (UnauthorizedAccessException e) {
ignoreExpectedException();
}
}
use of teammates.common.exception.UnauthorizedAccessException in project teammates by TEAMMATES.
the class GateKeeper method verifyAccessibleForCurrentUserAsInstructorOrTeamMemberOrAdmin.
public void verifyAccessibleForCurrentUserAsInstructorOrTeamMemberOrAdmin(AccountAttributes account, String courseId, String section, String email) {
if (isAdministrator()) {
return;
}
InstructorAttributes instructor = instructorsLogic.getInstructorForGoogleId(courseId, account.googleId);
if (instructor != null) {
verifyInstructorCanViewPhoto(instructor, section);
return;
}
StudentAttributes student = studentsLogic.getStudentForCourseIdAndGoogleId(courseId, account.googleId);
if (student != null) {
verifyStudentCanViewPhoto(student, courseId, email);
return;
}
throw new UnauthorizedAccessException("User is not in the course that student belongs to");
}
use of teammates.common.exception.UnauthorizedAccessException in project teammates by TEAMMATES.
the class InstructorEditStudentFeedbackSaveAction method checkAdditionalConstraints.
@Override
protected void checkAdditionalConstraints() {
// check the instructor did not submit responses to questions that he/she should not be able
// to view during moderation
InstructorAttributes instructor = logic.getInstructorForGoogleId(courseId, account.googleId);
int numOfQuestionsToGet = data.bundle.questionResponseBundle.size();
for (int questionIndx = 1; questionIndx <= numOfQuestionsToGet; questionIndx++) {
String questionId = getRequestParamValue(Const.ParamsNames.FEEDBACK_QUESTION_ID + "-" + questionIndx);
if (questionId == null) {
// we do not throw an error if the question was not present on the page for instructors to edit
continue;
}
FeedbackQuestionAttributes questionAttributes = data.bundle.getQuestionAttributes(questionId);
if (questionAttributes == null) {
statusToUser.add(new StatusMessage("The feedback session or questions may have changed " + "while you were submitting. Please check your responses " + "to make sure they are saved correctly.", StatusMessageColor.WARNING));
isError = true;
log.warning("Question not found. (deleted or invalid id passed?) id: " + questionId + " index: " + questionIndx);
continue;
}
boolean isGiverVisibleToInstructors = questionAttributes.showGiverNameTo.contains(FeedbackParticipantType.INSTRUCTORS);
boolean isRecipientVisibleToInstructors = questionAttributes.showRecipientNameTo.contains(FeedbackParticipantType.INSTRUCTORS);
boolean isResponseVisibleToInstructors = questionAttributes.showResponsesTo.contains(FeedbackParticipantType.INSTRUCTORS);
if (!isResponseVisibleToInstructors || !isGiverVisibleToInstructors || !isRecipientVisibleToInstructors) {
isError = true;
throw new UnauthorizedAccessException("Feedback session [" + feedbackSessionName + "] question [" + questionAttributes.getId() + "] is not accessible " + "to instructor [" + instructor.email + "]");
}
}
}
Aggregations